From 7912da607232c1f155b76650bd425a3452fd7d0c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 4 Feb 2013 19:47:35 +0100 Subject: [PATCH] actually show the containment's qml --- plasma/applet.cpp | 14 ++++ plasma/applet.h | 12 +++ plasma/private/applet_p.cpp | 1 + plasma/private/applet_p.h | 3 + .../qml/plasmoid/declarativeappletscript.cpp | 4 +- shell/desktopcorona.cpp | 22 ++++- shell/desktopcorona.h | 1 + .../qmlpackages/desktop/contents/ui/main.qml | 81 +++---------------- shell/testcontainment/contents/ui/main.qml | 66 ++++++++++++++- shell/view.cpp | 40 ++++++++- shell/view.h | 8 ++ 11 files changed, 174 insertions(+), 78 deletions(-) diff --git a/plasma/applet.cpp b/plasma/applet.cpp index ef031a36b..04eaa46e9 100644 --- a/plasma/applet.cpp +++ b/plasma/applet.cpp @@ -203,6 +203,20 @@ uint Applet::id() const return d->appletId; } +QObject *Applet::graphicObject() const +{ + return d->graphicObject; +} + +void Applet::setGraphicObject(QObject *obj) +{ + if (d->graphicObject == obj) { + return; + } + d->graphicObject = obj; + emit graphicObjectChanged(); +} + void Applet::save(KConfigGroup &g) const { if (d->transient) { diff --git a/plasma/applet.h b/plasma/applet.h index ccf439463..62f522236 100644 --- a/plasma/applet.h +++ b/plasma/applet.h @@ -94,6 +94,13 @@ class PLASMA_EXPORT Applet : public QObject */ uint id() const; + /** + * @since: 5.0 + * A pointer to the graphical representation of this applet + */ + QObject *graphicObject() const; + void setGraphicObject(QObject *obj); + /** * Returns the KConfigGroup to access the applets configuration. * @@ -569,6 +576,11 @@ class PLASMA_EXPORT Applet : public QObject bool hasValidAssociatedApplication() const; Q_SIGNALS: + /** + * emitted when/if the graphic representation of the applet changes + */ + void graphicObjectChanged(); + /** * This signal indicates that an application launch, window * creation or window focus event was triggered. This is used, for instance, diff --git a/plasma/private/applet_p.cpp b/plasma/private/applet_p.cpp index fb9016aa1..31320aea6 100644 --- a/plasma/private/applet_p.cpp +++ b/plasma/private/applet_p.cpp @@ -71,6 +71,7 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int itemStatus(UnknownStatus), preferredSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored), modificationsTimer(0), + graphicObject(0), hasConfigurationInterface(false), failed(false), isContainment(false), diff --git a/plasma/private/applet_p.h b/plasma/private/applet_p.h index 33246096a..f0666b404 100644 --- a/plasma/private/applet_p.h +++ b/plasma/private/applet_p.h @@ -173,6 +173,9 @@ public: QBasicTimer constraintsTimer; QBasicTimer *modificationsTimer; + // Everything graphics related that remains in Applet + QObject *graphicObject; + // a great green field of booleans :) bool hasConfigurationInterface : 1; bool failed : 1; diff --git a/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/scriptengines/qml/plasmoid/declarativeappletscript.cpp index c9109ca1d..3e4dd079f 100644 --- a/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -104,8 +104,6 @@ bool DeclarativeAppletScript::init() Plasma::Applet *a = applet(); Plasma::Containment *cont = qobject_cast(a); - //TODO: assign the graphical root object - if (cont) { m_interface = new ContainmentInterface(this); //fail? so it's a normal Applet @@ -125,6 +123,8 @@ void DeclarativeAppletScript::qmlCreationFinished() { //If it's a popupapplet and the root object has a "compactRepresentation" component, use that instead of the icon Plasma::Applet *a = applet(); + a->setGraphicObject(m_qmlObject->rootObject()); + //TODO: access rootItem from m_interface //m_self->setProperty("rootItem", QVariant::fromValue(m_qmlObject->rootObject())); diff --git a/shell/desktopcorona.cpp b/shell/desktopcorona.cpp index 8fe1be095..dd65873a2 100644 --- a/shell/desktopcorona.cpp +++ b/shell/desktopcorona.cpp @@ -37,6 +37,8 @@ DesktopCorona::DesktopCorona(QObject *parent) connect(m_desktopWidget, SIGNAL(workAreaResized(int)), this, SLOT(workAreaResized(int))); + connect(this, SIGNAL(screenOwnerChanged(int, int, Plasma::Containment *)), + this, SLOT(updateScreenOwner(int, int, Plasma::Containment *))); checkViews(); } @@ -49,8 +51,11 @@ DesktopCorona::~DesktopCorona() void DesktopCorona::loadDefaultLayout() { Plasma::Containment *cont = addContainment("org.kde.testcontainment"); - Plasma::Applet *appl = cont->addApplet("foo"); - qDebug() << "Containment:" << cont->name() << "Applet:" << appl->name() << appl; + cont->setScreen(0); + qDebug() << containmentForScreen(0); + //Plasma::Applet *appl = cont->addApplet("foo"); + qDebug() << "Containment:" << cont << cont->name(); + //qDebug() << "Applet:" << appl->name() << appl; } void DesktopCorona::checkScreens(bool signalWhenExists) @@ -79,7 +84,7 @@ void DesktopCorona::checkScreen(int screen, bool signalWhenExists) //TODO: restore activities //Activity *currentActivity = activity(m_activityController->currentActivity()); //ensure the desktop(s) have a containment and view - checkDesktop(/*currentActivity,*/ signalWhenExists, screen, 0); + checkDesktop(/*currentActivity,*/ signalWhenExists, screen, -1); //ensure the panels get views too @@ -184,5 +189,16 @@ void DesktopCorona::checkViews() } } +void DesktopCorona::updateScreenOwner(int wasScreen, int isScreen, Plasma::Containment *containment) +{ + qDebug() << "Was screen" << wasScreen << "Is screen" << isScreen <<"Containment" << containment; + if (isScreen < 0 || m_views.count() < isScreen + 1) { + qWarning() << "Invalid screen"; + return; + } + + m_views[isScreen]->setContainment(containment); +} + #include "desktopcorona.moc" diff --git a/shell/desktopcorona.h b/shell/desktopcorona.h index 899cf97d7..1c5e1f119 100644 --- a/shell/desktopcorona.h +++ b/shell/desktopcorona.h @@ -69,6 +69,7 @@ protected Q_SLOTS: void workAreaResized(int screen); void checkViews(); + void updateScreenOwner(int wasScreen, int isScreen, Plasma::Containment *containment); private: QDesktopWidget *m_desktopWidget; diff --git a/shell/qmlpackages/desktop/contents/ui/main.qml b/shell/qmlpackages/desktop/contents/ui/main.qml index 9ab2eead7..e6c71b91b 100644 --- a/shell/qmlpackages/desktop/contents/ui/main.qml +++ b/shell/qmlpackages/desktop/contents/ui/main.qml @@ -21,79 +21,20 @@ import QtQuick 2.0 import org.kde.plasma.core 0.1 as PlasmaCore + Rectangle { - color: "darkblue" + color: "red" width: 640 height: 480 - PlasmaCore.Svg { - id: actionssvg - imagePath: "widgets/configuration-icons" + property Item containment + + onContainmentChanged: { + print("New Containment: " + containment + containment.parent) + //containment.parent = root + containment.visible = true + containment.anchors.fill = root } - PlasmaCore.FrameSvgItem { - id: frame - x: 50 - y: 50 - width: txt.paintedWidth + 80 - height: txt.paintedHeight + 80 * 2 - property int small: 100 - property int large: parent.width - width - 150 - imagePath: "widgets/background" - MouseArea { - anchors.fill: parent - drag.target: parent - onClicked: { - var s = (frame.x == frame.large) ? frame.small : frame.large; - frame.x = s - frame.height = s - } - } - Behavior on x { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } } - //Behavior on y { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } } - Behavior on height { PropertyAnimation { easing.type: Easing.InOutDouble; duration: 300 } } - - Text { - id: txt - text: "Click or Drag"; - anchors.centerIn: parent - } - PlasmaCore.SvgItem { - svg: actionssvg - elementId: "rotate" - width: 16 - height: width - anchors.margins: frame.margins.left - anchors { - top: parent.top - left: parent.left - } - //Rectangle { color: "white"; opacity: 0.2; anchors.fill: parent; } - } - } -// PlasmaCore.SvgItem { -// svg: actionssvg -// elementId: "rotate" -// width: 128 -// height: width -// } - PlasmaCore.IconItem { - source: "accessories-dictionary" - x: 50 - y: 350 - width: 48 - height: 48 - Rectangle { color: "white"; opacity: 0.2; anchors.fill: parent; } - } - -// Svg { -// x: 200 -// y: 200 -// width: 100 -// height: 100 -// MouseArea { -// anchors.fill: parent -// drag.target: parent -// } -// } -} \ No newline at end of file + Component.onCompleted: print("View QML loaded") +} diff --git a/shell/testcontainment/contents/ui/main.qml b/shell/testcontainment/contents/ui/main.qml index 79ff1ac48..f10c90d86 100644 --- a/shell/testcontainment/contents/ui/main.qml +++ b/shell/testcontainment/contents/ui/main.qml @@ -17,14 +17,76 @@ */ import QtQuick 2.0 -//import org.kde.plasma 2.0 import org.kde.plasma.core 0.1 as PlasmaCore Rectangle { - color: "red" + id: root + color: "darkblue" width: 640 height: 480 + property Item containment + + PlasmaCore.Svg { + id: actionssvg + imagePath: "widgets/configuration-icons" + } + + PlasmaCore.FrameSvgItem { + id: frame + x: 50 + y: 50 + width: txt.paintedWidth + 80 + height: txt.paintedHeight + 80 * 2 + property int small: 100 + property int large: parent.width - width - 150 + imagePath: "widgets/background" + MouseArea { + anchors.fill: parent + drag.target: parent + onClicked: { + var s = (frame.x == frame.large) ? frame.small : frame.large; + frame.x = s + frame.height = s + } + } + Behavior on x { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } } + //Behavior on y { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } } + Behavior on height { PropertyAnimation { easing.type: Easing.InOutDouble; duration: 300 } } + + Text { + id: txt + text: "Click or Drag"; + anchors.centerIn: parent + } + PlasmaCore.SvgItem { + svg: actionssvg + elementId: "rotate" + width: 16 + height: width + anchors.margins: frame.margins.left + anchors { + top: parent.top + left: parent.left + } + //Rectangle { color: "white"; opacity: 0.2; anchors.fill: parent; } + } + } +// PlasmaCore.SvgItem { +// svg: actionssvg +// elementId: "rotate" +// width: 128 +// height: width +// } + PlasmaCore.IconItem { + source: "accessories-dictionary" + x: 50 + y: 350 + width: 48 + height: 48 + Rectangle { color: "white"; opacity: 0.2; anchors.fill: parent; } + } + Component.onCompleted: print("Test Containment loaded") } \ No newline at end of file diff --git a/shell/view.cpp b/shell/view.cpp index 4c89ceabf..e3f62183f 100644 --- a/shell/view.cpp +++ b/shell/view.cpp @@ -19,7 +19,8 @@ #include "view.h" #include - +#include +#include #include "plasma/pluginloader.h" View::View(QWindow *parent) @@ -44,4 +45,41 @@ View::~View() +void View::setContainment(Plasma::Containment *cont) +{ + if (m_containment) { + disconnect(m_containment.data(), 0, this, 0); + } + + m_containment = cont; + + if (!cont) { + return; + } + + connect(cont, SIGNAL(graphicObjectChanged()), this, SLOT(syncGraphicObject())); + + if (m_containment.data()->graphicObject()) { + syncGraphicObject(); + } +} + +Plasma::Containment *View::containment() const +{ + return m_containment.data(); +} + +void View::syncGraphicObject() +{ + qDebug() << "using as graphic containment" << m_containment.data()->graphicObject()<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" diff --git a/shell/view.h b/shell/view.h index fc7ac73ef..cb52187ea 100644 --- a/shell/view.h +++ b/shell/view.h @@ -23,6 +23,7 @@ #include "plasma/package.h" +#include "plasma/containment.h" class View : public QQuickView @@ -33,8 +34,15 @@ public: View(QWindow *parent = 0); virtual ~View(); + void setContainment(Plasma::Containment *cont); + Plasma::Containment *containment() const; + +protected Q_SLOTS: + void syncGraphicObject(); + private: Plasma::Package m_package; + QWeakPointer m_containment; }; #endif // VIEW_H