From a644a7cc6749f8dd5ca20589ee6e59acc2892b3e Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 27 Sep 2011 04:51:30 +0200 Subject: new qmafw watchlet --- libsowatch/declarativewatchlet.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'libsowatch/declarativewatchlet.cpp') diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp index ca60fb0..dbd4759 100644 --- a/libsowatch/declarativewatchlet.cpp +++ b/libsowatch/declarativewatchlet.cpp @@ -29,6 +29,11 @@ DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id) _engine->rootContext()->setContextProperty("watch", _wrapper); } +DeclarativeWatchlet::~DeclarativeWatchlet() +{ + +} + void DeclarativeWatchlet::setSource(const QUrl &url) { if (_item) { @@ -64,6 +69,11 @@ QDeclarativeContext* DeclarativeWatchlet::rootContext() return _engine->rootContext(); } +QDeclarativeItem* DeclarativeWatchlet::rootObject() +{ + return _item; +} + void DeclarativeWatchlet::activate() { GraphicsWatchlet::activate(); @@ -76,6 +86,19 @@ void DeclarativeWatchlet::deactivate() GraphicsWatchlet::deactivate(); } +void DeclarativeWatchlet::setRootObject(QDeclarativeItem *item) +{ + Q_ASSERT(_item == 0); /* This function should not be called with a current object. */ + if (!item) { + qWarning() << "QML root object is not a declarative item?"; + return; + } + + _item = item; + // TODO Resize _item + scene()->addItem(_item); +} + void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status status) { QObject *obj; @@ -93,9 +116,7 @@ void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status st qWarning() << _component->errors(); return; } - Q_ASSERT(_item == 0); - _item = qobject_cast(obj); - scene()->addItem(_item); + setRootObject(qobject_cast(obj)); break; case QDeclarativeComponent::Error: qWarning() << "QML has errors found while loading:"; -- cgit v1.2.3