From db078f8b53d3e193ccd3813ba1a2b0ed8c8323fd Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 14 Feb 2013 14:00:31 +0100 Subject: [PATCH] basic support for wallpapers --- plasma/private/containment_p.h | 2 +- .../qml/plasmoid/containmentinterface.cpp | 47 +++++++++++++++++++ .../qml/plasmoid/containmentinterface.h | 5 ++ shell/qmlpackages/CMakeLists.txt | 1 + shell/qmlpackages/toolbox/metadata.desktop | 1 - shell/qmlpackages/wallpaper/CMakeLists.txt | 4 ++ .../wallpaper/contents/ui/main.qml | 25 ++++++++++ shell/qmlpackages/wallpaper/metadata.desktop | 15 ++++++ shell/testcontainment/contents/ui/main.qml | 3 +- shell/view.cpp | 1 + 10 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 shell/qmlpackages/wallpaper/CMakeLists.txt create mode 100644 shell/qmlpackages/wallpaper/contents/ui/main.qml create mode 100644 shell/qmlpackages/wallpaper/metadata.desktop diff --git a/plasma/private/containment_p.h b/plasma/private/containment_p.h index 4de04e78b..76cc480c5 100644 --- a/plasma/private/containment_p.h +++ b/plasma/private/containment_p.h @@ -57,7 +57,7 @@ public: desktop(-1), // all desktops lastDesktop(-1), type(Containment::NoContainmentType), - drawWallpaper(true), + drawWallpaper(false), containmentActionsSource(Global) { } diff --git a/scriptengines/qml/plasmoid/containmentinterface.cpp b/scriptengines/qml/plasmoid/containmentinterface.cpp index 368c1caa3..1e15daa98 100644 --- a/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -21,10 +21,16 @@ #include "containmentinterface.h" +#include +#include + #include #include #include +#include + +#include "declarative/qmlobject.h" ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent) : AppletInterface(parent) @@ -41,6 +47,7 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent) connect(containment()->corona(), SIGNAL(availableScreenRegionChanged()), this, SIGNAL(availableScreenRegionChanged())); } + loadWallpaper(); } QVariantList ContainmentInterface::applets() @@ -56,7 +63,13 @@ QVariantList ContainmentInterface::applets() void ContainmentInterface::setDrawWallpaper(bool drawWallpaper) { + if (drawWallpaper == m_appletScriptEngine->drawWallpaper()) { + return; + } + m_appletScriptEngine->setDrawWallpaper(drawWallpaper); + + loadWallpaper(); } bool ContainmentInterface::drawWallpaper() @@ -139,7 +152,41 @@ void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) void ContainmentInterface::loadWallpaper() { + if (m_appletScriptEngine->drawWallpaper()) { + if (m_wallpaperQmlObject) { + return; + } + Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); + pkg.setPath("org.kde.wallpaper.image"); + + m_wallpaperQmlObject = new QmlObject(this); + m_wallpaperQmlObject->setQmlPath(pkg.filePath("mainscript")); + + if (m_wallpaperQmlObject->mainComponent() && + m_wallpaperQmlObject->rootObject() && + !m_wallpaperQmlObject->mainComponent()->isError()) { + m_wallpaperQmlObject->rootObject()->setProperty("z", -1000); + m_wallpaperQmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this)); + + //set anchors + QQmlExpression expr(m_appletScriptEngine->engine()->rootContext(), m_wallpaperQmlObject->rootObject(), "parent"); + QQmlProperty prop(m_wallpaperQmlObject->rootObject(), "anchors.fill"); + prop.write(expr.evaluate()); + + } else if (m_wallpaperQmlObject->mainComponent()) { + qWarning() << "Error loading the wallpaper" << m_wallpaperQmlObject->mainComponent()->errors(); + m_wallpaperQmlObject->deleteLater(); + m_wallpaperQmlObject = 0; + + } else { + qWarning() << "Error loading the wallpaper, package not found"; + } + + } else { + m_wallpaperQmlObject->deleteLater(); + m_wallpaperQmlObject = 0; + } } QString ContainmentInterface::activityId() const diff --git a/scriptengines/qml/plasmoid/containmentinterface.h b/scriptengines/qml/plasmoid/containmentinterface.h index 03d8f77a1..5e5fbe59b 100644 --- a/scriptengines/qml/plasmoid/containmentinterface.h +++ b/scriptengines/qml/plasmoid/containmentinterface.h @@ -25,6 +25,8 @@ #include "appletinterface.h" +class QmlObject; + class ContainmentInterface : public AppletInterface { Q_OBJECT @@ -72,6 +74,9 @@ protected Q_SLOTS: void appletAddedForward(Plasma::Applet *applet, const QPointF &pos); void appletRemovedForward(Plasma::Applet *applet); void loadWallpaper(); + +private: + QmlObject *m_wallpaperQmlObject; }; #endif diff --git a/shell/qmlpackages/CMakeLists.txt b/shell/qmlpackages/CMakeLists.txt index 4b49ca56d..66664060d 100644 --- a/shell/qmlpackages/CMakeLists.txt +++ b/shell/qmlpackages/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(desktop) add_subdirectory(toolbox) +add_subdirectory(wallpaper) diff --git a/shell/qmlpackages/toolbox/metadata.desktop b/shell/qmlpackages/toolbox/metadata.desktop index 1b112bb2e..94359c9e5 100644 --- a/shell/qmlpackages/toolbox/metadata.desktop +++ b/shell/qmlpackages/toolbox/metadata.desktop @@ -11,7 +11,6 @@ Name[uk]=Набір інструментів для стаціонарних к Name[x-test]=xxDesktop Toolboxxx Type=Service -X-KDE-ServiceTypes=Plasma/Applet X-KDE-ParentApp= X-KDE-PluginInfo-Author=Marco Martin X-KDE-PluginInfo-Category= diff --git a/shell/qmlpackages/wallpaper/CMakeLists.txt b/shell/qmlpackages/wallpaper/CMakeLists.txt new file mode 100644 index 000000000..6dd02e176 --- /dev/null +++ b/shell/qmlpackages/wallpaper/CMakeLists.txt @@ -0,0 +1,4 @@ + +install(DIRECTORY . DESTINATION ${DATA_INSTALL_DIR}/plasma/packages/org.kde.wallpaper.image PATTERN .svn EXCLUDE PATTERN CMakeLists.txt EXCLUDE PATTERN Messages.sh EXCLUDE) + + diff --git a/shell/qmlpackages/wallpaper/contents/ui/main.qml b/shell/qmlpackages/wallpaper/contents/ui/main.qml new file mode 100644 index 000000000..5b35d9b70 --- /dev/null +++ b/shell/qmlpackages/wallpaper/contents/ui/main.qml @@ -0,0 +1,25 @@ +/* + * 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 + +Rectangle { + id: root + color: "darkblue" + +} \ No newline at end of file diff --git a/shell/qmlpackages/wallpaper/metadata.desktop b/shell/qmlpackages/wallpaper/metadata.desktop new file mode 100644 index 000000000..36c0bdba4 --- /dev/null +++ b/shell/qmlpackages/wallpaper/metadata.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Encoding=UTF-8 +Keywords= +Name=Image wallpaper +Type=Service + +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.wallpaper.image +X-KDE-PluginInfo-Version= +X-KDE-PluginInfo-Website= +X-Plasma-MainScript=ui/main.qml diff --git a/shell/testcontainment/contents/ui/main.qml b/shell/testcontainment/contents/ui/main.qml index 0535426ea..8708aefdc 100644 --- a/shell/testcontainment/contents/ui/main.qml +++ b/shell/testcontainment/contents/ui/main.qml @@ -21,9 +21,8 @@ import QtQuick 2.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.components 0.1 as PlasmaComponents -Rectangle { +Item { id: root - color: "darkblue" width: 640 height: 480 diff --git a/shell/view.cpp b/shell/view.cpp index 475edf5e6..bc35907f9 100644 --- a/shell/view.cpp +++ b/shell/view.cpp @@ -61,6 +61,7 @@ void View::setContainment(Plasma::Containment *cont) qDebug() << "using as graphic containment" << graphicObject << m_containment.data(); //graphicObject->setProperty("visible", false); + graphicObject->setProperty("drawWallpaper", true); graphicObject->setProperty("parent", QVariant::fromValue(rootObject())); rootObject()->setProperty("containment", QVariant::fromValue(graphicObject)); } else {