get rid of the ugly async syncgraphicObject()

This commit is contained in:
Marco Martin 2013-02-05 11:03:40 +01:00
parent 5562c65127
commit b5a65921d0
3 changed files with 14 additions and 20 deletions

View File

@ -91,6 +91,7 @@ bool DeclarativeAppletScript::init()
engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory(&package(), &m_auth)); engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory(&package(), &m_auth));
m_qmlObject->setQmlPath(mainScript()); m_qmlObject->setQmlPath(mainScript());
if (!m_qmlObject->engine() || !m_qmlObject->engine()->rootContext() || !m_qmlObject->engine()->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) { if (!m_qmlObject->engine() || !m_qmlObject->engine()->rootContext() || !m_qmlObject->engine()->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) {
QString reason; QString reason;
@ -102,7 +103,9 @@ bool DeclarativeAppletScript::init()
} }
Plasma::Applet *a = applet(); Plasma::Applet *a = applet();
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(a); Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(a);
if (cont) { if (cont) {
m_interface = new ContainmentInterface(this); m_interface = new ContainmentInterface(this);
@ -115,6 +118,8 @@ bool DeclarativeAppletScript::init()
this, SLOT(activate())); this, SLOT(activate()));
setupObjects(); setupObjects();
m_qmlObject->completeInitialization();
a->setGraphicObject(m_qmlObject->rootObject());
return true; return true;
} }
@ -123,7 +128,6 @@ void DeclarativeAppletScript::qmlCreationFinished()
{ {
//If it's a popupapplet and the root object has a "compactRepresentation" component, use that instead of the icon //If it's a popupapplet and the root object has a "compactRepresentation" component, use that instead of the icon
Plasma::Applet *a = applet(); Plasma::Applet *a = applet();
a->setGraphicObject(m_qmlObject->rootObject());
//TODO: access rootItem from m_interface //TODO: access rootItem from m_interface
//m_self->setProperty("rootItem", QVariant::fromValue(m_qmlObject->rootObject())); //m_self->setProperty("rootItem", QVariant::fromValue(m_qmlObject->rootObject()));

View File

@ -58,10 +58,16 @@ void View::setContainment(Plasma::Containment *cont)
return; return;
} }
connect(cont, SIGNAL(graphicObjectChanged()), this, SLOT(syncGraphicObject()));
if (m_containment.data()->graphicObject()) { if (m_containment.data()->graphicObject()) {
syncGraphicObject(); qDebug() << "using as graphic containment" << m_containment.data()->graphicObject()<<m_containment.data();
if (!m_containment || !m_containment.data()->graphicObject()) {
qWarning() << "Containment not valid (yet?)";
return;
}
m_containment.data()->graphicObject()->setProperty("visible", false);
m_containment.data()->graphicObject()->setProperty("parent", QVariant::fromValue(rootObject()));
rootObject()->setProperty("containment", QVariant::fromValue(m_containment.data()->graphicObject()));
} }
} }
@ -70,17 +76,4 @@ Plasma::Containment *View::containment() const
return m_containment.data(); return m_containment.data();
} }
void View::syncGraphicObject()
{
qDebug() << "using as graphic containment" << m_containment.data()->graphicObject()<<m_containment.data();
if (!m_containment || !m_containment.data()->graphicObject()) {
qWarning() << "Containment not valid (yet?)";
return;
}
m_containment.data()->graphicObject()->setProperty("visible", false);
m_containment.data()->graphicObject()->setProperty("parent", QVariant::fromValue(rootObject()));
rootObject()->setProperty("containment", QVariant::fromValue(m_containment.data()->graphicObject()));
}
#include "moc_view.cpp" #include "moc_view.cpp"

View File

@ -37,9 +37,6 @@ public:
void setContainment(Plasma::Containment *cont); void setContainment(Plasma::Containment *cont);
Plasma::Containment *containment() const; Plasma::Containment *containment() const;
protected Q_SLOTS:
void syncGraphicObject();
private: private:
Plasma::Package m_package; Plasma::Package m_package;
QWeakPointer<Plasma::Containment> m_containment; QWeakPointer<Plasma::Containment> m_containment;