From 866fe4312045aac6dada8bb3894e24c82fe9d417 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Jan 2014 18:26:46 +0100 Subject: [PATCH 01/31] experiment with AppletInterface to be attached Plasmoid.title etc would be attached properties to the root object instead of being a component itself --- .../applets/widgetgallery/contents/ui/main.qml | 4 ++++ src/scriptengines/qml/plasmoid/appletinterface.cpp | 5 +++++ src/scriptengines/qml/plasmoid/appletinterface.h | 14 +++++++++++++- .../qml/plasmoid/declarativeappletscript.cpp | 4 +++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/examples/applets/widgetgallery/contents/ui/main.qml b/examples/applets/widgetgallery/contents/ui/main.qml index 723c7240c..f586741fc 100644 --- a/examples/applets/widgetgallery/contents/ui/main.qml +++ b/examples/applets/widgetgallery/contents/ui/main.qml @@ -19,14 +19,18 @@ import QtQuick 2.0 import org.kde.plasma.components 2.0 +import org.kde.shell 2.0 Item { property int minimumWidth: 300 property int minimumHeight: 400 + AppletInterface.title: "bah" + ToolBar { id: toolBar z: 10 + //AppletInterface.title: "bah" anchors { top: parent.top left: parent.left diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index eac58b51c..5376aa46b 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -52,6 +52,8 @@ Q_DECLARE_METATYPE(AppletInterface*) +QHash AppletInterface::s_rootObjects = QHash(); + AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent) : QQuickItem(parent), m_appletScriptEngine(script), @@ -96,6 +98,7 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa AppletInterface::~AppletInterface() { + s_rootObjects.remove(m_qmlObject->engine()); } void AppletInterface::init() @@ -109,6 +112,8 @@ void AppletInterface::init() //use our own custom network access manager that will access Plasma packages and to manage security (i.e. deny access to remote stuff when the proper extension isn't enabled QQmlEngine *engine = m_qmlObject->engine(); + s_rootObjects[m_qmlObject->engine()] = this; + //Hook generic url resolution to the applet package as well //TODO: same thing will have to be done for every qqmlengine: PackageUrlInterceptor is material for plasmaquick? PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, m_appletScriptEngine->package()); diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 7714689fa..466a9dcdd 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -237,7 +237,15 @@ public: * DEPRECATED: use plasmoid.configuration instead */ Q_INVOKABLE void writeConfig(const QString &entry, const QVariant &value); - + + static AppletInterface *qmlAttachedProperties(QObject *object) + { + if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) { + return s_rootObjects.value(QtQml::qmlEngine(object)); + } else { + return 0; + } + } //PROPERTY ACCESSORS------------------------------------------------------------------- QString icon() const; @@ -361,6 +369,10 @@ private: bool m_expanded : 1; bool m_hideOnDeactivate : 1; friend class ContainmentInterface; + + static QHash s_rootObjects; }; +QML_DECLARE_TYPEINFO(AppletInterface, QML_HAS_ATTACHED_PROPERTIES) + #endif diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 9876e8c7c..4c64df507 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -54,7 +54,9 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant : Plasma::AppletScript(parent), m_interface(0) { - qmlRegisterType(); + //qmlRegisterType(); + qmlRegisterUncreatableType("org.kde.shell", 2, 0, "AppletInterface", + QLatin1String("Do not create objects of type AppletInterface")); qmlRegisterType(); Q_UNUSED(args); } From 075d55c84240f8f5f4f4eee0006567d053a93977 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Jan 2014 22:55:02 +0100 Subject: [PATCH 02/31] entation switching done by appletloader --- .../widgetgallery/contents/ui/main.qml | 11 +- src/scriptengines/qml/CMakeLists.txt | 3 + .../qml/plasmoid/appletinterface.cpp | 15 +- .../qml/plasmoid/appletinterface.h | 8 +- .../qml/plasmoid/appletloader.cpp | 532 ++++++++++++++++++ src/scriptengines/qml/plasmoid/appletloader.h | 169 ++++++ .../qml/plasmoid/declarativeappletscript.cpp | 4 +- 7 files changed, 725 insertions(+), 17 deletions(-) create mode 100644 src/scriptengines/qml/plasmoid/appletloader.cpp create mode 100644 src/scriptengines/qml/plasmoid/appletloader.h diff --git a/examples/applets/widgetgallery/contents/ui/main.qml b/examples/applets/widgetgallery/contents/ui/main.qml index f586741fc..6c0e0ea81 100644 --- a/examples/applets/widgetgallery/contents/ui/main.qml +++ b/examples/applets/widgetgallery/contents/ui/main.qml @@ -18,14 +18,17 @@ */ import QtQuick 2.0 +import QtQuick.Layouts 1.1 import org.kde.plasma.components 2.0 -import org.kde.shell 2.0 +import org.kde.plasma.shell 2.0 Item { - property int minimumWidth: 300 - property int minimumHeight: 400 + Layout.minimumWidth: 300 + Layout.minimumHeight: 400 - AppletInterface.title: "bah" + Plasmoid.title: "bah" + Plasmoid.switchWidth: 300 + Plasmoid.switchHeight: 400 ToolBar { id: toolBar diff --git a/src/scriptengines/qml/CMakeLists.txt b/src/scriptengines/qml/CMakeLists.txt index 0a60665ae..75dc8cf4c 100644 --- a/src/scriptengines/qml/CMakeLists.txt +++ b/src/scriptengines/qml/CMakeLists.txt @@ -8,6 +8,9 @@ endif() #DECLARATIVE APPLET set(declarative_appletscript_SRCS + plasmoid/declarativeappletscript.cpp + + plasmoid/appletloader.cpp plasmoid/appletinterface.cpp plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 5376aa46b..d1410f4c7 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -55,8 +55,7 @@ Q_DECLARE_METATYPE(AppletInterface*) QHash AppletInterface::s_rootObjects = QHash(); AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent) - : QQuickItem(parent), - m_appletScriptEngine(script), + : AppletLoader(script, parent), m_actionSignals(0), m_backgroundHints(Plasma::Types::StandardBackground), m_busy(false), @@ -93,7 +92,7 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa m_collapseTimer = new QTimer(this); m_collapseTimer->setSingleShot(true); - connect(m_collapseTimer, &QTimer::timeout, this, &AppletInterface::compactRepresentationCheck); + //connect(m_collapseTimer, &QTimer::timeout, this, &AppletInterface::compactRepresentationCheck); } AppletInterface::~AppletInterface() @@ -103,6 +102,8 @@ AppletInterface::~AppletInterface() void AppletInterface::init() { + AppletLoader::init(); + if (m_qmlObject->rootObject()) { return; } @@ -239,7 +240,7 @@ 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) { + if (/*!m_compactUiObject ||*/ qobject_cast(this) || m_expanded == expanded) { return; } @@ -610,11 +611,11 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o { Q_UNUSED(oldGeometry) - QQuickItem::geometryChanged(newGeometry, oldGeometry); + AppletLoader::geometryChanged(newGeometry, oldGeometry); m_collapseTimer->start(100); } -void AppletInterface::compactRepresentationCheck() +void AppletInterface::_compactRepresentationCheck() { if (width() <= 0 || height() <= 0 || !m_qmlObject->rootObject() || qobject_cast(this)) { @@ -839,7 +840,7 @@ void AppletInterface::itemChange(ItemChange change, const ItemChangeData &value) init(); } } - QQuickItem::itemChange(change, value); + AppletLoader::itemChange(change, value); } KDeclarative::QmlObject *AppletInterface::qmlObject() diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 466a9dcdd..1f23ed6a3 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -29,6 +29,7 @@ #include #include +#include "appletloader.h" #include "declarativeappletscript.h" class QAction; @@ -48,7 +49,7 @@ namespace Plasma class ConfigLoader; } // namespace Plasma -class AppletInterface : public QQuickItem +class AppletInterface : public AppletLoader { Q_OBJECT @@ -335,13 +336,13 @@ protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void itemChange(ItemChange change, const ItemChangeData &value); - DeclarativeAppletScript *m_appletScriptEngine; + protected Q_SLOTS: virtual void init(); private Q_SLOTS: - void compactRepresentationCheck(); + void _compactRepresentationCheck(); void updatePopupSize(); void updateImplicitWidth(); void updateImplicitHeight(); @@ -359,7 +360,6 @@ private: KDeclarative::ConfigPropertyMap *m_configuration; //UI-specific members ------------------ - KDeclarative::QmlObject *m_qmlObject; QWeakPointer m_compactUiObject; QTimer *m_collapseTimer; diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp new file mode 100644 index 000000000..cd91493c2 --- /dev/null +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -0,0 +1,532 @@ +/* + * Copyright 2014 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 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 "appletloader.h" + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + + + +AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) + : QQuickItem(parent), + m_switchWidth(-1), + m_switchHeight(-1), + m_appletScriptEngine(script) +{ + m_compactRepresentationCheckTimer.setSingleShot(true); + m_compactRepresentationCheckTimer.setInterval(250); + connect (&m_compactRepresentationCheckTimer, SIGNAL(timeout()), + this, SLOT(compactRepresentationCheck())); + m_compactRepresentationCheckTimer.start(); + + m_fullRepresentationResizeTimer.setSingleShot(true); + m_fullRepresentationResizeTimer.setInterval(250); + connect (&m_fullRepresentationResizeTimer, &QTimer::timeout, + [=]() { + KConfigGroup cg = applet()->config(); + cg = KConfigGroup(&cg, "PopupApplet"); + cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt()); + cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt()); + } + ); + + //hide all the children that aren't the known ones. + //all the UI is supposed to happen in the representations + /* connect (this, &QQuickItem::childrenChanged, [=]() { + foreach (QQuickItem *child, childItems()) { + if (child != m_compactRepresentationItem.data() && + child != m_fullRepresentationItem.data() && + child != m_compactRepresentationExpanderItem.data()) { + child->setVisible(false); + } + } + });*/ + + + + m_applet = m_appletScriptEngine->applet(); + + m_qmlObject = new KDeclarative::QmlObject(this); +} + +AppletLoader::~AppletLoader() +{ +} + +Plasma::Applet *AppletLoader::applet() const +{ + return m_applet; +} + +Plasma::AppletScript *AppletLoader::appletScript() +{ + return m_appletScriptEngine; +} + +int AppletLoader::switchWidth() const +{ + return m_switchWidth; +} + +void AppletLoader::setSwitchWidth(int width) +{ + if (m_switchWidth == width) { + return; + } + + m_switchWidth = width; + emit switchWidthChanged(width); +} + +int AppletLoader::switchHeight() const +{ + return m_switchHeight; +} + +void AppletLoader::setSwitchHeight(int width) +{ + if (m_switchHeight == width) { + return; + } + + m_switchHeight = width; + emit switchHeightChanged(width); +} + +QQmlComponent *AppletLoader::compactRepresentation() +{ + return m_compactRepresentation.data(); +} + +void AppletLoader::setCompactRepresentation(QQmlComponent *component) +{ + if (m_compactRepresentation.data() == component) { + return; + } + + m_compactRepresentation = component; + emit compactRepresentationChanged(component); +} + + +QQmlComponent *AppletLoader::fullRepresentation() +{ + return m_fullRepresentation.data(); +} + +void AppletLoader::setFullRepresentation(QQmlComponent *component) +{ + if (m_fullRepresentation.data() == component) { + return; + } + + m_fullRepresentation = component; + emit fullRepresentationChanged(component); +} + +QQmlComponent *AppletLoader::preferredRepresentation() +{ + return m_preferredRepresentation.data(); +} + +void AppletLoader::setPreferredRepresentation(QQmlComponent *component) +{ + if (m_preferredRepresentation.data() == component) { + return; + } + + m_preferredRepresentation = component; + emit preferredRepresentationChanged(component); +} + + +////////////Internals + +void AppletLoader::classBegin() +{ + Q_ASSERT(m_qmlObject->engine()); + m_qmlObject->engine()->rootContext()->setContextProperty("plasmoid", this); + +} + +void AppletLoader::init() +{ + //m_appletScriptEngine = property("_plasma_appletscript").value(); + + Q_ASSERT(m_appletScriptEngine); + // m_applet = m_appletScriptEngine->applet(); + Q_ASSERT(m_applet); + + // m_qmlObject = new KDeclarative::QmlObject(m_qmlObject->engine(), this); + + //default m_compactRepresentation is a simple icon provided by the shell package + if (!m_compactRepresentation) { + m_compactRepresentation = new QQmlComponent(m_qmlObject->engine(), this); + m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("defaultcompactrepresentation"))); + } + + //we really want a full representation, default m_fullRepresentation is an error message + /* if (!m_fullRepresentation) { + m_fullRepresentation = new QQmlComponent(m_qmlObject->engine(), this); + m_fullRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("appleterror"))); + }*/ + + //default m_compactRepresentationExpander is the popup in which fullRepresentation goes + if (!m_compactRepresentationExpander) { + m_compactRepresentationExpander = new QQmlComponent(m_qmlObject->engine(), this); + m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("compactapplet"))); + } + +} + + + +KDeclarative::QmlObject *AppletLoader::qmlObject() +{ + return m_qmlObject; +} + +QObject *AppletLoader::compactRepresentationItem() +{ + return m_compactRepresentationItem.data(); +} + +QObject *AppletLoader::fullRepresentationItem() +{ + return m_fullRepresentationItem.data(); +} + +QObject *AppletLoader::compactRepresentationExpanderItem() +{ + return m_compactRepresentationExpanderItem.data(); +} + + + +QObject *AppletLoader::createCompactRepresentationItem() +{ + if (!m_compactRepresentation) { + return 0; + } + + if (m_compactRepresentationItem) { + return m_compactRepresentationItem.data(); + } + + m_compactRepresentationItem = m_qmlObject->createObjectFromComponent(m_compactRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject())); + + emit compactRepresentationItemChanged(m_compactRepresentationItem.data()); + + return m_compactRepresentationItem.data(); +} + +QObject *AppletLoader::createFullRepresentationItem() +{ + if (m_fullRepresentationItem) { + return m_fullRepresentationItem.data(); + } + + if (m_fullRepresentation) { + m_fullRepresentationItem = m_qmlObject->createObjectFromComponent(m_fullRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject())); + } else { + m_fullRepresentationItem = m_qmlObject->rootObject(); + } + + QQuickItem *graphicsObj = qobject_cast(m_fullRepresentationItem.data()); + connect (graphicsObj, &QQuickItem::widthChanged, [=]() { + m_fullRepresentationResizeTimer.start(); + }); + connect (graphicsObj, &QQuickItem::heightChanged, [=]() { + m_fullRepresentationResizeTimer.start(); + }); + + emit fullRepresentationItemChanged(m_fullRepresentationItem.data()); + + return m_fullRepresentationItem.data(); +} + +QObject *AppletLoader::createCompactRepresentationExpanderItem() +{ + if (!m_compactRepresentationExpander) { + return 0; + } + + if (m_compactRepresentationExpanderItem) { + return m_compactRepresentationExpanderItem.data(); + } + + m_compactRepresentationExpanderItem = m_qmlObject->createObjectFromComponent(m_compactRepresentationExpander.data(), QtQml::qmlContext(m_qmlObject->rootObject())); + + emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpanderItem.data()); + + return m_compactRepresentationExpanderItem.data(); +} + +void AppletLoader::connectLayoutAttached(QObject *item) +{ + QObject *layout = 0; + + //Extract the representation's Layout, if any + //No Item? + if (!item) { + return; + } + + //Search a child that has the needed Layout properties + //HACK: here we are not type safe, but is the only way to access to a pointer of Layout + foreach (QObject *child, item->children()) { + //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight + if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && + child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && + child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && + child->property("fillWidth").isValid() && child->property("fillHeight").isValid() + ) { + layout = child; + } + } + + if (!layout) { + return; + } + + //propagate all the size hints + propagateSizeHint("minimumWidth"); + propagateSizeHint("minimumHeight"); + propagateSizeHint("preferredWidth"); + propagateSizeHint("preferredHeight"); + propagateSizeHint("maximumWidth"); + propagateSizeHint("maximumHeight"); + propagateSizeHint("fillWidth"); + propagateSizeHint("fillHeight"); + + //HACK: check the Layout properties we wrote + QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(m_qmlObject->rootObject())); + QObject *ownLayout = p.object(); + + //this should never happen, since we ask to create it if doesn't exists + if (!ownLayout) { + return; + } + + //if the representation didn't change, don't do anything + if (m_representationLayout.data() == layout || + m_ownLayout.data() == ownLayout) { + return; + } + + disconnect(layout, 0, this, 0); + + //Here we can't use the new connect syntax because we can't link against QtQuick layouts + connect(layout, SIGNAL(minimumWidthChanged()), + this, SLOT(minimumWidthChanged())); + connect(layout, SIGNAL(minimumHeightChanged()), + this, SLOT(minimumHeightChanged())); + + connect(layout, SIGNAL(preferredWidthChanged()), + this, SLOT(preferredWidthChanged())); + connect(layout, SIGNAL(preferredHeightChanged()), + this, SLOT(preferredHeightChanged())); + + connect(layout, SIGNAL(maximumWidthChanged()), + this, SLOT(maximumWidthChanged())); + connect(layout, SIGNAL(maximumHeightChanged()), + this, SLOT(maximumHeightChanged())); + + connect(layout, SIGNAL(fillWidthChanged()), + this, SLOT(fillWidthChanged())); + connect(layout, SIGNAL(fillHeightChanged()), + this, SLOT(fillHeightChanged())); + + m_representationLayout = layout; + m_ownLayout = ownLayout; +} + +void AppletLoader::propagateSizeHint(const QByteArray &layoutProperty) +{ + if (!m_currentRepresentationItem) { + return; + } + + QQmlExpression *expr = new QQmlExpression(QtQml::qmlContext(m_currentRepresentationItem.data()), m_currentRepresentationItem.data(), "Layout."+layoutProperty); + QQmlProperty prop(this, "Layout."+layoutProperty, QtQml::qmlContext(m_currentRepresentationItem.data())); + prop.write(expr->evaluate()); +} + +void AppletLoader::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_UNUSED(oldGeometry) + + QQuickItem::geometryChanged(newGeometry, oldGeometry); + m_compactRepresentationCheckTimer.start(); +} + +void AppletLoader::itemChange(ItemChange change, const ItemChangeData &value) +{ + if (change == QQuickItem::ItemSceneChange) { + //we have a window: create the representations if needed + if (value.window) { + m_compactRepresentationCheckTimer.start(); + } + } + + QQuickItem::itemChange(change, value); +} + + +//// Slots + +void AppletLoader::compactRepresentationCheck() +{ + //ignore 0,0 sizes; + if (width() <= 0 && height() <= 0) { + return; + } + + bool full = false; + + if (applet()->isContainment()) { + full = true; + + } else { + if (m_switchWidth > 0 && m_switchHeight > 0) { + full = width() > m_switchWidth && height() > m_switchHeight; + //if a size to switch wasn't set, determine what representation to always chose + } else { + //preferred representation set? + if (m_preferredRepresentation) { + full = m_preferredRepresentation.data() == m_fullRepresentation.data(); + //Otherwise, base on FormFactor + } else { + full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical); + } + } + + if ((full && m_fullRepresentationItem && m_fullRepresentationItem.data() == m_currentRepresentationItem.data()) || + (!full && m_compactRepresentationItem && m_compactRepresentationItem.data() == m_currentRepresentationItem.data()) + ) { + return; + } + } + + //Expanded + if (full) { + QQuickItem *item = qobject_cast(createFullRepresentationItem()); + + if (item) { + item->setParentItem(this); + { + //set anchors + QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), item, "parent"); + QQmlProperty prop(item, "anchors.fill"); + prop.write(expr.evaluate()); + } + if (m_compactRepresentationItem) { + m_compactRepresentationItem.data()->setProperty("visible", false); + } + if (m_compactRepresentationExpanderItem) { + m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant()); + m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant()); + } + + m_currentRepresentationItem = item; + connectLayoutAttached(item); + } + + //Icon + } else { + QQuickItem *fullItem = qobject_cast(createFullRepresentationItem()); + QQuickItem *compactItem = qobject_cast(createCompactRepresentationItem()); + QObject *compactExpanderItem = createCompactRepresentationExpanderItem(); + + if (fullItem && compactItem && compactExpanderItem) { + //set the root item as the main visible item + compactItem->setParentItem(this); + compactItem->setVisible(true); + { + //set anchors + QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), compactItem, "parent"); + QQmlProperty prop(compactItem, "anchors.fill"); + prop.write(expr.evaluate()); + } + + compactExpanderItem->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); + compactExpanderItem->setProperty("fullRepresentation", QVariant::fromValue(fullItem)); + m_currentRepresentationItem = compactItem; + connectLayoutAttached(compactItem); + } + } +} + +void AppletLoader::minimumWidthChanged() +{ + propagateSizeHint("minimumWidth"); +} + +void AppletLoader::minimumHeightChanged() +{ + propagateSizeHint("minimumHeight"); +} + +void AppletLoader::preferredWidthChanged() +{ + propagateSizeHint("preferredWidth"); +} + +void AppletLoader::preferredHeightChanged() +{ + propagateSizeHint("preferredHeight"); +} + +void AppletLoader::maximumWidthChanged() +{ + propagateSizeHint("maximumWidth"); +} + +void AppletLoader::maximumHeightChanged() +{ + propagateSizeHint("maximumHeight"); +} + +void AppletLoader::fillWidthChanged() +{ + propagateSizeHint("fillWidth"); +} + +void AppletLoader::fillHeightChanged() +{ + propagateSizeHint("fillHeight"); +} + + + +#include "moc_appletloader.cpp" + diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h new file mode 100644 index 000000000..11988c351 --- /dev/null +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -0,0 +1,169 @@ +/* + * Copyright 2014 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 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 APPLETLOADER_P +#define APPLETLOADER_P + +#include +#include +#include +#include + +#include "declarativeappletscript.h" + +class QQmlComponent; + +namespace Plasma { + class Applet; + class AppletScript; +} + +namespace KDeclarative { + class QmlObject; +} + + +class AppletLoader : public QQuickItem +{ + Q_OBJECT + + Q_PROPERTY(int switchWidth READ switchWidth WRITE setSwitchWidth NOTIFY switchWidthChanged) + Q_PROPERTY(int switchHeight READ switchHeight WRITE setSwitchHeight NOTIFY switchHeightChanged) + + Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged) + Q_PROPERTY(QObject *compactRepresentationItem READ compactRepresentationItem NOTIFY compactRepresentationItemChanged) + + Q_PROPERTY(QQmlComponent *fullRepresentation READ fullRepresentation WRITE setFullRepresentation NOTIFY fullRepresentationChanged) + Q_PROPERTY(QObject *fullRepresentationItem READ fullRepresentationItem NOTIFY fullRepresentationItemChanged) + + + /** + * this is supposed to be either one between compactRepresentation or fullRepresentation + */ + Q_PROPERTY(QQmlComponent *preferredRepresentation READ preferredRepresentation WRITE setPreferredRepresentation NOTIFY preferredRepresentationChanged) + + //FIXME: is it wise to expose this? + Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged) + +public: + AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0); + ~AppletLoader(); + + Plasma::Applet *applet() const; + Plasma::AppletScript *appletScript(); + + int switchWidth() const; + void setSwitchWidth(int width); + + int switchHeight() const; + void setSwitchHeight(int width); + + + QQmlComponent *compactRepresentation(); + void setCompactRepresentation(QQmlComponent *component); + + QQmlComponent *fullRepresentation(); + void setFullRepresentation(QQmlComponent *component); + + QQmlComponent *preferredRepresentation(); + void setPreferredRepresentation(QQmlComponent *component); + + + QQmlComponent *compactRepresentationExpander(); + void setCompactRepresentationExpander(QQmlComponent *component); + + QObject *compactRepresentationItem(); + QObject *fullRepresentationItem(); + QObject *compactRepresentationExpanderItem(); + + //Reimplemented + virtual void classBegin(); + virtual void init(); + +Q_SIGNALS: + void switchWidthChanged(int width); + void switchHeightChanged(int height); + + void compactRepresentationChanged(QQmlComponent *compactRepresentation); + void fullRepresentationChanged(QQmlComponent *fullRepresentation); + void preferredRepresentationChanged(QQmlComponent *preferredRepresentation); + + void compactRepresentationExpanderChanged(QQmlComponent *compactRepresentationExpander); + + void compactRepresentationItemChanged(QObject *compactRepresentationItem); + void fullRepresentationItemChanged(QObject *fullRepresentationItem); + void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem); + +protected: + KDeclarative::QmlObject *qmlObject(); + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + void itemChange(ItemChange change, const ItemChangeData &value); + + QObject *createCompactRepresentationItem(); + QObject *createFullRepresentationItem(); + QObject *createCompactRepresentationExpanderItem(); + + //look into item, and return the Layout attached property, if found + void connectLayoutAttached(QObject *item); + void propagateSizeHint(const QByteArray &layoutProperty); + +private Q_SLOTS: + void compactRepresentationCheck(); + + //handlers of Layout signals + void minimumWidthChanged(); + void minimumHeightChanged(); + void preferredWidthChanged(); + void preferredHeightChanged(); + void maximumWidthChanged(); + void maximumHeightChanged(); + void fillWidthChanged(); + void fillHeightChanged(); + +//FIXME: +protected: + DeclarativeAppletScript *m_appletScriptEngine; + KDeclarative::QmlObject *m_qmlObject; + +private: + int m_switchWidth; + int m_switchHeight; + + QWeakPointer m_compactRepresentation; + QWeakPointer m_fullRepresentation; + QWeakPointer m_preferredRepresentation; + QWeakPointer m_compactRepresentationExpander; + + QWeakPointer m_compactRepresentationItem; + QWeakPointer m_fullRepresentationItem; + QWeakPointer m_compactRepresentationExpanderItem; + QWeakPointer m_currentRepresentationItem; + + //Attached layout objects: own and the representation's one + QWeakPointer m_representationLayout; + QWeakPointer m_ownLayout; + + QTimer m_compactRepresentationCheckTimer; + QTimer m_fullRepresentationResizeTimer; + + Plasma::Applet *m_applet; +}; + + +#endif diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 4c64df507..df9476e61 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -55,8 +55,8 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant m_interface(0) { //qmlRegisterType(); - qmlRegisterUncreatableType("org.kde.shell", 2, 0, "AppletInterface", - QLatin1String("Do not create objects of type AppletInterface")); + qmlRegisterUncreatableType("org.kde.plasma.shell", 2, 0, "Plasmoid", + QLatin1String("Do not create objects of type Plasmoid")); qmlRegisterType(); Q_UNUSED(args); } From 012554d8d93e06b9999c6e7fba79e0d411aea895 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 29 Jan 2014 11:11:43 +0100 Subject: [PATCH 03/31] get rid of the old sizehint mechanism --- .../qml/plasmoid/appletinterface.cpp | 295 ------------------ .../qml/plasmoid/appletinterface.h | 34 -- .../qml/plasmoid/appletloader.cpp | 7 - src/scriptengines/qml/plasmoid/appletloader.h | 1 - .../qml/plasmoid/containmentinterface.cpp | 36 --- 5 files changed, 373 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index d1410f4c7..20204d892 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -458,92 +458,6 @@ int AppletInterface::apiVersion() const return offers.first()->property("X-KDE-PluginInfo-Version", QVariant::Int).toInt(); } -bool AppletInterface::fillWidth() const -{ - if (!m_qmlObject->rootObject()) { - return false; - } - - - QVariant prop; - - if (m_compactUiObject) { - prop = m_compactUiObject.data()->property("fillWidth"); - } else { - prop = m_qmlObject->rootObject()->property("fillWidth"); - } - - if (prop.isValid() && prop.canConvert()) { - return prop.toBool(); - } else { - return false; - } -} - -bool AppletInterface::fillHeight() const -{ - if (!m_qmlObject->rootObject()) { - return false; - } - - - QVariant prop; - - if (m_compactUiObject) { - prop = m_compactUiObject.data()->property("fillHeight"); - } else { - prop = m_qmlObject->rootObject()->property("fillHeight"); - } - - if (prop.isValid() && prop.canConvert()) { - return prop.toBool(); - } else { - return false; - } -} - -//private api, just an helper -qreal AppletInterface::readGraphicsObjectSizeHint(const char *hint) const -{ - if (!m_qmlObject->rootObject()) { - return -1; - } - - - QVariant prop; - - if (m_compactUiObject) { - prop = m_compactUiObject.data()->property(hint); - } else { - prop = m_qmlObject->rootObject()->property(hint); - } - - if (prop.isValid() && prop.canConvert()) { - return prop.toReal(); - } else { - return -1; - } -} - -qreal AppletInterface::minimumWidth() const -{ - return readGraphicsObjectSizeHint("minimumWidth"); -} - -qreal AppletInterface::minimumHeight() const -{ - return readGraphicsObjectSizeHint("minimumHeight"); -} - -qreal AppletInterface::maximumWidth() const -{ - return readGraphicsObjectSizeHint("maximumWidth"); -} - -qreal AppletInterface::maximumHeight() const -{ - return readGraphicsObjectSizeHint("maximumHeight"); -} void AppletInterface::setAssociatedApplication(const QString &string) { @@ -615,215 +529,6 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o m_collapseTimer->start(100); } -void AppletInterface::_compactRepresentationCheck() -{ - if (width() <= 0 || height() <= 0 || !m_qmlObject->rootObject() || - qobject_cast(this)) { - return; - } - - //Read the minimum width of the full representation, not our own, since we could be in collapsed mode - QSizeF minHint(-1, -1); - if (m_qmlObject->rootObject()->property("minimumWidth").canConvert()) { - minHint.setWidth(m_qmlObject->rootObject()->property("minimumWidth").toReal()); - } - - if (m_qmlObject->rootObject()->property("minimumHeight").canConvert()) { - minHint.setHeight(m_qmlObject->rootObject()->property("minimumHeight").toReal()); - } - - //Make it an icon - if (width() < minHint.width() || height() < minHint.height()) { - m_expanded = false; - - //we are already an icon: nothing to do - if (m_compactUiObject) { - return; - } - - m_compactUiObject = m_qmlObject->createObjectFromSource(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("compactapplet"))); - - QObject *compactRepresentation = 0; - - //build the icon representation - if (m_compactUiObject) { - QQmlComponent *compactComponent = m_qmlObject->rootObject()->property("compactRepresentation").value(); - - if (compactComponent) { - compactRepresentation = compactComponent->create(compactComponent->creationContext()); - } else { - compactRepresentation = m_qmlObject->createObjectFromSource(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("defaultcompactrepresentation"))); - } - - if (compactRepresentation && compactComponent) { - compactComponent->setParent(compactRepresentation); - } else { - delete compactComponent; - } - } - - if (m_compactUiObject && compactRepresentation) { - //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)); - - { - //set anchors - QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_compactUiObject.data(), "parent"); - QQmlProperty prop(m_compactUiObject.data(), "anchors.fill"); - prop.write(expr.evaluate()); - } - - m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(m_compactUiObject.data())); - - - { - //reset all the anchors - QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "anchors.fill=undefined;anchors.left=undefined;anchors.right=undefined;anchors.top=undefined;anchors.bottom=undefined;"); - expr.evaluate(); - } - - KConfigGroup cg = applet()->config(); - cg = KConfigGroup(&cg, "PopupApplet"); - int width = cg.readEntry("DialogWidth", 0); - int height = cg.readEntry("DialogHeight", 0); - - m_qmlObject->rootObject()->setProperty("width", width); - m_qmlObject->rootObject()->setProperty("height", height); - - m_compactUiObject.data()->setProperty("applet", QVariant::fromValue(m_qmlObject->rootObject())); - - //hook m_compactUiObject size hints to this size hint - //Here we have to use the old connect syntax, because we don't have access to the class type - if (m_qmlObject->rootObject()) { - disconnect(m_qmlObject->rootObject(), 0, this, 0); - } - - //resize of the root object means popup resize when iconified - connect(m_qmlObject->rootObject(), SIGNAL(widthChanged()), - this, SLOT(updatePopupSize())); - connect(m_qmlObject->rootObject(), SIGNAL(heightChanged()), - this, SLOT(updatePopupSize())); - - if (m_compactUiObject.data()->property("minimumWidth").isValid()) { - connect(m_compactUiObject.data(), SIGNAL(minimumWidthChanged()), - this, SIGNAL(minimumWidthChanged())); - } - if (m_compactUiObject.data()->property("minimumHeight").isValid()) { - connect(m_compactUiObject.data(), SIGNAL(minimumHeightChanged()), - this, SIGNAL(minimumHeightChanged())); - } - - if (m_compactUiObject.data()->property("maximumWidth").isValid()) { - connect(m_compactUiObject.data(), SIGNAL(maximumWidthChanged()), - this, SIGNAL(maximumWidthChanged())); - } - if (m_compactUiObject.data()->property("maximumHeight").isValid()) { - connect(m_compactUiObject.data(), SIGNAL(maximumHeightChanged()), - this, SIGNAL(maximumHeightChanged())); - } - - if (m_compactUiObject.data()->property("implicitWidth").isValid()) { - connect(m_compactUiObject.data(), SIGNAL(implicitWidthChanged()), - this, SIGNAL(implicitWidthChanged())); - } - if (m_compactUiObject.data()->property("implicitHeight").isValid()) { - connect(m_compactUiObject.data(), SIGNAL(implicitHeightChanged()), - this, SIGNAL(implicitHeightChanged())); - } - - emit fillWidthChanged(); - emit fillHeightChanged(); - emit minimumWidthChanged(); - emit minimumHeightChanged(); - emit implicitWidthChanged(); - emit implicitHeightChanged(); - emit maximumWidthChanged(); - emit maximumHeightChanged(); - //failed to create UI, don't do anything, return in expanded status - } else { - m_expanded = true; - } - - emit expandedChanged(); - - //show the full UI - } else { - m_expanded = true; - emit expandedChanged(); - - //we are already expanded: nothing to do - if (m_compactUiObject) { - disconnect(m_compactUiObject.data(), 0, this, 0); - } - - disconnect(m_qmlObject->rootObject(), SIGNAL(widthChanged()), - this, SLOT(updatePopupSize())); - disconnect(m_qmlObject->rootObject(), SIGNAL(heightChanged()), - this, SLOT(updatePopupSize())); - - //Here we have to use the old connect syntax, because we don't have access to the class type - if (m_qmlObject->rootObject()->property("minimumWidth").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(minimumWidthChanged()), - this, SIGNAL(minimumWidthChanged())); - } - if (m_qmlObject->rootObject()->property("minimumHeight").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(minimumHeightChanged()), - this, SIGNAL(minimumHeightChanged())); - } - - if (m_qmlObject->rootObject()->property("maximumWidth").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(maximumWidthChanged()), - this, SIGNAL(maximumWidthChanged())); - } - if (m_qmlObject->rootObject()->property("maximumHeight").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(maximumHeightChanged()), - this, SIGNAL(maximumHeightChanged())); - } - - if (m_qmlObject->rootObject()->property("implicitWidth").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(implicitWidthChanged()), - this, SLOT(updateImplicitWidth())); - } - if (m_qmlObject->rootObject()->property("implicitHeight").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(implicitHeightChanged()), - this, SLOT(updateImplicitHeight())); - } - - emit fillWidthChanged(); - emit fillHeightChanged(); - emit minimumWidthChanged(); - emit minimumHeightChanged(); - emit maximumWidthChanged(); - emit maximumHeightChanged(); - - m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this)); - if (m_compactUiObject) { - m_compactUiObject.data()->deleteLater(); - } - - //set anchors - QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "parent"); - QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill"); - prop.write(expr.evaluate()); - } -} - -void AppletInterface::updateImplicitWidth() -{ - setImplicitWidth(readGraphicsObjectSizeHint("implicitWidth")); -} - -void AppletInterface::updateImplicitHeight() -{ - setImplicitHeight(readGraphicsObjectSizeHint("implicitHeight")); -} - - void AppletInterface::updatePopupSize() { KConfigGroup cg = applet()->config(); diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 1f23ed6a3..a6b30215f 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -146,22 +146,6 @@ class AppletInterface : public AppletLoader // would be preferrable if found. Q_PROPERTY(int screen READ screen NOTIFY screenChanged) - //Size hints. Note that the containments may chose to not respect them. - Q_PROPERTY(qreal minimumWidth READ minimumWidth NOTIFY minimumWidthChanged) - Q_PROPERTY(qreal minimumHeight READ minimumHeight NOTIFY minimumHeightChanged) - Q_PROPERTY(qreal maximumWidth READ maximumWidth NOTIFY maximumWidthChanged) - Q_PROPERTY(qreal maximumHeight READ maximumHeight NOTIFY maximumHeightChanged) - - /** - * If the plasmoid is in a linear layout, such as a panel, it indicates to take as much horizontal space as possible - */ - Q_PROPERTY(bool fillWidth READ fillWidth NOTIFY fillWidthChanged) - - /** - * If the plasmoid is in a linear layout, such as a panel, it indicates to take as much vertical space as possible - */ - Q_PROPERTY(bool fillHeight READ fillHeight NOTIFY fillHeightChanged) - /** * Whether the dialog should be hidden when the dialog loses focus. * @@ -292,13 +276,6 @@ public: bool hideOnWindowDeactivate() const; void setHideOnWindowDeactivate(bool hide); - bool fillWidth() const; - bool fillHeight() const; - qreal minimumWidth() const; - qreal minimumHeight() const; - qreal maximumWidth() const; - qreal maximumHeight() const; - Q_SIGNALS: /** * somebody else, usually the containment sent some data to the applet @@ -324,12 +301,6 @@ Q_SIGNALS: void screenChanged(); void hideOnWindowDeactivateChanged(); - void minimumWidthChanged(); - void minimumHeightChanged(); - void maximumWidthChanged(); - void maximumHeightChanged(); - void fillWidthChanged(); - void fillHeightChanged(); void userConfiguringChanged(); protected: @@ -342,14 +313,9 @@ protected Q_SLOTS: virtual void init(); private Q_SLOTS: - void _compactRepresentationCheck(); void updatePopupSize(); - void updateImplicitWidth(); - void updateImplicitHeight(); private: - //Helper for minimumWidth etc. - qreal readGraphicsObjectSizeHint(const char *hint) const; QStringList m_actions; QSignalMapper *m_actionSignals; diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index cd91493c2..82323144e 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -171,13 +171,6 @@ void AppletLoader::setPreferredRepresentation(QQmlComponent *component) ////////////Internals -void AppletLoader::classBegin() -{ - Q_ASSERT(m_qmlObject->engine()); - m_qmlObject->engine()->rootContext()->setContextProperty("plasmoid", this); - -} - void AppletLoader::init() { //m_appletScriptEngine = property("_plasma_appletscript").value(); diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index 11988c351..4ae3118f1 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -93,7 +93,6 @@ public: QObject *compactRepresentationExpanderItem(); //Reimplemented - virtual void classBegin(); virtual void init(); Q_SIGNALS: diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 23edb672d..2bb0c928d 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -152,42 +152,6 @@ void ContainmentInterface::init() QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill"); prop.write(expr.evaluate()); } - - if (m_qmlObject->rootObject()->property("minimumWidth").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(minimumWidthChanged()), - this, SIGNAL(minimumWidthChanged())); - } - if (m_qmlObject->rootObject()->property("minimumHeight").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(minimumHeightChanged()), - this, SIGNAL(minimumHeightChanged())); - } - - if (m_qmlObject->rootObject()->property("maximumWidth").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(maximumWidthChanged()), - this, SIGNAL(maximumWidthChanged())); - } - if (m_qmlObject->rootObject()->property("maximumHeight").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(maximumHeightChanged()), - this, SIGNAL(maximumHeightChanged())); - } - - if (m_qmlObject->rootObject()->property("implicitWidth").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(implicitWidthChanged()), - this, SIGNAL(implicitWidthChanged())); - } - if (m_qmlObject->rootObject()->property("implicitHeight").isValid()) { - connect(m_qmlObject->rootObject(), SIGNAL(implicitHeightChanged()), - this, SIGNAL(implicitHeightChanged())); - } - - emit fillWidthChanged(); - emit fillHeightChanged(); - emit minimumWidthChanged(); - emit minimumHeightChanged(); - emit implicitWidthChanged(); - emit implicitHeightChanged(); - emit maximumWidthChanged(); - emit maximumHeightChanged(); } QList ContainmentInterface::applets() From 2a37efbdb73263f19cf85a66fada83cae8bd8e72 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 29 Jan 2014 16:20:39 +0100 Subject: [PATCH 04/31] cleanups move qmlobject initialization in appletloader --- .../qml/plasmoid/appletinterface.cpp | 108 +++------------ .../qml/plasmoid/appletinterface.h | 21 +-- .../qml/plasmoid/appletloader.cpp | 131 ++++++++++-------- src/scriptengines/qml/plasmoid/appletloader.h | 29 ++-- .../qml/plasmoid/containmentinterface.cpp | 26 ++-- .../qml/plasmoid/containmentinterface.h | 7 +- .../qml/plasmoid/declarativeappletscript.cpp | 7 +- .../qml/plasmoid/declarativeappletscript.h | 1 + 8 files changed, 144 insertions(+), 186 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 20204d892..610fd539a 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -48,12 +48,10 @@ #include #include -#include + Q_DECLARE_METATYPE(AppletInterface*) -QHash AppletInterface::s_rootObjects = QHash(); - AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent) : AppletLoader(script, parent), m_actionSignals(0), @@ -75,11 +73,11 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa connect(applet(), &Plasma::Applet::statusChanged, this, &AppletInterface::statusChanged); - connect(m_appletScriptEngine, &DeclarativeAppletScript::formFactorChanged, + connect(appletScript(), &DeclarativeAppletScript::formFactorChanged, this, &AppletInterface::formFactorChanged); - connect(m_appletScriptEngine, &DeclarativeAppletScript::locationChanged, + connect(appletScript(), &DeclarativeAppletScript::locationChanged, this, &AppletInterface::locationChanged); - connect(m_appletScriptEngine, &DeclarativeAppletScript::contextChanged, + connect(appletScript(), &DeclarativeAppletScript::contextChanged, this, &AppletInterface::contextChanged); if (applet()->containment()) { @@ -87,71 +85,21 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa this, &ContainmentInterface::screenChanged); } - m_qmlObject = new KDeclarative::QmlObject(this); - m_qmlObject->setInitializationDelayed(true); - - m_collapseTimer = new QTimer(this); - m_collapseTimer->setSingleShot(true); - //connect(m_collapseTimer, &QTimer::timeout, this, &AppletInterface::compactRepresentationCheck); } AppletInterface::~AppletInterface() { - s_rootObjects.remove(m_qmlObject->engine()); } void AppletInterface::init() { - AppletLoader::init(); - - if (m_qmlObject->rootObject()) { + if (qmlObject()->rootObject() && m_configuration) { return; } m_configuration = new KDeclarative::ConfigPropertyMap(applet()->configScheme(), this); - //use our own custom network access manager that will access Plasma packages and to manage security (i.e. deny access to remote stuff when the proper extension isn't enabled - QQmlEngine *engine = m_qmlObject->engine(); - - s_rootObjects[m_qmlObject->engine()] = this; - - //Hook generic url resolution to the applet package as well - //TODO: same thing will have to be done for every qqmlengine: PackageUrlInterceptor is material for plasmaquick? - PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, m_appletScriptEngine->package()); - interceptor->addAllowedPath(applet()->containment()->corona()->package().path()); - engine->setUrlInterceptor(interceptor); - - m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript())); - - if (!m_qmlObject->engine() || !m_qmlObject->engine()->rootContext() || !m_qmlObject->engine()->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) { - QString reason; - foreach (QQmlError error, m_qmlObject->mainComponent()->errors()) { - reason += error.toString()+'\n'; - } - reason = i18n("Error loading QML file: %1", reason); - - m_qmlObject->setSource(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("appleterror"))); - m_qmlObject->completeInitialization(); - - - //even the error message QML may fail - if (m_qmlObject->mainComponent()->isError()) { - return; - } else { - m_qmlObject->rootObject()->setProperty("reason", reason); - } - - m_appletScriptEngine->setLaunchErrorMessage(reason); - } - - - m_qmlObject->engine()->rootContext()->setContextProperty("plasmoid", this); - - //initialize size, so an useless resize less - QVariantHash initialProperties; - initialProperties["width"] = width(); - initialProperties["height"] = height(); - m_qmlObject->completeInitialization(initialProperties); + AppletLoader::init(); qDebug() << "Graphic object created:" << applet() << applet()->property("graphicObject"); @@ -218,7 +166,7 @@ void AppletInterface::setTitle(const QString &title) bool AppletInterface::isBusy() const { - return !m_qmlObject->rootObject() || m_busy; + return m_busy; } void AppletInterface::setBusy(bool busy) @@ -240,7 +188,7 @@ 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) { + if (qobject_cast(this) || m_expanded == expanded) { return; } @@ -265,7 +213,7 @@ void AppletInterface::setBackgroundHints(Plasma::Types::BackgroundHints hint) void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason) { - m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason); + appletScript()->setConfigurationRequired(needsConfiguring, reason); } QString AppletInterface::activeConfig() const @@ -283,7 +231,7 @@ void AppletInterface::setActiveConfig(const QString &name) Plasma::ConfigLoader *loader = m_configs.value(name, 0); if (!loader) { - QString path = m_appletScriptEngine->filePath("config", name + ".xml"); + QString path = appletScript()->filePath("config", name + ".xml"); if (path.isEmpty()) { return; } @@ -313,7 +261,7 @@ void AppletInterface::writeConfig(const QString &entry, const QVariant &value) config->blockSignals(true); config->writeConfig(); config->blockSignals(false); - m_appletScriptEngine->configNeedsSaving(); + appletScript()->configNeedsSaving(); } } else qWarning() << "Couldn't find a configuration entry"; @@ -339,12 +287,12 @@ QVariant AppletInterface::readConfig(const QString &entry) const QString AppletInterface::file(const QString &fileType) { - return m_appletScriptEngine->filePath(fileType, QString()); + return appletScript()->filePath(fileType, QString()); } QString AppletInterface::file(const QString &fileType, const QString &filePath) { - return m_appletScriptEngine->filePath(fileType, filePath); + return appletScript()->filePath(fileType, filePath); } QList AppletInterface::contextualActions() const @@ -398,7 +346,7 @@ void AppletInterface::setAction(const QString &name, const QString &text, const if (!m_actionSignals) { m_actionSignals = new QSignalMapper(this); connect(m_actionSignals, SIGNAL(mapped(QString)), - m_appletScriptEngine, SLOT(executeAction(QString))); + appletScript(), SLOT(executeAction(QString))); } connect(action, SIGNAL(triggered()), m_actionSignals, SLOT(map())); @@ -521,36 +469,20 @@ 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) - - AppletLoader::geometryChanged(newGeometry, oldGeometry); - m_collapseTimer->start(100); -} - void AppletInterface::updatePopupSize() { KConfigGroup cg = applet()->config(); cg = KConfigGroup(&cg, "PopupApplet"); - cg.writeEntry("DialogWidth", m_qmlObject->rootObject()->property("width").toInt()); - cg.writeEntry("DialogHeight", m_qmlObject->rootObject()->property("height").toInt()); + cg.writeEntry("DialogWidth", qmlObject()->rootObject()->property("width").toInt()); + cg.writeEntry("DialogHeight", qmlObject()->rootObject()->property("height").toInt()); } -void AppletInterface::itemChange(ItemChange change, const ItemChangeData &value) + +void AppletInterface::executeAction(const QString &name) { - if (change == QQuickItem::ItemSceneChange) { - //we have a window: create the - if (value.window && !m_qmlObject->rootObject()) { - init(); - } + if (qmlObject()->rootObject()) { + QMetaObject::invokeMethod(qmlObject()->rootObject(), QString("action_" + name).toLatin1(), Qt::DirectConnection); } - AppletLoader::itemChange(change, value); -} - -KDeclarative::QmlObject *AppletInterface::qmlObject() -{ - return m_qmlObject; } #include "moc_appletinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index a6b30215f..427408618 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -159,11 +159,12 @@ public: ~AppletInterface(); //API not intended for the QML part - KDeclarative::QmlObject *qmlObject(); QList contextualActions() const; - inline Plasma::Applet *applet() const { return m_appletScriptEngine->applet(); } + void executeAction(const QString &name); + + Plasma::Applet *applet() const { return appletScript()->applet(); } //QML API------------------------------------------------------------------- @@ -225,11 +226,7 @@ public: static AppletInterface *qmlAttachedProperties(QObject *object) { - if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) { - return s_rootObjects.value(QtQml::qmlEngine(object)); - } else { - return 0; - } + return qobject_cast(AppletLoader::qmlAttachedProperties(object)); } //PROPERTY ACCESSORS------------------------------------------------------------------- @@ -303,12 +300,6 @@ Q_SIGNALS: void userConfiguringChanged(); -protected: - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - void itemChange(ItemChange change, const ItemChangeData &value); - - - protected Q_SLOTS: virtual void init(); @@ -326,17 +317,13 @@ private: KDeclarative::ConfigPropertyMap *m_configuration; //UI-specific members ------------------ - QWeakPointer m_compactUiObject; - QTimer *m_collapseTimer; Plasma::Types::BackgroundHints m_backgroundHints; bool m_busy : 1; bool m_expanded : 1; bool m_hideOnDeactivate : 1; friend class ContainmentInterface; - - static QHash s_rootObjects; }; QML_DECLARE_TYPEINFO(AppletInterface, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index 82323144e..f28375b98 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -27,6 +27,8 @@ #include +#include + #include #include #include @@ -34,7 +36,9 @@ #include #include +#include +QHash AppletLoader::s_rootObjects = QHash(); AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) : QQuickItem(parent), @@ -48,7 +52,7 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) this, SLOT(compactRepresentationCheck())); m_compactRepresentationCheckTimer.start(); - m_fullRepresentationResizeTimer.setSingleShot(true); + /* m_fullRepresentationResizeTimer.setSingleShot(true); m_fullRepresentationResizeTimer.setInterval(250); connect (&m_fullRepresentationResizeTimer, &QTimer::timeout, [=]() { @@ -57,37 +61,88 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt()); cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt()); } - ); - - //hide all the children that aren't the known ones. - //all the UI is supposed to happen in the representations - /* connect (this, &QQuickItem::childrenChanged, [=]() { - foreach (QQuickItem *child, childItems()) { - if (child != m_compactRepresentationItem.data() && - child != m_fullRepresentationItem.data() && - child != m_compactRepresentationExpanderItem.data()) { - child->setVisible(false); - } - } - });*/ + );*/ - m_applet = m_appletScriptEngine->applet(); - m_qmlObject = new KDeclarative::QmlObject(this); + m_qmlObject->setInitializationDelayed(true); } AppletLoader::~AppletLoader() { + s_rootObjects.remove(m_qmlObject->engine()); } -Plasma::Applet *AppletLoader::applet() const +void AppletLoader::init() { - return m_applet; + s_rootObjects[m_qmlObject->engine()] = this; + + Q_ASSERT(m_appletScriptEngine); + + + //Initialize the main QML file + QQmlEngine *engine = m_qmlObject->engine(); + + PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, appletScript()->package()); + interceptor->addAllowedPath(m_appletScriptEngine->applet()->containment()->corona()->package().path()); + engine->setUrlInterceptor(interceptor); + + m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript())); + + if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) { + QString reason; + foreach (QQmlError error, m_qmlObject->mainComponent()->errors()) { + reason += error.toString()+'\n'; + } + reason = i18n("Error loading QML file: %1", reason); + + m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("appleterror"))); + m_qmlObject->completeInitialization(); + + + //even the error message QML may fail + if (m_qmlObject->mainComponent()->isError()) { + return; + } else { + m_qmlObject->rootObject()->setProperty("reason", reason); + } + + appletScript()->setLaunchErrorMessage(reason); + } + +qWarning()<<"AAAAAAAAAAA"<mainComponent()->errors(); + engine->rootContext()->setContextProperty("plasmoid", this); + + //initialize size, so an useless resize less + QVariantHash initialProperties; + initialProperties["width"] = width(); + initialProperties["height"] = height(); + m_qmlObject->completeInitialization(initialProperties); +qWarning()<<"BBBBB"; + + + //default m_compactRepresentation is a simple icon provided by the shell package + if (!m_compactRepresentation) { + m_compactRepresentation = new QQmlComponent(engine, this); + m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("defaultcompactrepresentation"))); + } + + //we really want a full representation, default m_fullRepresentation is an error message + /* if (!m_fullRepresentation) { + m_fullRepresentation = new QQmlComponent(m_qmlObject->engine(), this); + m_fullRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("appleterror"))); + }*/ + + //default m_compactRepresentationExpander is the popup in which fullRepresentation goes + if (!m_compactRepresentationExpander) { + m_compactRepresentationExpander = new QQmlComponent(engine, this); + m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("compactapplet"))); + } + } -Plasma::AppletScript *AppletLoader::appletScript() +DeclarativeAppletScript *AppletLoader::appletScript() const { return m_appletScriptEngine; } @@ -171,37 +226,6 @@ void AppletLoader::setPreferredRepresentation(QQmlComponent *component) ////////////Internals -void AppletLoader::init() -{ - //m_appletScriptEngine = property("_plasma_appletscript").value(); - - Q_ASSERT(m_appletScriptEngine); - // m_applet = m_appletScriptEngine->applet(); - Q_ASSERT(m_applet); - - // m_qmlObject = new KDeclarative::QmlObject(m_qmlObject->engine(), this); - - //default m_compactRepresentation is a simple icon provided by the shell package - if (!m_compactRepresentation) { - m_compactRepresentation = new QQmlComponent(m_qmlObject->engine(), this); - m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("defaultcompactrepresentation"))); - } - - //we really want a full representation, default m_fullRepresentation is an error message - /* if (!m_fullRepresentation) { - m_fullRepresentation = new QQmlComponent(m_qmlObject->engine(), this); - m_fullRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("appleterror"))); - }*/ - - //default m_compactRepresentationExpander is the popup in which fullRepresentation goes - if (!m_compactRepresentationExpander) { - m_compactRepresentationExpander = new QQmlComponent(m_qmlObject->engine(), this); - m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("compactapplet"))); - } - -} - - KDeclarative::QmlObject *AppletLoader::qmlObject() { @@ -387,7 +411,7 @@ void AppletLoader::itemChange(ItemChange change, const ItemChangeData &value) if (change == QQuickItem::ItemSceneChange) { //we have a window: create the representations if needed if (value.window) { - m_compactRepresentationCheckTimer.start(); + init(); } } @@ -406,7 +430,7 @@ void AppletLoader::compactRepresentationCheck() bool full = false; - if (applet()->isContainment()) { + if (m_appletScriptEngine->applet()->isContainment()) { full = true; } else { @@ -419,7 +443,7 @@ void AppletLoader::compactRepresentationCheck() full = m_preferredRepresentation.data() == m_fullRepresentation.data(); //Otherwise, base on FormFactor } else { - full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical); + full = (m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Horizontal && m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Vertical); } } @@ -520,6 +544,5 @@ void AppletLoader::fillHeightChanged() } - #include "moc_appletloader.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index 4ae3118f1..2f995e1c4 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -65,8 +65,7 @@ public: AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0); ~AppletLoader(); - Plasma::Applet *applet() const; - Plasma::AppletScript *appletScript(); + DeclarativeAppletScript *appletScript() const; int switchWidth() const; void setSwitchWidth(int width); @@ -94,7 +93,18 @@ public: //Reimplemented virtual void init(); - + + static AppletLoader *qmlAttachedProperties(QObject *object) + { + //at the moment of the attached object creation, the root item is the only one that hasn't a parent + //only way to avoid creation of this attached for everybody but the root item + if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) { + return s_rootObjects.value(QtQml::qmlEngine(object)); + } else { + return 0; + } + } + Q_SIGNALS: void switchWidthChanged(int width); void switchHeightChanged(int height); @@ -112,7 +122,7 @@ Q_SIGNALS: protected: KDeclarative::QmlObject *qmlObject(); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - void itemChange(ItemChange change, const ItemChangeData &value); + virtual void itemChange(ItemChange change, const ItemChangeData &value); QObject *createCompactRepresentationItem(); QObject *createFullRepresentationItem(); @@ -135,11 +145,6 @@ private Q_SLOTS: void fillWidthChanged(); void fillHeightChanged(); -//FIXME: -protected: - DeclarativeAppletScript *m_appletScriptEngine; - KDeclarative::QmlObject *m_qmlObject; - private: int m_switchWidth; int m_switchHeight; @@ -161,8 +166,12 @@ private: QTimer m_compactRepresentationCheckTimer; QTimer m_fullRepresentationResizeTimer; - Plasma::Applet *m_applet; + DeclarativeAppletScript *m_appletScriptEngine; + KDeclarative::QmlObject *m_qmlObject; + + static QHash s_rootObjects; }; +QML_DECLARE_TYPEINFO(AppletLoader, QML_HAS_ATTACHED_PROPERTIES) #endif diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 2bb0c928d..b5bf2d5c1 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -119,15 +119,15 @@ void ContainmentInterface::init() pkg.setPath("org.kde.desktoptoolbox"); } - PackageUrlInterceptor *interceptor = dynamic_cast(m_qmlObject->engine()->urlInterceptor()); + PackageUrlInterceptor *interceptor = dynamic_cast(qmlObject()->engine()->urlInterceptor()); if (interceptor) { interceptor->addAllowedPath(pkg.path()); } if (pkg.isValid()) { - QObject *toolBoxObject = m_qmlObject->createObjectFromSource(QUrl::fromLocalFile(pkg.filePath("mainscript"))); + QObject *toolBoxObject = qmlObject()->createObjectFromSource(QUrl::fromLocalFile(pkg.filePath("mainscript"))); - QObject *containmentGraphicObject = m_qmlObject->rootObject(); + QObject *containmentGraphicObject = qmlObject()->rootObject(); if (containmentGraphicObject && toolBoxObject) { toolBoxObject->setProperty("parent", QVariant::fromValue(containmentGraphicObject)); @@ -144,12 +144,12 @@ void ContainmentInterface::init() //set parent, both as object hyerarchy and visually //do this only for containments, applets will do it in compactrepresentationcheck - if (m_qmlObject->rootObject()) { - m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this)); + if (qmlObject()->rootObject()) { + qmlObject()->rootObject()->setProperty("parent", QVariant::fromValue(this)); //set anchors - QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "parent"); - QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill"); + QQmlExpression expr(qmlObject()->engine()->rootContext(), qmlObject()->rootObject(), "parent"); + QQmlProperty prop(qmlObject()->rootObject(), "anchors.fill"); prop.write(expr.evaluate()); } } @@ -161,28 +161,28 @@ QList ContainmentInterface::applets() void ContainmentInterface::setDrawWallpaper(bool drawWallpaper) { - if (drawWallpaper == m_appletScriptEngine->drawWallpaper()) { + if (drawWallpaper == appletScript()->drawWallpaper()) { return; } - m_appletScriptEngine->setDrawWallpaper(drawWallpaper); + appletScript()->setDrawWallpaper(drawWallpaper); loadWallpaper(); } bool ContainmentInterface::drawWallpaper() { - return m_appletScriptEngine->drawWallpaper(); + return appletScript()->drawWallpaper(); } Plasma::Types::ContainmentType ContainmentInterface::containmentType() const { - return m_appletScriptEngine->containmentType(); + return appletScript()->containmentType(); } void ContainmentInterface::setContainmentType(Plasma::Types::ContainmentType type) { - m_appletScriptEngine->setContainmentType(type); + appletScript()->setContainmentType(type); } void ContainmentInterface::lockWidgets(bool locked) @@ -548,7 +548,7 @@ void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) void ContainmentInterface::loadWallpaper() { - if (m_appletScriptEngine->drawWallpaper() && !containment()->wallpaper().isEmpty()) { + if (appletScript()->drawWallpaper() && !containment()->wallpaper().isEmpty()) { delete m_wallpaperInterface; m_wallpaperInterface = new WallpaperInterface(this); diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index 0ed586850..f5a27dafc 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -75,7 +75,7 @@ class ContainmentInterface : public AppletInterface public: ContainmentInterface(DeclarativeAppletScript *parent); //Not for QML - inline Plasma::Containment *containment() const { return static_cast(m_appletScriptEngine->applet()->containment()); } + Plasma::Containment *containment() const { return static_cast(appletScript()->applet()->containment()); } inline WallpaperInterface *wallpaperInterface() const { return m_wallpaperInterface;} @@ -112,6 +112,11 @@ public: */ Q_INVOKABLE void processMimeData(QMimeData *data, int x, int y); + static ContainmentInterface *qmlAttachedProperties(QObject *object) + { + return qobject_cast(AppletLoader::qmlAttachedProperties(object)); + } + protected: void init(); void mousePressEvent(QMouseEvent *event); diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index df9476e61..e182725e1 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -57,6 +57,9 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant //qmlRegisterType(); qmlRegisterUncreatableType("org.kde.plasma.shell", 2, 0, "Plasmoid", QLatin1String("Do not create objects of type Plasmoid")); + qmlRegisterUncreatableType("org.kde.plasma.shell", 2, 0, "Containment", + QLatin1String("Do not create objects of type Containment")); + qmlRegisterType(); Q_UNUSED(args); } @@ -111,9 +114,7 @@ void DeclarativeAppletScript::constraintsEvent(Plasma::Types::Constraints constr void DeclarativeAppletScript::executeAction(const QString &name) { - if (m_interface->qmlObject()->rootObject()) { - QMetaObject::invokeMethod(m_interface->qmlObject()->rootObject(), QString("action_" + name).toLatin1(), Qt::DirectConnection); - } + m_interface->executeAction(name); } QList DeclarativeAppletScript::contextualActions() diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.h b/src/scriptengines/qml/plasmoid/declarativeappletscript.h index 1649e5dd8..a3257ab7e 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.h +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.h @@ -56,6 +56,7 @@ Q_SIGNALS: private: AppletInterface *m_interface; + friend class AppletLoader; friend class AppletInterface; friend class ContainmentInterface; }; From 428c10e24caedae01e3ad1fbfa5cfe2e6bc14b8e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 29 Jan 2014 17:09:43 +0100 Subject: [PATCH 05/31] fullrepresentation and the expander are created on demand --- .../qml/plasmoid/appletinterface.cpp | 27 -------- .../qml/plasmoid/appletinterface.h | 14 ---- .../qml/plasmoid/appletloader.cpp | 69 ++++++++++++++----- src/scriptengines/qml/plasmoid/appletloader.h | 13 ++++ 4 files changed, 65 insertions(+), 58 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 610fd539a..7f3b95992 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -57,7 +57,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa m_actionSignals(0), m_backgroundHints(Plasma::Types::StandardBackground), m_busy(false), - m_expanded(false), m_hideOnDeactivate(true) { qmlRegisterType(); @@ -179,23 +178,6 @@ 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 (qobject_cast(this) || m_expanded == expanded) { - return; - } - - m_expanded = expanded; - emit expandedChanged(); -} - Plasma::Types::BackgroundHints AppletInterface::backgroundHints() const { return m_backgroundHints; @@ -469,15 +451,6 @@ QStringList AppletInterface::downloadedFiles() const return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable); } -void AppletInterface::updatePopupSize() -{ - KConfigGroup cg = applet()->config(); - cg = KConfigGroup(&cg, "PopupApplet"); - cg.writeEntry("DialogWidth", qmlObject()->rootObject()->property("width").toInt()); - cg.writeEntry("DialogHeight", qmlObject()->rootObject()->property("height").toInt()); -} - - void AppletInterface::executeAction(const QString &name) { if (qmlObject()->rootObject()) { diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 427408618..688e07581 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -108,12 +108,6 @@ class AppletInterface : public AppletLoader */ Q_PROPERTY(bool busy WRITE setBusy READ isBusy NOTIFY busyChanged) - /** - * True when the applet is showing its full representation. either as the main only view, or in a popup. - * Setting it will open or close the popup if the plasmoid is iconified, however it won't have effect if the applet is open - */ - Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged) - /** * How the applet wants its background to be drawn. The containment may chose to ignore this hint. */ @@ -249,9 +243,6 @@ public: bool isBusy() const; void setBusy(bool busy); - bool isExpanded() const; - void setExpanded(bool expanded); - Plasma::Types::BackgroundHints backgroundHints() const; void setBackgroundHints(Plasma::Types::BackgroundHints hint); @@ -294,7 +285,6 @@ Q_SIGNALS: void statusChanged(); void backgroundHintsChanged(); void busyChanged(); - void expandedChanged(); void screenChanged(); void hideOnWindowDeactivateChanged(); @@ -303,9 +293,6 @@ Q_SIGNALS: protected Q_SLOTS: virtual void init(); -private Q_SLOTS: - void updatePopupSize(); - private: QStringList m_actions; @@ -321,7 +308,6 @@ private: Plasma::Types::BackgroundHints m_backgroundHints; bool m_busy : 1; - bool m_expanded : 1; bool m_hideOnDeactivate : 1; friend class ContainmentInterface; }; diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index f28375b98..f5d17817f 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -44,7 +44,8 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) : QQuickItem(parent), m_switchWidth(-1), m_switchHeight(-1), - m_appletScriptEngine(script) + m_appletScriptEngine(script), + m_expanded(false) { m_compactRepresentationCheckTimer.setSingleShot(true); m_compactRepresentationCheckTimer.setInterval(250); @@ -52,16 +53,16 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) this, SLOT(compactRepresentationCheck())); m_compactRepresentationCheckTimer.start(); - /* m_fullRepresentationResizeTimer.setSingleShot(true); + m_fullRepresentationResizeTimer.setSingleShot(true); m_fullRepresentationResizeTimer.setInterval(250); connect (&m_fullRepresentationResizeTimer, &QTimer::timeout, [=]() { - KConfigGroup cg = applet()->config(); + KConfigGroup cg = m_appletScriptEngine->applet()->config(); cg = KConfigGroup(&cg, "PopupApplet"); cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt()); cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt()); } - );*/ + ); @@ -71,11 +72,20 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) AppletLoader::~AppletLoader() { + //Here the order is important + delete m_compactRepresentationItem.data(); + delete m_fullRepresentationItem.data(); + delete m_compactRepresentationExpanderItem.data(); + s_rootObjects.remove(m_qmlObject->engine()); } void AppletLoader::init() { + if (s_rootObjects.contains(this)) { + return; + } + s_rootObjects[m_qmlObject->engine()] = this; Q_ASSERT(m_appletScriptEngine); @@ -111,7 +121,6 @@ void AppletLoader::init() appletScript()->setLaunchErrorMessage(reason); } -qWarning()<<"AAAAAAAAAAA"<mainComponent()->errors(); engine->rootContext()->setContextProperty("plasmoid", this); //initialize size, so an useless resize less @@ -119,7 +128,7 @@ qWarning()<<"AAAAAAAAAAA"<mainComponent()->errors(); initialProperties["width"] = width(); initialProperties["height"] = height(); m_qmlObject->completeInitialization(initialProperties); -qWarning()<<"BBBBB"; + //default m_compactRepresentation is a simple icon provided by the shell package @@ -128,12 +137,6 @@ qWarning()<<"BBBBB"; m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("defaultcompactrepresentation"))); } - //we really want a full representation, default m_fullRepresentation is an error message - /* if (!m_fullRepresentation) { - m_fullRepresentation = new QQmlComponent(m_qmlObject->engine(), this); - m_fullRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("appleterror"))); - }*/ - //default m_compactRepresentationExpander is the popup in which fullRepresentation goes if (!m_compactRepresentationExpander) { m_compactRepresentationExpander = new QQmlComponent(engine, this); @@ -223,6 +226,29 @@ void AppletLoader::setPreferredRepresentation(QQmlComponent *component) emit preferredRepresentationChanged(component); } +bool AppletLoader::isExpanded() const +{ + return m_expanded; +} + +void AppletLoader::setExpanded(bool expanded) +{ + if (m_appletScriptEngine->applet()->isContainment()) { + expanded = true; + } + + //if there is no compact representation it means it's always expanded + //Containnments are always expanded + if (m_expanded == expanded) { + return; + } + + createFullRepresentationItem(); + createCompactRepresentationExpanderItem(); + + m_expanded = expanded; + emit expandedChanged(); +} ////////////Internals @@ -303,6 +329,10 @@ QObject *AppletLoader::createCompactRepresentationExpanderItem() m_compactRepresentationExpanderItem = m_qmlObject->createObjectFromComponent(m_compactRepresentationExpander.data(), QtQml::qmlContext(m_qmlObject->rootObject())); + + m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem())); + m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpanderItem.data()); return m_compactRepresentationExpanderItem.data(); @@ -480,11 +510,9 @@ void AppletLoader::compactRepresentationCheck() //Icon } else { - QQuickItem *fullItem = qobject_cast(createFullRepresentationItem()); QQuickItem *compactItem = qobject_cast(createCompactRepresentationItem()); - QObject *compactExpanderItem = createCompactRepresentationExpanderItem(); - if (fullItem && compactItem && compactExpanderItem) { + if (compactItem) { //set the root item as the main visible item compactItem->setParentItem(this); compactItem->setVisible(true); @@ -495,8 +523,15 @@ void AppletLoader::compactRepresentationCheck() prop.write(expr.evaluate()); } - compactExpanderItem->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); - compactExpanderItem->setProperty("fullRepresentation", QVariant::fromValue(fullItem)); + if (m_fullRepresentationItem) { + m_fullRepresentationItem.data()->setProperty("parent", QVariant()); + } + + if (m_compactRepresentationExpanderItem) { + m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); + m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + } + m_currentRepresentationItem = compactItem; connectLayoutAttached(compactItem); } diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index 2f995e1c4..d32c5b8d5 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -61,6 +61,12 @@ class AppletLoader : public QQuickItem //FIXME: is it wise to expose this? Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged) + /** + * True when the applet is showing its full representation. either as the main only view, or in a popup. + * Setting it will open or close the popup if the plasmoid is iconified, however it won't have effect if the applet is open + */ + Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged) + public: AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0); ~AppletLoader(); @@ -105,6 +111,9 @@ public: } } + bool isExpanded() const; + void setExpanded(bool expanded); + Q_SIGNALS: void switchWidthChanged(int width); void switchHeightChanged(int height); @@ -119,6 +128,8 @@ Q_SIGNALS: void fullRepresentationItemChanged(QObject *fullRepresentationItem); void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem); + void expandedChanged(); + protected: KDeclarative::QmlObject *qmlObject(); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -169,6 +180,8 @@ private: DeclarativeAppletScript *m_appletScriptEngine; KDeclarative::QmlObject *m_qmlObject; + bool m_expanded : 1; + static QHash s_rootObjects; }; From 3a4093f15f4637dc5fac27f30dd673eb180f31b3 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 29 Jan 2014 17:35:33 +0100 Subject: [PATCH 06/31] update porting script --- tools/port-plasma2.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/port-plasma2.sh b/tools/port-plasma2.sh index 3ce1a3c86..d894d69d5 100755 --- a/tools/port-plasma2.sh +++ b/tools/port-plasma2.sh @@ -138,5 +138,19 @@ for FS in `find $PWD -name '*.h' -o -name '*.cpp'`; do perl -p -i -e 's/Plasma\:\:AcceptingInputStatus/Plasma::Types::AcceptingInputStatus/g' $FS done +# make compactrepresentation come from Plasmoid.* +# size hints come from Layout +for FS in `find $PWD -type f -name '*.qml'`; do + perl -p -i -e 's/property Component compactRepresentation/Plasmoid.compactRepresentation/g' $FS + perl -p -i -e 's/property int minimumWidth/Layout.minimumWidth/g' $FS + perl -p -i -e 's/property int minimumHeight/Layout.minimumHeight/g' $FS + perl -p -i -e 's/property int maximumWidth/Layout.maximumWidth/g' $FS + perl -p -i -e 's/property int maximumHeight/Layout.maximumHeight/g' $FS + perl -p -i -e 's/property bool fillWidth/Layout.fillWidth/g' $FS + perl -p -i -e 's/property bool fillHeight/Layout.fillHeight/g' $FS +done +for FS in `find $PWD -type f -name '*main.qml'`; do + perl -p -i -e 's/QtQuick 2.0/QtQuick 2.0\nimport org.kde.plasma.shell 2.0/g' $FS +done From bf648ceeb694aca899d39e9e628f6ed300fb4dbe Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 29 Jan 2014 20:07:29 +0100 Subject: [PATCH 07/31] default full component as the root component if a fullrepresentation wasn't specified, use the root as fullrepresentation: item and component --- src/scriptengines/qml/plasmoid/appletloader.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index f5d17817f..6d9278cec 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -129,18 +129,25 @@ void AppletLoader::init() initialProperties["height"] = height(); m_qmlObject->completeInitialization(initialProperties); - + //default fullrepresentation is our root main component, if none specified + if (!m_fullRepresentation) { + m_fullRepresentation = m_qmlObject->mainComponent(); + m_fullRepresentationItem = m_qmlObject->rootObject(); + emit fullRepresentationChanged(m_fullRepresentation.data()); + } //default m_compactRepresentation is a simple icon provided by the shell package if (!m_compactRepresentation) { m_compactRepresentation = new QQmlComponent(engine, this); m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("defaultcompactrepresentation"))); + emit compactRepresentationChanged(m_compactRepresentation.data()); } //default m_compactRepresentationExpander is the popup in which fullRepresentation goes if (!m_compactRepresentationExpander) { m_compactRepresentationExpander = new QQmlComponent(engine, this); m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("compactapplet"))); + emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpander.data()); } } @@ -301,7 +308,9 @@ QObject *AppletLoader::createFullRepresentationItem() if (m_fullRepresentation) { m_fullRepresentationItem = m_qmlObject->createObjectFromComponent(m_fullRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject())); } else { + m_fullRepresentation = m_qmlObject->mainComponent(); m_fullRepresentationItem = m_qmlObject->rootObject(); + emit fullRepresentationChanged(m_fullRepresentation.data()); } QQuickItem *graphicsObj = qobject_cast(m_fullRepresentationItem.data()); From 9e65dbc78905deffc6a8aba673235aa8646d9019 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 30 Jan 2014 22:38:44 +0100 Subject: [PATCH 08/31] export compactRepresentationExpander still have to decide if this is a really bad idea --- src/scriptengines/qml/plasmoid/appletloader.cpp | 17 ++++++++++++++++- src/scriptengines/qml/plasmoid/appletloader.h | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index 6d9278cec..a31f770cd 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -218,6 +218,21 @@ void AppletLoader::setFullRepresentation(QQmlComponent *component) emit fullRepresentationChanged(component); } +QQmlComponent *AppletLoader::compactRepresentationExpander() +{ + return m_compactRepresentationExpander.data(); +} + +void AppletLoader::setCompactRepresentationExpander(QQmlComponent *component) +{ + if (m_compactRepresentationExpander.data() == component) { + return; + } + + m_compactRepresentationExpander = component; + emit compactRepresentationExpanderChanged(component); +} + QQmlComponent *AppletLoader::preferredRepresentation() { return m_preferredRepresentation.data(); @@ -254,7 +269,7 @@ void AppletLoader::setExpanded(bool expanded) createCompactRepresentationExpanderItem(); m_expanded = expanded; - emit expandedChanged(); + emit expandedChanged(expanded); } ////////////Internals diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index d32c5b8d5..4862e2cb8 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -59,7 +59,7 @@ class AppletLoader : public QQuickItem Q_PROPERTY(QQmlComponent *preferredRepresentation READ preferredRepresentation WRITE setPreferredRepresentation NOTIFY preferredRepresentationChanged) //FIXME: is it wise to expose this? - Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged) + Q_PROPERTY(QQmlComponent *compactRepresentationExpander READ compactRepresentationExpander WRITE setCompactRepresentationExpander NOTIFY compactRepresentationExpanderChanged) /** * True when the applet is showing its full representation. either as the main only view, or in a popup. @@ -128,7 +128,7 @@ Q_SIGNALS: void fullRepresentationItemChanged(QObject *fullRepresentationItem); void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem); - void expandedChanged(); + void expandedChanged(bool expanded); protected: KDeclarative::QmlObject *qmlObject(); From 856e16e803972eb7a74b9a1342cd93225a11d2a4 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 31 Jan 2014 16:56:16 +0100 Subject: [PATCH 09/31] safer sizehint propagation --- .../qml/plasmoid/appletloader.cpp | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index a31f770cd..69c50d242 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -90,7 +90,6 @@ void AppletLoader::init() Q_ASSERT(m_appletScriptEngine); - //Initialize the main QML file QQmlEngine *engine = m_qmlObject->engine(); @@ -401,7 +400,19 @@ void AppletLoader::connectLayoutAttached(QObject *item) //HACK: check the Layout properties we wrote QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(m_qmlObject->rootObject())); - QObject *ownLayout = p.object(); + + QObject *ownLayout = 0; + + foreach (QObject *child, children()) { + //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight + if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && + child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && + child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && + child->property("fillWidth").isValid() && child->property("fillHeight").isValid() + ) { + ownLayout = child; + } + } //this should never happen, since we ask to create it if doesn't exists if (!ownLayout) { @@ -409,12 +420,13 @@ void AppletLoader::connectLayoutAttached(QObject *item) } //if the representation didn't change, don't do anything - if (m_representationLayout.data() == layout || - m_ownLayout.data() == ownLayout) { + if (m_representationLayout.data() == layout) { return; } - disconnect(layout, 0, this, 0); + if (m_representationLayout) { + disconnect(m_representationLayout.data(), 0, this, 0); + } //Here we can't use the new connect syntax because we can't link against QtQuick layouts connect(layout, SIGNAL(minimumWidthChanged()), @@ -439,17 +451,22 @@ void AppletLoader::connectLayoutAttached(QObject *item) m_representationLayout = layout; m_ownLayout = ownLayout; + + propagateSizeHint("minimumWidth"); + propagateSizeHint("minimumHeight"); + propagateSizeHint("preferredWidth"); + propagateSizeHint("preferredHeight"); + propagateSizeHint("maximumWidth"); + propagateSizeHint("maximumHeight"); + propagateSizeHint("fillWidth"); + propagateSizeHint("fillHeight"); } void AppletLoader::propagateSizeHint(const QByteArray &layoutProperty) { - if (!m_currentRepresentationItem) { - return; + if (m_ownLayout && m_representationLayout) { + m_ownLayout.data()->setProperty(layoutProperty, m_representationLayout.data()->property(layoutProperty)); } - - QQmlExpression *expr = new QQmlExpression(QtQml::qmlContext(m_currentRepresentationItem.data()), m_currentRepresentationItem.data(), "Layout."+layoutProperty); - QQmlProperty prop(this, "Layout."+layoutProperty, QtQml::qmlContext(m_currentRepresentationItem.data())); - prop.write(expr->evaluate()); } void AppletLoader::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) From 89cb417e9fb36cde82c52b61731ab7c197bbf8a4 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 31 Jan 2014 19:59:45 +0100 Subject: [PATCH 10/31] propagate sizehints from mainItem --- src/declarativeimports/core/dialog.cpp | 69 ++++++++++++++++++++++++++ src/declarativeimports/core/dialog.h | 8 +++ 2 files changed, 77 insertions(+) diff --git a/src/declarativeimports/core/dialog.cpp b/src/declarativeimports/core/dialog.cpp index bb746da63..a4f5d23d0 100644 --- a/src/declarativeimports/core/dialog.cpp +++ b/src/declarativeimports/core/dialog.cpp @@ -44,6 +44,10 @@ #include #endif +//Unfortunately QWINDOWSIZE_MAX is not exported +#define DIALOGSIZE_MAX ((1<<24)-1) + + DialogProxy::DialogProxy(QQuickItem *parent) : QQuickWindow(parent ? parent->window() : 0), m_location(Plasma::Types::BottomEdge), @@ -111,6 +115,35 @@ void DialogProxy::setMainItem(QQuickItem *mainItem) m_syncTimer->stop(); syncToMainItemSize(); } + + //Extract the representation's Layout, if any + QObject *layout = 0; + + //Search a child that has the needed Layout properties + //HACK: here we are not type safe, but is the only way to access to a pointer of Layout + foreach (QObject *child, mainItem->children()) { + //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight + if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && + child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && + child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && + child->property("fillWidth").isValid() && child->property("fillHeight").isValid() + ) { + layout = child; + } + } + m_mainItemLayout = layout; + + if (layout) { + connect(layout, SIGNAL(minimumWidthChanged()), this, SLOT(updateMinimumWidth())); + connect(layout, SIGNAL(minimumHeightChanged()), this, SLOT(updateMinimumHeight())); + connect(layout, SIGNAL(maximumWidthChanged()), this, SLOT(updatemaximumWidth())); + connect(layout, SIGNAL(maximumHeightChanged()), this, SLOT(updatemaximumHeight())); + + updateMinimumWidth(); + updateMinimumHeight(); + updateMaximumWidth(); + updateMaximumHeight(); + } } //if this is called in Component.onCompleted we have to wait a loop the item is added to a scene @@ -559,5 +592,41 @@ void DialogProxy::updateInputShape() #endif } +void DialogProxy::updateMinimumWidth() +{ + if (m_mainItemLayout) { + setMinimumWidth(m_mainItemLayout.data()->property("minimumWidth").toInt()); + } else { + setMinimumWidth(-1); + } +} + +void DialogProxy::updateMinimumHeight() +{ + if (m_mainItemLayout) { + setMinimumHeight(m_mainItemLayout.data()->property("minimumHeight").toInt()); + } else { + setMinimumHeight(-1); + } +} + +void DialogProxy::updateMaximumWidth() +{ + if (m_mainItemLayout) { + setMaximumWidth(m_mainItemLayout.data()->property("maximumWidth").toInt()); + } else { + setMaximumWidth(DIALOGSIZE_MAX); + } +} + +void DialogProxy::updateMaximumHeight() +{ + if (m_mainItemLayout) { + setMaximumHeight(m_mainItemLayout.data()->property("maximumWidth").toInt()); + } else { + setMaximumHeight(DIALOGSIZE_MAX); + } +} + #include "dialog.moc" diff --git a/src/declarativeimports/core/dialog.h b/src/declarativeimports/core/dialog.h index a76e01635..c03cab0ab 100644 --- a/src/declarativeimports/core/dialog.h +++ b/src/declarativeimports/core/dialog.h @@ -171,12 +171,20 @@ private Q_SLOTS: void updateVisibility(bool visible); + void updateMinimumWidth(); + void updateMinimumHeight(); + void updateMaximumWidth(); + void updateMaximumHeight(); + private: QRect m_cachedGeometry; WindowType m_type; bool m_hideOnWindowDeactivate; bool m_outputOnly; Plasma::Theme m_theme; + + //Attached Layout property of mainItem, if any + QWeakPointer m_mainItemLayout; }; #endif From b68bbca6c8ad397e913c48c0ed8aec10953929b7 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 31 Jan 2014 20:03:33 +0100 Subject: [PATCH 11/31] check for validity --- src/declarativeimports/core/dialog.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/declarativeimports/core/dialog.cpp b/src/declarativeimports/core/dialog.cpp index a4f5d23d0..80cb674e4 100644 --- a/src/declarativeimports/core/dialog.cpp +++ b/src/declarativeimports/core/dialog.cpp @@ -613,7 +613,12 @@ void DialogProxy::updateMinimumHeight() void DialogProxy::updateMaximumWidth() { if (m_mainItemLayout) { - setMaximumWidth(m_mainItemLayout.data()->property("maximumWidth").toInt()); + const int hint = m_mainItemLayout.data()->property("maximumWidth").toInt(); + if (hint > 0) { + setMaximumWidth(hint); + } else { + setMaximumWidth(DIALOGSIZE_MAX); + } } else { setMaximumWidth(DIALOGSIZE_MAX); } @@ -622,7 +627,12 @@ void DialogProxy::updateMaximumWidth() void DialogProxy::updateMaximumHeight() { if (m_mainItemLayout) { - setMaximumHeight(m_mainItemLayout.data()->property("maximumWidth").toInt()); + const int hint = m_mainItemLayout.data()->property("maximumHeight").toInt(); + if (hint > 0) { + setMaximumWidth(hint); + } else { + setMaximumWidth(DIALOGSIZE_MAX); + } } else { setMaximumHeight(DIALOGSIZE_MAX); } From 362a5017b611ae1357c13168159152b709930826 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 3 Feb 2014 18:47:51 +0100 Subject: [PATCH 12/31] support a corona child of an applet this is an ad-hoc thing for the systray, would be better not having something like that --- src/plasma/private/applet_p.cpp | 20 ++++++++++--------- .../qml/plasmoid/appletinterface.cpp | 1 + 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index 7afcdd37c..2dc3a3083 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -358,12 +358,21 @@ KConfigGroup *AppletPrivate::mainConfigGroup() return mainConfig; } + Containment *c = q->containment(); + Plasma::Applet *parentApplet = 0; + if (c && c->corona()) { + parentApplet = qobject_cast(c->corona()->parent()); + } + if (q->isContainment()) { Corona *corona = static_cast(q)->corona(); KConfigGroup containmentConfig; //qDebug() << "got a corona, baby?" << (QObject*)corona << (QObject*)q; - if (corona) { + if (parentApplet) { + containmentConfig = parentApplet->config(); + containmentConfig = KConfigGroup(&containmentConfig, "Containments"); + } else if (corona) { containmentConfig = KConfigGroup(corona->config(), "Containments"); } else { containmentConfig = KConfigGroup(KSharedConfig::openConfig(), "Containments"); @@ -373,14 +382,7 @@ KConfigGroup *AppletPrivate::mainConfigGroup() } else { KConfigGroup appletConfig; - Containment *c = q->containment(); - Applet *parentApplet = qobject_cast(q->parent()); - if (parentApplet && parentApplet != static_cast(c)) { - // this applet is nested inside another applet! use it's config - // as the parent group in the config - appletConfig = parentApplet->config(); - appletConfig = KConfigGroup(&appletConfig, "Applets"); - } else if (c) { + if (c) { // applet directly in a Containment, as usual appletConfig = c->config(); appletConfig = KConfigGroup(&appletConfig, "Applets"); diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 7f3b95992..7e0ccb3e9 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -84,6 +84,7 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa this, &ContainmentInterface::screenChanged); } + setProperty("_plasma_applet", QVariant::fromValue(applet())); } AppletInterface::~AppletInterface() From 68f2de9ec3788fc627219ef86bf5a51e1fb57487 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 4 Feb 2014 16:18:45 +0100 Subject: [PATCH 13/31] correctly export containment properties --- src/scriptengines/qml/plasmoid/containmentinterface.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index f5a27dafc..80d43ec65 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -171,4 +171,6 @@ private: KActivities::Info *m_activityInfo; }; +QML_DECLARE_TYPEINFO(ContainmentInterface, QML_HAS_ATTACHED_PROPERTIES) + #endif From 2a0384c3c70f5a14227e16e9c9925e51ef995e25 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 4 Feb 2014 16:43:47 +0100 Subject: [PATCH 14/31] keep locally applet and corona packages less references to the corona() --- src/scriptengines/qml/plasmoid/appletloader.cpp | 13 +++++++++---- src/scriptengines/qml/plasmoid/appletloader.h | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index 69c50d242..9ebe7cbe0 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -47,6 +47,11 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) m_appletScriptEngine(script), m_expanded(false) { + m_appletPackage = m_appletScriptEngine->package(); + if (m_appletScriptEngine->applet() && m_appletScriptEngine->applet()->containment() && m_appletScriptEngine->applet()->containment()->corona()) { + m_coronaPackage = m_appletScriptEngine->applet()->containment()->corona()->package(); + } + m_compactRepresentationCheckTimer.setSingleShot(true); m_compactRepresentationCheckTimer.setInterval(250); connect (&m_compactRepresentationCheckTimer, SIGNAL(timeout()), @@ -94,7 +99,7 @@ void AppletLoader::init() QQmlEngine *engine = m_qmlObject->engine(); PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, appletScript()->package()); - interceptor->addAllowedPath(m_appletScriptEngine->applet()->containment()->corona()->package().path()); + interceptor->addAllowedPath(m_coronaPackage.path()); engine->setUrlInterceptor(interceptor); m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript())); @@ -106,7 +111,7 @@ void AppletLoader::init() } reason = i18n("Error loading QML file: %1", reason); - m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("appleterror"))); + m_qmlObject->setSource(QUrl::fromLocalFile(m_coronaPackage.filePath("appleterror"))); m_qmlObject->completeInitialization(); @@ -138,14 +143,14 @@ void AppletLoader::init() //default m_compactRepresentation is a simple icon provided by the shell package if (!m_compactRepresentation) { m_compactRepresentation = new QQmlComponent(engine, this); - m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("defaultcompactrepresentation"))); + m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_coronaPackage.filePath("defaultcompactrepresentation"))); emit compactRepresentationChanged(m_compactRepresentation.data()); } //default m_compactRepresentationExpander is the popup in which fullRepresentation goes if (!m_compactRepresentationExpander) { m_compactRepresentationExpander = new QQmlComponent(engine, this); - m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("compactapplet"))); + m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_coronaPackage.filePath("compactapplet"))); emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpander.data()); } diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index 4862e2cb8..440b57d24 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -180,6 +180,9 @@ private: DeclarativeAppletScript *m_appletScriptEngine; KDeclarative::QmlObject *m_qmlObject; + Plasma::Package m_appletPackage; + Plasma::Package m_coronaPackage; + bool m_expanded : 1; static QHash s_rootObjects; From be4c13e62735546a78eb5c8a214cdc9a51f7e24e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 4 Feb 2014 17:01:28 +0100 Subject: [PATCH 15/31] call the import org.kde.plasma.plasmoid --- src/scriptengines/qml/plasmoid/declarativeappletscript.cpp | 4 ++-- tools/port-plasma2.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index e182725e1..5f8793a71 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -55,9 +55,9 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant m_interface(0) { //qmlRegisterType(); - qmlRegisterUncreatableType("org.kde.plasma.shell", 2, 0, "Plasmoid", + qmlRegisterUncreatableType("org.kde.plasma.plasmoid", 2, 0, "Plasmoid", QLatin1String("Do not create objects of type Plasmoid")); - qmlRegisterUncreatableType("org.kde.plasma.shell", 2, 0, "Containment", + qmlRegisterUncreatableType("org.kde.plasma.plasmoid", 2, 0, "Containment", QLatin1String("Do not create objects of type Containment")); qmlRegisterType(); diff --git a/tools/port-plasma2.sh b/tools/port-plasma2.sh index d894d69d5..d4f398339 100755 --- a/tools/port-plasma2.sh +++ b/tools/port-plasma2.sh @@ -151,6 +151,6 @@ for FS in `find $PWD -type f -name '*.qml'`; do done for FS in `find $PWD -type f -name '*main.qml'`; do - perl -p -i -e 's/QtQuick 2.0/QtQuick 2.0\nimport org.kde.plasma.shell 2.0/g' $FS + perl -p -i -e 's/QtQuick 2.0/QtQuick 2.0\nimport org.kde.plasma.plasmoid 2.0/g' $FS done From 9275e84a995304c37d0bf456f7bf4020fad7935d Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 4 Feb 2014 17:23:22 +0100 Subject: [PATCH 16/31] add a Wallpaper attached property for wallpapers --- .../qml/plasmoid/appletinterface.cpp | 1 - .../qml/plasmoid/containmentinterface.cpp | 2 -- .../qml/plasmoid/declarativeappletscript.cpp | 4 ++++ .../qml/plasmoid/wallpaperinterface.cpp | 8 +++++++- .../qml/plasmoid/wallpaperinterface.h | 16 ++++++++++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 7e0ccb3e9..e105f8a0a 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -59,7 +59,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa m_busy(false), m_hideOnDeactivate(true) { - qmlRegisterType(); qmlRegisterType(); connect(this, &AppletInterface::configNeedsSaving, diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index b5bf2d5c1..64bf4ecc1 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -59,8 +59,6 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent) { setAcceptedMouseButtons(Qt::AllButtons); - qmlRegisterType(); - connect(containment(), &Plasma::Containment::appletRemoved, this, &ContainmentInterface::appletRemovedForward); connect(containment(), &Plasma::Containment::appletAdded, diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 5f8793a71..d3099f310 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -42,6 +42,7 @@ #include "plasmoid/appletinterface.h" #include "plasmoid/containmentinterface.h" +#include "plasmoid/wallpaperinterface.h" #include #include @@ -60,6 +61,9 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant qmlRegisterUncreatableType("org.kde.plasma.plasmoid", 2, 0, "Containment", QLatin1String("Do not create objects of type Containment")); + qmlRegisterUncreatableType("org.kde.plasma.plasmoid", 2, 0, "Wallpaper", + QLatin1String("Do not create objects of type Wallpaper")); + qmlRegisterType(); Q_UNUSED(args); } diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp index 1d5f80d9d..88099f185 100644 --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp @@ -36,6 +36,8 @@ #include #include +QHash WallpaperInterface::s_rootObjects = QHash(); + WallpaperInterface::WallpaperInterface(ContainmentInterface *parent) : QQuickItem(parent), m_containmentInterface(parent), @@ -55,7 +57,9 @@ WallpaperInterface::WallpaperInterface(ContainmentInterface *parent) } WallpaperInterface::~WallpaperInterface() -{} +{ + s_rootObjects.remove(m_qmlObject->engine()); +} KPluginInfo::List WallpaperInterface::listWallpaperInfoForMimetype(const QString &mimetype, const QString &formFactor) { @@ -109,6 +113,7 @@ void WallpaperInterface::syncWallpaperPackage() if (!m_qmlObject) { m_qmlObject = new KDeclarative::QmlObject(this); + s_rootObjects[m_qmlObject->engine()] = this; m_qmlObject->setInitializationDelayed(true); } @@ -142,6 +147,7 @@ void WallpaperInterface::syncWallpaperPackage() } else if (m_qmlObject->mainComponent()) { qWarning() << "Error loading the wallpaper" << m_qmlObject->mainComponent()->errors(); + s_rootObjects.remove(m_qmlObject->engine()); m_qmlObject->deleteLater(); m_qmlObject = 0; diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.h b/src/scriptengines/qml/plasmoid/wallpaperinterface.h index 8750dc03f..8a4621f9e 100644 --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.h +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.h @@ -21,6 +21,7 @@ #define WALLPAPERINTERFACE_H #include +#include #include @@ -78,6 +79,17 @@ public: Q_INVOKABLE QAction *action(QString name) const; + static WallpaperInterface *qmlAttachedProperties(QObject *object) + { + //at the moment of the attached object creation, the root item is the only one that hasn't a parent + //only way to avoid creation of this attached for everybody but the root item + if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) { + return s_rootObjects.value(QtQml::qmlEngine(object)); + } else { + return 0; + } + } + Q_SIGNALS: void packageChanged(); void configurationChanged(); @@ -95,6 +107,10 @@ private: Plasma::ConfigLoader *m_configLoader; KActionCollection *m_actions; QSignalMapper *m_actionSignals; + + static QHash s_rootObjects; }; +QML_DECLARE_TYPEINFO(WallpaperInterface, QML_HAS_ATTACHED_PROPERTIES) + #endif From 308f59bc6890c66983b3d180205a11610f43277f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 4 Feb 2014 17:29:28 +0100 Subject: [PATCH 17/31] port to new api --- .../contents/ui/main.qml | 7 +-- .../conditionalloader/contents/ui/main.qml | 7 +-- examples/applets/config/contents/ui/main.qml | 4 +- .../dataenginemodel/contents/ui/main.qml | 5 +- .../applets/helloworld/contents/ui/main.qml | 5 +- examples/applets/notes/contents/ui/main.qml | 5 +- .../applets/qmltasks/contents/ui/qmltasks.qml | 4 +- .../contents/ui/testcomponents.qml | 4 +- .../contents/ui/testshaderapplet.qml | 4 +- .../testtheme/contents/ui/testtheme.qml | 4 +- .../widgetgallery/contents/ui/main.qml | 52 +++++++++---------- .../application/tablet/ui/main.qml | 5 +- .../windowthumbnails/contents/ui/main.qml | 5 +- 13 files changed, 59 insertions(+), 52 deletions(-) diff --git a/examples/applets/compactrepresentation/contents/ui/main.qml b/examples/applets/compactrepresentation/contents/ui/main.qml index 8a1ef7196..78c81576a 100644 --- a/examples/applets/compactrepresentation/contents/ui/main.qml +++ b/examples/applets/compactrepresentation/contents/ui/main.qml @@ -19,13 +19,14 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents Item { - property int minimumWidth: 200 - property int minimumHeight: 300 - property Component compactRepresentation: Component { + Layout.minimumWidth: 200 + Layout.minimumHeight: 300 + Plasmoid.compactRepresentation: Component { PlasmaComponents.Button { text: i18n("Click me") onClicked: plasmoid.expanded = !plasmoid.expanded diff --git a/examples/applets/conditionalloader/contents/ui/main.qml b/examples/applets/conditionalloader/contents/ui/main.qml index 0f855da24..985868ff4 100644 --- a/examples/applets/conditionalloader/contents/ui/main.qml +++ b/examples/applets/conditionalloader/contents/ui/main.qml @@ -17,6 +17,7 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore @@ -30,10 +31,10 @@ Rectangle { height: 100 radius: 10 smooth: true - property int minimumWidth: units.gridUnit * 20 - property int minimumHeight: column.implicitHeight + Layout.minimumWidth: units.gridUnit * 20 + Layout.minimumHeight: column.implicitHeight - property Component compactRepresentation: Component { + Plasmoid.compactRepresentation: Component { Rectangle { MouseArea { anchors.fill: parent diff --git a/examples/applets/config/contents/ui/main.qml b/examples/applets/config/contents/ui/main.qml index 15969b0bc..2c0cb62ce 100644 --- a/examples/applets/config/contents/ui/main.qml +++ b/examples/applets/config/contents/ui/main.qml @@ -26,8 +26,8 @@ Item { id: root width: 100 height: 100 - property int minimumWidth: units.gridUnit * 20 - property int minimumHeight: column.implicitHeight + Layout.minimumWidth: units.gridUnit * 20 + Layout.minimumHeight: column.implicitHeight ColumnLayout { diff --git a/examples/applets/dataenginemodel/contents/ui/main.qml b/examples/applets/dataenginemodel/contents/ui/main.qml index d64e71f48..e28741200 100644 --- a/examples/applets/dataenginemodel/contents/ui/main.qml +++ b/examples/applets/dataenginemodel/contents/ui/main.qml @@ -19,6 +19,7 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras @@ -26,8 +27,8 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras Column { width: 500 height: 500 - property int minimumWidth: 200 - property int minimumHeight: 300 + Layout.minimumWidth: 200 + Layout.minimumHeight: 300 PlasmaCore.DataSource { id: source diff --git a/examples/applets/helloworld/contents/ui/main.qml b/examples/applets/helloworld/contents/ui/main.qml index 810d5f8b1..c6746f5b2 100644 --- a/examples/applets/helloworld/contents/ui/main.qml +++ b/examples/applets/helloworld/contents/ui/main.qml @@ -19,12 +19,13 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents Item { - property int minimumWidth: 200 - property int minimumHeight: 300 + Layout.minimumWidth: 200 + Layout.minimumHeight: 300 PlasmaComponents.Label { text: i18n("Hello world") diff --git a/examples/applets/notes/contents/ui/main.qml b/examples/applets/notes/contents/ui/main.qml index d0c5e13fc..b74e15203 100644 --- a/examples/applets/notes/contents/ui/main.qml +++ b/examples/applets/notes/contents/ui/main.qml @@ -18,12 +18,13 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents PlasmaCore.SvgItem { - property int minimumWidth: 150 - property int minimumHeight: 150 + Layout.minimumWidth: 150 + Layout.minimumHeight: 150 svg: PlasmaCore.Svg("widgets/notes") elementId: "yellow-notes" diff --git a/examples/applets/qmltasks/contents/ui/qmltasks.qml b/examples/applets/qmltasks/contents/ui/qmltasks.qml index 91a99106e..e6e538a74 100644 --- a/examples/applets/qmltasks/contents/ui/qmltasks.qml +++ b/examples/applets/qmltasks/contents/ui/qmltasks.qml @@ -27,8 +27,8 @@ Item { width: 400 height: 32 - property bool fillWidth: true - property bool fillHeight: true + Layout.fillWidth: true + Layout.fillHeight: true implicitWidth: tasksModel.count * 50 PlasmaCore.DataSource { diff --git a/examples/applets/testcomponents/contents/ui/testcomponents.qml b/examples/applets/testcomponents/contents/ui/testcomponents.qml index 8b6c3f0d1..19909a95b 100644 --- a/examples/applets/testcomponents/contents/ui/testcomponents.qml +++ b/examples/applets/testcomponents/contents/ui/testcomponents.qml @@ -28,8 +28,8 @@ Item { width: 100 height: 100 clip: true - property int minimumWidth: units.gridUnit * 20 - property int minimumHeight: units.gridUnit * 30 + Layout.minimumWidth: units.gridUnit * 20 + Layout.minimumHeight: units.gridUnit * 30 property int _s: units.iconSizes.small property int _h: units.iconSizes.desktop diff --git a/examples/applets/testshaders/contents/ui/testshaderapplet.qml b/examples/applets/testshaders/contents/ui/testshaderapplet.qml index b6ed67e59..f517383e9 100644 --- a/examples/applets/testshaders/contents/ui/testshaderapplet.qml +++ b/examples/applets/testshaders/contents/ui/testshaderapplet.qml @@ -28,8 +28,8 @@ Item { width: 400 height: 400 - property int minimumWidth: units.gridUnit * 20 - property int minimumHeight: units.gridUnit * 30 + Layout.minimumWidth: units.gridUnit * 20 + Layout.minimumHeight: units.gridUnit * 30 property int _s: units.iconSizes.small property int _h: units.iconSizes.desktop property int _m: 12 diff --git a/examples/applets/testtheme/contents/ui/testtheme.qml b/examples/applets/testtheme/contents/ui/testtheme.qml index 2fcaa02c1..8e4f0c02a 100644 --- a/examples/applets/testtheme/contents/ui/testtheme.qml +++ b/examples/applets/testtheme/contents/ui/testtheme.qml @@ -28,8 +28,8 @@ Item { width: 300 height: 400 clip: true - property int minimumWidth: units.gridUnit * 10 - property int minimumHeight: units.gridUnit * 10 + Layout.minimumWidth: units.gridUnit * 10 + Layout.minimumHeight: units.gridUnit * 10 property int _s: units.iconSizes.small property int _h: units.iconSizes.medium diff --git a/examples/applets/widgetgallery/contents/ui/main.qml b/examples/applets/widgetgallery/contents/ui/main.qml index 6c0e0ea81..68d84089a 100644 --- a/examples/applets/widgetgallery/contents/ui/main.qml +++ b/examples/applets/widgetgallery/contents/ui/main.qml @@ -18,40 +18,40 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.components 2.0 -import org.kde.plasma.shell 2.0 Item { - Layout.minimumWidth: 300 - Layout.minimumHeight: 400 - - Plasmoid.title: "bah" Plasmoid.switchWidth: 300 Plasmoid.switchHeight: 400 - ToolBar { - id: toolBar - z: 10 - //AppletInterface.title: "bah" - anchors { - top: parent.top - left: parent.left - right: parent.right - } - } + Plasmoid.fullRepresentation: Item { + Layout.minimumWidth: 300 + Layout.minimumHeight: 400 - - PageStack { - id: pageStack - toolBar: toolBar - clip: true - anchors { - top: toolBar.bottom - left: parent.left - right: parent.right - bottom: parent.bottom + ToolBar { + id: toolBar + z: 10 + //AppletInterface.title: "bah" + anchors { + top: parent.top + left: parent.left + right: parent.right + } + } + + PageStack { + id: pageStack + toolBar: toolBar + clip: true + anchors { + top: toolBar.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } + initialPage: Qt.createComponent("Menu.qml") } - initialPage: Qt.createComponent("Menu.qml") } } diff --git a/examples/applets/widgetgallery/platformcontents/application/tablet/ui/main.qml b/examples/applets/widgetgallery/platformcontents/application/tablet/ui/main.qml index fe51e5044..057dd3d99 100644 --- a/examples/applets/widgetgallery/platformcontents/application/tablet/ui/main.qml +++ b/examples/applets/widgetgallery/platformcontents/application/tablet/ui/main.qml @@ -18,11 +18,12 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.components 2.0 Image { - property int minimumWidth: 300 - property int minimumHeight: 400 + Layout.minimumWidth: 300 + Layout.minimumHeight: 400 source: "image://appbackgrounds/standard" fillMode: Image.Tile asynchronous: true diff --git a/examples/applets/windowthumbnails/contents/ui/main.qml b/examples/applets/windowthumbnails/contents/ui/main.qml index 92ec7f282..bf8f01b25 100644 --- a/examples/applets/windowthumbnails/contents/ui/main.qml +++ b/examples/applets/windowthumbnails/contents/ui/main.qml @@ -20,6 +20,7 @@ */ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras @@ -28,8 +29,8 @@ Item { width: 400 height: 32 - property bool fillWidth: true - property bool fillHeight: true + Layout.fillWidth: true + Layout.fillHeight: true PlasmaCore.DataSource { id: tasksSource From e2ee69bf085484f5e77c3fb56b2f2f60579b766e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 12:09:56 +0100 Subject: [PATCH 18/31] note about subclass property at left hand --- src/scriptengines/qml/plasmoid/declarativeappletscript.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index d3099f310..cef4dddda 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -56,6 +56,9 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant m_interface(0) { //qmlRegisterType(); + //FIXME: use this if/when will be possible to have properties of attached items subclasses on the left hand of expressions + /*qmlRegisterUncreatableType("org.kde.plasma.plasmoid", 2, 0, "Plasmoid", + QLatin1String("Do not create objects of type Plasmoid"));*/ qmlRegisterUncreatableType("org.kde.plasma.plasmoid", 2, 0, "Plasmoid", QLatin1String("Do not create objects of type Plasmoid")); qmlRegisterUncreatableType("org.kde.plasma.plasmoid", 2, 0, "Containment", From 3325f24992b3038fad55246b1adc610724765116 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 12:51:31 +0100 Subject: [PATCH 19/31] appletLoader doesn't depend from Declarativeappletscript --- src/plasma/applet.h | 31 +++++++------- .../qml/plasmoid/appletinterface.cpp | 10 +++-- .../qml/plasmoid/appletinterface.h | 5 ++- .../qml/plasmoid/appletloader.cpp | 41 ++++++++++--------- src/scriptengines/qml/plasmoid/appletloader.h | 10 ++--- .../qml/plasmoid/declarativeappletscript.cpp | 2 - 6 files changed, 52 insertions(+), 47 deletions(-) diff --git a/src/plasma/applet.h b/src/plasma/applet.h index c91cb6e3b..7fce564f4 100644 --- a/src/plasma/applet.h +++ b/src/plasma/applet.h @@ -415,6 +415,21 @@ class PLASMA_EXPORT Applet : public QObject public Q_SLOTS: //BOOKKEEPING + /** + * Call this method when the applet fails to launch properly. An + * optional reason can be provided. + * + * Not that all children items will be deleted when this method is + * called. If you have pointers to these items, you will need to + * reset them after calling this method. + * + * @param failed true when the applet failed, false when it succeeded + * @param reason an optional reason to show the user why the applet + * failed to launch + * @since 5.0 + **/ + void setLaunchErrorMessage(const QString &reason = QString()); + /** * Sets the immutability type for this applet (not immutable, * user immutable or system immutable) @@ -488,22 +503,6 @@ class PLASMA_EXPORT Applet : public QObject */ Applet(QObject *parent, const QVariantList &args); -//BOOKEEPING - /** - * Call this method when the applet fails to launch properly. An - * optional reason can be provided. - * - * Not that all children items will be deleted when this method is - * called. If you have pointers to these items, you will need to - * reset them after calling this method. - * - * @param failed true when the applet failed, false when it succeeded - * @param reason an optional reason to show the user why the applet - * failed to launch - * @since 5.0 - **/ - void setLaunchErrorMessage(const QString &reason = QString()); - //CONFIGURATION /** * When called, the Applet should write any information needed as part diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index e105f8a0a..3d83dfc02 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -53,8 +53,9 @@ Q_DECLARE_METATYPE(AppletInterface*) AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent) - : AppletLoader(script, parent), + : AppletLoader(script->applet(), parent), m_actionSignals(0), + m_appletScriptEngine(script), m_backgroundHints(Plasma::Types::StandardBackground), m_busy(false), m_hideOnDeactivate(true) @@ -82,14 +83,17 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa connect(applet()->containment(), &Plasma::Containment::screenChanged, this, &ContainmentInterface::screenChanged); } - - setProperty("_plasma_applet", QVariant::fromValue(applet())); } AppletInterface::~AppletInterface() { } +DeclarativeAppletScript *AppletInterface::appletScript() const +{ + return m_appletScriptEngine; +} + void AppletInterface::init() { if (qmlObject()->rootObject() && m_configuration) { diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 688e07581..bdac08362 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -154,12 +154,12 @@ public: //API not intended for the QML part + DeclarativeAppletScript *appletScript() const; + QList contextualActions() const; void executeAction(const QString &name); - Plasma::Applet *applet() const { return appletScript()->applet(); } - //QML API------------------------------------------------------------------- /** @@ -302,6 +302,7 @@ private: KDeclarative::ConfigPropertyMap *m_configuration; + DeclarativeAppletScript *m_appletScriptEngine; //UI-specific members ------------------ diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index 9ebe7cbe0..921e9d99a 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -40,16 +39,16 @@ QHash AppletLoader::s_rootObjects = QHash(); -AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) +AppletLoader::AppletLoader(Plasma::Applet *applet, QQuickItem *parent) : QQuickItem(parent), m_switchWidth(-1), m_switchHeight(-1), - m_appletScriptEngine(script), + m_applet(applet), m_expanded(false) { - m_appletPackage = m_appletScriptEngine->package(); - if (m_appletScriptEngine->applet() && m_appletScriptEngine->applet()->containment() && m_appletScriptEngine->applet()->containment()->corona()) { - m_coronaPackage = m_appletScriptEngine->applet()->containment()->corona()->package(); + m_appletPackage = m_applet->package(); + if (m_applet && m_applet->containment() && m_applet->containment()->corona()) { + m_coronaPackage = m_applet->containment()->corona()->package(); } m_compactRepresentationCheckTimer.setSingleShot(true); @@ -62,7 +61,7 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) m_fullRepresentationResizeTimer.setInterval(250); connect (&m_fullRepresentationResizeTimer, &QTimer::timeout, [=]() { - KConfigGroup cg = m_appletScriptEngine->applet()->config(); + KConfigGroup cg = m_applet->config(); cg = KConfigGroup(&cg, "PopupApplet"); cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt()); cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt()); @@ -73,6 +72,10 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent) m_qmlObject = new KDeclarative::QmlObject(this); m_qmlObject->setInitializationDelayed(true); + + // set the graphicObject dynamic property on applet + m_applet->setProperty("graphicObject", QVariant::fromValue(this)); + setProperty("_plasma_applet", QVariant::fromValue(applet)); } AppletLoader::~AppletLoader() @@ -85,6 +88,11 @@ AppletLoader::~AppletLoader() s_rootObjects.remove(m_qmlObject->engine()); } +Plasma::Applet *AppletLoader::applet() const +{ + return m_applet; +} + void AppletLoader::init() { if (s_rootObjects.contains(this)) { @@ -93,16 +101,16 @@ void AppletLoader::init() s_rootObjects[m_qmlObject->engine()] = this; - Q_ASSERT(m_appletScriptEngine); + Q_ASSERT(m_applet); //Initialize the main QML file QQmlEngine *engine = m_qmlObject->engine(); - PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, appletScript()->package()); + PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, m_applet->package()); interceptor->addAllowedPath(m_coronaPackage.path()); engine->setUrlInterceptor(interceptor); - m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript())); + m_qmlObject->setSource(QUrl::fromLocalFile(m_applet->package().filePath("mainscript"))); if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) { QString reason; @@ -122,7 +130,7 @@ void AppletLoader::init() m_qmlObject->rootObject()->setProperty("reason", reason); } - appletScript()->setLaunchErrorMessage(reason); + m_applet->setLaunchErrorMessage(reason); } engine->rootContext()->setContextProperty("plasmoid", this); @@ -156,11 +164,6 @@ void AppletLoader::init() } -DeclarativeAppletScript *AppletLoader::appletScript() const -{ - return m_appletScriptEngine; -} - int AppletLoader::switchWidth() const { return m_switchWidth; @@ -259,7 +262,7 @@ bool AppletLoader::isExpanded() const void AppletLoader::setExpanded(bool expanded) { - if (m_appletScriptEngine->applet()->isContainment()) { + if (m_applet->isContainment()) { expanded = true; } @@ -506,7 +509,7 @@ void AppletLoader::compactRepresentationCheck() bool full = false; - if (m_appletScriptEngine->applet()->isContainment()) { + if (m_applet->isContainment()) { full = true; } else { @@ -519,7 +522,7 @@ void AppletLoader::compactRepresentationCheck() full = m_preferredRepresentation.data() == m_fullRepresentation.data(); //Otherwise, base on FormFactor } else { - full = (m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Horizontal && m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Vertical); + full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical); } } diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index 440b57d24..38e6f1c3f 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -23,15 +23,15 @@ #include #include #include +#include #include -#include "declarativeappletscript.h" +#include class QQmlComponent; namespace Plasma { class Applet; - class AppletScript; } namespace KDeclarative { @@ -68,10 +68,10 @@ class AppletLoader : public QQuickItem Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged) public: - AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0); + AppletLoader(Plasma::Applet *applet, QQuickItem *parent = 0); ~AppletLoader(); - DeclarativeAppletScript *appletScript() const; + Plasma::Applet *applet() const; int switchWidth() const; void setSwitchWidth(int width); @@ -177,7 +177,7 @@ private: QTimer m_compactRepresentationCheckTimer; QTimer m_fullRepresentationResizeTimer; - DeclarativeAppletScript *m_appletScriptEngine; + Plasma::Applet *m_applet; KDeclarative::QmlObject *m_qmlObject; Plasma::Package m_appletPackage; diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index cef4dddda..ab9cd856d 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -93,8 +93,6 @@ bool DeclarativeAppletScript::init() } m_interface->setParent(this); - // set the graphicObject dynamic property on applet - a->setProperty("graphicObject", QVariant::fromValue(m_interface)); return true; } From 74515ee2f5be240923233b3ba3fbc5166b1d3a98 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 12:59:33 +0100 Subject: [PATCH 20/31] use "_plasma_graphicObject" in applet* to avoid possible collisions, use the private looking name "_plasma_graphicObject" for the dynamic property of Applet that represents the AppletInterface* pointer --- src/plasmaquick/configview.cpp | 2 +- src/plasmaquick/plasmaquickview.cpp | 4 ++-- src/scriptengines/qml/plasmoid/appletinterface.cpp | 2 +- src/scriptengines/qml/plasmoid/appletloader.cpp | 2 +- .../qml/plasmoid/containmentinterface.cpp | 10 +++++----- src/shell/scripting/panel.cpp | 10 +++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/plasmaquick/configview.cpp b/src/plasmaquick/configview.cpp index cf9c1df19..3fc69973a 100644 --- a/src/plasmaquick/configview.cpp +++ b/src/plasmaquick/configview.cpp @@ -92,7 +92,7 @@ void ConfigViewPrivate::init() delete object; } - q->engine()->rootContext()->setContextProperty("plasmoid", applet->property("graphicObject").value()); + q->engine()->rootContext()->setContextProperty("plasmoid", applet->property("_plasma_graphicObject").value()); q->engine()->rootContext()->setContextProperty("configDialog", q); component->completeCreate(); delete component; diff --git a/src/plasmaquick/plasmaquickview.cpp b/src/plasmaquick/plasmaquickview.cpp index 03fe00e66..d137b6d30 100644 --- a/src/plasmaquick/plasmaquickview.cpp +++ b/src/plasmaquick/plasmaquickview.cpp @@ -67,7 +67,7 @@ void PlasmaQuickViewPrivate::setContainment(Plasma::Containment *cont) if (containment) { QObject::disconnect(containment.data(), 0, q, 0); - QObject *oldGraphicObject = containment.data()->property("graphicObject").value(); + QObject *oldGraphicObject = containment.data()->property("_plasma_graphicObject").value(); if (oldGraphicObject) { qDebug() << "Old graphics Object:" << oldGraphicObject << "Old containment" << containment.data(); //make sure the graphic object won't die with us @@ -100,7 +100,7 @@ void PlasmaQuickViewPrivate::setContainment(Plasma::Containment *cont) return; } - QQuickItem *graphicObject = qobject_cast(containment.data()->property("graphicObject").value()); + QQuickItem *graphicObject = qobject_cast(containment.data()->property("_plasma_graphicObject").value()); if (graphicObject) { diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 3d83dfc02..fef880c96 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -104,7 +104,7 @@ void AppletInterface::init() AppletLoader::init(); - qDebug() << "Graphic object created:" << applet() << applet()->property("graphicObject"); + qDebug() << "Graphic object created:" << applet() << this; geometryChanged(QRectF(), QRectF(x(), y(), width(), height())); emit busyChanged(); diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index 921e9d99a..e1dc2c73c 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -74,7 +74,7 @@ AppletLoader::AppletLoader(Plasma::Applet *applet, QQuickItem *parent) m_qmlObject->setInitializationDelayed(true); // set the graphicObject dynamic property on applet - m_applet->setProperty("graphicObject", QVariant::fromValue(this)); + m_applet->setProperty("_plasma_graphicObject", QVariant::fromValue(this)); setProperty("_plasma_applet", QVariant::fromValue(applet)); } diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 64bf4ecc1..f82a5bba4 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -222,7 +222,7 @@ Plasma::Applet *ContainmentInterface::addApplet(const QString &plugin, const QVa if (applet) { - QObject *appletGraphicObject = applet->property("graphicObject").value(); + QObject *appletGraphicObject = applet->property("_plasma_graphicObject").value(); blockSignals(false); @@ -239,7 +239,7 @@ void ContainmentInterface::setAppletArgs(Plasma::Applet *applet, const QString & return; } - AppletInterface *appletInterface = applet->property("graphicObject").value(); + AppletInterface *appletInterface = applet->property("_plasma_graphicObject").value(); if (appletInterface) { emit appletInterface->externalData(mimetype, data); } @@ -509,8 +509,8 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) return; } - QObject *appletGraphicObject = applet->property("graphicObject").value(); - QObject *contGraphicObject = containment()->property("graphicObject").value(); + QObject *appletGraphicObject = applet->property("_plasma_graphicObject").value(); + QObject *contGraphicObject = containment()->property("_plasma_graphicObject").value(); qDebug() << "Applet added on containment:" << containment()->title() << contGraphicObject << "Applet: " << applet << applet->title() << appletGraphicObject; @@ -538,7 +538,7 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) { - QObject *appletGraphicObject = applet->property("graphicObject").value(); + QObject *appletGraphicObject = applet->property("_plasma_graphicObject").value(); m_appletInterfaces.removeAll(appletGraphicObject); emit appletRemoved(appletGraphicObject); emit appletsChanged(); diff --git a/src/shell/scripting/panel.cpp b/src/shell/scripting/panel.cpp index ee66c400e..8f268d020 100644 --- a/src/shell/scripting/panel.cpp +++ b/src/shell/scripting/panel.cpp @@ -182,7 +182,7 @@ void Panel::setOffset(int pixels) return; } - QQuickItem *graphicObject = qobject_cast(c->property("graphicObject").value()); + QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); if (!graphicObject) { return; @@ -222,7 +222,7 @@ int Panel::length() const if (!c) { return 0; } - QQuickItem *graphicObject = qobject_cast(c->property("graphicObject").value()); + QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); if (!graphicObject) { return 0; @@ -242,7 +242,7 @@ void Panel::setLength(int pixels) return; } - QQuickItem *graphicObject = qobject_cast(c->property("graphicObject").value()); + QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); if (!graphicObject) { return; @@ -279,7 +279,7 @@ int Panel::height() const return 0; } - QQuickItem *graphicObject = qobject_cast(c->property("graphicObject").value()); + QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); if (!graphicObject) { return 0; @@ -296,7 +296,7 @@ void Panel::setHeight(int height) return; } - QQuickItem *graphicObject = qobject_cast(c->property("graphicObject").value()); + QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); if (!graphicObject) { return; From 4a5c20f9543f6b76792a97a778c82e76657f5e9e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 13:51:41 +0100 Subject: [PATCH 21/31] getters and setters for packages --- .../qml/plasmoid/appletloader.cpp | 20 ++++++++++++ src/scriptengines/qml/plasmoid/appletloader.h | 31 +++++++++++++------ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index e1dc2c73c..7bd378337 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -164,6 +164,26 @@ void AppletLoader::init() } +Plasma::Package AppletLoader::appletPackage() const +{ + return m_appletPackage; +} + +void AppletLoader::setAppletPackage(const Plasma::Package &package) +{ + m_appletPackage = package; +} + +Plasma::Package AppletLoader::coronaPackage() const +{ + return m_coronaPackage; +} + +void AppletLoader::setCoronaPackage(const Plasma::Package &package) +{ + m_coronaPackage = package; +} + int AppletLoader::switchWidth() const { return m_switchWidth; diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index 38e6f1c3f..211c18fe8 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -39,6 +39,7 @@ namespace KDeclarative { } + class AppletLoader : public QQuickItem { Q_OBJECT @@ -71,8 +72,23 @@ public: AppletLoader(Plasma::Applet *applet, QQuickItem *parent = 0); ~AppletLoader(); +////API NOT SUPPOSED TO BE USED BY QML Plasma::Applet *applet() const; + //Make the constructor lighter and delay the actual instantiation of the qml in the applet + virtual void init(); + + Plasma::Package appletPackage() const; + void setAppletPackage(const Plasma::Package &package); + + Plasma::Package coronaPackage() const; + void setCoronaPackage(const Plasma::Package &package); + + QObject *compactRepresentationItem(); + QObject *fullRepresentationItem(); + QObject *compactRepresentationExpanderItem(); + +////PROPERTY ACCESSORS int switchWidth() const; void setSwitchWidth(int width); @@ -93,13 +109,10 @@ public: QQmlComponent *compactRepresentationExpander(); void setCompactRepresentationExpander(QQmlComponent *component); - QObject *compactRepresentationItem(); - QObject *fullRepresentationItem(); - QObject *compactRepresentationExpanderItem(); - - //Reimplemented - virtual void init(); + bool isExpanded() const; + void setExpanded(bool expanded); +////NEEDED BY QML TO CREATE ATTACHED PROPERTIES static AppletLoader *qmlAttachedProperties(QObject *object) { //at the moment of the attached object creation, the root item is the only one that hasn't a parent @@ -111,13 +124,13 @@ public: } } - bool isExpanded() const; - void setExpanded(bool expanded); Q_SIGNALS: void switchWidthChanged(int width); void switchHeightChanged(int height); + void expandedChanged(bool expanded); + void compactRepresentationChanged(QQmlComponent *compactRepresentation); void fullRepresentationChanged(QQmlComponent *fullRepresentation); void preferredRepresentationChanged(QQmlComponent *preferredRepresentation); @@ -128,8 +141,6 @@ Q_SIGNALS: void fullRepresentationItemChanged(QObject *fullRepresentationItem); void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem); - void expandedChanged(bool expanded); - protected: KDeclarative::QmlObject *qmlObject(); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); From b8a41a88f3bcc6c2cec6cfd7cf8d98dfe2f9fddc Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 14:07:23 +0100 Subject: [PATCH 22/31] get rid of compactrepresentationexpander property --- src/scriptengines/qml/plasmoid/appletloader.cpp | 15 --------------- src/scriptengines/qml/plasmoid/appletloader.h | 7 ------- 2 files changed, 22 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletloader.cpp index 7bd378337..d9bde7c3c 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletloader.cpp @@ -245,21 +245,6 @@ void AppletLoader::setFullRepresentation(QQmlComponent *component) emit fullRepresentationChanged(component); } -QQmlComponent *AppletLoader::compactRepresentationExpander() -{ - return m_compactRepresentationExpander.data(); -} - -void AppletLoader::setCompactRepresentationExpander(QQmlComponent *component) -{ - if (m_compactRepresentationExpander.data() == component) { - return; - } - - m_compactRepresentationExpander = component; - emit compactRepresentationExpanderChanged(component); -} - QQmlComponent *AppletLoader::preferredRepresentation() { return m_preferredRepresentation.data(); diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletloader.h index 211c18fe8..62e7c74ea 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletloader.h @@ -59,9 +59,6 @@ class AppletLoader : public QQuickItem */ Q_PROPERTY(QQmlComponent *preferredRepresentation READ preferredRepresentation WRITE setPreferredRepresentation NOTIFY preferredRepresentationChanged) - //FIXME: is it wise to expose this? - Q_PROPERTY(QQmlComponent *compactRepresentationExpander READ compactRepresentationExpander WRITE setCompactRepresentationExpander NOTIFY compactRepresentationExpanderChanged) - /** * True when the applet is showing its full representation. either as the main only view, or in a popup. * Setting it will open or close the popup if the plasmoid is iconified, however it won't have effect if the applet is open @@ -105,10 +102,6 @@ public: QQmlComponent *preferredRepresentation(); void setPreferredRepresentation(QQmlComponent *component); - - QQmlComponent *compactRepresentationExpander(); - void setCompactRepresentationExpander(QQmlComponent *component); - bool isExpanded() const; void setExpanded(bool expanded); From c196f8b748962465336c53c822d5de1a3b844eb5 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 14:19:39 +0100 Subject: [PATCH 23/31] AppletLoader->AppletquickItem --- src/scriptengines/qml/CMakeLists.txt | 2 +- .../qml/plasmoid/appletinterface.cpp | 4 +- .../qml/plasmoid/appletinterface.h | 6 +- .../{appletloader.cpp => appletquickitem.cpp} | 86 +++++++++---------- .../{appletloader.h => appletquickitem.h} | 16 ++-- .../qml/plasmoid/containmentinterface.h | 2 +- 6 files changed, 58 insertions(+), 58 deletions(-) rename src/scriptengines/qml/plasmoid/{appletloader.cpp => appletquickitem.cpp} (87%) rename src/scriptengines/qml/plasmoid/{appletloader.h => appletquickitem.h} (94%) diff --git a/src/scriptengines/qml/CMakeLists.txt b/src/scriptengines/qml/CMakeLists.txt index 75dc8cf4c..150e4ab6d 100644 --- a/src/scriptengines/qml/CMakeLists.txt +++ b/src/scriptengines/qml/CMakeLists.txt @@ -10,7 +10,7 @@ endif() set(declarative_appletscript_SRCS plasmoid/declarativeappletscript.cpp - plasmoid/appletloader.cpp + plasmoid/appletquickitem.cpp plasmoid/appletinterface.cpp plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index fef880c96..1e7cbad6d 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -53,7 +53,7 @@ Q_DECLARE_METATYPE(AppletInterface*) AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent) - : AppletLoader(script->applet(), parent), + : AppletQuickItem(script->applet(), parent), m_actionSignals(0), m_appletScriptEngine(script), m_backgroundHints(Plasma::Types::StandardBackground), @@ -102,7 +102,7 @@ void AppletInterface::init() m_configuration = new KDeclarative::ConfigPropertyMap(applet()->configScheme(), this); - AppletLoader::init(); + AppletQuickItem::init(); qDebug() << "Graphic object created:" << applet() << this; diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index bdac08362..92fbd60e0 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -29,7 +29,7 @@ #include #include -#include "appletloader.h" +#include "appletquickitem.h" #include "declarativeappletscript.h" class QAction; @@ -49,7 +49,7 @@ namespace Plasma class ConfigLoader; } // namespace Plasma -class AppletInterface : public AppletLoader +class AppletInterface : public AppletQuickItem { Q_OBJECT @@ -220,7 +220,7 @@ public: static AppletInterface *qmlAttachedProperties(QObject *object) { - return qobject_cast(AppletLoader::qmlAttachedProperties(object)); + return qobject_cast(AppletQuickItem::qmlAttachedProperties(object)); } //PROPERTY ACCESSORS------------------------------------------------------------------- diff --git a/src/scriptengines/qml/plasmoid/appletloader.cpp b/src/scriptengines/qml/plasmoid/appletquickitem.cpp similarity index 87% rename from src/scriptengines/qml/plasmoid/appletloader.cpp rename to src/scriptengines/qml/plasmoid/appletquickitem.cpp index d9bde7c3c..2dedf0e75 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.cpp +++ b/src/scriptengines/qml/plasmoid/appletquickitem.cpp @@ -17,7 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "appletloader.h" +#include "appletquickitem.h" #include #include @@ -37,9 +37,9 @@ #include -QHash AppletLoader::s_rootObjects = QHash(); +QHash AppletQuickItem::s_rootObjects = QHash(); -AppletLoader::AppletLoader(Plasma::Applet *applet, QQuickItem *parent) +AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent) : QQuickItem(parent), m_switchWidth(-1), m_switchHeight(-1), @@ -78,7 +78,7 @@ AppletLoader::AppletLoader(Plasma::Applet *applet, QQuickItem *parent) setProperty("_plasma_applet", QVariant::fromValue(applet)); } -AppletLoader::~AppletLoader() +AppletQuickItem::~AppletQuickItem() { //Here the order is important delete m_compactRepresentationItem.data(); @@ -88,12 +88,12 @@ AppletLoader::~AppletLoader() s_rootObjects.remove(m_qmlObject->engine()); } -Plasma::Applet *AppletLoader::applet() const +Plasma::Applet *AppletQuickItem::applet() const { return m_applet; } -void AppletLoader::init() +void AppletQuickItem::init() { if (s_rootObjects.contains(this)) { return; @@ -164,32 +164,32 @@ void AppletLoader::init() } -Plasma::Package AppletLoader::appletPackage() const +Plasma::Package AppletQuickItem::appletPackage() const { return m_appletPackage; } -void AppletLoader::setAppletPackage(const Plasma::Package &package) +void AppletQuickItem::setAppletPackage(const Plasma::Package &package) { m_appletPackage = package; } -Plasma::Package AppletLoader::coronaPackage() const +Plasma::Package AppletQuickItem::coronaPackage() const { return m_coronaPackage; } -void AppletLoader::setCoronaPackage(const Plasma::Package &package) +void AppletQuickItem::setCoronaPackage(const Plasma::Package &package) { m_coronaPackage = package; } -int AppletLoader::switchWidth() const +int AppletQuickItem::switchWidth() const { return m_switchWidth; } -void AppletLoader::setSwitchWidth(int width) +void AppletQuickItem::setSwitchWidth(int width) { if (m_switchWidth == width) { return; @@ -199,12 +199,12 @@ void AppletLoader::setSwitchWidth(int width) emit switchWidthChanged(width); } -int AppletLoader::switchHeight() const +int AppletQuickItem::switchHeight() const { return m_switchHeight; } -void AppletLoader::setSwitchHeight(int width) +void AppletQuickItem::setSwitchHeight(int width) { if (m_switchHeight == width) { return; @@ -214,12 +214,12 @@ void AppletLoader::setSwitchHeight(int width) emit switchHeightChanged(width); } -QQmlComponent *AppletLoader::compactRepresentation() +QQmlComponent *AppletQuickItem::compactRepresentation() { return m_compactRepresentation.data(); } -void AppletLoader::setCompactRepresentation(QQmlComponent *component) +void AppletQuickItem::setCompactRepresentation(QQmlComponent *component) { if (m_compactRepresentation.data() == component) { return; @@ -230,12 +230,12 @@ void AppletLoader::setCompactRepresentation(QQmlComponent *component) } -QQmlComponent *AppletLoader::fullRepresentation() +QQmlComponent *AppletQuickItem::fullRepresentation() { return m_fullRepresentation.data(); } -void AppletLoader::setFullRepresentation(QQmlComponent *component) +void AppletQuickItem::setFullRepresentation(QQmlComponent *component) { if (m_fullRepresentation.data() == component) { return; @@ -245,12 +245,12 @@ void AppletLoader::setFullRepresentation(QQmlComponent *component) emit fullRepresentationChanged(component); } -QQmlComponent *AppletLoader::preferredRepresentation() +QQmlComponent *AppletQuickItem::preferredRepresentation() { return m_preferredRepresentation.data(); } -void AppletLoader::setPreferredRepresentation(QQmlComponent *component) +void AppletQuickItem::setPreferredRepresentation(QQmlComponent *component) { if (m_preferredRepresentation.data() == component) { return; @@ -260,12 +260,12 @@ void AppletLoader::setPreferredRepresentation(QQmlComponent *component) emit preferredRepresentationChanged(component); } -bool AppletLoader::isExpanded() const +bool AppletQuickItem::isExpanded() const { return m_expanded; } -void AppletLoader::setExpanded(bool expanded) +void AppletQuickItem::setExpanded(bool expanded) { if (m_applet->isContainment()) { expanded = true; @@ -287,29 +287,29 @@ void AppletLoader::setExpanded(bool expanded) ////////////Internals -KDeclarative::QmlObject *AppletLoader::qmlObject() +KDeclarative::QmlObject *AppletQuickItem::qmlObject() { return m_qmlObject; } -QObject *AppletLoader::compactRepresentationItem() +QObject *AppletQuickItem::compactRepresentationItem() { return m_compactRepresentationItem.data(); } -QObject *AppletLoader::fullRepresentationItem() +QObject *AppletQuickItem::fullRepresentationItem() { return m_fullRepresentationItem.data(); } -QObject *AppletLoader::compactRepresentationExpanderItem() +QObject *AppletQuickItem::compactRepresentationExpanderItem() { return m_compactRepresentationExpanderItem.data(); } -QObject *AppletLoader::createCompactRepresentationItem() +QObject *AppletQuickItem::createCompactRepresentationItem() { if (!m_compactRepresentation) { return 0; @@ -326,7 +326,7 @@ QObject *AppletLoader::createCompactRepresentationItem() return m_compactRepresentationItem.data(); } -QObject *AppletLoader::createFullRepresentationItem() +QObject *AppletQuickItem::createFullRepresentationItem() { if (m_fullRepresentationItem) { return m_fullRepresentationItem.data(); @@ -353,7 +353,7 @@ QObject *AppletLoader::createFullRepresentationItem() return m_fullRepresentationItem.data(); } -QObject *AppletLoader::createCompactRepresentationExpanderItem() +QObject *AppletQuickItem::createCompactRepresentationExpanderItem() { if (!m_compactRepresentationExpander) { return 0; @@ -374,7 +374,7 @@ QObject *AppletLoader::createCompactRepresentationExpanderItem() return m_compactRepresentationExpanderItem.data(); } -void AppletLoader::connectLayoutAttached(QObject *item) +void AppletQuickItem::connectLayoutAttached(QObject *item) { QObject *layout = 0; @@ -475,14 +475,14 @@ void AppletLoader::connectLayoutAttached(QObject *item) propagateSizeHint("fillHeight"); } -void AppletLoader::propagateSizeHint(const QByteArray &layoutProperty) +void AppletQuickItem::propagateSizeHint(const QByteArray &layoutProperty) { if (m_ownLayout && m_representationLayout) { m_ownLayout.data()->setProperty(layoutProperty, m_representationLayout.data()->property(layoutProperty)); } } -void AppletLoader::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +void AppletQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_UNUSED(oldGeometry) @@ -490,7 +490,7 @@ void AppletLoader::geometryChanged(const QRectF &newGeometry, const QRectF &oldG m_compactRepresentationCheckTimer.start(); } -void AppletLoader::itemChange(ItemChange change, const ItemChangeData &value) +void AppletQuickItem::itemChange(ItemChange change, const ItemChangeData &value) { if (change == QQuickItem::ItemSceneChange) { //we have a window: create the representations if needed @@ -505,7 +505,7 @@ void AppletLoader::itemChange(ItemChange change, const ItemChangeData &value) //// Slots -void AppletLoader::compactRepresentationCheck() +void AppletQuickItem::compactRepresentationCheck() { //ignore 0,0 sizes; if (width() <= 0 && height() <= 0) { @@ -592,46 +592,46 @@ void AppletLoader::compactRepresentationCheck() } } -void AppletLoader::minimumWidthChanged() +void AppletQuickItem::minimumWidthChanged() { propagateSizeHint("minimumWidth"); } -void AppletLoader::minimumHeightChanged() +void AppletQuickItem::minimumHeightChanged() { propagateSizeHint("minimumHeight"); } -void AppletLoader::preferredWidthChanged() +void AppletQuickItem::preferredWidthChanged() { propagateSizeHint("preferredWidth"); } -void AppletLoader::preferredHeightChanged() +void AppletQuickItem::preferredHeightChanged() { propagateSizeHint("preferredHeight"); } -void AppletLoader::maximumWidthChanged() +void AppletQuickItem::maximumWidthChanged() { propagateSizeHint("maximumWidth"); } -void AppletLoader::maximumHeightChanged() +void AppletQuickItem::maximumHeightChanged() { propagateSizeHint("maximumHeight"); } -void AppletLoader::fillWidthChanged() +void AppletQuickItem::fillWidthChanged() { propagateSizeHint("fillWidth"); } -void AppletLoader::fillHeightChanged() +void AppletQuickItem::fillHeightChanged() { propagateSizeHint("fillHeight"); } -#include "moc_appletloader.cpp" +#include "moc_appletquickitem.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletloader.h b/src/scriptengines/qml/plasmoid/appletquickitem.h similarity index 94% rename from src/scriptengines/qml/plasmoid/appletloader.h rename to src/scriptengines/qml/plasmoid/appletquickitem.h index 62e7c74ea..ea6d09fe4 100644 --- a/src/scriptengines/qml/plasmoid/appletloader.h +++ b/src/scriptengines/qml/plasmoid/appletquickitem.h @@ -17,8 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef APPLETLOADER_P -#define APPLETLOADER_P +#ifndef APPLETQUICKITEM_P +#define APPLETQUICKITEM_P #include #include @@ -40,7 +40,7 @@ namespace KDeclarative { -class AppletLoader : public QQuickItem +class AppletQuickItem : public QQuickItem { Q_OBJECT @@ -66,8 +66,8 @@ class AppletLoader : public QQuickItem Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged) public: - AppletLoader(Plasma::Applet *applet, QQuickItem *parent = 0); - ~AppletLoader(); + AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent = 0); + ~AppletQuickItem(); ////API NOT SUPPOSED TO BE USED BY QML Plasma::Applet *applet() const; @@ -106,7 +106,7 @@ public: void setExpanded(bool expanded); ////NEEDED BY QML TO CREATE ATTACHED PROPERTIES - static AppletLoader *qmlAttachedProperties(QObject *object) + static AppletQuickItem *qmlAttachedProperties(QObject *object) { //at the moment of the attached object creation, the root item is the only one that hasn't a parent //only way to avoid creation of this attached for everybody but the root item @@ -189,9 +189,9 @@ private: bool m_expanded : 1; - static QHash s_rootObjects; + static QHash s_rootObjects; }; -QML_DECLARE_TYPEINFO(AppletLoader, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPEINFO(AppletQuickItem, QML_HAS_ATTACHED_PROPERTIES) #endif diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index 80d43ec65..7746e99a1 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -114,7 +114,7 @@ public: static ContainmentInterface *qmlAttachedProperties(QObject *object) { - return qobject_cast(AppletLoader::qmlAttachedProperties(object)); + return qobject_cast(AppletQuickItem::qmlAttachedProperties(object)); } protected: From 7e53c7276a3cc8421bf8e498a9b50863ee896fad Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 14:54:22 +0100 Subject: [PATCH 24/31] move private members in AppletQuickItemPrivate --- .../qml/plasmoid/appletquickitem.cpp | 287 +++++++++--------- .../qml/plasmoid/appletquickitem.h | 38 +-- .../qml/plasmoid/appletquickitem_p.h | 71 +++++ 3 files changed, 224 insertions(+), 172 deletions(-) create mode 100644 src/scriptengines/qml/plasmoid/appletquickitem_p.h diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.cpp b/src/scriptengines/qml/plasmoid/appletquickitem.cpp index 2dedf0e75..1832cae1c 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.cpp +++ b/src/scriptengines/qml/plasmoid/appletquickitem.cpp @@ -37,100 +37,109 @@ #include -QHash AppletQuickItem::s_rootObjects = QHash(); +QHash AppletQuickItemPrivate::s_rootObjects = QHash(); + +AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a) + : switchWidth(-1), + switchHeight(-1), + applet(a), + expanded(false) +{ +} + + AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent) : QQuickItem(parent), - m_switchWidth(-1), - m_switchHeight(-1), - m_applet(applet), - m_expanded(false) + d(new AppletQuickItemPrivate(applet)) { - m_appletPackage = m_applet->package(); - if (m_applet && m_applet->containment() && m_applet->containment()->corona()) { - m_coronaPackage = m_applet->containment()->corona()->package(); + if (d->applet) { + d->appletPackage = d->applet->package(); + } + if (d->applet && d->applet->containment() && d->applet->containment()->corona()) { + d->coronaPackage = d->applet->containment()->corona()->package(); } - m_compactRepresentationCheckTimer.setSingleShot(true); - m_compactRepresentationCheckTimer.setInterval(250); - connect (&m_compactRepresentationCheckTimer, SIGNAL(timeout()), + d->compactRepresentationCheckTimer.setSingleShot(true); + d->compactRepresentationCheckTimer.setInterval(250); + connect (&d->compactRepresentationCheckTimer, SIGNAL(timeout()), this, SLOT(compactRepresentationCheck())); - m_compactRepresentationCheckTimer.start(); + d->compactRepresentationCheckTimer.start(); - m_fullRepresentationResizeTimer.setSingleShot(true); - m_fullRepresentationResizeTimer.setInterval(250); - connect (&m_fullRepresentationResizeTimer, &QTimer::timeout, + d->fullRepresentationResizeTimer.setSingleShot(true); + d->fullRepresentationResizeTimer.setInterval(250); + connect (&d->fullRepresentationResizeTimer, &QTimer::timeout, [=]() { - KConfigGroup cg = m_applet->config(); + KConfigGroup cg = d->applet->config(); cg = KConfigGroup(&cg, "PopupApplet"); - cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt()); - cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt()); + cg.writeEntry("DialogWidth", d->fullRepresentationItem.data()->property("width").toInt()); + cg.writeEntry("DialogHeight", d->fullRepresentationItem.data()->property("height").toInt()); } ); - m_qmlObject = new KDeclarative::QmlObject(this); - m_qmlObject->setInitializationDelayed(true); + d->qmlObject = new KDeclarative::QmlObject(this); + d->qmlObject->setInitializationDelayed(true); // set the graphicObject dynamic property on applet - m_applet->setProperty("_plasma_graphicObject", QVariant::fromValue(this)); + d->applet->setProperty("_plasma_graphicObject", QVariant::fromValue(this)); setProperty("_plasma_applet", QVariant::fromValue(applet)); } AppletQuickItem::~AppletQuickItem() { //Here the order is important - delete m_compactRepresentationItem.data(); - delete m_fullRepresentationItem.data(); - delete m_compactRepresentationExpanderItem.data(); + delete d->compactRepresentationItem.data(); + delete d->fullRepresentationItem.data(); + delete d->compactRepresentationExpanderItem.data(); - s_rootObjects.remove(m_qmlObject->engine()); + AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->engine()); } Plasma::Applet *AppletQuickItem::applet() const { - return m_applet; + return d->applet; } void AppletQuickItem::init() { - if (s_rootObjects.contains(this)) { + if (AppletQuickItemPrivate::s_rootObjects.contains(this)) { return; } - s_rootObjects[m_qmlObject->engine()] = this; + AppletQuickItemPrivate::s_rootObjects[d->qmlObject->engine()] = this; - Q_ASSERT(m_applet); + Q_ASSERT(d->applet); //Initialize the main QML file - QQmlEngine *engine = m_qmlObject->engine(); + QQmlEngine *engine = d->qmlObject->engine(); - PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, m_applet->package()); - interceptor->addAllowedPath(m_coronaPackage.path()); + PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, d->applet->package()); + interceptor->addAllowedPath(d->coronaPackage.path()); engine->setUrlInterceptor(interceptor); - m_qmlObject->setSource(QUrl::fromLocalFile(m_applet->package().filePath("mainscript"))); + d->qmlObject->setSource(QUrl::fromLocalFile(d->applet->package().filePath("mainscript"))); - if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) { + if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || d->qmlObject->mainComponent()->isError()) { QString reason; - foreach (QQmlError error, m_qmlObject->mainComponent()->errors()) { + foreach (QQmlError error, d->qmlObject->mainComponent()->errors()) { reason += error.toString()+'\n'; } reason = i18n("Error loading QML file: %1", reason); - m_qmlObject->setSource(QUrl::fromLocalFile(m_coronaPackage.filePath("appleterror"))); - m_qmlObject->completeInitialization(); + d->qmlObject->setSource(QUrl::fromLocalFile(d->coronaPackage.filePath("appleterror"))); + d->qmlObject->completeInitialization(); //even the error message QML may fail - if (m_qmlObject->mainComponent()->isError()) { + if (d->qmlObject->mainComponent()->isError()) { return; } else { - m_qmlObject->rootObject()->setProperty("reason", reason); + d->qmlObject->rootObject()->setProperty("reason", reason); } - m_applet->setLaunchErrorMessage(reason); + d->applet->setLaunchErrorMessage(reason); } engine->rootContext()->setContextProperty("plasmoid", this); @@ -139,148 +148,148 @@ void AppletQuickItem::init() QVariantHash initialProperties; initialProperties["width"] = width(); initialProperties["height"] = height(); - m_qmlObject->completeInitialization(initialProperties); + d->qmlObject->completeInitialization(initialProperties); //default fullrepresentation is our root main component, if none specified - if (!m_fullRepresentation) { - m_fullRepresentation = m_qmlObject->mainComponent(); - m_fullRepresentationItem = m_qmlObject->rootObject(); - emit fullRepresentationChanged(m_fullRepresentation.data()); + if (!d->fullRepresentation) { + d->fullRepresentation = d->qmlObject->mainComponent(); + d->fullRepresentationItem = d->qmlObject->rootObject(); + emit fullRepresentationChanged(d->fullRepresentation.data()); } - //default m_compactRepresentation is a simple icon provided by the shell package - if (!m_compactRepresentation) { - m_compactRepresentation = new QQmlComponent(engine, this); - m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_coronaPackage.filePath("defaultcompactrepresentation"))); - emit compactRepresentationChanged(m_compactRepresentation.data()); + //default d->compactRepresentation is a simple icon provided by the shell package + if (!d->compactRepresentation) { + d->compactRepresentation = new QQmlComponent(engine, this); + d->compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(d->coronaPackage.filePath("defaultcompactrepresentation"))); + emit compactRepresentationChanged(d->compactRepresentation.data()); } - //default m_compactRepresentationExpander is the popup in which fullRepresentation goes - if (!m_compactRepresentationExpander) { - m_compactRepresentationExpander = new QQmlComponent(engine, this); - m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_coronaPackage.filePath("compactapplet"))); - emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpander.data()); + //default d->compactRepresentationExpander is the popup in which fullRepresentation goes + if (!d->compactRepresentationExpander) { + d->compactRepresentationExpander = new QQmlComponent(engine, this); + d->compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(d->coronaPackage.filePath("compactapplet"))); + emit compactRepresentationExpanderItemChanged(d->compactRepresentationExpander.data()); } } Plasma::Package AppletQuickItem::appletPackage() const { - return m_appletPackage; + return d->appletPackage; } void AppletQuickItem::setAppletPackage(const Plasma::Package &package) { - m_appletPackage = package; + d->appletPackage = package; } Plasma::Package AppletQuickItem::coronaPackage() const { - return m_coronaPackage; + return d->coronaPackage; } void AppletQuickItem::setCoronaPackage(const Plasma::Package &package) { - m_coronaPackage = package; + d->coronaPackage = package; } int AppletQuickItem::switchWidth() const { - return m_switchWidth; + return d->switchWidth; } void AppletQuickItem::setSwitchWidth(int width) { - if (m_switchWidth == width) { + if (d->switchWidth == width) { return; } - m_switchWidth = width; + d->switchWidth = width; emit switchWidthChanged(width); } int AppletQuickItem::switchHeight() const { - return m_switchHeight; + return d->switchHeight; } void AppletQuickItem::setSwitchHeight(int width) { - if (m_switchHeight == width) { + if (d->switchHeight == width) { return; } - m_switchHeight = width; + d->switchHeight = width; emit switchHeightChanged(width); } QQmlComponent *AppletQuickItem::compactRepresentation() { - return m_compactRepresentation.data(); + return d->compactRepresentation.data(); } void AppletQuickItem::setCompactRepresentation(QQmlComponent *component) { - if (m_compactRepresentation.data() == component) { + if (d->compactRepresentation.data() == component) { return; } - m_compactRepresentation = component; + d->compactRepresentation = component; emit compactRepresentationChanged(component); } QQmlComponent *AppletQuickItem::fullRepresentation() { - return m_fullRepresentation.data(); + return d->fullRepresentation.data(); } void AppletQuickItem::setFullRepresentation(QQmlComponent *component) { - if (m_fullRepresentation.data() == component) { + if (d->fullRepresentation.data() == component) { return; } - m_fullRepresentation = component; + d->fullRepresentation = component; emit fullRepresentationChanged(component); } QQmlComponent *AppletQuickItem::preferredRepresentation() { - return m_preferredRepresentation.data(); + return d->preferredRepresentation.data(); } void AppletQuickItem::setPreferredRepresentation(QQmlComponent *component) { - if (m_preferredRepresentation.data() == component) { + if (d->preferredRepresentation.data() == component) { return; } - m_preferredRepresentation = component; + d->preferredRepresentation = component; emit preferredRepresentationChanged(component); } bool AppletQuickItem::isExpanded() const { - return m_expanded; + return d->expanded; } void AppletQuickItem::setExpanded(bool expanded) { - if (m_applet->isContainment()) { + if (d->applet->isContainment()) { expanded = true; } //if there is no compact representation it means it's always expanded //Containnments are always expanded - if (m_expanded == expanded) { + if (d->expanded == expanded) { return; } createFullRepresentationItem(); createCompactRepresentationExpanderItem(); - m_expanded = expanded; + d->expanded = expanded; emit expandedChanged(expanded); } @@ -289,89 +298,89 @@ void AppletQuickItem::setExpanded(bool expanded) KDeclarative::QmlObject *AppletQuickItem::qmlObject() { - return m_qmlObject; + return d->qmlObject; } QObject *AppletQuickItem::compactRepresentationItem() { - return m_compactRepresentationItem.data(); + return d->compactRepresentationItem.data(); } QObject *AppletQuickItem::fullRepresentationItem() { - return m_fullRepresentationItem.data(); + return d->fullRepresentationItem.data(); } QObject *AppletQuickItem::compactRepresentationExpanderItem() { - return m_compactRepresentationExpanderItem.data(); + return d->compactRepresentationExpanderItem.data(); } QObject *AppletQuickItem::createCompactRepresentationItem() { - if (!m_compactRepresentation) { + if (!d->compactRepresentation) { return 0; } - if (m_compactRepresentationItem) { - return m_compactRepresentationItem.data(); + if (d->compactRepresentationItem) { + return d->compactRepresentationItem.data(); } - m_compactRepresentationItem = m_qmlObject->createObjectFromComponent(m_compactRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject())); + d->compactRepresentationItem = d->qmlObject->createObjectFromComponent(d->compactRepresentation.data(), QtQml::qmlContext(d->qmlObject->rootObject())); - emit compactRepresentationItemChanged(m_compactRepresentationItem.data()); + emit compactRepresentationItemChanged(d->compactRepresentationItem.data()); - return m_compactRepresentationItem.data(); + return d->compactRepresentationItem.data(); } QObject *AppletQuickItem::createFullRepresentationItem() { - if (m_fullRepresentationItem) { - return m_fullRepresentationItem.data(); + if (d->fullRepresentationItem) { + return d->fullRepresentationItem.data(); } - if (m_fullRepresentation) { - m_fullRepresentationItem = m_qmlObject->createObjectFromComponent(m_fullRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject())); + if (d->fullRepresentation) { + d->fullRepresentationItem = d->qmlObject->createObjectFromComponent(d->fullRepresentation.data(), QtQml::qmlContext(d->qmlObject->rootObject())); } else { - m_fullRepresentation = m_qmlObject->mainComponent(); - m_fullRepresentationItem = m_qmlObject->rootObject(); - emit fullRepresentationChanged(m_fullRepresentation.data()); + d->fullRepresentation = d->qmlObject->mainComponent(); + d->fullRepresentationItem = d->qmlObject->rootObject(); + emit fullRepresentationChanged(d->fullRepresentation.data()); } - QQuickItem *graphicsObj = qobject_cast(m_fullRepresentationItem.data()); + QQuickItem *graphicsObj = qobject_cast(d->fullRepresentationItem.data()); connect (graphicsObj, &QQuickItem::widthChanged, [=]() { - m_fullRepresentationResizeTimer.start(); + d->fullRepresentationResizeTimer.start(); }); connect (graphicsObj, &QQuickItem::heightChanged, [=]() { - m_fullRepresentationResizeTimer.start(); + d->fullRepresentationResizeTimer.start(); }); - emit fullRepresentationItemChanged(m_fullRepresentationItem.data()); + emit fullRepresentationItemChanged(d->fullRepresentationItem.data()); - return m_fullRepresentationItem.data(); + return d->fullRepresentationItem.data(); } QObject *AppletQuickItem::createCompactRepresentationExpanderItem() { - if (!m_compactRepresentationExpander) { + if (!d->compactRepresentationExpander) { return 0; } - if (m_compactRepresentationExpanderItem) { - return m_compactRepresentationExpanderItem.data(); + if (d->compactRepresentationExpanderItem) { + return d->compactRepresentationExpanderItem.data(); } - m_compactRepresentationExpanderItem = m_qmlObject->createObjectFromComponent(m_compactRepresentationExpander.data(), QtQml::qmlContext(m_qmlObject->rootObject())); + d->compactRepresentationExpanderItem = d->qmlObject->createObjectFromComponent(d->compactRepresentationExpander.data(), QtQml::qmlContext(d->qmlObject->rootObject())); - m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem())); - m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem())); + d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); - emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpanderItem.data()); + emit compactRepresentationExpanderItemChanged(d->compactRepresentationExpanderItem.data()); - return m_compactRepresentationExpanderItem.data(); + return d->compactRepresentationExpanderItem.data(); } void AppletQuickItem::connectLayoutAttached(QObject *item) @@ -412,7 +421,7 @@ void AppletQuickItem::connectLayoutAttached(QObject *item) propagateSizeHint("fillHeight"); //HACK: check the Layout properties we wrote - QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(m_qmlObject->rootObject())); + QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(d->qmlObject->rootObject())); QObject *ownLayout = 0; @@ -433,12 +442,12 @@ void AppletQuickItem::connectLayoutAttached(QObject *item) } //if the representation didn't change, don't do anything - if (m_representationLayout.data() == layout) { + if (d->representationLayout.data() == layout) { return; } - if (m_representationLayout) { - disconnect(m_representationLayout.data(), 0, this, 0); + if (d->representationLayout) { + disconnect(d->representationLayout.data(), 0, this, 0); } //Here we can't use the new connect syntax because we can't link against QtQuick layouts @@ -462,8 +471,8 @@ void AppletQuickItem::connectLayoutAttached(QObject *item) connect(layout, SIGNAL(fillHeightChanged()), this, SLOT(fillHeightChanged())); - m_representationLayout = layout; - m_ownLayout = ownLayout; + d->representationLayout = layout; + d->ownLayout = ownLayout; propagateSizeHint("minimumWidth"); propagateSizeHint("minimumHeight"); @@ -477,8 +486,8 @@ void AppletQuickItem::connectLayoutAttached(QObject *item) void AppletQuickItem::propagateSizeHint(const QByteArray &layoutProperty) { - if (m_ownLayout && m_representationLayout) { - m_ownLayout.data()->setProperty(layoutProperty, m_representationLayout.data()->property(layoutProperty)); + if (d->ownLayout && d->representationLayout) { + d->ownLayout.data()->setProperty(layoutProperty, d->representationLayout.data()->property(layoutProperty)); } } @@ -487,7 +496,7 @@ void AppletQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &o Q_UNUSED(oldGeometry) QQuickItem::geometryChanged(newGeometry, oldGeometry); - m_compactRepresentationCheckTimer.start(); + d->compactRepresentationCheckTimer.start(); } void AppletQuickItem::itemChange(ItemChange change, const ItemChangeData &value) @@ -514,25 +523,25 @@ void AppletQuickItem::compactRepresentationCheck() bool full = false; - if (m_applet->isContainment()) { + if (d->applet->isContainment()) { full = true; } else { - if (m_switchWidth > 0 && m_switchHeight > 0) { - full = width() > m_switchWidth && height() > m_switchHeight; + if (d->switchWidth > 0 && d->switchHeight > 0) { + full = width() > d->switchWidth && height() > d->switchHeight; //if a size to switch wasn't set, determine what representation to always chose } else { //preferred representation set? - if (m_preferredRepresentation) { - full = m_preferredRepresentation.data() == m_fullRepresentation.data(); + if (d->preferredRepresentation) { + full = d->preferredRepresentation.data() == d->fullRepresentation.data(); //Otherwise, base on FormFactor } else { - full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical); + full = (d->applet->formFactor() != Plasma::Types::Horizontal && d->applet->formFactor() != Plasma::Types::Vertical); } } - if ((full && m_fullRepresentationItem && m_fullRepresentationItem.data() == m_currentRepresentationItem.data()) || - (!full && m_compactRepresentationItem && m_compactRepresentationItem.data() == m_currentRepresentationItem.data()) + if ((full && d->fullRepresentationItem && d->fullRepresentationItem.data() == d->currentRepresentationItem.data()) || + (!full && d->compactRepresentationItem && d->compactRepresentationItem.data() == d->currentRepresentationItem.data()) ) { return; } @@ -546,19 +555,19 @@ void AppletQuickItem::compactRepresentationCheck() item->setParentItem(this); { //set anchors - QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), item, "parent"); + QQmlExpression expr(QtQml::qmlContext(d->qmlObject->rootObject()), item, "parent"); QQmlProperty prop(item, "anchors.fill"); prop.write(expr.evaluate()); } - if (m_compactRepresentationItem) { - m_compactRepresentationItem.data()->setProperty("visible", false); + if (d->compactRepresentationItem) { + d->compactRepresentationItem.data()->setProperty("visible", false); } - if (m_compactRepresentationExpanderItem) { - m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant()); - m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant()); + if (d->compactRepresentationExpanderItem) { + d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant()); + d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant()); } - m_currentRepresentationItem = item; + d->currentRepresentationItem = item; connectLayoutAttached(item); } @@ -572,21 +581,21 @@ void AppletQuickItem::compactRepresentationCheck() compactItem->setVisible(true); { //set anchors - QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), compactItem, "parent"); + QQmlExpression expr(QtQml::qmlContext(d->qmlObject->rootObject()), compactItem, "parent"); QQmlProperty prop(compactItem, "anchors.fill"); prop.write(expr.evaluate()); } - if (m_fullRepresentationItem) { - m_fullRepresentationItem.data()->setProperty("parent", QVariant()); + if (d->fullRepresentationItem) { + d->fullRepresentationItem.data()->setProperty("parent", QVariant()); } - if (m_compactRepresentationExpanderItem) { - m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); - m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + if (d->compactRepresentationExpanderItem) { + d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); + d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); } - m_currentRepresentationItem = compactItem; + d->currentRepresentationItem = compactItem; connectLayoutAttached(compactItem); } } diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.h b/src/scriptengines/qml/plasmoid/appletquickitem.h index ea6d09fe4..ee9857e0e 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.h +++ b/src/scriptengines/qml/plasmoid/appletquickitem.h @@ -28,7 +28,8 @@ #include -class QQmlComponent; +#include "appletquickitem_p.h" + namespace Plasma { class Applet; @@ -39,7 +40,6 @@ namespace KDeclarative { } - class AppletQuickItem : public QQuickItem { Q_OBJECT @@ -110,8 +110,8 @@ public: { //at the moment of the attached object creation, the root item is the only one that hasn't a parent //only way to avoid creation of this attached for everybody but the root item - if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) { - return s_rootObjects.value(QtQml::qmlEngine(object)); + if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(QtQml::qmlEngine(object))) { + return AppletQuickItemPrivate::s_rootObjects.value(QtQml::qmlEngine(object)); } else { return 0; } @@ -161,35 +161,7 @@ private Q_SLOTS: void fillHeightChanged(); private: - int m_switchWidth; - int m_switchHeight; - - QWeakPointer m_compactRepresentation; - QWeakPointer m_fullRepresentation; - QWeakPointer m_preferredRepresentation; - QWeakPointer m_compactRepresentationExpander; - - QWeakPointer m_compactRepresentationItem; - QWeakPointer m_fullRepresentationItem; - QWeakPointer m_compactRepresentationExpanderItem; - QWeakPointer m_currentRepresentationItem; - - //Attached layout objects: own and the representation's one - QWeakPointer m_representationLayout; - QWeakPointer m_ownLayout; - - QTimer m_compactRepresentationCheckTimer; - QTimer m_fullRepresentationResizeTimer; - - Plasma::Applet *m_applet; - KDeclarative::QmlObject *m_qmlObject; - - Plasma::Package m_appletPackage; - Plasma::Package m_coronaPackage; - - bool m_expanded : 1; - - static QHash s_rootObjects; + AppletQuickItemPrivate *const d; }; QML_DECLARE_TYPEINFO(AppletQuickItem, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/scriptengines/qml/plasmoid/appletquickitem_p.h b/src/scriptengines/qml/plasmoid/appletquickitem_p.h new file mode 100644 index 000000000..ad4e080fa --- /dev/null +++ b/src/scriptengines/qml/plasmoid/appletquickitem_p.h @@ -0,0 +1,71 @@ +/* + * Copyright 2014 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 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 APPLETQUICKITEM_H +#define APPLETQUICKITEM_H + +#include + +namespace Plasma { + class Applet; +} + +namespace KDeclarative { + class QmlObject; +} + +class AppletQuickItem; + +class AppletQuickItemPrivate +{ +public: + AppletQuickItemPrivate(Plasma::Applet *a); + + int switchWidth; + int switchHeight; + + QWeakPointer compactRepresentation; + QWeakPointer fullRepresentation; + QWeakPointer preferredRepresentation; + QWeakPointer compactRepresentationExpander; + + QWeakPointer compactRepresentationItem; + QWeakPointer fullRepresentationItem; + QWeakPointer compactRepresentationExpanderItem; + QWeakPointer currentRepresentationItem; + + //Attached layout objects: own and the representation's one + QWeakPointer representationLayout; + QWeakPointer ownLayout; + + QTimer compactRepresentationCheckTimer; + QTimer fullRepresentationResizeTimer; + + Plasma::Applet *applet; + KDeclarative::QmlObject *qmlObject; + + Plasma::Package appletPackage; + Plasma::Package coronaPackage; + + bool expanded : 1; + + static QHash s_rootObjects; +}; + +#endif From c86a956c281bff0de60e5db378aecccb72445f4d Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 16:02:28 +0100 Subject: [PATCH 25/31] move private methods and slots in private --- .../qml/plasmoid/appletquickitem.cpp | 450 +++++++++--------- .../qml/plasmoid/appletquickitem.h | 19 +- .../qml/plasmoid/appletquickitem_p.h | 23 +- 3 files changed, 249 insertions(+), 243 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.cpp b/src/scriptengines/qml/plasmoid/appletquickitem.cpp index 1832cae1c..5791afb80 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.cpp +++ b/src/scriptengines/qml/plasmoid/appletquickitem.cpp @@ -39,19 +39,234 @@ QHash AppletQuickItemPrivate::s_rootObjects = QHash(); -AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a) - : switchWidth(-1), +AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickItem *item) + : q(item), + switchWidth(-1), switchHeight(-1), applet(a), expanded(false) { } +void AppletQuickItemPrivate::connectLayoutAttached(QObject *item) +{ + QObject *layout = 0; + + //Extract the representation's Layout, if any + //No Item? + if (!item) { + return; + } + + //Search a child that has the needed Layout properties + //HACK: here we are not type safe, but is the only way to access to a pointer of Layout + foreach (QObject *child, item->children()) { + //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight + if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && + child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && + child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && + child->property("fillWidth").isValid() && child->property("fillHeight").isValid() + ) { + layout = child; + } + } + + if (!layout) { + return; + } + + //propagate all the size hints + propagateSizeHint("minimumWidth"); + propagateSizeHint("minimumHeight"); + propagateSizeHint("preferredWidth"); + propagateSizeHint("preferredHeight"); + propagateSizeHint("maximumWidth"); + propagateSizeHint("maximumHeight"); + propagateSizeHint("fillWidth"); + propagateSizeHint("fillHeight"); + + //HACK: check the Layout properties we wrote + QQmlProperty p(q, "Layout.minimumWidth", QtQml::qmlContext(qmlObject->rootObject())); + + QObject *ownLayout = 0; + + foreach (QObject *child, q->children()) { + //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight + if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && + child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && + child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && + child->property("fillWidth").isValid() && child->property("fillHeight").isValid() + ) { + ownLayout = child; + } + } + + //this should never happen, since we ask to create it if doesn't exists + if (!ownLayout) { + return; + } + + //if the representation didn't change, don't do anything + if (representationLayout.data() == layout) { + return; + } + + if (representationLayout) { + QObject::disconnect(representationLayout.data(), 0, q, 0); + } + + //Here we can't use the new connect syntax because we can't link against QtQuick layouts + QObject::connect(layout, SIGNAL(minimumWidthChanged()), + q, SLOT(minimumWidthChanged())); + QObject::connect(layout, SIGNAL(minimumHeightChanged()), + q, SLOT(minimumHeightChanged())); + + QObject::connect(layout, SIGNAL(preferredWidthChanged()), + q, SLOT(preferredWidthChanged())); + QObject::connect(layout, SIGNAL(preferredHeightChanged()), + q, SLOT(preferredHeightChanged())); + + QObject::connect(layout, SIGNAL(maximumWidthChanged()), + q, SLOT(maximumWidthChanged())); + QObject::connect(layout, SIGNAL(maximumHeightChanged()), + q, SLOT(maximumHeightChanged())); + + QObject::connect(layout, SIGNAL(fillWidthChanged()), + q, SLOT(fillWidthChanged())); + QObject::connect(layout, SIGNAL(fillHeightChanged()), + q, SLOT(fillHeightChanged())); + + representationLayout = layout; + AppletQuickItemPrivate::ownLayout = ownLayout; + + propagateSizeHint("minimumWidth"); + propagateSizeHint("minimumHeight"); + propagateSizeHint("preferredWidth"); + propagateSizeHint("preferredHeight"); + propagateSizeHint("maximumWidth"); + propagateSizeHint("maximumHeight"); + propagateSizeHint("fillWidth"); + propagateSizeHint("fillHeight"); +} + +void AppletQuickItemPrivate::propagateSizeHint(const QByteArray &layoutProperty) +{ + if (ownLayout && representationLayout) { + ownLayout.data()->setProperty(layoutProperty, representationLayout.data()->property(layoutProperty)); + } +} + +QObject *AppletQuickItemPrivate::createCompactRepresentationItem() +{ + if (!compactRepresentation) { + return 0; + } + + if (compactRepresentationItem) { + return compactRepresentationItem.data(); + } + + compactRepresentationItem = qmlObject->createObjectFromComponent(compactRepresentation.data(), QtQml::qmlContext(qmlObject->rootObject())); + + emit q->compactRepresentationItemChanged(compactRepresentationItem.data()); + + return compactRepresentationItem.data(); +} + +QObject *AppletQuickItemPrivate::createFullRepresentationItem() +{ + if (fullRepresentationItem) { + return fullRepresentationItem.data(); + } + + if (fullRepresentation) { + fullRepresentationItem = qmlObject->createObjectFromComponent(fullRepresentation.data(), QtQml::qmlContext(qmlObject->rootObject())); + } else { + fullRepresentation = qmlObject->mainComponent(); + fullRepresentationItem = qmlObject->rootObject(); + emit q->fullRepresentationChanged(fullRepresentation.data()); + } + + QQuickItem *graphicsObj = qobject_cast(fullRepresentationItem.data()); + QObject::connect (graphicsObj, &QQuickItem::widthChanged, [=]() { + fullRepresentationResizeTimer.start(); + }); + QObject::connect (graphicsObj, &QQuickItem::heightChanged, [=]() { + fullRepresentationResizeTimer.start(); + }); + + emit q->fullRepresentationItemChanged(fullRepresentationItem.data()); + + return fullRepresentationItem.data(); +} + +QObject *AppletQuickItemPrivate::createCompactRepresentationExpanderItem() +{ + if (!compactRepresentationExpander) { + return 0; + } + + if (compactRepresentationExpanderItem) { + return compactRepresentationExpanderItem.data(); + } + + compactRepresentationExpanderItem = qmlObject->createObjectFromComponent(compactRepresentationExpander.data(), QtQml::qmlContext(qmlObject->rootObject())); + + + compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem())); + compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + + emit q->compactRepresentationExpanderItemChanged(compactRepresentationExpanderItem.data()); + + return compactRepresentationExpanderItem.data(); +} + +void AppletQuickItemPrivate::minimumWidthChanged() +{ + propagateSizeHint("minimumWidth"); +} + +void AppletQuickItemPrivate::minimumHeightChanged() +{ + propagateSizeHint("minimumHeight"); +} + +void AppletQuickItemPrivate::preferredWidthChanged() +{ + propagateSizeHint("preferredWidth"); +} + +void AppletQuickItemPrivate::preferredHeightChanged() +{ + propagateSizeHint("preferredHeight"); +} + +void AppletQuickItemPrivate::maximumWidthChanged() +{ + propagateSizeHint("maximumWidth"); +} + +void AppletQuickItemPrivate::maximumHeightChanged() +{ + propagateSizeHint("maximumHeight"); +} + +void AppletQuickItemPrivate::fillWidthChanged() +{ + propagateSizeHint("fillWidth"); +} + +void AppletQuickItemPrivate::fillHeightChanged() +{ + propagateSizeHint("fillHeight"); +} + + AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent) : QQuickItem(parent), - d(new AppletQuickItemPrivate(applet)) + d(new AppletQuickItemPrivate(applet, this)) { if (d->applet) { d->appletPackage = d->applet->package(); @@ -286,8 +501,8 @@ void AppletQuickItem::setExpanded(bool expanded) return; } - createFullRepresentationItem(); - createCompactRepresentationExpanderItem(); + d->createFullRepresentationItem(); + d->createCompactRepresentationExpanderItem(); d->expanded = expanded; emit expandedChanged(expanded); @@ -316,181 +531,6 @@ QObject *AppletQuickItem::compactRepresentationExpanderItem() return d->compactRepresentationExpanderItem.data(); } - - -QObject *AppletQuickItem::createCompactRepresentationItem() -{ - if (!d->compactRepresentation) { - return 0; - } - - if (d->compactRepresentationItem) { - return d->compactRepresentationItem.data(); - } - - d->compactRepresentationItem = d->qmlObject->createObjectFromComponent(d->compactRepresentation.data(), QtQml::qmlContext(d->qmlObject->rootObject())); - - emit compactRepresentationItemChanged(d->compactRepresentationItem.data()); - - return d->compactRepresentationItem.data(); -} - -QObject *AppletQuickItem::createFullRepresentationItem() -{ - if (d->fullRepresentationItem) { - return d->fullRepresentationItem.data(); - } - - if (d->fullRepresentation) { - d->fullRepresentationItem = d->qmlObject->createObjectFromComponent(d->fullRepresentation.data(), QtQml::qmlContext(d->qmlObject->rootObject())); - } else { - d->fullRepresentation = d->qmlObject->mainComponent(); - d->fullRepresentationItem = d->qmlObject->rootObject(); - emit fullRepresentationChanged(d->fullRepresentation.data()); - } - - QQuickItem *graphicsObj = qobject_cast(d->fullRepresentationItem.data()); - connect (graphicsObj, &QQuickItem::widthChanged, [=]() { - d->fullRepresentationResizeTimer.start(); - }); - connect (graphicsObj, &QQuickItem::heightChanged, [=]() { - d->fullRepresentationResizeTimer.start(); - }); - - emit fullRepresentationItemChanged(d->fullRepresentationItem.data()); - - return d->fullRepresentationItem.data(); -} - -QObject *AppletQuickItem::createCompactRepresentationExpanderItem() -{ - if (!d->compactRepresentationExpander) { - return 0; - } - - if (d->compactRepresentationExpanderItem) { - return d->compactRepresentationExpanderItem.data(); - } - - d->compactRepresentationExpanderItem = d->qmlObject->createObjectFromComponent(d->compactRepresentationExpander.data(), QtQml::qmlContext(d->qmlObject->rootObject())); - - - d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem())); - d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); - - emit compactRepresentationExpanderItemChanged(d->compactRepresentationExpanderItem.data()); - - return d->compactRepresentationExpanderItem.data(); -} - -void AppletQuickItem::connectLayoutAttached(QObject *item) -{ - QObject *layout = 0; - - //Extract the representation's Layout, if any - //No Item? - if (!item) { - return; - } - - //Search a child that has the needed Layout properties - //HACK: here we are not type safe, but is the only way to access to a pointer of Layout - foreach (QObject *child, item->children()) { - //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight - if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && - child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && - child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && - child->property("fillWidth").isValid() && child->property("fillHeight").isValid() - ) { - layout = child; - } - } - - if (!layout) { - return; - } - - //propagate all the size hints - propagateSizeHint("minimumWidth"); - propagateSizeHint("minimumHeight"); - propagateSizeHint("preferredWidth"); - propagateSizeHint("preferredHeight"); - propagateSizeHint("maximumWidth"); - propagateSizeHint("maximumHeight"); - propagateSizeHint("fillWidth"); - propagateSizeHint("fillHeight"); - - //HACK: check the Layout properties we wrote - QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(d->qmlObject->rootObject())); - - QObject *ownLayout = 0; - - foreach (QObject *child, children()) { - //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight - if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && - child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && - child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && - child->property("fillWidth").isValid() && child->property("fillHeight").isValid() - ) { - ownLayout = child; - } - } - - //this should never happen, since we ask to create it if doesn't exists - if (!ownLayout) { - return; - } - - //if the representation didn't change, don't do anything - if (d->representationLayout.data() == layout) { - return; - } - - if (d->representationLayout) { - disconnect(d->representationLayout.data(), 0, this, 0); - } - - //Here we can't use the new connect syntax because we can't link against QtQuick layouts - connect(layout, SIGNAL(minimumWidthChanged()), - this, SLOT(minimumWidthChanged())); - connect(layout, SIGNAL(minimumHeightChanged()), - this, SLOT(minimumHeightChanged())); - - connect(layout, SIGNAL(preferredWidthChanged()), - this, SLOT(preferredWidthChanged())); - connect(layout, SIGNAL(preferredHeightChanged()), - this, SLOT(preferredHeightChanged())); - - connect(layout, SIGNAL(maximumWidthChanged()), - this, SLOT(maximumWidthChanged())); - connect(layout, SIGNAL(maximumHeightChanged()), - this, SLOT(maximumHeightChanged())); - - connect(layout, SIGNAL(fillWidthChanged()), - this, SLOT(fillWidthChanged())); - connect(layout, SIGNAL(fillHeightChanged()), - this, SLOT(fillHeightChanged())); - - d->representationLayout = layout; - d->ownLayout = ownLayout; - - propagateSizeHint("minimumWidth"); - propagateSizeHint("minimumHeight"); - propagateSizeHint("preferredWidth"); - propagateSizeHint("preferredHeight"); - propagateSizeHint("maximumWidth"); - propagateSizeHint("maximumHeight"); - propagateSizeHint("fillWidth"); - propagateSizeHint("fillHeight"); -} - -void AppletQuickItem::propagateSizeHint(const QByteArray &layoutProperty) -{ - if (d->ownLayout && d->representationLayout) { - d->ownLayout.data()->setProperty(layoutProperty, d->representationLayout.data()->property(layoutProperty)); - } -} - void AppletQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_UNUSED(oldGeometry) @@ -549,7 +589,7 @@ void AppletQuickItem::compactRepresentationCheck() //Expanded if (full) { - QQuickItem *item = qobject_cast(createFullRepresentationItem()); + QQuickItem *item = qobject_cast(d->createFullRepresentationItem()); if (item) { item->setParentItem(this); @@ -568,12 +608,12 @@ void AppletQuickItem::compactRepresentationCheck() } d->currentRepresentationItem = item; - connectLayoutAttached(item); + d->connectLayoutAttached(item); } //Icon } else { - QQuickItem *compactItem = qobject_cast(createCompactRepresentationItem()); + QQuickItem *compactItem = qobject_cast(d->createCompactRepresentationItem()); if (compactItem) { //set the root item as the main visible item @@ -592,55 +632,15 @@ void AppletQuickItem::compactRepresentationCheck() if (d->compactRepresentationExpanderItem) { d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); - d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(d->createFullRepresentationItem())); } d->currentRepresentationItem = compactItem; - connectLayoutAttached(compactItem); + d->connectLayoutAttached(compactItem); } } } -void AppletQuickItem::minimumWidthChanged() -{ - propagateSizeHint("minimumWidth"); -} - -void AppletQuickItem::minimumHeightChanged() -{ - propagateSizeHint("minimumHeight"); -} - -void AppletQuickItem::preferredWidthChanged() -{ - propagateSizeHint("preferredWidth"); -} - -void AppletQuickItem::preferredHeightChanged() -{ - propagateSizeHint("preferredHeight"); -} - -void AppletQuickItem::maximumWidthChanged() -{ - propagateSizeHint("maximumWidth"); -} - -void AppletQuickItem::maximumHeightChanged() -{ - propagateSizeHint("maximumHeight"); -} - -void AppletQuickItem::fillWidthChanged() -{ - propagateSizeHint("fillWidth"); -} - -void AppletQuickItem::fillHeightChanged() -{ - propagateSizeHint("fillHeight"); -} - #include "moc_appletquickitem.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.h b/src/scriptengines/qml/plasmoid/appletquickitem.h index ee9857e0e..c417df20a 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.h +++ b/src/scriptengines/qml/plasmoid/appletquickitem.h @@ -139,29 +139,14 @@ protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); virtual void itemChange(ItemChange change, const ItemChangeData &value); - QObject *createCompactRepresentationItem(); - QObject *createFullRepresentationItem(); - QObject *createCompactRepresentationExpanderItem(); - - //look into item, and return the Layout attached property, if found - void connectLayoutAttached(QObject *item); - void propagateSizeHint(const QByteArray &layoutProperty); private Q_SLOTS: void compactRepresentationCheck(); - //handlers of Layout signals - void minimumWidthChanged(); - void minimumHeightChanged(); - void preferredWidthChanged(); - void preferredHeightChanged(); - void maximumWidthChanged(); - void maximumHeightChanged(); - void fillWidthChanged(); - void fillHeightChanged(); - private: AppletQuickItemPrivate *const d; + + Q_PRIVATE_SLOT(d, void minimumWidthChanged()) }; QML_DECLARE_TYPEINFO(AppletQuickItem, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/scriptengines/qml/plasmoid/appletquickitem_p.h b/src/scriptengines/qml/plasmoid/appletquickitem_p.h index ad4e080fa..9952ac78b 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem_p.h +++ b/src/scriptengines/qml/plasmoid/appletquickitem_p.h @@ -35,7 +35,28 @@ class AppletQuickItem; class AppletQuickItemPrivate { public: - AppletQuickItemPrivate(Plasma::Applet *a); + AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickItem *item); + + QObject *createCompactRepresentationItem(); + QObject *createFullRepresentationItem(); + QObject *createCompactRepresentationExpanderItem(); + + //look into item, and return the Layout attached property, if found + void connectLayoutAttached(QObject *item); + void propagateSizeHint(const QByteArray &layoutProperty); + + //handlers of Layout signals, private slots + void minimumWidthChanged(); + void minimumHeightChanged(); + void preferredWidthChanged(); + void preferredHeightChanged(); + void maximumWidthChanged(); + void maximumHeightChanged(); + void fillWidthChanged(); + void fillHeightChanged(); + + + AppletQuickItem *q; int switchWidth; int switchHeight; From 0f16569daa3fd00ef88d2fb6008295dd8af78bfb Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 16:23:57 +0100 Subject: [PATCH 26/31] move more stuff in private --- .../qml/plasmoid/appletquickitem.cpp | 184 +++++++++--------- .../qml/plasmoid/appletquickitem.h | 16 +- .../qml/plasmoid/appletquickitem_p.h | 1 + 3 files changed, 98 insertions(+), 103 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.cpp b/src/scriptengines/qml/plasmoid/appletquickitem.cpp index 5791afb80..70e3ab64a 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.cpp +++ b/src/scriptengines/qml/plasmoid/appletquickitem.cpp @@ -216,11 +216,96 @@ QObject *AppletQuickItemPrivate::createCompactRepresentationExpanderItem() compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem())); compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); - emit q->compactRepresentationExpanderItemChanged(compactRepresentationExpanderItem.data()); - return compactRepresentationExpanderItem.data(); } +void AppletQuickItemPrivate::compactRepresentationCheck() +{ + //ignore 0,0 sizes; + if (q->width() <= 0 && q->height() <= 0) { + return; + } + + bool full = false; + + if (applet->isContainment()) { + full = true; + + } else { + if (switchWidth > 0 && switchHeight > 0) { + full = q->width() > switchWidth && q->height() > switchHeight; + //if a size to switch wasn't set, determine what representation to always chose + } else { + //preferred representation set? + if (preferredRepresentation) { + full = preferredRepresentation.data() == fullRepresentation.data(); + //Otherwise, base on FormFactor + } else { + full = (applet->formFactor() != Plasma::Types::Horizontal && applet->formFactor() != Plasma::Types::Vertical); + } + } + + if ((full && fullRepresentationItem && fullRepresentationItem.data() == currentRepresentationItem.data()) || + (!full && compactRepresentationItem && compactRepresentationItem.data() == currentRepresentationItem.data()) + ) { + return; + } + } + + //Expanded + if (full) { + QQuickItem *item = qobject_cast(createFullRepresentationItem()); + + if (item) { + item->setParentItem(q); + { + //set anchors + QQmlExpression expr(QtQml::qmlContext(qmlObject->rootObject()), item, "parent"); + QQmlProperty prop(item, "anchors.fill"); + prop.write(expr.evaluate()); + } + if (compactRepresentationItem) { + compactRepresentationItem.data()->setProperty("visible", false); + } + if (compactRepresentationExpanderItem) { + compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant()); + compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant()); + } + + currentRepresentationItem = item; + connectLayoutAttached(item); + } + + //Icon + } else { + QQuickItem *compactItem = qobject_cast(createCompactRepresentationItem()); + + if (compactItem) { + //set the root item as the main visible item + compactItem->setParentItem(q); + compactItem->setVisible(true); + { + //set anchors + QQmlExpression expr(QtQml::qmlContext(qmlObject->rootObject()), compactItem, "parent"); + QQmlProperty prop(compactItem, "anchors.fill"); + prop.write(expr.evaluate()); + } + + if (fullRepresentationItem) { + fullRepresentationItem.data()->setProperty("parent", QVariant()); + } + + if (compactRepresentationExpanderItem) { + compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); + compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + } + + currentRepresentationItem = compactItem; + connectLayoutAttached(compactItem); + } + } +} + void AppletQuickItemPrivate::minimumWidthChanged() { propagateSizeHint("minimumWidth"); @@ -383,7 +468,6 @@ void AppletQuickItem::init() if (!d->compactRepresentationExpander) { d->compactRepresentationExpander = new QQmlComponent(engine, this); d->compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(d->coronaPackage.filePath("compactapplet"))); - emit compactRepresentationExpanderItemChanged(d->compactRepresentationExpander.data()); } } @@ -526,11 +610,6 @@ QObject *AppletQuickItem::fullRepresentationItem() return d->fullRepresentationItem.data(); } -QObject *AppletQuickItem::compactRepresentationExpanderItem() -{ - return d->compactRepresentationExpanderItem.data(); -} - void AppletQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_UNUSED(oldGeometry) @@ -552,95 +631,6 @@ void AppletQuickItem::itemChange(ItemChange change, const ItemChangeData &value) } -//// Slots - -void AppletQuickItem::compactRepresentationCheck() -{ - //ignore 0,0 sizes; - if (width() <= 0 && height() <= 0) { - return; - } - - bool full = false; - - if (d->applet->isContainment()) { - full = true; - - } else { - if (d->switchWidth > 0 && d->switchHeight > 0) { - full = width() > d->switchWidth && height() > d->switchHeight; - //if a size to switch wasn't set, determine what representation to always chose - } else { - //preferred representation set? - if (d->preferredRepresentation) { - full = d->preferredRepresentation.data() == d->fullRepresentation.data(); - //Otherwise, base on FormFactor - } else { - full = (d->applet->formFactor() != Plasma::Types::Horizontal && d->applet->formFactor() != Plasma::Types::Vertical); - } - } - - if ((full && d->fullRepresentationItem && d->fullRepresentationItem.data() == d->currentRepresentationItem.data()) || - (!full && d->compactRepresentationItem && d->compactRepresentationItem.data() == d->currentRepresentationItem.data()) - ) { - return; - } - } - - //Expanded - if (full) { - QQuickItem *item = qobject_cast(d->createFullRepresentationItem()); - - if (item) { - item->setParentItem(this); - { - //set anchors - QQmlExpression expr(QtQml::qmlContext(d->qmlObject->rootObject()), item, "parent"); - QQmlProperty prop(item, "anchors.fill"); - prop.write(expr.evaluate()); - } - if (d->compactRepresentationItem) { - d->compactRepresentationItem.data()->setProperty("visible", false); - } - if (d->compactRepresentationExpanderItem) { - d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant()); - d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant()); - } - - d->currentRepresentationItem = item; - d->connectLayoutAttached(item); - } - - //Icon - } else { - QQuickItem *compactItem = qobject_cast(d->createCompactRepresentationItem()); - - if (compactItem) { - //set the root item as the main visible item - compactItem->setParentItem(this); - compactItem->setVisible(true); - { - //set anchors - QQmlExpression expr(QtQml::qmlContext(d->qmlObject->rootObject()), compactItem, "parent"); - QQmlProperty prop(compactItem, "anchors.fill"); - prop.write(expr.evaluate()); - } - - if (d->fullRepresentationItem) { - d->fullRepresentationItem.data()->setProperty("parent", QVariant()); - } - - if (d->compactRepresentationExpanderItem) { - d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); - d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(d->createFullRepresentationItem())); - } - - d->currentRepresentationItem = compactItem; - d->connectLayoutAttached(compactItem); - } - } -} - #include "moc_appletquickitem.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.h b/src/scriptengines/qml/plasmoid/appletquickitem.h index c417df20a..ecf00c9f0 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.h +++ b/src/scriptengines/qml/plasmoid/appletquickitem.h @@ -83,7 +83,6 @@ public: QObject *compactRepresentationItem(); QObject *fullRepresentationItem(); - QObject *compactRepresentationExpanderItem(); ////PROPERTY ACCESSORS int switchWidth() const; @@ -128,25 +127,30 @@ Q_SIGNALS: void fullRepresentationChanged(QQmlComponent *fullRepresentation); void preferredRepresentationChanged(QQmlComponent *preferredRepresentation); - void compactRepresentationExpanderChanged(QQmlComponent *compactRepresentationExpander); - void compactRepresentationItemChanged(QObject *compactRepresentationItem); void fullRepresentationItemChanged(QObject *fullRepresentationItem); - void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem); protected: KDeclarative::QmlObject *qmlObject(); + + //Reimplementation void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); virtual void itemChange(ItemChange change, const ItemChangeData &value); -private Q_SLOTS: - void compactRepresentationCheck(); private: AppletQuickItemPrivate *const d; + Q_PRIVATE_SLOT(d, void compactRepresentationCheck()) Q_PRIVATE_SLOT(d, void minimumWidthChanged()) + Q_PRIVATE_SLOT(d, void minimumHeightChanged()) + Q_PRIVATE_SLOT(d, void preferredWidthChanged()) + Q_PRIVATE_SLOT(d, void preferredHeightChanged()) + Q_PRIVATE_SLOT(d, void maximumWidthChanged()) + Q_PRIVATE_SLOT(d, void maximumHeightChanged()) + Q_PRIVATE_SLOT(d, void fillWidthChanged()) + Q_PRIVATE_SLOT(d, void fillHeightChanged()) }; QML_DECLARE_TYPEINFO(AppletQuickItem, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/scriptengines/qml/plasmoid/appletquickitem_p.h b/src/scriptengines/qml/plasmoid/appletquickitem_p.h index 9952ac78b..c28149234 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem_p.h +++ b/src/scriptengines/qml/plasmoid/appletquickitem_p.h @@ -46,6 +46,7 @@ public: void propagateSizeHint(const QByteArray &layoutProperty); //handlers of Layout signals, private slots + void compactRepresentationCheck(); void minimumWidthChanged(); void minimumHeightChanged(); void preferredWidthChanged(); From 2f17e371d58f033804ad2e978d5b12fbf8a5fbe4 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 16:31:47 +0100 Subject: [PATCH 27/31] comments++ --- src/scriptengines/qml/plasmoid/appletquickitem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.h b/src/scriptengines/qml/plasmoid/appletquickitem.h index ecf00c9f0..ffd4ad051 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.h +++ b/src/scriptengines/qml/plasmoid/appletquickitem.h @@ -118,6 +118,7 @@ public: Q_SIGNALS: +//Property signals void switchWidthChanged(int width); void switchHeightChanged(int height); From c363b33b435659de4ad43ab8ac5ca29dbb0f7fed Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 16:39:06 +0100 Subject: [PATCH 28/31] don't assume containment() exists --- src/scriptengines/qml/plasmoid/appletinterface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 1e7cbad6d..99a33c602 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -124,7 +124,11 @@ Plasma::Types::Location AppletInterface::location() const QString AppletInterface::currentActivity() const { - return applet()->containment()->activity(); + if (applet()->containment()) { + return applet()->containment()->activity(); + } else { + return QString(); + } } QObject* AppletInterface::configuration() const From f8b649fba9eb3a341d461d0c55ce9d41005b0277 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 17:23:52 +0100 Subject: [PATCH 29/31] move AppletQuickItem in libplasmaquick --- src/plasmaquick/CMakeLists.txt | 2 ++ .../plasmoid => plasmaquick}/appletquickitem.cpp | 11 +++++++++++ .../plasmoid => plasmaquick}/appletquickitem.h | 16 ++++------------ .../private}/appletquickitem_p.h | 0 src/scriptengines/qml/CMakeLists.txt | 1 - src/scriptengines/qml/plasmoid/appletinterface.h | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) rename src/{scriptengines/qml/plasmoid => plasmaquick}/appletquickitem.cpp (97%) rename src/{scriptengines/qml/plasmoid => plasmaquick}/appletquickitem.h (90%) rename src/{scriptengines/qml/plasmoid => plasmaquick/private}/appletquickitem_p.h (100%) diff --git a/src/plasmaquick/CMakeLists.txt b/src/plasmaquick/CMakeLists.txt index 45260693e..03251bc07 100644 --- a/src/plasmaquick/CMakeLists.txt +++ b/src/plasmaquick/CMakeLists.txt @@ -1,6 +1,7 @@ project(PlasmaQuick) set(plasmaquick_LIB_SRC + appletquickitem.cpp plasmaquickview.cpp configmodel.cpp configview.cpp @@ -36,6 +37,7 @@ generate_export_header(KF5PlasmaQuick BASE_NAME PlasmaQuick) set(plasmaquick_LIB_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/plasmaquick_export.h + appletquickitem.h plasmaquickview.h configview.h configmodel.h diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp similarity index 97% rename from src/scriptengines/qml/plasmoid/appletquickitem.cpp rename to src/plasmaquick/appletquickitem.cpp index 70e3ab64a..f6027730b 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -397,6 +397,17 @@ AppletQuickItem::~AppletQuickItem() AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->engine()); } + AppletQuickItem *AppletQuickItem::qmlAttachedProperties(QObject *object) +{ + //at the moment of the attached object creation, the root item is the only one that hasn't a parent + //only way to avoid creation of this attached for everybody but the root item + if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(QtQml::qmlEngine(object))) { + return AppletQuickItemPrivate::s_rootObjects.value(QtQml::qmlEngine(object)); + } else { + return 0; + } +} + Plasma::Applet *AppletQuickItem::applet() const { return d->applet; diff --git a/src/scriptengines/qml/plasmoid/appletquickitem.h b/src/plasmaquick/appletquickitem.h similarity index 90% rename from src/scriptengines/qml/plasmoid/appletquickitem.h rename to src/plasmaquick/appletquickitem.h index ffd4ad051..0f4ace061 100644 --- a/src/scriptengines/qml/plasmoid/appletquickitem.h +++ b/src/plasmaquick/appletquickitem.h @@ -28,8 +28,9 @@ #include -#include "appletquickitem_p.h" +#include "private/appletquickitem_p.h" +#include namespace Plasma { class Applet; @@ -40,7 +41,7 @@ namespace KDeclarative { } -class AppletQuickItem : public QQuickItem +class PLASMAQUICK_EXPORT AppletQuickItem : public QQuickItem { Q_OBJECT @@ -105,16 +106,7 @@ public: void setExpanded(bool expanded); ////NEEDED BY QML TO CREATE ATTACHED PROPERTIES - static AppletQuickItem *qmlAttachedProperties(QObject *object) - { - //at the moment of the attached object creation, the root item is the only one that hasn't a parent - //only way to avoid creation of this attached for everybody but the root item - if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(QtQml::qmlEngine(object))) { - return AppletQuickItemPrivate::s_rootObjects.value(QtQml::qmlEngine(object)); - } else { - return 0; - } - } + static AppletQuickItem *qmlAttachedProperties(QObject *object); Q_SIGNALS: diff --git a/src/scriptengines/qml/plasmoid/appletquickitem_p.h b/src/plasmaquick/private/appletquickitem_p.h similarity index 100% rename from src/scriptengines/qml/plasmoid/appletquickitem_p.h rename to src/plasmaquick/private/appletquickitem_p.h diff --git a/src/scriptengines/qml/CMakeLists.txt b/src/scriptengines/qml/CMakeLists.txt index 150e4ab6d..b5497b377 100644 --- a/src/scriptengines/qml/CMakeLists.txt +++ b/src/scriptengines/qml/CMakeLists.txt @@ -10,7 +10,6 @@ endif() set(declarative_appletscript_SRCS plasmoid/declarativeappletscript.cpp - plasmoid/appletquickitem.cpp plasmoid/appletinterface.cpp plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 92fbd60e0..7c0c3cd7c 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -29,7 +29,7 @@ #include #include -#include "appletquickitem.h" +#include #include "declarativeappletscript.h" class QAction; From 29c72a9898134a8602306eb06729f16a94c94155 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 5 Feb 2014 18:00:05 +0100 Subject: [PATCH 30/31] include appletquickitem_p.h from the right file --- src/plasmaquick/appletquickitem.cpp | 1 + src/plasmaquick/appletquickitem.h | 8 ++++---- src/plasmaquick/private/appletquickitem_p.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp index f6027730b..804084a79 100644 --- a/src/plasmaquick/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -18,6 +18,7 @@ */ #include "appletquickitem.h" +#include "private/appletquickitem_p.h" #include #include diff --git a/src/plasmaquick/appletquickitem.h b/src/plasmaquick/appletquickitem.h index 0f4ace061..28bdab877 100644 --- a/src/plasmaquick/appletquickitem.h +++ b/src/plasmaquick/appletquickitem.h @@ -17,8 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef APPLETQUICKITEM_P -#define APPLETQUICKITEM_P +#ifndef APPLETQUICKITEM_H +#define APPLETQUICKITEM_H #include #include @@ -28,8 +28,6 @@ #include -#include "private/appletquickitem_p.h" - #include namespace Plasma { @@ -41,6 +39,8 @@ namespace KDeclarative { } +class AppletQuickItemPrivate; + class PLASMAQUICK_EXPORT AppletQuickItem : public QQuickItem { Q_OBJECT diff --git a/src/plasmaquick/private/appletquickitem_p.h b/src/plasmaquick/private/appletquickitem_p.h index c28149234..7e111136e 100644 --- a/src/plasmaquick/private/appletquickitem_p.h +++ b/src/plasmaquick/private/appletquickitem_p.h @@ -17,8 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef APPLETQUICKITEM_H -#define APPLETQUICKITEM_H +#ifndef APPLETQUICKITEM_P_H +#define APPLETQUICKITEM_P_H #include From 3bb0e7d3d01ec95f06c64e3b6e93fefd6a8a2194 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 6 Feb 2014 12:12:43 +0100 Subject: [PATCH 31/31] use the config of the applet parent of containment that's the systray specific hack --- src/plasma/private/applet_p.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index 2dc3a3083..26d48e306 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -360,8 +360,8 @@ KConfigGroup *AppletPrivate::mainConfigGroup() Containment *c = q->containment(); Plasma::Applet *parentApplet = 0; - if (c && c->corona()) { - parentApplet = qobject_cast(c->corona()->parent()); + if (c) { + parentApplet = qobject_cast(c->parent()); } if (q->isContainment()) {