diff --git a/scriptengines/qml/plasmoid/appletinterface.cpp b/scriptengines/qml/plasmoid/appletinterface.cpp index f5b421178..925278d12 100644 --- a/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/scriptengines/qml/plasmoid/appletinterface.cpp @@ -49,7 +49,8 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa m_appletScriptEngine(script), m_actionSignals(0), m_backgroundHints(Plasma::StandardBackground), - m_busy(false) + m_busy(false), + m_expanded(false) { qmlRegisterType(); connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus())); @@ -120,6 +121,23 @@ void AppletInterface::setBusy(bool busy) emit busyChanged(); } +bool AppletInterface::isExpanded() const +{ + return m_expanded; +} + +void AppletInterface::setExpanded(bool expanded) +{ + //if there is no compact representation it means it's always expanded + //Containnments are always expanded + if (!m_compactUiObject || qobject_cast(this) || m_expanded == expanded) { + return; + } + + m_expanded = expanded; + emit expandedChanged(); +} + AppletInterface::BackgroundHints AppletInterface::backgroundHints() const { return (BackgroundHints)m_backgroundHints; @@ -377,13 +395,15 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o 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) { + m_expanded = false; + //we are already an icon: nothing to do if (m_compactUiObject) { return; @@ -391,12 +411,30 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), this); component->loadUrl(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("ui", "CompactApplet.qml"))); - m_compactUiObject = component->create(); + m_compactUiObject = component->create(m_appletScriptEngine->engine()->rootContext()); + QObject *compactRepresentation = 0; + + //build the icon representation if (m_compactUiObject) { + QQmlComponent *compactComponent = new QQmlComponent(m_appletScriptEngine->engine(), this); + compactComponent->loadUrl(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("ui", "DefaultCompactRepresentation.qml"))); + compactRepresentation = compactComponent->create(m_appletScriptEngine->engine()->rootContext()); + if (compactRepresentation) { + compactComponent->setParent(compactRepresentation); + } else { + delete compactComponent; + } + } + + if (m_compactUiObject && compactRepresentation) { //for memory management component->setParent(m_compactUiObject.data()); + //put compactRepresentation in the icon place + compactRepresentation->setProperty("parent", QVariant::fromValue(m_compactUiObject.data())); + m_compactUiObject.data()->setProperty("compactRepresentation", QVariant::fromValue(compactRepresentation)); + //replace the full applet with the collapsed view m_compactUiObject.data()->setProperty("visible", true); m_compactUiObject.data()->setProperty("parent", QVariant::fromValue(this)); @@ -408,13 +446,19 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o 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 + //failed to create UI, don't do anything, return in expanded status } else { qWarning() << component->errors(); + m_expanded = true; delete component; } + emit expandedChanged(); + } else { + m_expanded = true; + emit expandedChanged(); + //we are already expanded: nothing to do if (!m_compactUiObject) { return; diff --git a/scriptengines/qml/plasmoid/appletinterface.h b/scriptengines/qml/plasmoid/appletinterface.h index 1598304d7..59e7620e4 100644 --- a/scriptengines/qml/plasmoid/appletinterface.h +++ b/scriptengines/qml/plasmoid/appletinterface.h @@ -59,6 +59,7 @@ class AppletInterface : public QQuickItem Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged) Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig) Q_PROPERTY(bool busy WRITE setBusy READ isBusy NOTIFY busyChanged) + Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged) Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints NOTIFY backgroundHintsChanged) Q_PROPERTY(bool immutable READ immutable NOTIFY immutableChanged) Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5 @@ -185,6 +186,9 @@ enum IntervalAlignment { bool isBusy() const; void setBusy(bool busy); + bool isExpanded() const; + void setExpanded(bool expanded); + BackgroundHints backgroundHints() const; void setBackgroundHints(BackgroundHints hint); @@ -213,6 +217,7 @@ Q_SIGNALS: void statusChanged(); void backgroundHintsChanged(); void busyChanged(); + void expandedChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -232,6 +237,7 @@ private: Plasma::BackgroundHints m_backgroundHints; bool m_busy : 1; + bool m_expanded : 1; }; diff --git a/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 387b0f52c..d4c005c9a 100644 --- a/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -115,7 +115,6 @@ bool DeclarativeAppletScript::init() Plasma::Containment *cont = qobject_cast(a); - if (cont) { m_interface = new ContainmentInterface(this); //fail? so it's a normal Applet diff --git a/shell/qmlpackages/desktop/contents/ui/CompactApplet.qml b/shell/qmlpackages/desktop/contents/ui/CompactApplet.qml index 523536b51..775a3895b 100644 --- a/shell/qmlpackages/desktop/contents/ui/CompactApplet.qml +++ b/shell/qmlpackages/desktop/contents/ui/CompactApplet.qml @@ -22,24 +22,28 @@ import QtQuick.Window 2.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.components 0.1 as PlasmaComponents -Rectangle { +Item { id: root - color: "darkgreen" property Item applet + property Item compactRepresentation onAppletChanged: applet.parent = appletParent - - - MouseArea { - anchors.fill: parent - onClicked: popupWindow.visible = !popupWindow.visible + onCompactRepresentationChanged: { + compactRepresentation.parent = root + compactRepresentation.anchors.fill = root } + Window { id: popupWindow - visible: false + visible: plasmoid.expanded + onVisibleChanged: { + if (!visible) { + plasmoid.expanded = false + } + } width: 200 height: 200 Item { diff --git a/shell/qmlpackages/desktop/contents/ui/DefaultCompactRepresentation.qml b/shell/qmlpackages/desktop/contents/ui/DefaultCompactRepresentation.qml new file mode 100644 index 000000000..02a5e8b05 --- /dev/null +++ b/shell/qmlpackages/desktop/contents/ui/DefaultCompactRepresentation.qml @@ -0,0 +1,31 @@ +/* + * 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.core 0.1 as PlasmaCore + +Rectangle { + id: root + color: "darkgreen" + + MouseArea { + anchors.fill: parent + onClicked: plasmoid.expanded = !plasmoid.expanded + } +} \ No newline at end of file diff --git a/shell/testcontainment/contents/ui/main.qml b/shell/testcontainment/contents/ui/main.qml index f26b84526..199280832 100644 --- a/shell/testcontainment/contents/ui/main.qml +++ b/shell/testcontainment/contents/ui/main.qml @@ -57,7 +57,7 @@ Rectangle { height: large property alias applet: appletContainer.children - property int small: 100 + property int small: 90 property int large: root.width /2 imagePath: applet[0].backgroundHints == 0 ? "" : "widgets/background" MouseArea {