From dc791aad5b14271a2143a8835a7ca052874ccbfe Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Feb 2012 12:11:22 +0100 Subject: [PATCH 1/7] a fullscreen sheet derived from fullscreendialog --- .../plasmacomponents/CMakeLists.txt | 1 + .../plasmacomponents/fullscreendialog.cpp | 9 +- .../plasmacomponents/fullscreendialog.h | 1 + .../plasmacomponents/fullscreensheet.cpp | 38 +++ .../plasmacomponents/fullscreensheet.h | 36 +++ .../platformcomponents/touch/Sheet.qml | 189 +++++++++++++++ .../plasmacomponents/qml/Sheet.qml | 227 ++++++++++++++++++ 7 files changed, 499 insertions(+), 2 deletions(-) create mode 100644 declarativeimports/plasmacomponents/fullscreensheet.cpp create mode 100644 declarativeimports/plasmacomponents/fullscreensheet.h create mode 100644 declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml create mode 100644 declarativeimports/plasmacomponents/qml/Sheet.qml diff --git a/declarativeimports/plasmacomponents/CMakeLists.txt b/declarativeimports/plasmacomponents/CMakeLists.txt index bf013c45b..8428f2be2 100644 --- a/declarativeimports/plasmacomponents/CMakeLists.txt +++ b/declarativeimports/plasmacomponents/CMakeLists.txt @@ -2,6 +2,7 @@ project(plasmacomponents) set(plasmacomponents_SRCS fullscreendialog.cpp + fullscreensheet.cpp plasmacomponentsplugin.cpp qrangemodel.cpp enums.cpp diff --git a/declarativeimports/plasmacomponents/fullscreendialog.cpp b/declarativeimports/plasmacomponents/fullscreendialog.cpp index 90e6d3d6f..76542e2a3 100644 --- a/declarativeimports/plasmacomponents/fullscreendialog.cpp +++ b/declarativeimports/plasmacomponents/fullscreendialog.cpp @@ -116,7 +116,7 @@ FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent) QString filePath; if (componentsPlatform == "desktop") { foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "imports/")) { - filePath = importPath % "org/kde/plasma/components/Dialog.qml"; + filePath = importPath % "org/kde/plasma/components/" % componentName() % ".qml"; QFile f(filePath); if (f.exists()) { break; @@ -124,7 +124,7 @@ FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent) } } else { foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "platformimports/" % componentsPlatform)) { - filePath = importPath % "org/kde/plasma/components/Dialog.qml"; + filePath = importPath % "org/kde/plasma/components/" % componentName() % ".qml"; QFile f(filePath); if (f.exists()) { break; @@ -158,6 +158,11 @@ FullScreenDialog::~FullScreenDialog() delete m_view; } +QString FullScreenDialog::componentName() const +{ + return "Dialog"; +} + QGraphicsObject *FullScreenDialog::mainItem() const { return m_mainItem.data(); diff --git a/declarativeimports/plasmacomponents/fullscreendialog.h b/declarativeimports/plasmacomponents/fullscreendialog.h index 4eac4a37b..53132bea6 100644 --- a/declarativeimports/plasmacomponents/fullscreendialog.h +++ b/declarativeimports/plasmacomponents/fullscreendialog.h @@ -80,6 +80,7 @@ private Q_SLOTS: protected: bool eventFilter(QObject *watched, QEvent *event); + virtual QString componentName() const; private: QGraphicsView *m_view; diff --git a/declarativeimports/plasmacomponents/fullscreensheet.cpp b/declarativeimports/plasmacomponents/fullscreensheet.cpp new file mode 100644 index 000000000..66e897c2c --- /dev/null +++ b/declarativeimports/plasmacomponents/fullscreensheet.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright 2012 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "fullscreensheet.h" + + +FullScreenSheet::FullScreenSheet(QDeclarativeItem *parent) + : FullScreenDialog(parent) +{ +} + +FullScreenSheet::~FullScreenSheet() +{ +} + +QString FullScreenSheet::componentName() const +{ + return "Sheet"; +} + +#include "fullscreensheet.moc" + diff --git a/declarativeimports/plasmacomponents/fullscreensheet.h b/declarativeimports/plasmacomponents/fullscreensheet.h new file mode 100644 index 000000000..4590c737a --- /dev/null +++ b/declarativeimports/plasmacomponents/fullscreensheet.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright 2012 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ +#ifndef FULLSCREENSHEET_P +#define FULLSCREENSHEET_P + +#include "fullscreendialog.h" + +class FullScreenSheet : public FullScreenDialog +{ + Q_OBJECT + +public: + FullScreenSheet(QDeclarativeItem *parent = 0); + ~FullScreenSheet(); + +protected: + virtual QString componentName() const; +}; + +#endif diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml new file mode 100644 index 000000000..cbc7a50db --- /dev/null +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Marco Martin +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Components project. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import org.kde.plasma.core 0.1 as PlasmaCore +import "private/AppManager.js" as Utils +import "." 0.1 + +Item { + id: root + width: dialog.width + height: dialog.height + + property alias title: titleBar.children + property alias content: contentItem.children + property alias buttons: buttonItem.children +// property alias visualParent: dialog.visualParent + property int status: DialogStatus.Closed + + + property alias privateTitleHeight: titleBar.height + property alias privateButtonsHeight: buttonItem.height + + signal accepted + signal rejected + signal clickedOutside + + function open() + { + status = DialogStatus.Opening + delayOpenTimer.restart() + } + + function accept() + { + if (status == DialogStatus.Open) { + status = DialogStatus.Closing + accepted() + dialog.state = "closed" + } + } + + function reject() + { + if (status == DialogStatus.Open) { + status = DialogStatus.Closing + dialog.state = "closed" + rejected() + } + } + + function close() + { + dialog.state = "closed" + } + + + MouseArea { + anchors.fill: parent + onClicked: { + clickedOutside() + close() + } + } + Timer { + id: delayOpenTimer + running: false + interval: 100 + onTriggered: dialog.state = "" + } + + PlasmaCore.FrameSvgItem { + id: dialog + width: mainItem.width + margins.left + margins.right + height: mainItem.height + margins.top + margins.bottom + anchors.centerIn: parent + imagePath: "dialogs/background" + + state: "closed" + + //state: "Hidden" + + Item { + id: mainItem + x: dialog.margins.left + y: dialog.margins.top + width: theme.defaultFont.mSize.width * 40 + height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8 + + + // Consume all key events that are not processed by children + Keys.onPressed: event.accepted = true + Keys.onReleased: event.accepted = true + + Item { + id: titleBar + + height: childrenRect.height + anchors { + top: parent.top + left: parent.left + right: parent.right + } + } + + Item { + id: contentItem + + clip: true + onChildrenRectChanged: mainItem.width = Math.max(childrenRect.width, buttonItem.childrenRect.width) + anchors { + top: titleBar.bottom + left: parent.left + right: parent.right + bottom: buttonItem.top + } + } + + Item { + id: buttonItem + + height: childrenRect.height + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom + bottomMargin: 8 + } + } + } + + states: [ + State { + name: "closed" + PropertyChanges { + target: root + status: DialogStatus.Closed + } + }, + State { + name: "" + PropertyChanges { + target: root + status: DialogStatus.Open + } + } + ] + + } +} diff --git a/declarativeimports/plasmacomponents/qml/Sheet.qml b/declarativeimports/plasmacomponents/qml/Sheet.qml new file mode 100644 index 000000000..76bf53d43 --- /dev/null +++ b/declarativeimports/plasmacomponents/qml/Sheet.qml @@ -0,0 +1,227 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Marco Martin +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Components project. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/**Documented API +Inherits: + Item + +Imports: + QtQuick 1.0 + org.kde.plasma.core + +Description: + Provides a top-level window for short-term tasks and brief interaction with the user. + A dialog floats on the top layer of the application view, usually overlapping the area reserved for the application content. Normally, a dialog provides information and gives warnings to the user, or asks the user to answer a question or select an option. + +Properties: + list buttons: + A list of items in the dialog's button area. For example, you can use Row or Button components but you can also use any number of components that are based on Item component. + + list content: + A list of items in the dialog's content area. You can use any component that is based on Item. For example, you can use ListView, so that the user can select from a list of names. + + int status: + Indicates the dialog's phase in its life cycle. The values are as follows: + - DialogStatus.Opening - the dialog is opening + - DialogStatus.Open - the dialog is open and visible to the user + - DialogStatus.Closing - the dialog is closing + - DialogStatus.Closed - the dialog is closed and not visible to the user + The dialog's initial status is DialogStatus.Closed. + + list title: + A list of items in the dialog's title area. You can use a Text component but also any number of components that are based on Item. For example, you can use Text and Image components. + + Item visualParent: + The item that is dimmed when the dialog opens. By default the root parent object is visualParent. + +Signals: + accepted(): + This signal is emitted when the user accepts the dialog's request or the accept() method is called. + See also rejected(). + + clickedOutside(): This signal is emitted when the user taps in the area that is inside the dialog's visual parent area but outside the dialog's area. Normally the visual parent is the root object. In that case this signal is emitted if the user taps anywhere outside the dialog's area. + See also visualParent. + + rejected(): + This signal is emitted when the user rejects the dialog's request or the reject() method is called. + See also accepted(). + +Methods: + void accept(): + Accepts the dialog's request without any user interaction. The method emits the accepted() signal and closes the dialog. + See also reject(). + + void close(): + Closes the dialog without any user interaction. + + void open(): + Shows the dialog to the user. + + void reject(): + Rejects the dialog's request without any user interaction. The method emits the rejected() signal and closes the dialog. + See also accept(). +**/ + +import QtQuick 1.0 +import org.kde.plasma.core 0.1 as PlasmaCore +import "private/AppManager.js" as Utils +import "." 0.1 + +Item { + id: root + + property alias title: titleBar.children + property alias content: contentItem.children + property alias buttons: buttonItem.children +// property alias visualParent: dialog.visualParent + property int status: DialogStatus.Closed + + + property alias privateTitleHeight: titleBar.height + property alias privateButtonsHeight: buttonItem.height + + signal accepted + signal rejected + signal clickedOutside + + function open() + { + var pos = dialog.popupPosition(null, Qt.alignCenter) + dialog.x = pos.x + dialog.y = pos.y + + dialog.visible = true + dialog.activateWindow() + } + + function accept() + { + if (status == DialogStatus.Open) { + dialog.visible = false + accepted() + } + } + + function reject() { + if (status == DialogStatus.Open) { + dialog.visible = false + rejected() + } + } + + function close() { + dialog.visible = false + } + + visible: false + + PlasmaCore.Dialog { + id: dialog + windowFlags: Qt.Dialog + + + //onFaderClicked: root.clickedOutside() + property Item rootItem + + //state: "Hidden" + visible: false + onVisibleChanged: { + if (visible) { + status = DialogStatus.Open + } else { + status = DialogStatus.Closed + } + } + + mainItem: Item { + id: mainItem + width: theme.defaultFont.mSize.width * 40 + height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8 + + // Consume all key events that are not processed by children + Keys.onPressed: event.accepted = true + Keys.onReleased: event.accepted = true + + Item { + id: titleBar + + height: childrenRect.height + anchors { + top: parent.top + left: parent.left + right: parent.right + } + } + + Item { + id: contentItem + + onChildrenRectChanged: mainItem.width = Math.max(childrenRect.width, buttonItem.childrenRect.width) + + clip: true + anchors { + top: titleBar.bottom + left: parent.left + right: parent.right + bottom: buttonItem.top + bottomMargin: 8 + } + } + + Item { + id: buttonItem + + height: childrenRect.height + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom + bottomMargin: 4 + } + } + } + + Component.onCompleted: { + rootItem = Utils.rootObject() + } + } +} From 07b7041b9289048fd498eb489e8fab2fa92417d6 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Feb 2012 14:49:20 +0100 Subject: [PATCH 2/7] common class for sheet and dialog --- .../plasmacomponents/CMakeLists.txt | 1 + .../plasmacomponents/fullscreendialog.cpp | 337 +-------------- .../plasmacomponents/fullscreendialog.h | 71 +--- .../plasmacomponents/fullscreensheet.cpp | 78 +++- .../plasmacomponents/fullscreensheet.h | 28 +- .../plasmacomponents/fullscreenwindow.cpp | 383 ++++++++++++++++++ .../plasmacomponents/fullscreenwindow.h | 101 +++++ .../plasmacomponentsplugin.cpp | 2 + .../platformcomponents/touch/Sheet.qml | 48 ++- .../plasmacomponents/qml/Sheet.qml | 36 +- 10 files changed, 643 insertions(+), 442 deletions(-) create mode 100644 declarativeimports/plasmacomponents/fullscreenwindow.cpp create mode 100644 declarativeimports/plasmacomponents/fullscreenwindow.h diff --git a/declarativeimports/plasmacomponents/CMakeLists.txt b/declarativeimports/plasmacomponents/CMakeLists.txt index 8428f2be2..8563e8cc4 100644 --- a/declarativeimports/plasmacomponents/CMakeLists.txt +++ b/declarativeimports/plasmacomponents/CMakeLists.txt @@ -3,6 +3,7 @@ project(plasmacomponents) set(plasmacomponents_SRCS fullscreendialog.cpp fullscreensheet.cpp + fullscreenwindow.cpp plasmacomponentsplugin.cpp qrangemodel.cpp enums.cpp diff --git a/declarativeimports/plasmacomponents/fullscreendialog.cpp b/declarativeimports/plasmacomponents/fullscreendialog.cpp index 76542e2a3..591e02442 100644 --- a/declarativeimports/plasmacomponents/fullscreendialog.cpp +++ b/declarativeimports/plasmacomponents/fullscreendialog.cpp @@ -18,351 +18,18 @@ ***************************************************************************/ #include "fullscreendialog.h" -#include "../core/declarativeitemcontainer_p.h" -#include "plasmacomponentsplugin.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - - -uint FullScreenDialog::s_numItems = 0; - -class Background : public QWidget -{ -public: - Background(FullScreenDialog *dialog) - : QWidget( 0L ), - m_dialog(dialog) - { - setAttribute( Qt::WA_NoSystemBackground ); - setAttribute( Qt::WA_TranslucentBackground ); - - setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint); - KWindowSystem::setOnAllDesktops(winId(), true); - unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager | NET::MaxVert | NET::MaxHoriz; - KWindowSystem::setState(effectiveWinId(), state); - } - - ~Background() - {} - - void paintEvent( QPaintEvent *e ) - { - QPainter painter( this ); - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(e->rect(), QColor(0, 0, 0, 80)); - } - - void mousePressEvent(QMouseEvent *event) - { - event->accept(); - m_dialog->view()->winId(); - KWindowSystem::forceActiveWindow(m_dialog->view()->winId()); - } - - void mouseReleaseEvent(QMouseEvent *event) - { - if (!m_dialog->view()->geometry().contains(event->globalPos())) { - m_dialog->close(); - } - } - -private: - FullScreenDialog *m_dialog; -}; FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent) - : QDeclarativeItem(parent), - m_declarativeItemContainer(0) + : FullScreenWindow(parent) { - m_view = new QGraphicsView(); - m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_view->installEventFilter(this); - m_view->setAutoFillBackground(false); - m_view->viewport()->setAutoFillBackground(false); - m_view->setAttribute(Qt::WA_TranslucentBackground); - m_view->setAttribute(Qt::WA_NoSystemBackground); - m_view->viewport()->setAttribute(Qt::WA_NoSystemBackground); - m_view->setCacheMode(QGraphicsView::CacheNone); - m_view->setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint); - m_view->setFrameShape(QFrame::NoFrame); - KWindowSystem::setOnAllDesktops(m_view->winId(), true); - unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager; - KWindowSystem::setState(m_view->effectiveWinId(), state); + init("Dialog"); - //Try to figure out the path of the dialog component - QString componentsPlatform = getenv("KDE_PLASMA_COMPONENTS_PLATFORM"); - if (componentsPlatform.isEmpty()) { - KConfigGroup cg(KSharedConfig::openConfig("kdeclarativerc"), "Components-platform"); - componentsPlatform = cg.readEntry("name", "desktop"); - } - - QString filePath; - if (componentsPlatform == "desktop") { - foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "imports/")) { - filePath = importPath % "org/kde/plasma/components/" % componentName() % ".qml"; - QFile f(filePath); - if (f.exists()) { - break; - } - } - } else { - foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "platformimports/" % componentsPlatform)) { - filePath = importPath % "org/kde/plasma/components/" % componentName() % ".qml"; - QFile f(filePath); - if (f.exists()) { - break; - } - } - } - - - QDeclarativeEngine *engine = EngineBookKeeping::self()->engineFor(this); - QDeclarativeComponent *component = new QDeclarativeComponent(engine, filePath, this); - - QDeclarativeContext *creationContext = component->creationContext(); - m_rootObject = component->create(creationContext); - if (component->status() == QDeclarativeComponent::Error) { - kWarning()<errors(); - } - - if (m_rootObject) { - setMainItem(qobject_cast(m_rootObject.data())); - connect(m_rootObject.data(), SIGNAL(statusChanged()), this, SLOT(statusHasChanged())); - connect(m_rootObject.data(), SIGNAL(accepted()), this, SIGNAL(accepted())); - connect(m_rootObject.data(), SIGNAL(rejected()), this, SIGNAL(rejected())); - connect(m_rootObject.data(), SIGNAL(clickedOutside()), this, SIGNAL(clickedOutside())); - } - - m_background = new Background(this); } FullScreenDialog::~FullScreenDialog() { - delete m_view; } -QString FullScreenDialog::componentName() const -{ - return "Dialog"; -} - -QGraphicsObject *FullScreenDialog::mainItem() const -{ - return m_mainItem.data(); -} - -void FullScreenDialog::setMainItem(QGraphicsObject *mainItem) -{ - if (m_mainItem.data() != mainItem) { - if (m_mainItem) { - m_mainItem.data()->setParent(mainItem->parent()); - m_mainItem.data()->removeEventFilter(this); - m_mainItem.data()->setY(0); - m_scene = 0; - } - m_mainItem = mainItem; - if (mainItem) { - mainItem->setParentItem(0); - mainItem->setParent(this); - m_scene = mainItem->scene(); - } - - mainItem->installEventFilter(this); - - //if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene - QTimer::singleShot(0, this, SLOT(syncMainItem())); - } -} - -void FullScreenDialog::syncMainItem() -{ - if (!m_mainItem) { - return; - } - - //not have a scene? go up in the hyerarchy until we find something with a scene - QGraphicsScene *scene = m_mainItem.data()->scene(); - if (!scene) { - QObject *parent = m_mainItem.data(); - while ((parent = parent->parent())) { - QGraphicsObject *qo = qobject_cast(parent); - if (qo) { - scene = qo->scene(); - - if (scene) { - scene->addItem(m_mainItem.data()); - ++s_numItems; - Plasma::Corona *corona = qobject_cast(scene); - QDeclarativeItem *di = qobject_cast(m_mainItem.data()); - - if (corona && di) { - if (!m_declarativeItemContainer) { - m_declarativeItemContainer = new DeclarativeItemContainer(); - scene->addItem(m_declarativeItemContainer); - corona->addOffscreenWidget(m_declarativeItemContainer); - } - m_declarativeItemContainer->setDeclarativeItem(di); - } else { - m_mainItem.data()->setY(-10000*s_numItems); - m_mainItem.data()->setY(10000*s_numItems); - } - break; - } - } - } - } - - if (!scene) { - return; - } - - m_view->setScene(scene); - - - if (m_declarativeItemContainer) { - m_view->resize(m_declarativeItemContainer->size().toSize()); - m_view->setSceneRect(m_declarativeItemContainer->geometry()); - } else { - QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()), - QSizeF(m_mainItem.data()->boundingRect().size())); - m_view->resize(itemGeometry.size().toSize()); - m_view->setSceneRect(itemGeometry); - } - - m_view->move(QApplication::desktop()->availableGeometry().center() - QPoint(m_view->width()/2, m_view->height()/2)); -} - -bool FullScreenDialog::isVisible() const -{ - return m_view->isVisible(); -} - -void FullScreenDialog::setVisible(const bool visible) -{ - if (m_view->isVisible() != visible) { - m_background->setVisible(visible); - Plasma::WindowEffects::slideWindow(m_view->winId(), Plasma::BottomEdge, 0); - m_view->setVisible(visible); - unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager; - KWindowSystem::setState(m_view->effectiveWinId(), state); - KWindowSystem::setState(m_background->effectiveWinId(), state); - if (visible) { - m_view->raise(); - KWindowSystem::forceActiveWindow(m_view->effectiveWinId()); - } - } -} - -QGraphicsView *FullScreenDialog::view() const -{ - return m_view; -} - -QDeclarativeListProperty FullScreenDialog::title() -{ - if (m_rootObject) { - return m_rootObject.data()->property("title").value >(); - } else { - return QDeclarativeListProperty(this, m_dummyTitleElements); - } -} - -QDeclarativeListProperty FullScreenDialog::content() -{ - if (m_rootObject) { - return m_rootObject.data()->property("content").value >(); - } else { - return QDeclarativeListProperty(this, m_dummyContentElements); - } -} - -QDeclarativeListProperty FullScreenDialog::buttons() -{ - if (m_rootObject) { - return m_rootObject.data()->property("buttons").value >(); - } else { - return QDeclarativeListProperty(this, m_dummyButtonsElements); - } -} - -DialogStatus::Status FullScreenDialog::status() const -{ - if (m_rootObject) { - return (DialogStatus::Status)m_rootObject.data()->property("status").toInt(); - } else { - return DialogStatus::Closed; - } -} - - -void FullScreenDialog::statusHasChanged() -{ - if (status() == DialogStatus::Closed) { - setVisible(false); - } else { - setVisible(true); - } - emit statusChanged(); -} - -void FullScreenDialog::open() -{ - if (m_rootObject) { - QMetaObject::invokeMethod(m_rootObject.data(), "open"); - } -} - -void FullScreenDialog::accept() -{ - if (m_rootObject) { - QMetaObject::invokeMethod(m_rootObject.data(), "accept"); - } -} - -void FullScreenDialog::reject() -{ - if (m_rootObject) { - QMetaObject::invokeMethod(m_rootObject.data(), "reject"); - } -} - -void FullScreenDialog::close() -{ - if (m_rootObject) { - QMetaObject::invokeMethod(m_rootObject.data(), "close"); - } -} - - - - -bool FullScreenDialog::eventFilter(QObject *watched, QEvent *event) -{ - if (watched == m_mainItem.data() && - (event->type() == QEvent::GraphicsSceneResize)) { - syncMainItem(); - } - return false; -} - - - #include "fullscreendialog.moc" diff --git a/declarativeimports/plasmacomponents/fullscreendialog.h b/declarativeimports/plasmacomponents/fullscreendialog.h index 53132bea6..6cd8adf41 100644 --- a/declarativeimports/plasmacomponents/fullscreendialog.h +++ b/declarativeimports/plasmacomponents/fullscreendialog.h @@ -19,82 +19,15 @@ #ifndef FULLSCREENDIALOG_P #define FULLSCREENDIALOG_P -#include -#include -#include -#include -#include -#include +#include "fullscreenwindow.h" -#include "enums.h" - -class QGraphicsObject; -class QGraphicsView; -class QGraphicsScene; -class DeclarativeItemContainer; -class Background; - -class FullScreenDialog : public QDeclarativeItem +class FullScreenDialog : public FullScreenWindow { Q_OBJECT - Q_PROPERTY(QDeclarativeListProperty title READ title DESIGNABLE false) - Q_PROPERTY(QDeclarativeListProperty content READ content DESIGNABLE false) - Q_PROPERTY(QDeclarativeListProperty buttons READ buttons DESIGNABLE false) - Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged) - - public: FullScreenDialog(QDeclarativeItem *parent = 0); ~FullScreenDialog(); - - QGraphicsObject *mainItem() const; - void setMainItem(QGraphicsObject *mainItem); - - bool isVisible() const; - void setVisible(const bool visible); - - QGraphicsView *view() const; - - //QML properties - QDeclarativeListProperty title(); - QDeclarativeListProperty content(); - QDeclarativeListProperty buttons(); - DialogStatus::Status status() const; - - Q_INVOKABLE void open(); - Q_INVOKABLE void accept(); - Q_INVOKABLE void reject(); - Q_INVOKABLE void close(); - -Q_SIGNALS: - void accepted(); - void rejected(); - void clickedOutside(); - void statusChanged(); - - -private Q_SLOTS: - void syncMainItem(); - void statusHasChanged(); - -protected: - bool eventFilter(QObject *watched, QEvent *event); - virtual QString componentName() const; - -private: - QGraphicsView *m_view; - QWeakPointer m_mainItem; - DeclarativeItemContainer *m_declarativeItemContainer; - QGraphicsScene *m_scene; - QWeakPointer m_rootObject; - static uint s_numItems; - Background *m_background; - - //those only used in case of error, to not make plasma crash - QList m_dummyTitleElements; - QList m_dummyContentElements; - QList m_dummyButtonsElements; }; #endif diff --git a/declarativeimports/plasmacomponents/fullscreensheet.cpp b/declarativeimports/plasmacomponents/fullscreensheet.cpp index 66e897c2c..91eb82786 100644 --- a/declarativeimports/plasmacomponents/fullscreensheet.cpp +++ b/declarativeimports/plasmacomponents/fullscreensheet.cpp @@ -19,19 +19,91 @@ #include "fullscreensheet.h" +#include FullScreenSheet::FullScreenSheet(QDeclarativeItem *parent) - : FullScreenDialog(parent) + : FullScreenWindow(parent) { + init("Sheet"); + + if (mainItem()) { + connect(mainItem(), SIGNAL(acceptButtonChanged()), + this, SIGNAL(acceptButtonChanged())); + connect(mainItem(), SIGNAL(rejectButtonChanged()), + this, SIGNAL(rejectButtonChanged())); + connect(mainItem(), SIGNAL(acceptButtonTextChanged()), + this, SIGNAL(acceptButtonTextChanged())); + connect(mainItem(), SIGNAL(rejectButtonTextChanged()), + this, SIGNAL(rejectButtonTextChanged())); + } } FullScreenSheet::~FullScreenSheet() { } -QString FullScreenSheet::componentName() const +QGraphicsObject *FullScreenSheet::acceptButton() const { - return "Sheet"; + if (mainItem()) { + return mainItem()->property("acceptButton").value(); + } else { + return 0; + } +} + +void FullScreenSheet::setAcceptButton(QGraphicsObject *button) +{ + if (mainItem()) { + mainItem()->setProperty("acceptButton", QVariant::fromValue(button)); + } +} + +QGraphicsObject *FullScreenSheet::rejectButton() const +{ + if (mainItem()) { + return mainItem()->property("rejectButton").value(); + } else { + return 0; + } +} + +void FullScreenSheet::setRejectButton(QGraphicsObject *button) +{ + if (mainItem()) { + mainItem()->setProperty("rejectButton", QVariant::fromValue(button)); + } +} + +QString FullScreenSheet::acceptButtonText() const +{ + if (mainItem()) { + return mainItem()->property("acceptButtonText").toString(); + } else { + return 0; + } +} + +void FullScreenSheet::setAcceptButtonText(const QString &text) +{ + if (mainItem()) { + mainItem()->setProperty("acceptButtonText", QVariant::fromValue(text)); + } +} + +QString FullScreenSheet::rejectButtonText() const +{ + if (mainItem()) { + return mainItem()->property("rejectButtonText").toString(); + } else { + return 0; + } +} + +void FullScreenSheet::setRejectButtonText(const QString &text) +{ + if (mainItem()) { + mainItem()->setProperty("rejectButtonText", QVariant::fromValue(text)); + } } #include "fullscreensheet.moc" diff --git a/declarativeimports/plasmacomponents/fullscreensheet.h b/declarativeimports/plasmacomponents/fullscreensheet.h index 4590c737a..17c1bbe44 100644 --- a/declarativeimports/plasmacomponents/fullscreensheet.h +++ b/declarativeimports/plasmacomponents/fullscreensheet.h @@ -19,18 +19,38 @@ #ifndef FULLSCREENSHEET_P #define FULLSCREENSHEET_P -#include "fullscreendialog.h" +#include "fullscreenwindow.h" -class FullScreenSheet : public FullScreenDialog +class FullScreenSheet : public FullScreenWindow { Q_OBJECT + Q_PROPERTY(QGraphicsObject *acceptButton READ acceptButton WRITE setAcceptButton NOTIFY acceptButtonChanged) + Q_PROPERTY(QGraphicsObject *rejectButton READ rejectButton WRITE setRejectButton NOTIFY rejectButtonChanged) + + Q_PROPERTY(QString acceptButtonText READ acceptButtonText WRITE setAcceptButtonText NOTIFY acceptButtonTextChanged) + Q_PROPERTY(QString rejectButtonText READ rejectButtonText WRITE setRejectButtonText NOTIFY rejectButtonTextChanged) public: FullScreenSheet(QDeclarativeItem *parent = 0); ~FullScreenSheet(); -protected: - virtual QString componentName() const; + QGraphicsObject *acceptButton() const; + void setAcceptButton(QGraphicsObject *button); + + QGraphicsObject *rejectButton() const; + void setRejectButton(QGraphicsObject *button); + + QString acceptButtonText() const; + void setAcceptButtonText(const QString &text); + + QString rejectButtonText() const; + void setRejectButtonText(const QString &text); + +Q_SIGNALS: + void acceptButtonChanged(); + void rejectButtonChanged(); + void acceptButtonTextChanged(); + void rejectButtonTextChanged(); }; #endif diff --git a/declarativeimports/plasmacomponents/fullscreenwindow.cpp b/declarativeimports/plasmacomponents/fullscreenwindow.cpp new file mode 100644 index 000000000..486bdbe6e --- /dev/null +++ b/declarativeimports/plasmacomponents/fullscreenwindow.cpp @@ -0,0 +1,383 @@ +/*************************************************************************** + * Copyright 2012 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "fullscreenwindow.h" +#include "../core/declarativeitemcontainer_p.h" +#include "plasmacomponentsplugin.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + + +uint FullScreenWindow::s_numItems = 0; + +class Background : public QWidget +{ +public: + Background(FullScreenWindow *dialog) + : QWidget( 0L ), + m_dialog(dialog) + { + setAttribute( Qt::WA_NoSystemBackground ); + setAttribute( Qt::WA_TranslucentBackground ); + + setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint); + KWindowSystem::setOnAllDesktops(winId(), true); + unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager | NET::MaxVert | NET::MaxHoriz; + KWindowSystem::setState(effectiveWinId(), state); + } + + ~Background() + {} + + void paintEvent( QPaintEvent *e ) + { + QPainter painter( this ); + painter.setCompositionMode(QPainter::CompositionMode_Source); + painter.fillRect(e->rect(), QColor(0, 0, 0, 80)); + } + + void mousePressEvent(QMouseEvent *event) + { + event->accept(); + m_dialog->view()->winId(); + KWindowSystem::forceActiveWindow(m_dialog->view()->winId()); + } + + void mouseReleaseEvent(QMouseEvent *event) + { + if (!m_dialog->view()->geometry().contains(event->globalPos())) { + m_dialog->close(); + } + } + +private: + FullScreenWindow *m_dialog; +}; + +FullScreenWindow::FullScreenWindow(QDeclarativeItem *parent) + : QDeclarativeItem(parent), + m_declarativeItemContainer(0) +{ + m_view = new QGraphicsView(); + m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->installEventFilter(this); + m_view->setAutoFillBackground(false); + m_view->viewport()->setAutoFillBackground(false); + m_view->setAttribute(Qt::WA_TranslucentBackground); + m_view->setAttribute(Qt::WA_NoSystemBackground); + m_view->viewport()->setAttribute(Qt::WA_NoSystemBackground); + m_view->setCacheMode(QGraphicsView::CacheNone); + m_view->setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint); + m_view->setFrameShape(QFrame::NoFrame); + KWindowSystem::setOnAllDesktops(m_view->winId(), true); + unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager; + KWindowSystem::setState(m_view->effectiveWinId(), state); + + m_background = new Background(this); +} + +FullScreenWindow::~FullScreenWindow() +{ + delete m_view; +} + +void FullScreenWindow::init(const QString &componentName) +{ + if (m_rootObject) { + return; + } + + //Try to figure out the path of the dialog component + QString componentsPlatform = getenv("KDE_PLASMA_COMPONENTS_PLATFORM"); + if (componentsPlatform.isEmpty()) { + KConfigGroup cg(KSharedConfig::openConfig("kdeclarativerc"), "Components-platform"); + componentsPlatform = cg.readEntry("name", "desktop"); + } + + QString filePath; + if (componentsPlatform == "desktop") { + foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "imports/")) { + filePath = importPath % "org/kde/plasma/components/" % componentName % ".qml"; + QFile f(filePath); + if (f.exists()) { + break; + } + } + } else { + foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "platformimports/" % componentsPlatform)) { + filePath = importPath % "org/kde/plasma/components/" % componentName % ".qml"; + QFile f(filePath); + if (f.exists()) { + break; + } + } + } + + + QDeclarativeEngine *engine = EngineBookKeeping::self()->engineFor(this); + QDeclarativeComponent *component = new QDeclarativeComponent(engine, filePath, this); + + QDeclarativeContext *creationContext = component->creationContext(); + m_rootObject = component->create(creationContext); + if (component->status() == QDeclarativeComponent::Error) { + kWarning()<errors(); + } + + if (m_rootObject) { + setMainItem(qobject_cast(m_rootObject.data())); + connect(m_rootObject.data(), SIGNAL(statusChanged()), this, SLOT(statusHasChanged())); + connect(m_rootObject.data(), SIGNAL(accepted()), this, SIGNAL(accepted())); + connect(m_rootObject.data(), SIGNAL(rejected()), this, SIGNAL(rejected())); + connect(m_rootObject.data(), SIGNAL(clickedOutside()), this, SIGNAL(clickedOutside())); + } +} + +QGraphicsObject *FullScreenWindow::mainItem() const +{ + return m_mainItem.data(); +} + +void FullScreenWindow::setMainItem(QGraphicsObject *mainItem) +{ + if (m_mainItem.data() != mainItem) { + if (m_mainItem) { + m_mainItem.data()->setParent(mainItem->parent()); + m_mainItem.data()->removeEventFilter(this); + m_mainItem.data()->setY(0); + m_scene = 0; + } + m_mainItem = mainItem; + if (mainItem) { + mainItem->setParentItem(0); + mainItem->setParent(this); + m_scene = mainItem->scene(); + } + + mainItem->installEventFilter(this); + + //if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene + QTimer::singleShot(0, this, SLOT(syncViewToMainItem())); + } +} + +void FullScreenWindow::syncViewToMainItem() +{ + if (!m_mainItem) { + return; + } + + //not have a scene? go up in the hyerarchy until we find something with a scene + QGraphicsScene *scene = m_mainItem.data()->scene(); + if (!scene) { + QObject *parent = m_mainItem.data(); + while ((parent = parent->parent())) { + QGraphicsObject *qo = qobject_cast(parent); + if (qo) { + scene = qo->scene(); + + if (scene) { + scene->addItem(m_mainItem.data()); + ++s_numItems; + Plasma::Corona *corona = qobject_cast(scene); + QDeclarativeItem *di = qobject_cast(m_mainItem.data()); + + if (corona && di) { + if (!m_declarativeItemContainer) { + m_declarativeItemContainer = new DeclarativeItemContainer(); + scene->addItem(m_declarativeItemContainer); + corona->addOffscreenWidget(m_declarativeItemContainer); + } + m_declarativeItemContainer->setDeclarativeItem(di); + } else { + m_mainItem.data()->setY(-10000*s_numItems); + m_mainItem.data()->setY(10000*s_numItems); + } + break; + } + } + } + } + + if (!scene) { + return; + } + + m_view->setScene(scene); + + + if (m_declarativeItemContainer) { + m_view->resize(m_declarativeItemContainer->size().toSize()); + m_view->setSceneRect(m_declarativeItemContainer->geometry()); + } else { + QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()), + QSizeF(m_mainItem.data()->boundingRect().size())); + m_view->resize(itemGeometry.size().toSize()); + m_view->setSceneRect(itemGeometry); + } + + m_view->move(QApplication::desktop()->availableGeometry().center() - QPoint(m_view->width()/2, m_view->height()/2)); +} + +void FullScreenWindow::syncMainItemToView() +{ + if (!m_mainItem) { + return; + } + + m_mainItem.data()->setProperty("width", m_view->width()); + m_mainItem.data()->setProperty("height", m_view->height()); +} + +bool FullScreenWindow::isVisible() const +{ + return m_view->isVisible(); +} + +void FullScreenWindow::setVisible(const bool visible) +{ + if (m_view->isVisible() != visible) { + m_background->setVisible(visible); + Plasma::WindowEffects::slideWindow(m_view->winId(), Plasma::BottomEdge, 0); + m_view->setVisible(visible); + unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager; + KWindowSystem::setState(m_view->effectiveWinId(), state); + KWindowSystem::setState(m_background->effectiveWinId(), state); + if (visible) { + m_view->raise(); + KWindowSystem::forceActiveWindow(m_view->effectiveWinId()); + } + } +} + +QGraphicsView *FullScreenWindow::view() const +{ + return m_view; +} + +QDeclarativeListProperty FullScreenWindow::title() +{ + if (m_rootObject) { + return m_rootObject.data()->property("title").value >(); + } else { + return QDeclarativeListProperty(this, m_dummyTitleElements); + } +} + +QDeclarativeListProperty FullScreenWindow::content() +{ + if (m_rootObject) { + return m_rootObject.data()->property("content").value >(); + } else { + return QDeclarativeListProperty(this, m_dummyContentElements); + } +} + +QDeclarativeListProperty FullScreenWindow::buttons() +{ + if (m_rootObject) { + return m_rootObject.data()->property("buttons").value >(); + } else { + return QDeclarativeListProperty(this, m_dummyButtonsElements); + } +} + +DialogStatus::Status FullScreenWindow::status() const +{ + if (m_rootObject) { + return (DialogStatus::Status)m_rootObject.data()->property("status").toInt(); + } else { + return DialogStatus::Closed; + } +} + + +void FullScreenWindow::statusHasChanged() +{ + if (status() == DialogStatus::Closed) { + setVisible(false); + } else { + setVisible(true); + } + emit statusChanged(); +} + +void FullScreenWindow::open() +{ + if (m_rootObject) { + QMetaObject::invokeMethod(m_rootObject.data(), "open"); + } +} + +void FullScreenWindow::accept() +{ + if (m_rootObject) { + QMetaObject::invokeMethod(m_rootObject.data(), "accept"); + } +} + +void FullScreenWindow::reject() +{ + if (m_rootObject) { + QMetaObject::invokeMethod(m_rootObject.data(), "reject"); + } +} + +void FullScreenWindow::close() +{ + if (m_rootObject) { + QMetaObject::invokeMethod(m_rootObject.data(), "close"); + } +} + + + + +bool FullScreenWindow::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == m_mainItem.data() && + (event->type() == QEvent::GraphicsSceneResize)) { + syncViewToMainItem(); + } else if (watched == m_view && + (event->type() == QEvent::Resize)) { + syncMainItemToView(); + } + return false; +} + + + +#include "fullscreenwindow.moc" + diff --git a/declarativeimports/plasmacomponents/fullscreenwindow.h b/declarativeimports/plasmacomponents/fullscreenwindow.h new file mode 100644 index 000000000..c1a378604 --- /dev/null +++ b/declarativeimports/plasmacomponents/fullscreenwindow.h @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright 2012 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ +#ifndef FULLSCREENWINDOW_P +#define FULLSCREENWINDOW_P + +#include +#include +#include +#include +#include +#include + +#include "enums.h" + +class QGraphicsObject; +class QGraphicsView; +class QGraphicsScene; +class DeclarativeItemContainer; +class Background; + +class FullScreenWindow : public QDeclarativeItem +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty title READ title DESIGNABLE false) + Q_PROPERTY(QDeclarativeListProperty content READ content DESIGNABLE false) + Q_PROPERTY(QDeclarativeListProperty buttons READ buttons DESIGNABLE false) + Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged) + + +public: + FullScreenWindow(QDeclarativeItem *parent = 0); + ~FullScreenWindow(); + + QGraphicsObject *mainItem() const; + void setMainItem(QGraphicsObject *mainItem); + + bool isVisible() const; + void setVisible(const bool visible); + + QGraphicsView *view() const; + + //QML properties + QDeclarativeListProperty title(); + QDeclarativeListProperty content(); + QDeclarativeListProperty buttons(); + DialogStatus::Status status() const; + + Q_INVOKABLE void open(); + Q_INVOKABLE void accept(); + Q_INVOKABLE void reject(); + Q_INVOKABLE void close(); + +Q_SIGNALS: + void accepted(); + void rejected(); + void clickedOutside(); + void statusChanged(); + + +private Q_SLOTS: + void syncViewToMainItem(); + void syncMainItemToView(); + void statusHasChanged(); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + void init(const QString &componentName); + +private: + QGraphicsView *m_view; + QWeakPointer m_mainItem; + DeclarativeItemContainer *m_declarativeItemContainer; + QGraphicsScene *m_scene; + QWeakPointer m_rootObject; + static uint s_numItems; + Background *m_background; + + //those only used in case of error, to not make plasma crash + QList m_dummyTitleElements; + QList m_dummyContentElements; + QList m_dummyButtonsElements; +}; + +#endif diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index 615cfe845..ca75c2443 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -34,6 +34,7 @@ #include "qmenuitem.h" #include "kdialogproxy.h" #include "fullscreendialog.h" +#include "fullscreensheet.h" Q_EXPORT_PLUGIN2(plasmacomponentsplugin, PlasmaComponentsPlugin) @@ -100,6 +101,7 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri) //on touch systems the dialog is fullscreen, c++ needed to do that } else { qmlRegisterType(uri, 0, 1, "Dialog"); + qmlRegisterType(uri, 0, 1, "Sheet"); } qmlRegisterType(uri, 0, 1, "RangeModel"); diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml index cbc7a50db..c988996e0 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml @@ -47,18 +47,22 @@ import "." 0.1 Item { id: root - width: dialog.width - height: dialog.height + width: 600 + height: 200 + onHeightChanged:print(height) property alias title: titleBar.children property alias content: contentItem.children - property alias buttons: buttonItem.children // property alias visualParent: dialog.visualParent property int status: DialogStatus.Closed + property alias acceptButtonText: acceptButton.text + property alias rejectButtonText: rejectButton.text + property alias acceptButton: acceptButton + property alias rejectButton: rejectButton property alias privateTitleHeight: titleBar.height - property alias privateButtonsHeight: buttonItem.height + property alias privateButtonsHeight: buttonsRow.height signal accepted signal rejected @@ -110,9 +114,7 @@ Item { PlasmaCore.FrameSvgItem { id: dialog - width: mainItem.width + margins.left + margins.right - height: mainItem.height + margins.top + margins.bottom - anchors.centerIn: parent + anchors.fill: parent imagePath: "dialogs/background" state: "closed" @@ -123,9 +125,8 @@ Item { id: mainItem x: dialog.margins.left y: dialog.margins.top - width: theme.defaultFont.mSize.width * 40 - height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8 - + width: parent.width - dialog.margins.left - dialog.margins.right + height: parent.height - dialog.margins.top - dialog.margins.bottom // Consume all key events that are not processed by children Keys.onPressed: event.accepted = true @@ -146,24 +147,33 @@ Item { id: contentItem clip: true - onChildrenRectChanged: mainItem.width = Math.max(childrenRect.width, buttonItem.childrenRect.width) + onChildrenRectChanged: mainItem.width = Math.max(childrenRect.width, buttonsRow.childrenRect.width) anchors { top: titleBar.bottom left: parent.left right: parent.right - bottom: buttonItem.top + bottom: buttonsRow.top } } - Item { - id: buttonItem - - height: childrenRect.height + Row { + id: buttonsRow + spacing: 8 anchors { - left: parent.left - right: parent.right bottom: parent.bottom - bottomMargin: 8 + horizontalCenter: parent.horizontalCenter + //the bottom margin is disabled but we want it anyways + bottomMargin: theme.defaultFont.mSize.height*0.6 + } + + Button { + id: acceptButton + onClicked: accept() + } + + Button { + id: rejectButton + onClicked: reject() } } } diff --git a/declarativeimports/plasmacomponents/qml/Sheet.qml b/declarativeimports/plasmacomponents/qml/Sheet.qml index 76bf53d43..8ce6e94c8 100644 --- a/declarativeimports/plasmacomponents/qml/Sheet.qml +++ b/declarativeimports/plasmacomponents/qml/Sheet.qml @@ -111,13 +111,16 @@ Item { property alias title: titleBar.children property alias content: contentItem.children - property alias buttons: buttonItem.children // property alias visualParent: dialog.visualParent property int status: DialogStatus.Closed + property alias acceptButtonText: acceptButton.text + property alias rejectButtonText: rejectButton.text + property alias acceptButton: acceptButton + property alias rejectButton: rejectButton property alias privateTitleHeight: titleBar.height - property alias privateButtonsHeight: buttonItem.height + property alias privateButtonsHeight: buttonsRow.height signal accepted signal rejected @@ -175,7 +178,7 @@ Item { mainItem: Item { id: mainItem width: theme.defaultFont.mSize.width * 40 - height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8 + height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonsRow.childrenRect.height + 8 // Consume all key events that are not processed by children Keys.onPressed: event.accepted = true @@ -195,27 +198,36 @@ Item { Item { id: contentItem - onChildrenRectChanged: mainItem.width = Math.max(childrenRect.width, buttonItem.childrenRect.width) + onChildrenRectChanged: mainItem.width = Math.max(childrenRect.width, buttonsRow.childrenRect.width) clip: true anchors { top: titleBar.bottom left: parent.left right: parent.right - bottom: buttonItem.top + bottom: buttonsRow.top bottomMargin: 8 } } - Item { - id: buttonItem - - height: childrenRect.height + Row { + id: buttonsRow + spacing: 8 anchors { - left: parent.left - right: parent.right bottom: parent.bottom - bottomMargin: 4 + horizontalCenter: parent.horizontalCenter + //the bottom margin is disabled but we want it anyways + bottomMargin: theme.defaultFont.mSize.height*0.6 + } + + Button { + id: acceptButton + onClicked: accept() + } + + Button { + id: rejectButton + onClicked: reject() } } } From ab44729083da2c6a449ea60a59d6465338a0b02b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Feb 2012 14:58:24 +0100 Subject: [PATCH 3/7] sync scene --- declarativeimports/plasmacomponents/fullscreenwindow.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/declarativeimports/plasmacomponents/fullscreenwindow.cpp b/declarativeimports/plasmacomponents/fullscreenwindow.cpp index 486bdbe6e..f1fa80ae5 100644 --- a/declarativeimports/plasmacomponents/fullscreenwindow.cpp +++ b/declarativeimports/plasmacomponents/fullscreenwindow.cpp @@ -259,6 +259,15 @@ void FullScreenWindow::syncMainItemToView() m_mainItem.data()->setProperty("width", m_view->width()); m_mainItem.data()->setProperty("height", m_view->height()); + + if (m_declarativeItemContainer) { + m_view->resize(m_declarativeItemContainer->size().toSize()); + m_view->setSceneRect(m_declarativeItemContainer->geometry()); + } else { + QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()), + QSizeF(m_mainItem.data()->boundingRect().size())); + m_view->setSceneRect(itemGeometry); + } } bool FullScreenWindow::isVisible() const From db4d97ff8634832e60e51878ad21e82a98a45236 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Feb 2012 15:15:38 +0100 Subject: [PATCH 4/7] size the sheet accordingly to the screen geometry --- declarativeimports/plasmacomponents/fullscreensheet.cpp | 6 ++++++ declarativeimports/plasmacomponents/fullscreenwindow.cpp | 1 + 2 files changed, 7 insertions(+) diff --git a/declarativeimports/plasmacomponents/fullscreensheet.cpp b/declarativeimports/plasmacomponents/fullscreensheet.cpp index 91eb82786..5210a8330 100644 --- a/declarativeimports/plasmacomponents/fullscreensheet.cpp +++ b/declarativeimports/plasmacomponents/fullscreensheet.cpp @@ -19,6 +19,10 @@ #include "fullscreensheet.h" +#include +#include +#include + #include FullScreenSheet::FullScreenSheet(QDeclarativeItem *parent) @@ -26,6 +30,8 @@ FullScreenSheet::FullScreenSheet(QDeclarativeItem *parent) { init("Sheet"); + view()->setGeometry(QApplication::desktop()->availableGeometry().adjusted(50, 50, 0, 50)); + if (mainItem()) { connect(mainItem(), SIGNAL(acceptButtonChanged()), this, SIGNAL(acceptButtonChanged())); diff --git a/declarativeimports/plasmacomponents/fullscreenwindow.cpp b/declarativeimports/plasmacomponents/fullscreenwindow.cpp index f1fa80ae5..062b21380 100644 --- a/declarativeimports/plasmacomponents/fullscreenwindow.cpp +++ b/declarativeimports/plasmacomponents/fullscreenwindow.cpp @@ -296,6 +296,7 @@ QGraphicsView *FullScreenWindow::view() const return m_view; } + QDeclarativeListProperty FullScreenWindow::title() { if (m_rootObject) { From 6d9f9afcadadb202f6161443f679526a41b7182d Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Feb 2012 15:23:47 +0100 Subject: [PATCH 5/7] proper borders --- declarativeimports/plasmacomponents/fullscreensheet.cpp | 2 +- .../plasmacomponents/platformcomponents/touch/Sheet.qml | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/declarativeimports/plasmacomponents/fullscreensheet.cpp b/declarativeimports/plasmacomponents/fullscreensheet.cpp index 5210a8330..c728413ce 100644 --- a/declarativeimports/plasmacomponents/fullscreensheet.cpp +++ b/declarativeimports/plasmacomponents/fullscreensheet.cpp @@ -30,7 +30,7 @@ FullScreenSheet::FullScreenSheet(QDeclarativeItem *parent) { init("Sheet"); - view()->setGeometry(QApplication::desktop()->availableGeometry().adjusted(50, 50, 0, 50)); + view()->setGeometry(QApplication::desktop()->availableGeometry()); if (mainItem()) { connect(mainItem(), SIGNAL(acceptButtonChanged()), diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml index c988996e0..7aed660c7 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml @@ -114,8 +114,15 @@ Item { PlasmaCore.FrameSvgItem { id: dialog - anchors.fill: parent + anchors { + fill: parent + leftMargin: 50 + topMargin: 50 + rightMargin: 50 + bottomMargin: 0 + } imagePath: "dialogs/background" + enabledBorders: "LeftBorder|TopBorder|RightBorder" state: "closed" From f30b2da11bbce38aff23ef047886f19d9c45225b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 1 Mar 2012 15:03:45 +0100 Subject: [PATCH 6/7] fully working --- .../plasmacomponents/fullscreensheet.cpp | 39 ++++++++++++--- .../plasmacomponents/fullscreensheet.h | 20 +++++--- .../plasmacomponentsplugin.cpp | 14 +++++- .../plasmacomponents/plasmacomponentsplugin.h | 7 ++- .../platformcomponents/touch/Sheet.qml | 48 +++++++++++++++---- .../plasmacomponents/qml/Sheet.qml | 47 ++++++++++++++---- .../plasmacomponents/qml/qmldir | 1 + 7 files changed, 144 insertions(+), 32 deletions(-) diff --git a/declarativeimports/plasmacomponents/fullscreensheet.cpp b/declarativeimports/plasmacomponents/fullscreensheet.cpp index c728413ce..f630070ee 100644 --- a/declarativeimports/plasmacomponents/fullscreensheet.cpp +++ b/declarativeimports/plasmacomponents/fullscreensheet.cpp @@ -33,6 +33,8 @@ FullScreenSheet::FullScreenSheet(QDeclarativeItem *parent) view()->setGeometry(QApplication::desktop()->availableGeometry()); if (mainItem()) { + connect(mainItem(), SIGNAL(titleChanged()), + this, SIGNAL(titleChanged())); connect(mainItem(), SIGNAL(acceptButtonChanged()), this, SIGNAL(acceptButtonChanged())); connect(mainItem(), SIGNAL(rejectButtonChanged()), @@ -48,32 +50,48 @@ FullScreenSheet::~FullScreenSheet() { } -QGraphicsObject *FullScreenSheet::acceptButton() const +QString FullScreenSheet::title() const { if (mainItem()) { - return mainItem()->property("acceptButton").value(); + return mainItem()->property("title").toString(); } else { return 0; } } -void FullScreenSheet::setAcceptButton(QGraphicsObject *button) +void FullScreenSheet::setTitle(const QString &text) +{ + if (mainItem()) { + mainItem()->setProperty("title", QVariant::fromValue(text)); + } +} + +QDeclarativeItem *FullScreenSheet::acceptButton() const +{ + if (mainItem()) { + return mainItem()->property("acceptButton").value(); + } else { + return 0; + } +} + +void FullScreenSheet::setAcceptButton(QDeclarativeItem *button) { if (mainItem()) { mainItem()->setProperty("acceptButton", QVariant::fromValue(button)); } } -QGraphicsObject *FullScreenSheet::rejectButton() const +QDeclarativeItem *FullScreenSheet::rejectButton() const { if (mainItem()) { - return mainItem()->property("rejectButton").value(); + return mainItem()->property("rejectButton").value(); } else { return 0; } } -void FullScreenSheet::setRejectButton(QGraphicsObject *button) +void FullScreenSheet::setRejectButton(QDeclarativeItem *button) { if (mainItem()) { mainItem()->setProperty("rejectButton", QVariant::fromValue(button)); @@ -112,5 +130,14 @@ void FullScreenSheet::setRejectButtonText(const QString &text) } } +void FullScreenSheet::open() +{ + if (mainItem()) { + view()->setGeometry(QApplication::desktop()->availableGeometry()); + QMetaObject::invokeMethod(mainItem(), "open"); + } +} + + #include "fullscreensheet.moc" diff --git a/declarativeimports/plasmacomponents/fullscreensheet.h b/declarativeimports/plasmacomponents/fullscreensheet.h index 17c1bbe44..f1450cd28 100644 --- a/declarativeimports/plasmacomponents/fullscreensheet.h +++ b/declarativeimports/plasmacomponents/fullscreensheet.h @@ -24,8 +24,10 @@ class FullScreenSheet : public FullScreenWindow { Q_OBJECT - Q_PROPERTY(QGraphicsObject *acceptButton READ acceptButton WRITE setAcceptButton NOTIFY acceptButtonChanged) - Q_PROPERTY(QGraphicsObject *rejectButton READ rejectButton WRITE setRejectButton NOTIFY rejectButtonChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) + + Q_PROPERTY(QDeclarativeItem *acceptButton READ acceptButton WRITE setAcceptButton NOTIFY acceptButtonChanged) + Q_PROPERTY(QDeclarativeItem *rejectButton READ rejectButton WRITE setRejectButton NOTIFY rejectButtonChanged) Q_PROPERTY(QString acceptButtonText READ acceptButtonText WRITE setAcceptButtonText NOTIFY acceptButtonTextChanged) Q_PROPERTY(QString rejectButtonText READ rejectButtonText WRITE setRejectButtonText NOTIFY rejectButtonTextChanged) @@ -34,11 +36,14 @@ public: FullScreenSheet(QDeclarativeItem *parent = 0); ~FullScreenSheet(); - QGraphicsObject *acceptButton() const; - void setAcceptButton(QGraphicsObject *button); + QString title() const; + void setTitle(const QString &text); - QGraphicsObject *rejectButton() const; - void setRejectButton(QGraphicsObject *button); + QDeclarativeItem *acceptButton() const; + void setAcceptButton(QDeclarativeItem *button); + + QDeclarativeItem *rejectButton() const; + void setRejectButton(QDeclarativeItem *button); QString acceptButtonText() const; void setAcceptButtonText(const QString &text); @@ -46,7 +51,10 @@ public: QString rejectButtonText() const; void setRejectButtonText(const QString &text); + Q_INVOKABLE void open(); + Q_SIGNALS: + void titleChanged(); void acceptButtonChanged(); void rejectButtonChanged(); void acceptButtonTextChanged(); diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index ca75c2443..bfc98a7f3 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -55,10 +55,14 @@ EngineBookKeeping *EngineBookKeeping::self() } QDeclarativeEngine *EngineBookKeeping::engineFor(QObject *item) const -{return m_engines.values().first(); +{ + //for components creation, any engine will do, as long is valid + return m_engines.values().first(); + /* foreach (QDeclarativeEngine *engine, m_engines) { QObject *root = engine->rootContext()->contextObject(); QObject *candidate = item; + while (candidate) { if (candidate == root) { return engine; @@ -66,14 +70,20 @@ QDeclarativeEngine *EngineBookKeeping::engineFor(QObject *item) const candidate = candidate->parent(); } } - return 0; + return 0;*/ } void EngineBookKeeping::insertEngine(QDeclarativeEngine *engine) { + connect(engine, SIGNAL(destroyed(QObject *)), this, SLOT(engineDestroyed(QObject *deleted))); m_engines.insert(engine); } +void EngineBookKeeping::engineDestroyed(QObject *deleted) +{ + m_engines.remove(static_cast(deleted)); +} + void PlasmaComponentsPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri) diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.h b/declarativeimports/plasmacomponents/plasmacomponentsplugin.h index 11b19ea5f..e4226dc56 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.h +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.h @@ -27,8 +27,10 @@ class QDeclarativeEngine; class QDeclarativeItem; class PlasmaComponentsPlugin; -class EngineBookKeeping +class EngineBookKeeping : public QObject { + Q_OBJECT + public: EngineBookKeeping(); static EngineBookKeeping *self(); @@ -36,6 +38,9 @@ public: void insertEngine(QDeclarativeEngine *engine); QDeclarativeEngine *engineFor(QObject *item) const; +private Q_SLOTS: + void engineDestroyed(QObject *deleted); + private: QSet m_engines; }; diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml index 7aed660c7..ba7b4b20b 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml @@ -47,11 +47,11 @@ import "." 0.1 Item { id: root - width: 600 - height: 200 + width: 800 + height: 600 onHeightChanged:print(height) - property alias title: titleBar.children + property alias title: titleLabel.text property alias content: contentItem.children // property alias visualParent: dialog.visualParent property int status: DialogStatus.Closed @@ -139,14 +139,44 @@ Item { Keys.onPressed: event.accepted = true Keys.onReleased: event.accepted = true - Item { + PlasmaCore.FrameSvgItem { id: titleBar + imagePath: "widgets/extender-dragger" + prefix: "root" + anchors.left: parent.left + anchors.right: parent.right + //FIXME: +5 because of Plasma::Dialog margins + height: titleLabel.paintedHeight + margins.top + margins.bottom - height: childrenRect.height - anchors { - top: parent.top - left: parent.left - right: parent.right + Column { + id: titleLayoutHelper // needed to make the text mirror correctly + + anchors { + right: parent.right + left: parent.left + top: parent.top + bottom: parent.bottom + leftMargin: parent.margins.left + rightMargin: parent.margins.right + topMargin: parent.margins.top + bottomMargin: parent.margins.bottom + } + + Label { + id: titleLabel + elide: Text.ElideRight + height: paintedHeight + font.pointSize: theme.defaultFont.pointSize * 1.1 + font.weight: Font.Bold + style: Text.Raised + styleColor: Qt.rgba(1,1,1,0.8) + anchors { + left: parent.left + right: parent.right + } + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } } } diff --git a/declarativeimports/plasmacomponents/qml/Sheet.qml b/declarativeimports/plasmacomponents/qml/Sheet.qml index 8ce6e94c8..ac15e87d5 100644 --- a/declarativeimports/plasmacomponents/qml/Sheet.qml +++ b/declarativeimports/plasmacomponents/qml/Sheet.qml @@ -109,7 +109,7 @@ import "." 0.1 Item { id: root - property alias title: titleBar.children + property alias title: titleLabel.text property alias content: contentItem.children // property alias visualParent: dialog.visualParent property int status: DialogStatus.Closed @@ -160,6 +160,7 @@ Item { PlasmaCore.Dialog { id: dialog windowFlags: Qt.Dialog + location: 4 //FIXME: replace with BottomEdge when we have an enum reachable from everywhere in core //onFaderClicked: root.clickedOutside() @@ -178,20 +179,50 @@ Item { mainItem: Item { id: mainItem width: theme.defaultFont.mSize.width * 40 - height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonsRow.childrenRect.height + 8 + height: Math.max(titleBar.childrenRect.height + contentItem.childrenRect.height + buttonsRow.childrenRect.height + 8, theme.defaultFont.mSize.height * 25) // Consume all key events that are not processed by children Keys.onPressed: event.accepted = true Keys.onReleased: event.accepted = true - Item { + PlasmaCore.FrameSvgItem { id: titleBar + imagePath: "widgets/extender-dragger" + prefix: "root" + anchors.left: parent.left + anchors.right: parent.right + //FIXME: +5 because of Plasma::Dialog margins + height: titleLabel.paintedHeight + margins.top + margins.bottom - height: childrenRect.height - anchors { - top: parent.top - left: parent.left - right: parent.right + Column { + id: titleLayoutHelper // needed to make the text mirror correctly + + anchors { + right: parent.right + left: parent.left + top: parent.top + bottom: parent.bottom + leftMargin: parent.margins.left + rightMargin: parent.margins.right + topMargin: parent.margins.top + bottomMargin: parent.margins.bottom + } + + Label { + id: titleLabel + elide: Text.ElideRight + height: paintedHeight + font.pointSize: theme.defaultFont.pointSize * 1.1 + font.weight: Font.Bold + style: Text.Raised + styleColor: Qt.rgba(1,1,1,0.8) + anchors { + left: parent.left + right: parent.right + } + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } } } diff --git a/declarativeimports/plasmacomponents/qml/qmldir b/declarativeimports/plasmacomponents/qml/qmldir index c5619981a..41e75bb44 100644 --- a/declarativeimports/plasmacomponents/qml/qmldir +++ b/declarativeimports/plasmacomponents/qml/qmldir @@ -20,6 +20,7 @@ ScrollBar 0.1 ScrollBar.qml SectionScroller 0.1 SectionScroller.qml SelectionDialog 0.1 SelectionDialog.qml Slider 0.1 Slider.qml +Sheet 0.1 Sheet.qml Switch 0.1 Switch.qml TabBar 0.1 TabBar.qml TabButton 0.1 TabButton.qml From fda07f4473b3752c2462339296d594fb0974e342 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 1 Mar 2012 15:10:48 +0100 Subject: [PATCH 7/7] documentation --- .../platformcomponents/touch/Sheet.qml | 70 +++++++++++++++++++ .../plasmacomponents/qml/Sheet.qml | 21 ++++-- 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml index ba7b4b20b..281ccb236 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/Sheet.qml @@ -45,6 +45,76 @@ import org.kde.plasma.core 0.1 as PlasmaCore import "private/AppManager.js" as Utils import "." 0.1 +/**Documented API +Inherits: + Item + +Imports: + QtQuick 1.0 + org.kde.plasma.core + +Description: + Provides a top-level window for short-term tasks and brief interaction with the user. + Is intended to be for interaction more complex and bigger in size then Dialog. On the desktop its looks is almost identical to Dialog, on touch interfaces is an almost fullscreen sliding Sheet. It is provided mostly for compatibility with mobile implementations + +Properties: + list content: + A list of items in the dialog's content area. You can use any component that is based on Item. For example, you can use ListView, so that the user can select from a list of names. + + int status: + Indicates the dialog's phase in its life cycle. The values are as follows: + - DialogStatus.Opening - the dialog is opening + - DialogStatus.Open - the dialog is open and visible to the user + - DialogStatus.Closing - the dialog is closing + - DialogStatus.Closed - the dialog is closed and not visible to the user + The dialog's initial status is DialogStatus.Closed. + + string title: + The title text of this Sheet. + + Item acceptButton: + button that when pressed will close the dialog, representing the user accepting it, accepted() will be called + + Item rejectButton: + button that when pressed will close the dialog, representing the user rejecting it, rejected() will be called + + string acceptButtonText: + Text of the accept button + + string rejectButtonText: + Text of the reject button + + Item visualParent: + The item that is dimmed when the dialog opens. By default the root parent object is visualParent. + +Signals: + accepted(): + This signal is emitted when the user accepts the dialog's request or the accept() method is called. + See also rejected(). + + clickedOutside(): This signal is emitted when the user taps in the area that is inside the dialog's visual parent area but outside the dialog's area. Normally the visual parent is the root object. In that case this signal is emitted if the user taps anywhere outside the dialog's area. + See also visualParent. + + rejected(): + This signal is emitted when the user rejects the dialog's request or the reject() method is called. + See also accepted(). + +Methods: + void accept(): + Accepts the dialog's request without any user interaction. The method emits the accepted() signal and closes the dialog. + See also reject(). + + void close(): + Closes the dialog without any user interaction. + + void open(): + Shows the dialog to the user. + + void reject(): + Rejects the dialog's request without any user interaction. The method emits the rejected() signal and closes the dialog. + See also accept(). +**/ + Item { id: root width: 800 diff --git a/declarativeimports/plasmacomponents/qml/Sheet.qml b/declarativeimports/plasmacomponents/qml/Sheet.qml index ac15e87d5..f5798b0c1 100644 --- a/declarativeimports/plasmacomponents/qml/Sheet.qml +++ b/declarativeimports/plasmacomponents/qml/Sheet.qml @@ -50,12 +50,9 @@ Imports: Description: Provides a top-level window for short-term tasks and brief interaction with the user. - A dialog floats on the top layer of the application view, usually overlapping the area reserved for the application content. Normally, a dialog provides information and gives warnings to the user, or asks the user to answer a question or select an option. + Is intended to be for interaction more complex and bigger in size then Dialog. On the desktop its looks is almost identical to Dialog, on touch interfaces is an almost fullscreen sliding Sheet. It is provided mostly for compatibility with mobile implementations Properties: - list buttons: - A list of items in the dialog's button area. For example, you can use Row or Button components but you can also use any number of components that are based on Item component. - list content: A list of items in the dialog's content area. You can use any component that is based on Item. For example, you can use ListView, so that the user can select from a list of names. @@ -67,8 +64,20 @@ Properties: - DialogStatus.Closed - the dialog is closed and not visible to the user The dialog's initial status is DialogStatus.Closed. - list title: - A list of items in the dialog's title area. You can use a Text component but also any number of components that are based on Item. For example, you can use Text and Image components. + string title: + The title text of this Sheet. + + Item acceptButton: + button that when pressed will close the dialog, representing the user accepting it, accepted() will be called + + Item rejectButton: + button that when pressed will close the dialog, representing the user rejecting it, rejected() will be called + + string acceptButtonText: + Text of the accept button + + string rejectButtonText: + Text of the reject button Item visualParent: The item that is dimmed when the dialog opens. By default the root parent object is visualParent.