From 57e77a8591da45fe5f85c9a80541d27003cd6750 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 30 Nov 2012 00:00:37 +0100 Subject: [PATCH] remove the kdialog based querydialog Dialogs are always plasma-themed, and if possible are inline. only if there is not enough space (like in a panel) they get moved in a separate window this removes quite some c++ usage and hopefully solves some layouting problems in dialogs --- declarativeimports/core/dialog.cpp | 4 +- declarativeimports/core/dialog.h | 6 +- .../plasmacomponents/CMakeLists.txt | 5 +- .../plasmacomponents/fullscreendialog.cpp | 35 --- .../plasmacomponents/fullscreendialog.h | 33 --- .../plasmacomponents/kdialogproxy.cpp | 151 ------------ .../plasmacomponents/kdialogproxy.h | 88 ------- .../plasmacomponentsplugin.cpp | 6 +- .../platformcomponents/touch/Dialog.qml | 200 ---------------- .../plasmacomponents/qml/Dialog.qml | 226 ++++++++++++------ .../touch => qml}/QueryDialog.qml | 4 +- .../qml/private/InlineDialog.qml | 146 +++++++++++ .../plasmacomponents/qml/qmldir | 1 + 13 files changed, 306 insertions(+), 599 deletions(-) delete mode 100644 declarativeimports/plasmacomponents/fullscreendialog.cpp delete mode 100644 declarativeimports/plasmacomponents/fullscreendialog.h delete mode 100644 declarativeimports/plasmacomponents/kdialogproxy.cpp delete mode 100644 declarativeimports/plasmacomponents/kdialogproxy.h delete mode 100644 declarativeimports/plasmacomponents/platformcomponents/touch/Dialog.qml rename declarativeimports/plasmacomponents/{platformcomponents/touch => qml}/QueryDialog.qml (98%) create mode 100644 declarativeimports/plasmacomponents/qml/private/InlineDialog.qml diff --git a/declarativeimports/core/dialog.cpp b/declarativeimports/core/dialog.cpp index 7248c58c8..b19ff5b8c 100644 --- a/declarativeimports/core/dialog.cpp +++ b/declarativeimports/core/dialog.cpp @@ -89,8 +89,8 @@ int DialogMargins::bottom() const return m_bottom; } -DialogProxy::DialogProxy(QObject *parent) - : QObject(parent), +DialogProxy::DialogProxy(QDeclarativeItem *parent) + : QDeclarativeItem(parent), m_declarativeItemContainer(0), m_activeWindow(false), m_location(Plasma::Floating) diff --git a/declarativeimports/core/dialog.h b/declarativeimports/core/dialog.h index ce416c931..552f6a436 100644 --- a/declarativeimports/core/dialog.h +++ b/declarativeimports/core/dialog.h @@ -19,7 +19,7 @@ #ifndef DIALOG_PROXY_P #define DIALOG_PROXY_P -#include +#include #include #include @@ -84,7 +84,7 @@ private: friend class DialogProxy; }; -class DialogProxy : public QObject +class DialogProxy : public QDeclarativeItem { Q_OBJECT @@ -152,7 +152,7 @@ public: WA_X11NetWmWindowTypeDock = Qt::WA_X11NetWmWindowTypeDock }; - DialogProxy(QObject *parent = 0); + DialogProxy(QDeclarativeItem *parent = 0); ~DialogProxy(); QGraphicsObject *mainItem() const; diff --git a/declarativeimports/plasmacomponents/CMakeLists.txt b/declarativeimports/plasmacomponents/CMakeLists.txt index 249b02607..ff584fd49 100644 --- a/declarativeimports/plasmacomponents/CMakeLists.txt +++ b/declarativeimports/plasmacomponents/CMakeLists.txt @@ -1,7 +1,6 @@ project(plasmacomponents) set(plasmacomponents_SRCS - fullscreendialog.cpp fullscreensheet.cpp fullscreenwindow.cpp plasmacomponentsplugin.cpp @@ -9,7 +8,6 @@ set(plasmacomponents_SRCS enums.cpp qmenu.cpp qmenuitem.cpp - kdialogproxy.cpp ../core/declarativeitemcontainer.cpp ) @@ -43,12 +41,14 @@ install(FILES qml/Button.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/t install(FILES qml/ButtonRow.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/CheckBox.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/CommonDialog.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) +install(FILES qml/Dialog.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/Highlight.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/Label.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/ListItem.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/Page.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/PageStack.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/ProgressBar.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) +install(FILES qml/QueryDialog.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/RadioButton.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/SelectionDialog.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) install(FILES qml/Slider.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components) @@ -65,6 +65,7 @@ install(FILES qml/ToolButton.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimpor #Now install the private stuff! install(FILES qml/private/DualStateButton.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components/private) +install(FILES qml/private/InlineDialog.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components/private) install(FILES qml/private/PageStack.js DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components/private) install(FILES qml/private/TabGroup.js DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components/private) install(FILES qml/private/ScrollBarDelegate.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components/private) diff --git a/declarativeimports/plasmacomponents/fullscreendialog.cpp b/declarativeimports/plasmacomponents/fullscreendialog.cpp deleted file mode 100644 index 591e02442..000000000 --- a/declarativeimports/plasmacomponents/fullscreendialog.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * 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 "fullscreendialog.h" - - -FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent) - : FullScreenWindow(parent) -{ - init("Dialog"); - -} - -FullScreenDialog::~FullScreenDialog() -{ -} - -#include "fullscreendialog.moc" - diff --git a/declarativeimports/plasmacomponents/fullscreendialog.h b/declarativeimports/plasmacomponents/fullscreendialog.h deleted file mode 100644 index 6cd8adf41..000000000 --- a/declarativeimports/plasmacomponents/fullscreendialog.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * 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 FULLSCREENDIALOG_P -#define FULLSCREENDIALOG_P - -#include "fullscreenwindow.h" - -class FullScreenDialog : public FullScreenWindow -{ - Q_OBJECT - -public: - FullScreenDialog(QDeclarativeItem *parent = 0); - ~FullScreenDialog(); -}; - -#endif diff --git a/declarativeimports/plasmacomponents/kdialogproxy.cpp b/declarativeimports/plasmacomponents/kdialogproxy.cpp deleted file mode 100644 index 9e98d35f2..000000000 --- a/declarativeimports/plasmacomponents/kdialogproxy.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* -* Copyright (C) 2011 by Marco MArtin -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU Library General Public License as -* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details -* -* You should have received a copy of the GNU Library 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 "kdialogproxy.h" - -#include - -#include - -KDialogProxy::KDialogProxy (QObject *parent) - : QObject(parent), - m_status(DialogStatus::Closed) -{ - m_dialog = new KDialog(0); - m_label = new QLabel(m_dialog); - m_label->setWordWrap(true); - m_dialog->setMainWidget(m_label); - m_dialog->setButtons( KDialog::Ok | KDialog::Cancel); - connect(m_dialog, SIGNAL(okClicked()), this, SIGNAL(accepted())); - connect(m_dialog, SIGNAL(cancelClicked()), this, SIGNAL(rejected())); - connect(m_dialog, SIGNAL(closeClicked()), this, SIGNAL(rejected())); -} - -KDialogProxy::~KDialogProxy() -{ - delete m_dialog; -} - - -void KDialogProxy::setTitleText(const QString &text) -{ - if (text == m_titleText) { - return; - } - - m_dialog->setCaption(text); - m_titleText = text; - emit titleTextChanged(); -} - -QString KDialogProxy::titleText() const -{ - return m_titleText; -} - - -void KDialogProxy::setTitleIcon(const QString &icon) -{ - if (icon == m_titleIcon) { - return; - } - - m_dialog->setWindowIcon(KIcon(icon)); - m_titleIcon = icon; - emit titleIconChanged(); -} - -QString KDialogProxy::titleIcon() const -{ - return m_titleIcon; -} - - -void KDialogProxy::setMessage(const QString &message) -{ - if (message == m_message) { - return; - } - - m_label->setText(message); - m_message = message; - emit messageChanged(); -} - -QString KDialogProxy::message() const -{ - return m_message; -} - - -void KDialogProxy::setAcceptButtonText(const QString &text) -{ - if (text == m_acceptButtonText) { - return; - } - - m_dialog->setButtonText(KDialog::Ok, text); - m_acceptButtonText = text; - emit acceptButtonTextChanged(); -} - -QString KDialogProxy::acceptButtonText() const -{ - return m_acceptButtonText; -} - - -void KDialogProxy::setRejectButtonText(const QString &text) -{ - if (text == m_rejectButtonText) { - return; - } - - m_dialog->setButtonText(KDialog::Cancel, text); - m_rejectButtonText = text; - emit rejectButtonTextChanged(); -} - -QString KDialogProxy::rejectButtonText() const -{ - return m_rejectButtonText; -} - - -DialogStatus::Status KDialogProxy::status() const -{ - return m_status; -} - -void KDialogProxy::open() -{ - m_dialog->show(); - m_status = DialogStatus::Open; - emit statusChanged(); -} - -void KDialogProxy::close() -{ - m_dialog->hide(); - m_status = DialogStatus::Closed; - emit statusChanged(); -} - -#include "kdialogproxy.moc" - diff --git a/declarativeimports/plasmacomponents/kdialogproxy.h b/declarativeimports/plasmacomponents/kdialogproxy.h deleted file mode 100644 index 19e4ffa8f..000000000 --- a/declarativeimports/plasmacomponents/kdialogproxy.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -* Copyright (C) 2011 by Marco MArtin -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU Library General Public License as -* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details -* -* You should have received a copy of the GNU Library 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 KDIALOG_PROXY_H -#define KDIALOG_PROXY_H - -#include -#include -#include "kdialogproxy.h" -#include "enums.h" - -class QLabel; - -class KDialogProxy : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) - Q_PROPERTY(QString titleIcon READ titleIcon WRITE setTitleIcon NOTIFY titleIconChanged) - Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged) - Q_PROPERTY(QString acceptButtonText READ acceptButtonText WRITE setAcceptButtonText NOTIFY acceptButtonTextChanged) - Q_PROPERTY(QString rejectButtonText READ rejectButtonText WRITE setRejectButtonText NOTIFY rejectButtonTextChanged) - Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged) - -public: - KDialogProxy(QObject *parent = 0); - ~KDialogProxy(); - - void setTitleText(const QString &text); - QString titleText() const; - - void setTitleIcon(const QString &icon); - QString titleIcon() const; - - void setMessage(const QString &message); - QString message() const; - - void setAcceptButtonText(const QString &text); - QString acceptButtonText() const; - - void setRejectButtonText(const QString &text); - QString rejectButtonText() const; - - void setStatus(DialogStatus::Status status); - DialogStatus::Status status() const; - - Q_INVOKABLE void open(); - Q_INVOKABLE void close(); - -Q_SIGNALS: - void titleTextChanged(); - void titleIconChanged(); - void messageChanged(); - void acceptButtonTextChanged(); - void rejectButtonTextChanged(); - void statusChanged(); - void accepted(); - void rejected(); - -private: - KDialog *m_dialog; - QLabel *m_label; - QString m_titleText; - QString m_titleIcon; - QString m_message; - QString m_acceptButtonText; - QString m_rejectButtonText; - DialogStatus::Status m_status; -}; - -#endif //KDIALOG_PROXY_H - diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index 99dacc224..dbf6a76fa 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -28,14 +28,13 @@ #include #include +#include #include #include "enums.h" #include "qmenu.h" #include "qmenuitem.h" -#include "kdialogproxy.h" -#include "fullscreendialog.h" #include "fullscreensheet.h" Q_EXPORT_PLUGIN2(plasmacomponentsplugin, PlasmaComponentsPlugin) @@ -94,12 +93,9 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri) //platform specific c++ components const QString target = KDeclarative::componentsTarget(); if (target == KDeclarative::defaultComponentsTarget()) { - qmlRegisterType(uri, 0, 1, "QueryDialog"); qmlRegisterType(uri, 0, 1, "Menu"); qmlRegisterType(uri, 0, 1, "MenuItem"); } else { - //on touch systems the dialog is fullscreen, c++ needed to do that - qmlRegisterType(uri, 0, 1, "Dialog"); qmlRegisterType(uri, 0, 1, "Sheet"); } diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/Dialog.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/Dialog.qml deleted file mode 100644 index 246cde34e..000000000 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/Dialog.qml +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** -** -** 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: 300 - height: 200 - - 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 - anchors.fill: parent - imagePath: "dialogs/background" - - state: "closed" - - //state: "Hidden" - - Item { - id: mainItem - anchors { - fill: parent - leftMargin: dialog.margins.left - topMargin: dialog.margins.top - rightMargin: dialog.margins.right - bottomMargin: dialog.margins.bottom - } - - - // Consume all key events that are not processed by children - Keys.onPressed: event.accepted = true - Keys.onReleased: event.accepted = true - - Item { - id: titleBar - height: Math.max(theme.defaultFont.mSize.height * 1.5, childrenRect.height) - anchors { - top: parent.top - left: parent.left - right: parent.right - } - } - - Item { - id: contentItem - - clip: true - - function adjustSize() { - root.width = Math.max(childrenRect.width, buttonItem.childrenRect.width) + dialog.margins.left + dialog.margins.right - - root.height = Math.max(children[0].implicitHeight, childrenRect.height) + titleBar.height + buttonItem.height + dialog.margins.top + dialog.margins.bottom - } - onChildrenRectChanged: adjustSize() - Component.onCompleted: adjustSize() - - anchors { - top: titleBar.bottom - left: parent.left - right: parent.right - bottom: buttonItem.top - } - } - - Item { - id: buttonItem - - height: childrenRect.height - onChildrenRectChanged: contentItem.adjustSize() - Component.onCompleted: contentItem.adjustSize() - 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/Dialog.qml b/declarativeimports/plasmacomponents/qml/Dialog.qml index 6b2eb389f..ef593bebf 100644 --- a/declarativeimports/plasmacomponents/qml/Dialog.qml +++ b/declarativeimports/plasmacomponents/qml/Dialog.qml @@ -71,7 +71,7 @@ Properties: 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. + The item that the dialog refers to. The dialog will usually be positioned relative to VisualParent Signals: accepted(): @@ -87,7 +87,7 @@ Signals: Methods: void accept(): - Accepts the dialog's request without any user interaction. The method emits the accepted() signal and closes the dialog. + Accepts the dialog's request without any user interaction. The method emits the accepted() signal and closes the internalLoader.dialog. See also reject(). void close(): @@ -97,7 +97,7 @@ Methods: 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. + Rejects the dialog's request without any user interaction. The method emits the rejected() signal and closes the internalLoader.dialog. See also accept(). **/ @@ -105,6 +105,7 @@ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import "private/AppManager.js" as Utils import "." 0.1 +import "private" as Private Item { id: root @@ -112,7 +113,7 @@ Item { property alias title: titleBar.children property alias content: contentItem.children property alias buttons: buttonItem.children -// property alias visualParent: dialog.visualParent + property Item visualParent property int status: DialogStatus.Closed @@ -123,105 +124,174 @@ Item { signal rejected signal clickedOutside - function open() - { - var pos = dialog.popupPosition(null, Qt.AlignCenter) - dialog.x = pos.x - dialog.y = pos.y + function open() { + dialogLayout.parent = internalLoader.item.mainItem - dialog.visible = true - dialog.activateWindow() + if (internalLoader.dialog) { + var pos = internalLoader.dialog.popupPosition(root.visualParent, Qt.AlignCenter) + internalLoader.dialog.x = pos.x + internalLoader.dialog.y = pos.y + + internalLoader.dialog.visible = true + internalLoader.dialog.activateWindow() + } else { + internalLoader.inlineDialog.open() + } } - function accept() - { + function accept() { if (status == DialogStatus.Open) { - dialog.visible = false + if (internalLoader.dialog) { + internalLoader.dialog.visible = false + } else { + internalLoader.inlineDialog.close() + } accepted() } } function reject() { if (status == DialogStatus.Open) { - dialog.visible = false + if (internalLoader.dialog) { + internalLoader.dialog.visible = false + } else { + internalLoader.inlineDialog.close() + } rejected() } } function close() { - dialog.visible = false + if (internalLoader.dialog) { + internalLoader.dialog.visible = false + } else { + internalLoader.inlineDialog.close() + } } visible: false - PlasmaCore.Dialog { - id: dialog - windowFlags: Qt.Dialog - - - //onFaderClicked: root.clickedOutside() + Loader { + id: internalLoader + //the root item of the scene. Determines if there is enough room for an inline dialog property Item rootItem - //state: "Hidden" - visible: false - onVisibleChanged: { - if (visible) { - status = DialogStatus.Open - } else { - status = DialogStatus.Closed - } - } + //this is when the dialog is a separate window + property Item dialog: sourceComponent == dialogComponent ? item : null + //this is when the dialog is inline + property Item inlineDialog: sourceComponent == inlineDialogComponent ? item : null - 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 - } - } - } + property bool loadCompleted: false Component.onCompleted: { rootItem = Utils.rootObject() + loadCompleted = true + } + + sourceComponent: { + if (loadCompleted) { + if (rootItem == null || dialogLayout.width > rootItem.width || dialogLayout.height > rootItem.height) { + dialogComponent + } else { + inlineDialogComponent + } + } + } + } + + Component { + id: dialogComponent + PlasmaCore.Dialog { + windowFlags: Qt.Popup + + //state: "Hidden" + visible: false + onVisibleChanged: { + if (visible) { + root.status = DialogStatus.Open + } else { + root.status = DialogStatus.Closed + } + } + + mainItem: Item { + id: dialogMainItem + width: dialogLayout.width + height: dialogLayout.height + } + + Component.onCompleted: dialogLayout.parent = dialogMainItem + Component.onDestruction: dialogLayout.parent = root + } + } + + Component { + id: inlineDialogComponent + Private.InlineDialog { + id: inlineDialog + visualParent: root.visualParent + property Item mainItem: inlineDialogMainItem + onStatusChanged: root.status = status + + Item { + id: inlineDialogMainItem + width: dialogLayout.width + height: dialogLayout.height + } + + Component.onCompleted: { + dialogLayout.parent = inlineDialogMainItem + } + Component.onDestruction: dialogLayout.parent = root + } + } + + Item { + id: dialogLayout + width: theme.defaultFont.mSize.width * 40 + height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8 + + parent: internalLoader.dialog ? internalLoader.dialog : internalLoader.inlineDialog + // 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 + } } } } diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/QueryDialog.qml b/declarativeimports/plasmacomponents/qml/QueryDialog.qml similarity index 98% rename from declarativeimports/plasmacomponents/platformcomponents/touch/QueryDialog.qml rename to declarativeimports/plasmacomponents/qml/QueryDialog.qml index 8f962d93a..d95c8b2f8 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/QueryDialog.qml +++ b/declarativeimports/plasmacomponents/qml/QueryDialog.qml @@ -57,9 +57,9 @@ CommonDialog { onButtonClicked: { if (acceptButtonText && index == 0) - accepted() + accept() else - rejected() + reject() } content: Item { diff --git a/declarativeimports/plasmacomponents/qml/private/InlineDialog.qml b/declarativeimports/plasmacomponents/qml/private/InlineDialog.qml new file mode 100644 index 000000000..2ea740c14 --- /dev/null +++ b/declarativeimports/plasmacomponents/qml/private/InlineDialog.qml @@ -0,0 +1,146 @@ +/* + * Copyright 2012 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library 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. + */ + +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents + +Item { + id: root + property Item visualParent + z: 9000 + property int status: PlasmaComponents.DialogStatus.Closed + default property alias data: contentItem.data + + function open() + { + if (root.visualParent) { + internal.parentPos = root.visualParent.mapToItem(dismissArea.parent, 0, 0) + } + root.status = PlasmaComponents.DialogStatus.Opening + appearAnimation.running = true + } + + function close() + { + root.status = PlasmaComponents.DialogStatus.Closing + appearAnimation.running = true + } + + SequentialAnimation { + id: appearAnimation + NumberAnimation { + duration: 250 + easing.type: Easing.InOutQuad + target: dismissArea + properties: "opacity" + to: root.status == PlasmaComponents.DialogStatus.Opening ? 1 : 0 + } + ScriptAction { + script: root.status == PlasmaComponents.DialogStatus.Opening ? root.status = PlasmaComponents.DialogStatus.Open : PlasmaComponents.DialogStatus.Closed + } + } + + MouseArea { + id: dismissArea + z: 9000 + anchors.fill: parent + opacity: 0 + + PlasmaCore.FrameSvgItem { + id: internal + property variant parentPos + imagePath: "widgets/background" + property bool under: root.visualParent ? internal.parentPos.y + root.visualParent.height + height < dismissArea.height : true + //bindings won't work inside anchers definition + onUnderChanged: { + if (under) { + tipSvg.anchors.top = undefined + tipSvg.anchors.bottom = tipSvg.parent.top + } else { + tipSvg.anchors.bottom = undefined + tipSvg.anchors.top = tipSvg.parent.bottom + } + } + + x: { + if (root.visualParent) { + internal.parentPos.x - internal.width/2 + root.visualParent.width/2 + } else { + dismissArea.width/2 - internal.width/2 + } + } + y: { + if (root.visualParent) { + if (under) { + internal.parentPos.y + root.visualParent.height + } else { + internal.parentPos.y - internal.height + } + } else { + dismissArea.height/2 - internal.height/2 + } + } + width: contentItem.width + margins.left + margins.right + height: contentItem.height + margins.top + margins.bottom + + PlasmaCore.SvgItem { + id: tipSvg + visible: root.visualParent != null + svg: PlasmaCore.Svg { + id: backgroundSvg + imagePath: "widgets/background" + } + elementId: internal.under ? "baloon-tip-top" : "baloon-tip-bottom" + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.top + top: parent.bottom + topMargin: -backgroundSvg.elementSize("hint-bottom-shadow").height + bottomMargin: -backgroundSvg.elementSize("hint-top-shadow").height + } + width: naturalSize.width + height: naturalSize.height + } + MouseArea { + id: contentItem + x: parent.margins.left + y: parent.margins.top + width: childrenRect.width + height: childrenRect.height + onClicked: mouse.accepted = true + } + } + onClicked: { + root.close() + } + Component.onCompleted: { + var candidate = root + while (candidate.parent) { + candidate = candidate.parent + } + if (candidate) { + dismissArea.parent = candidate + } else { + dismissArea.visible = false + } + internal.parentPos = root.mapToItem(dismissArea.parent, 0, 0) + } + } +} diff --git a/declarativeimports/plasmacomponents/qml/qmldir b/declarativeimports/plasmacomponents/qml/qmldir index 41e75bb44..542aa7c10 100644 --- a/declarativeimports/plasmacomponents/qml/qmldir +++ b/declarativeimports/plasmacomponents/qml/qmldir @@ -15,6 +15,7 @@ ListItem 0.1 ListItem.qml Page 0.1 Page.qml PageStack 0.1 PageStack.qml ProgressBar 0.1 ProgressBar.qml +QueryDialog 0.1 QueryDialog.qml RadioButton 0.1 RadioButton.qml ScrollBar 0.1 ScrollBar.qml SectionScroller 0.1 SectionScroller.qml