From 95c82d3e825aaa33db58322723dccc4215973218 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 13 Feb 2013 16:46:43 +0100 Subject: [PATCH] manage qml object insertion in the scene in AppletInterface --- .../qml/plasmoid/appletinterface.cpp | 35 +++++++++++++------ scriptengines/qml/plasmoid/appletinterface.h | 18 +++++++--- .../qml/plasmoid/declarativeappletscript.cpp | 7 +--- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/scriptengines/qml/plasmoid/appletinterface.cpp b/scriptengines/qml/plasmoid/appletinterface.cpp index 85976333d..b8963f42e 100644 --- a/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/scriptengines/qml/plasmoid/appletinterface.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -66,6 +68,28 @@ AppletInterface::~AppletInterface() { } +void AppletInterface::setUiObject(QObject *object) +{ + if (m_uiObject.data() == object) { + return; + } + + m_uiObject = object; + + //set parent, both as object hyerarchy and visually + object->setProperty("parent", QVariant::fromValue(this)); + + //set anchors + QQmlExpression expr(m_appletScriptEngine->engine()->rootContext(), object, "parent"); + QQmlProperty prop(object, "anchors.fill"); + prop.write(expr.evaluate()); +} + +QObject *AppletInterface::uiObject() const +{ + return m_uiObject.data(); +} + AppletInterface::FormFactor AppletInterface::formFactor() const { return static_cast(applet()->formFactor()); @@ -306,17 +330,6 @@ int AppletInterface::apiVersion() const return offers.first()->property("X-KDE-PluginInfo-Version", QVariant::Int).toInt(); } -bool AppletInterface::include(const QString &script) -{ - const QString path = m_appletScriptEngine->filePath("scripts", script); - - if (path.isEmpty()) { - return false; - } - - return m_appletScriptEngine->include(path); -} - void AppletInterface::debug(const QString &msg) { kDebug() << msg; diff --git a/scriptengines/qml/plasmoid/appletinterface.h b/scriptengines/qml/plasmoid/appletinterface.h index 8b3b8afd9..3456c4a18 100644 --- a/scriptengines/qml/plasmoid/appletinterface.h +++ b/scriptengines/qml/plasmoid/appletinterface.h @@ -70,9 +70,15 @@ public: AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent = 0); ~AppletInterface(); +//API not intended for the QML part + void setUiObject(QObject *object); + QObject *uiObject() const; + //------------------------------------------------------------------ //enums copy&pasted from plasma.h because qtscript is evil + +//TODO: all of this should go from here enum FormFactor { Planar = 0, /**< The applet lives in a plane and has two degrees of freedom to grow. Optimize for @@ -140,7 +146,7 @@ enum IntervalAlignment { AlignToHour }; -//------------------------------------------------------------------- +//QML API------------------------------------------------------------------- Q_INVOKABLE void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString()); @@ -159,8 +165,6 @@ enum IntervalAlignment { Q_INVOKABLE QString file(const QString &fileType); Q_INVOKABLE QString file(const QString &fileType, const QString &filePath); - Q_INVOKABLE bool include(const QString &script); - Q_INVOKABLE void debug(const QString &msg); QList contextualActions() const; @@ -171,7 +175,7 @@ enum IntervalAlignment { Q_INVOKABLE QStringList downloadedFiles() const; -//PROPERTY ACCESSORS +//PROPERTY ACCESSORS------------------------------------------------------------------- FormFactor formFactor() const; Location location() const; @@ -201,6 +205,7 @@ Q_SIGNALS: void releaseVisualFocus(); void configNeedsSaving(); +//PROPERTY change notifiers-------------- void formFactorChanged(); void locationChanged(); void contextChanged(); @@ -218,7 +223,10 @@ private: QString m_currentConfig; QMap m_configs; -//UI-specific properties + +//UI-specific members ------------------ + QWeakPointer m_uiObject; + Plasma::BackgroundHints m_backgroundHints; bool m_busy : 1; }; diff --git a/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 25a4abbc5..387b0f52c 100644 --- a/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -132,12 +132,7 @@ bool DeclarativeAppletScript::init() m_qmlObject->completeInitialization(); - m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(m_interface)); - - //set anchors - QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "parent"); - QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill"); - prop.write(expr.evaluate()); + m_interface->setUiObject(m_qmlObject->rootObject()); // set the graphicObject dynamic property on applet a->setProperty("graphicObject", QVariant::fromValue(m_interface));