From 4e44bc4c3179dc2b82d349440a74f2edeae54b95 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 14 Feb 2013 19:11:17 +0100 Subject: [PATCH] support for containment type in the desktop file add a test panel containment --- src/plasma/corona.cpp | 1 + .../servicetypes/plasma-containment.desktop | 3 +- .../qml/plasmoid/declarativeappletscript.cpp | 20 +++- src/shell/CMakeLists.txt | 5 +- src/shell/applets/CMakeLists.txt | 3 + .../testapplet/contents/ui/main.qml | 0 .../{ => applets}/testapplet/metadata.desktop | 0 .../contents/ui/testcomponents.qml | 0 .../testcomponentsapplet/metadata.desktop | 0 src/shell/containments/CMakeLists.txt | 3 + .../testcontainment/contents/ui/main.qml | 0 .../testcontainment/metadata.desktop | 0 .../testpanel/contents/ui/main.qml | 113 ++++++++++++++++++ .../containments/testpanel/metadata.desktop | 18 +++ src/shell/desktopcorona.cpp | 2 +- src/shell/panelview.h | 2 +- src/shell/view.h | 2 +- 17 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 src/shell/applets/CMakeLists.txt rename src/shell/{ => applets}/testapplet/contents/ui/main.qml (100%) rename src/shell/{ => applets}/testapplet/metadata.desktop (100%) rename src/shell/{ => applets}/testcomponentsapplet/contents/ui/testcomponents.qml (100%) rename src/shell/{ => applets}/testcomponentsapplet/metadata.desktop (100%) create mode 100644 src/shell/containments/CMakeLists.txt rename src/shell/{ => containments}/testcontainment/contents/ui/main.qml (100%) rename src/shell/{ => containments}/testcontainment/metadata.desktop (100%) create mode 100644 src/shell/containments/testpanel/contents/ui/main.qml create mode 100644 src/shell/containments/testpanel/metadata.desktop diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp index c2f1c7b5c..503952ec5 100644 --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -210,6 +210,7 @@ QList Corona::importLayout(const KConfigGroup &conf) Containment *Corona::containmentForScreen(int screen, int desktop) const { foreach (Containment *containment, d->containments) { + kWarning() << "AAAAA"<screen()<location(); if (containment->screen() == screen && (desktop < 0 || containment->desktop() == desktop) && (containment->containmentType() == Containment::DesktopContainment || diff --git a/src/plasma/data/servicetypes/plasma-containment.desktop b/src/plasma/data/servicetypes/plasma-containment.desktop index 63ac683e7..c134cb46c 100644 --- a/src/plasma/data/servicetypes/plasma-containment.desktop +++ b/src/plasma/data/servicetypes/plasma-containment.desktop @@ -15,4 +15,5 @@ Comment[x-test]=xxPlasma applet container and background painterxx [PropertyDef::X-Plasma-ContainmentCategories] Type=QStringList - +[PropertyDef::X-Plasma-ContainmentType] +Type=QString diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index 9b76c100f..ac5539b03 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -68,6 +68,22 @@ DeclarativeAppletScript::~DeclarativeAppletScript() bool DeclarativeAppletScript::init() { + Plasma::Containment *pc = qobject_cast(applet()); + + if (pc) { + QString type = pc->pluginInfo().property("X-Plasma-ContainmentType").toString(); + + if (type == "DesktopContainment") { + pc->setContainmentType(Plasma::Containment::DesktopContainment); + } else if (type == "PanelContainment") { + pc->setContainmentType(Plasma::Containment::PanelContainment); + } if (type == "CustomContainment") { + pc->setContainmentType(Plasma::Containment::CustomContainment); + } else if (type == "CustomPanelContainment") { + pc->setContainmentType(Plasma::Containment::CustomPanelContainment); + } + } + m_qmlObject = new QmlObject(applet()); m_qmlObject->setInitializationDelayed(true); //FIXME: what replaced this? @@ -134,9 +150,7 @@ bool DeclarativeAppletScript::init() a->setProperty("graphicObject", QVariant::fromValue(m_interface)); qDebug() << "Graphic object created:" << a << a->property("graphicObject"); - //Is this a containment? - Plasma::Containment *pc = qobject_cast(a); - + //Create the ToolBox if (pc) { Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); pkg.setPath("org.kde.toolbox"); diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index e609bcb26..3585cb832 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -50,7 +50,6 @@ target_link_libraries(testplasma2 install(TARGETS testplasma2 ${INSTALL_TARGETS_DEFAULT_ARGS}) +add_subdirectory(applets) +add_subdirectory(containments) add_subdirectory(qmlpackages) -installPackage(testcontainment org.kde.testcontainment) -installPackage(testapplet org.kde.testapplet) -installPackage(testcomponentsapplet org.kde.testcomponentsapplet) diff --git a/src/shell/applets/CMakeLists.txt b/src/shell/applets/CMakeLists.txt new file mode 100644 index 000000000..f80e899a3 --- /dev/null +++ b/src/shell/applets/CMakeLists.txt @@ -0,0 +1,3 @@ + +installPackage(testapplet org.kde.testapplet) +installPackage(testcomponentsapplet org.kde.testcomponentsapplet) diff --git a/src/shell/testapplet/contents/ui/main.qml b/src/shell/applets/testapplet/contents/ui/main.qml similarity index 100% rename from src/shell/testapplet/contents/ui/main.qml rename to src/shell/applets/testapplet/contents/ui/main.qml diff --git a/src/shell/testapplet/metadata.desktop b/src/shell/applets/testapplet/metadata.desktop similarity index 100% rename from src/shell/testapplet/metadata.desktop rename to src/shell/applets/testapplet/metadata.desktop diff --git a/src/shell/testcomponentsapplet/contents/ui/testcomponents.qml b/src/shell/applets/testcomponentsapplet/contents/ui/testcomponents.qml similarity index 100% rename from src/shell/testcomponentsapplet/contents/ui/testcomponents.qml rename to src/shell/applets/testcomponentsapplet/contents/ui/testcomponents.qml diff --git a/src/shell/testcomponentsapplet/metadata.desktop b/src/shell/applets/testcomponentsapplet/metadata.desktop similarity index 100% rename from src/shell/testcomponentsapplet/metadata.desktop rename to src/shell/applets/testcomponentsapplet/metadata.desktop diff --git a/src/shell/containments/CMakeLists.txt b/src/shell/containments/CMakeLists.txt new file mode 100644 index 000000000..03da6caa7 --- /dev/null +++ b/src/shell/containments/CMakeLists.txt @@ -0,0 +1,3 @@ + +installPackage(testcontainment org.kde.testcontainment) +installPackage(testpanel org.kde.testpanel) diff --git a/src/shell/testcontainment/contents/ui/main.qml b/src/shell/containments/testcontainment/contents/ui/main.qml similarity index 100% rename from src/shell/testcontainment/contents/ui/main.qml rename to src/shell/containments/testcontainment/contents/ui/main.qml diff --git a/src/shell/testcontainment/metadata.desktop b/src/shell/containments/testcontainment/metadata.desktop similarity index 100% rename from src/shell/testcontainment/metadata.desktop rename to src/shell/containments/testcontainment/metadata.desktop diff --git a/src/shell/containments/testpanel/contents/ui/main.qml b/src/shell/containments/testpanel/contents/ui/main.qml new file mode 100644 index 000000000..8708aefdc --- /dev/null +++ b/src/shell/containments/testpanel/contents/ui/main.qml @@ -0,0 +1,113 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.0 + +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.components 0.1 as PlasmaComponents + +Item { + id: root + width: 640 + height: 480 + + property Item toolBox + + Connections { + target: plasmoid + onAppletAdded: { + var container = appletContainerComponent.createObject(root) + container.visible = true + print("Applet added: " + applet) + applet.parent = container + container.applet = applet + applet.anchors.fill= applet.parent + applet.visible = true + } + } + + Component { + id: appletContainerComponent + PlasmaCore.FrameSvgItem { + id: frame + x: 50 + y: 50 + + width: large + frame.margins.left + frame.margins.right + height: large + frame.margins.top + frame.margins.bottom + + property alias applet: appletContainer.children + + property int small: 90 + property int large: 400 + + property int tm: 0 + property int lm: 0 + + imagePath: applet.length > 0 && applet[0].backgroundHints == 0 ? "" : "widgets/background" + + onImagePathChanged: { + // Reposition applet so it fits into the frame + if (imagePath == "") { + frame.x = frame.x + lm; + frame.y = frame.y + tm; + } else { + // Cache values, so we can subtract them when the background is removed + frame.lm = frame.margins.left; + frame.tm = frame.margins.top; + + frame.x = frame.x - frame.margins.left; + frame.y = frame.y - frame.margins.top; + } + } + MouseArea { + anchors.fill: parent + drag.target: parent + onClicked: { + var s = (frame.width == frame.large) ? frame.small : frame.large; + frame.x = s + frame.height = s + frame.width = s + } + } + + Item { + id: appletContainer + anchors { + fill: parent + leftMargin: frame.margins.left + rightMargin: parent.margins.right + topMargin: parent.margins.top + bottomMargin: parent.margins.bottom + } + } + + PlasmaComponents.BusyIndicator { + z: 1000 + visible: applet.length > 0 && applet[0].busy + running: visible + anchors.centerIn: parent + } + } + } + + Component.onCompleted: { + print("Test Containment loaded") + print(plasmoid) + } +} \ No newline at end of file diff --git a/src/shell/containments/testpanel/metadata.desktop b/src/shell/containments/testpanel/metadata.desktop new file mode 100644 index 000000000..86e67ca26 --- /dev/null +++ b/src/shell/containments/testpanel/metadata.desktop @@ -0,0 +1,18 @@ +[Desktop Entry] +Encoding=UTF-8 +Keywords= +Name=Panel Test +Type=Service + +X-KDE-ServiceTypes=Plasma/Applet,Plasma/Containment +X-Plasma-API=declarativeappletscript +X-KDE-ParentApp= +X-KDE-PluginInfo-Author=Marco Martin +X-KDE-PluginInfo-Category= +X-KDE-PluginInfo-Email=mart@kde.org +X-KDE-PluginInfo-License=GPLv2+ +X-KDE-PluginInfo-Name=org.kde.testpanel +X-KDE-PluginInfo-Version= +X-KDE-PluginInfo-Website= +X-Plasma-MainScript=ui/main.qml +X-Plasma-ContainmentType=PanelContainment \ No newline at end of file diff --git a/src/shell/desktopcorona.cpp b/src/shell/desktopcorona.cpp index 03b5575f9..d2b355047 100644 --- a/src/shell/desktopcorona.cpp +++ b/src/shell/desktopcorona.cpp @@ -115,7 +115,7 @@ void DesktopCorona::checkScreen(int screen, bool signalWhenExists) void DesktopCorona::checkDesktop(/*Activity *activity,*/ bool signalWhenExists, int screen, int desktop) { Plasma::Containment *c = /*activity->*/containmentForScreen(screen, desktop); - +qWarning()<<"AAAAA"<formFactor(); //TODO: remove following when activities are restored if (!c) { c = addContainment("desktop"); diff --git a/src/shell/panelview.h b/src/shell/panelview.h index 8883b2a6f..8692d7f24 100644 --- a/src/shell/panelview.h +++ b/src/shell/panelview.h @@ -28,7 +28,7 @@ class PanelView : public View Q_OBJECT public: - PanelView(Plasma::Corona *corona, QWindow *parent = 0); + explicit PanelView(Plasma::Corona *corona, QWindow *parent = 0); virtual ~PanelView(); private: diff --git a/src/shell/view.h b/src/shell/view.h index 78d8139fb..25651f90a 100644 --- a/src/shell/view.h +++ b/src/shell/view.h @@ -31,7 +31,7 @@ class View : public QQuickView Q_OBJECT public: - View(Plasma::Corona *corona, QWindow *parent = 0); + explicit View(Plasma::Corona *corona, QWindow *parent = 0); virtual ~View(); //FIXME: not super nice, but we have to be sure qml assignment is done after window flags