make AppletInterface the root graphic object

AppletInterface is a QQuickItem ans
containments will receive pointers to AppletInterface as applets,
so will be able to have a limited access to it.
as an example of it working the button in the example applet enables/disables background hints

I'm still not 100% happy about it, we should see exactly what it happens when the containment deletes the graphic object.
This commit is contained in:
Marco Martin 2013-02-08 16:08:06 +01:00
parent 2bc4a08c10
commit 9ee93a0661
5 changed files with 18 additions and 9 deletions

View File

@ -29,7 +29,8 @@ target_link_libraries(plasma_appletscript_declarative
${KDE4_KIO_LIBS}
${KDE4_KDE4SUPPORT_LIBS}
${QT_QTSCRIPT_LIBRARY}
${QT_QTQML_LIBRARY}
${Qt5Quick_LIBRARIES}
${Qt5Qml_LIBRARIES}
${QT_QTUITOOLS_LIBRARY}
${KDE4_KDECORE_LIBS}
plasma

View File

@ -42,9 +42,9 @@
Q_DECLARE_METATYPE(AppletInterface*)
AppletInterface::AppletInterface(DeclarativeAppletScript *parent)
: QObject(parent),
m_appletScriptEngine(parent),
AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent)
: QQuickItem(parent),
m_appletScriptEngine(script),
m_actionSignals(0)
{
qmlRegisterType<AppletInterface>();

View File

@ -23,7 +23,7 @@
#define APPLETINTERFACE_H
#include <QAbstractAnimation>
#include <QObject>
#include <QQuickItem>
#include <QScriptValue>
#include <Plasma/Applet>
@ -44,7 +44,7 @@ namespace Plasma
class ConfigLoader;
} // namespace Plasa
class AppletInterface : public QObject
class AppletInterface : public QQuickItem
{
Q_OBJECT
Q_ENUMS(FormFactor)
@ -76,7 +76,7 @@ class AppletInterface : public QObject
Q_PROPERTY(QString associatedApplication WRITE setAssociatedApplication READ associatedApplication)
public:
AppletInterface(DeclarativeAppletScript *parent);
AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent = 0);
~AppletInterface();
//------------------------------------------------------------------

View File

@ -22,6 +22,7 @@
#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlExpression>
#include <QQmlProperty>
#include <QFile>
#include <QTimer>
#include <QUiLoader>
@ -60,6 +61,7 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant
m_env(0),
m_auth(this)
{
qmlRegisterType<AppletInterface>();
Q_UNUSED(args);
}
@ -109,6 +111,7 @@ bool DeclarativeAppletScript::init()
} else {
m_interface = new AppletInterface(this);
}
m_interface->setParent(this);
connect(applet(), SIGNAL(activate()),
this, SLOT(activate()));
@ -116,7 +119,12 @@ bool DeclarativeAppletScript::init()
setupObjects();
m_qmlObject->completeInitialization();
a->setProperty("graphicObject", QVariant::fromValue(m_qmlObject->rootObject()));
m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(m_interface));
m_qmlObject->rootObject()->setProperty("anchors.fill", "parent");
QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "parent");
QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill");
prop.write(expr.evaluate());
a->setProperty("graphicObject", QVariant::fromValue(m_interface));
qDebug() << "Graphic object created:" << a << a->property("graphicObject");
return true;

View File

@ -58,7 +58,7 @@ Rectangle {
property alias applet: appletContainer.children
property int small: 100
property int large: parent.width - width - 150
imagePath: "widgets/background"
imagePath: applet[0].backgroundHints == 0 ? "" : "widgets/background"
MouseArea {
anchors.fill: parent
drag.target: parent