From 2734ceaebb3511ec16209e1cf90c851ce30d8fef Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 5 Feb 2013 11:59:14 +0100 Subject: [PATCH] reparent applet graphicobject to containment graphicobject --- scriptengines/qml/plasmoid/appletinterface.cpp | 7 ++++++- scriptengines/qml/plasmoid/declarativeappletscript.cpp | 2 +- shell/CMakeLists.txt | 1 + shell/desktopcorona.cpp | 2 +- shell/testcontainment/contents/ui/main.qml | 9 ++++++++- shell/view.cpp | 2 +- 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scriptengines/qml/plasmoid/appletinterface.cpp b/scriptengines/qml/plasmoid/appletinterface.cpp index ccc5f6c41..9c8e37264 100644 --- a/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/scriptengines/qml/plasmoid/appletinterface.cpp @@ -469,7 +469,12 @@ QVariantList ContainmentInterface::availableScreenRegion(int id) const void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPointF &pos) { - emit appletAdded(applet, pos); + qDebug()<<"Applet added:"<name()<graphicObject(); + if (applet && containment()->graphicObject() && applet->graphicObject()) { + applet->graphicObject()->setProperty("visible", false); + applet->graphicObject()->setProperty("parent", QVariant::fromValue(containment()->graphicObject())); + } + emit appletAdded(applet->graphicObject(), pos); } void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) diff --git a/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 63e1fbc8b..666f1a3dc 100644 --- a/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -120,7 +120,7 @@ bool DeclarativeAppletScript::init() setupObjects(); m_qmlObject->completeInitialization(); a->setGraphicObject(m_qmlObject->rootObject()); - + qDebug()<<"Graphic object created:"<graphicObject(); return true; } diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 313696e83..8df818035 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -51,3 +51,4 @@ install(TARGETS testplasma2 ${INSTALL_TARGETS_DEFAULT_ARGS}) add_subdirectory(qmlpackages) installPackage(testcontainment org.kde.testcontainment) +installPackage(testapplet org.kde.testapplet) diff --git a/shell/desktopcorona.cpp b/shell/desktopcorona.cpp index 46044a1a0..7b113ad4a 100644 --- a/shell/desktopcorona.cpp +++ b/shell/desktopcorona.cpp @@ -53,7 +53,7 @@ void DesktopCorona::loadDefaultLayout() Plasma::Containment *cont = addContainment("org.kde.testcontainment"); cont->setScreen(0); qDebug() << containmentForScreen(0); - Plasma::Applet *appl = cont->addApplet("foo"); + Plasma::Applet *appl = cont->addApplet("org.kde.testapplet"); qDebug() << "Containment:" << cont << cont->name(); qDebug() << "Applet:" << appl->name() << appl; } diff --git a/shell/testcontainment/contents/ui/main.qml b/shell/testcontainment/contents/ui/main.qml index dfc432904..9ae5f884b 100644 --- a/shell/testcontainment/contents/ui/main.qml +++ b/shell/testcontainment/contents/ui/main.qml @@ -26,7 +26,14 @@ Rectangle { width: 640 height: 480 - property Item containment + Connections { + target: plasmoid + onAppletAdded: { + print("Applet added: " + applet) + applet.parent = root + applet.visible = true + } + } PlasmaCore.Svg { id: actionssvg diff --git a/shell/view.cpp b/shell/view.cpp index 233a1b3a4..3168fdaa5 100644 --- a/shell/view.cpp +++ b/shell/view.cpp @@ -36,7 +36,7 @@ View::View(QWindow *parent) setResizeMode(View::SizeRootObjectToView); setSource(QUrl::fromLocalFile(m_package.filePath("mainscript"))); - show();rootContext()->setContextProperty("plasmoid", this); + show(); } View::~View()