From 1263ada92a6eea7771f9d4021a75e9357b1c6db1 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 13 Feb 2013 17:36:38 +0100 Subject: [PATCH] primitive support for popups. is now using the horrible Window elements, when Dialog will be portedit will look definitely less broken --- .../qml/plasmoid/appletinterface.cpp | 60 +++++++++++++++++++ scriptengines/qml/plasmoid/appletinterface.h | 3 + .../desktop/contents/ui/CompactApplet.qml | 51 ++++++++++++++++ shell/testcontainment/contents/ui/main.qml | 11 ++-- 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 shell/qmlpackages/desktop/contents/ui/CompactApplet.qml diff --git a/scriptengines/qml/plasmoid/appletinterface.cpp b/scriptengines/qml/plasmoid/appletinterface.cpp index b8963f42e..f5b421178 100644 --- a/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/scriptengines/qml/plasmoid/appletinterface.cpp @@ -372,6 +372,65 @@ QStringList AppletInterface::downloadedFiles() const return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable); } +void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_UNUSED(oldGeometry) + + QQuickItem::geometryChanged(newGeometry, oldGeometry); + + if (!m_uiObject || qobject_cast(this)) { + return; + } + + //TODO: completely arbitrary for now + if (newGeometry.width() < 100 || newGeometry.height() < 100) { + //we are already an icon: nothing to do + if (m_compactUiObject) { + return; + } + + QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), this); + component->loadUrl(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("ui", "CompactApplet.qml"))); + m_compactUiObject = component->create(); + + if (m_compactUiObject) { + //for memory management + component->setParent(m_compactUiObject.data()); + + //replace the full applet with the collapsed view + m_compactUiObject.data()->setProperty("visible", true); + m_compactUiObject.data()->setProperty("parent", QVariant::fromValue(this)); + //set anchors + QQmlExpression expr(m_appletScriptEngine->engine()->rootContext(), m_compactUiObject.data(), "parent"); + QQmlProperty prop(m_compactUiObject.data(), "anchors.fill"); + prop.write(expr.evaluate()); + + m_uiObject.data()->setProperty("parent", QVariant::fromValue(m_compactUiObject.data())); + m_compactUiObject.data()->setProperty("applet", QVariant::fromValue(m_uiObject.data())); + + //failed to create UI, don't do anything + } else { + qWarning() << component->errors(); + delete component; + } + + } else { + //we are already expanded: nothing to do + if (!m_compactUiObject) { + return; + } + + m_uiObject.data()->setProperty("parent", QVariant::fromValue(this)); + m_compactUiObject.data()->deleteLater(); + } +} + + + + + + + ///////////// ContainmentInterface @@ -463,6 +522,7 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPoi if (applet && contGraphicObject && appletGraphicObject) { appletGraphicObject->setProperty("visible", false); appletGraphicObject->setProperty("parent", QVariant::fromValue(contGraphicObject)); + //if an appletGraphicObject is not set, we have to display some error message } else if (applet && contGraphicObject) { QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), applet); diff --git a/scriptengines/qml/plasmoid/appletinterface.h b/scriptengines/qml/plasmoid/appletinterface.h index 3456c4a18..1598304d7 100644 --- a/scriptengines/qml/plasmoid/appletinterface.h +++ b/scriptengines/qml/plasmoid/appletinterface.h @@ -215,6 +215,8 @@ Q_SIGNALS: void busyChanged(); protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + DeclarativeAppletScript *m_appletScriptEngine; private: @@ -226,6 +228,7 @@ private: //UI-specific members ------------------ QWeakPointer m_uiObject; + QWeakPointer m_compactUiObject; Plasma::BackgroundHints m_backgroundHints; bool m_busy : 1; diff --git a/shell/qmlpackages/desktop/contents/ui/CompactApplet.qml b/shell/qmlpackages/desktop/contents/ui/CompactApplet.qml new file mode 100644 index 000000000..523536b51 --- /dev/null +++ b/shell/qmlpackages/desktop/contents/ui/CompactApplet.qml @@ -0,0 +1,51 @@ +/* + * 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 QtQuick.Window 2.0 + +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents + +Rectangle { + id: root + color: "darkgreen" + + property Item applet + + + onAppletChanged: applet.parent = appletParent + + + MouseArea { + anchors.fill: parent + onClicked: popupWindow.visible = !popupWindow.visible + } + + Window { + id: popupWindow + visible: false + width: 200 + height: 200 + Item { + id: appletParent + width: applet.implicitWidth + height: applet.implicitHeight + } + } +} diff --git a/shell/testcontainment/contents/ui/main.qml b/shell/testcontainment/contents/ui/main.qml index 8dd2817d9..199c3af67 100644 --- a/shell/testcontainment/contents/ui/main.qml +++ b/shell/testcontainment/contents/ui/main.qml @@ -53,23 +53,26 @@ Rectangle { id: frame x: 50 y: 50 - width: 150 - height: 150 + width: 200 + height: 200 + property alias applet: appletContainer.children property int small: 100 - property int large: parent.width - width - 150 + property int large: root.width /2 imagePath: applet[0].backgroundHints == 0 ? "" : "widgets/background" MouseArea { anchors.fill: parent drag.target: parent onClicked: { - var s = (frame.x == frame.large) ? frame.small : frame.large; + var s = (frame.width == frame.large) ? frame.small : frame.large; frame.x = s frame.height = s + frame.width = s } } Behavior on x { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } } //Behavior on y { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } } + Behavior on width { PropertyAnimation { easing.type: Easing.InOutDouble; duration: 300 } } Behavior on height { PropertyAnimation { easing.type: Easing.InOutDouble; duration: 300 } } Item {