From cfe6a40d3d383eacb2479f82ae091fd7922622dd Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 22 Feb 2013 15:06:44 +0100 Subject: [PATCH] ad a stub config ui the config ui layout will be decided from the corona. the desktop one will end up having desktop components still missing: * binding to plasmoid object * way close the dialog * use ok/apply/cancel * how to implement difference between ok to apply and instant apply? --- src/plasma/applet.cpp | 4 +- .../qml/plasmoid/appletinterface.cpp | 40 +++++++ .../qml/plasmoid/appletinterface.h | 8 +- .../desktop/contents/ui/Configuration.qml | 113 ++++++++++++++++++ 4 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 src/shell/qmlpackages/desktop/contents/ui/Configuration.qml diff --git a/src/plasma/applet.cpp b/src/plasma/applet.cpp index ee8fd0115..0713f7c05 100644 --- a/src/plasma/applet.cpp +++ b/src/plasma/applet.cpp @@ -489,11 +489,11 @@ void Applet::flushPendingConstraintsEvents() QAction *configAction = d->actions->action("configure"); if (configAction) { - if (d->isContainment) { + /*if (d->isContainment) { connect(configAction, SIGNAL(triggered(bool)), this, SLOT(requestConfiguration()), Qt::UniqueConnection); } else { connect(configAction, SIGNAL(triggered(bool)), this, SLOT(showConfigurationInterface()), Qt::UniqueConnection); - } + }*/ if (d->hasConfigurationInterface) { bool canConfig = unlocked || KAuthorized::authorize("plasma/allow_configure_when_locked"); diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index f64ef9df7..0012e83c7 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -74,6 +74,9 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa connect(m_appletScriptEngine, SIGNAL(contextChanged()), this, SIGNAL(contextChanged())); + connect(applet()->action("configure"), &QAction::triggered, + this, &AppletInterface::configureTriggered); + m_qmlObject = new QmlObject(this); m_qmlObject->setInitializationDelayed(true); @@ -596,4 +599,41 @@ QmlObject *AppletInterface::qmlObject() return m_qmlObject; } +void AppletInterface::configureTriggered() +{ + setConfigurationInterfaceShown(true); +} + +void AppletInterface::setConfigurationInterfaceShown(bool show) +{ + if (!applet()->containment() || !applet()->containment()->corona()) { + return; + } + + if (show) { + if (m_configView) { + m_configView.data()->show(); + return; + } else { + m_configView = new QQuickView(); + //FIXME: problem on nvidia, all windows should be transparent or won't show + m_configView.data()->setColor(Qt::transparent); + m_configView.data()->setTitle(i18n("%1 Settings", applet()->title())); + } + + if (!applet()->containment()->corona()->package().isValid()) { + qWarning() << "Invalid home screen package"; + } + + m_configView.data()->setResizeMode(QQuickView::SizeRootObjectToView); + m_configView.data()->setSource(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("ui", "Configuration.qml"))); + m_configView.data()->show(); + } else { + if (m_configView) { + m_configView.data()->hide(); + m_configView.data()->deleteLater(); + } + } +} + #include "moc_appletinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index c559bd5cf..16585c7db 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -226,13 +227,15 @@ Q_SIGNALS: void busyChanged(); void expandedChanged(); -//it's important this slot is private because must not be invokable by qml -public Q_SLOTS: +//it's important those slots are private because must not be invokable by qml +private Q_SLOTS: void init(); + void configureTriggered(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void itemChange(ItemChange change, const ItemChangeData &value); + void setConfigurationInterfaceShown(bool show); DeclarativeAppletScript *m_appletScriptEngine; @@ -248,6 +251,7 @@ private: //UI-specific members ------------------ QmlObject *m_qmlObject; QWeakPointer m_compactUiObject; + QWeakPointer m_configView; QTimer *m_creationTimer; diff --git a/src/shell/qmlpackages/desktop/contents/ui/Configuration.qml b/src/shell/qmlpackages/desktop/contents/ui/Configuration.qml new file mode 100644 index 000000000..a9eb0c95a --- /dev/null +++ b/src/shell/qmlpackages/desktop/contents/ui/Configuration.qml @@ -0,0 +1,113 @@ +/* + * Copyright 2013 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. + */ + +import QtQuick 2.0 +import org.kde.plasma.components 0.1 as PlasmaComponents +import org.kde.plasma.extras 0.1 as PlasmaExtras +import org.kde.plasma.core 0.1 as PlasmaCore + +//TODO: all of this will be done with desktop components +Rectangle { + id: root + color: "lightgray" + width: 640 + height: 480 + + Column { + anchors.fill: parent + Row { + anchors { + left: parent.left + right: parent.right + } + height: parent.height - buttonsRow.height + PlasmaExtras.ScrollArea { + id: categoriesScroll + anchors { + top: parent.top + bottom: parent.bottom + } + width: 100 + Flickable { + contentWidth: width + contentHeight: categoriesColumn.height + Column { + id: categoriesColumn + width: parent.width + Column { + anchors { + left: parent.left + right: parent.right + } + PlasmaCore.IconItem { + anchors.horizontalCenter: parent.horizontalCenter + width: theme.IconSizeHuge + height: width + source: "preferences-desktop-keyboard" + } + PlasmaComponents.Label { + text: "Keyboard shortcut" + wrapMode: Text.Wrap + horizontalAlignment: Text.alignHCenter + } + } + } + } + } + PlasmaExtras.ScrollArea { + anchors { + top: parent.top + bottom: parent.bottom + } + width: parent.width - categoriesScroll.width + Flickable { + contentWidth: width + contentHeight: main.height + Item { + id: main + width: parent.width + height: childrenRect.height + Text { + text: "Configuration goes here" + } + } + } + } + } + Row { + id: buttonsRow + spacing: 4 + anchors { + right: parent.right + rightMargin: spacing + } + PlasmaComponents.Button { + iconSource: "dialog-ok" + text: "Ok" + } + PlasmaComponents.Button { + iconSource: "dialog-ok-apply" + text: "Apply" + } + PlasmaComponents.Button { + iconSource: "dialog-cancel" + text: "Cancel" + } + } + } +}