manage qml object insertion in the scene in AppletInterface

This commit is contained in:
Marco Martin 2013-02-13 16:46:43 +01:00
parent de5116ef01
commit 95c82d3e82
3 changed files with 38 additions and 22 deletions

View File

@ -25,6 +25,8 @@
#include <QDir>
#include <QFile>
#include <QQmlEngine>
#include <QQmlExpression>
#include <QQmlProperty>
#include <QQmlComponent>
#include <QSignalMapper>
#include <QTimer>
@ -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<FormFactor>(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;

View File

@ -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<QAction*> 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<QString, Plasma::ConfigLoader*> m_configs;
//UI-specific properties
//UI-specific members ------------------
QWeakPointer<QObject> m_uiObject;
Plasma::BackgroundHints m_backgroundHints;
bool m_busy : 1;
};

View File

@ -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));