From 0846a611e9ce20c54e65d9bc774feaca27e1326b Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 13 Feb 2013 22:26:28 +0100 Subject: [PATCH] put ContainmentInterface into its own file also try and get rid of a few unneeded headers --- scriptengines/qml/CMakeLists.txt | 1 + .../qml/plasmoid/appletinterface.cpp | 138 +----------------- scriptengines/qml/plasmoid/appletinterface.h | 54 ------- .../qml/plasmoid/declarativeappletscript.cpp | 1 + 4 files changed, 6 insertions(+), 188 deletions(-) diff --git a/scriptengines/qml/CMakeLists.txt b/scriptengines/qml/CMakeLists.txt index 8e14533f7..52b4453be 100644 --- a/scriptengines/qml/CMakeLists.txt +++ b/scriptengines/qml/CMakeLists.txt @@ -18,6 +18,7 @@ set(declarative_appletscript_SRCS declarative/packageaccessmanagerfactory.cpp declarative/qmlobject.cpp plasmoid/appletinterface.cpp + plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp ) diff --git a/scriptengines/qml/plasmoid/appletinterface.cpp b/scriptengines/qml/plasmoid/appletinterface.cpp index f5974afb5..229cfbb46 100644 --- a/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/scriptengines/qml/plasmoid/appletinterface.cpp @@ -1,7 +1,6 @@ /* - * Copyright 2008 Chani Armitage - * Copyright 2008, 2009 Aaron Seigo - * Copyright 2010 Marco Martin + * Copyright 2008-2013 Aaron Seigo + * Copyright 2010-2013 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -42,6 +41,8 @@ #include #include +#include "containmentinterface.h" + Q_DECLARE_METATYPE(AppletInterface*) AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent) @@ -475,135 +476,4 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o } } - - - - - - - -///////////// ContainmentInterface - -ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent) - : AppletInterface(parent), - m_movableApplets(true) -{ - qmlRegisterType(); - - connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *))); - connect(containment(), SIGNAL(appletAdded(Plasma::Applet *, const QPointF &)), this, SLOT(appletAddedForward(Plasma::Applet *, const QPointF &))); - connect(containment(), SIGNAL(screenChanged(int, int, Plasma::Containment*)), this, SIGNAL(screenChanged())); - connect(containment(), SIGNAL(activityChanged()), this, SIGNAL(activityChanged())); - connect(containment(), SIGNAL(wallpaperChanged()), this, SLOT(loadWallpaper())); - - if (containment()->corona()) { - connect(containment()->corona(), SIGNAL(availableScreenRegionChanged()), - this, SIGNAL(availableScreenRegionChanged())); - } -} - -QVariantList ContainmentInterface::applets() -{ - QVariantList list; - int i = 0; - foreach (Plasma::Applet *applet, containment()->applets()) { - list << QVariant::fromValue(applet); - ++i; - } - return list; -} - -void ContainmentInterface::setDrawWallpaper(bool drawWallpaper) -{ - m_appletScriptEngine->setDrawWallpaper(drawWallpaper); -} - -bool ContainmentInterface::drawWallpaper() -{ - return m_appletScriptEngine->drawWallpaper(); -} - -ContainmentInterface::Type ContainmentInterface::containmentType() const -{ - return (ContainmentInterface::Type)m_appletScriptEngine->containmentType(); -} - -void ContainmentInterface::setContainmentType(ContainmentInterface::Type type) -{ - m_appletScriptEngine->setContainmentType((Plasma::Containment::Type)type); -} - -int ContainmentInterface::screen() const -{ - return containment()->screen(); -} - -QRectF ContainmentInterface::screenGeometry(int id) const -{ - QRectF rect; - if (containment()->corona()) { - rect = QRectF(containment()->corona()->screenGeometry(id)); - } - - return rect; -} - -QVariantList ContainmentInterface::availableScreenRegion(int id) const -{ - QRegion reg; - if (containment()->corona()) { - reg = containment()->corona()->availableScreenRegion(id); - } - - QVariantList regVal; - foreach (QRect rect, reg.rects()) { - regVal << QVariant::fromValue(QRectF(rect)); - } - return regVal; -} - -void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPointF &pos) -{ - QObject *appletGraphicObject = applet->property("graphicObject").value(); - QObject *contGraphicObject = containment()->property("graphicObject").value(); - - qDebug() << "Applet added:" << applet << applet->title() << appletGraphicObject; - - if (applet && contGraphicObject && appletGraphicObject) { - appletGraphicObject->setProperty("visible", false); - appletGraphicObject->setProperty("parent", QVariant::fromValue(contGraphicObject)); - - //if an appletGraphicObject is not set, we have to display some error message - } else if (applet && contGraphicObject) { - QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), applet); - component->loadUrl(QUrl::fromLocalFile(containment()->corona()->package().filePath("ui", "AppletError.qml"))); - QObject *errorUi = component->create(); - - if (errorUi) { - errorUi->setProperty("visible", false); - errorUi->setProperty("parent", QVariant::fromValue(contGraphicObject)); - errorUi->setProperty("reason", applet->launchErrorMessage()); - appletGraphicObject = errorUi; - } - } - - emit appletAdded(appletGraphicObject, pos); -} - -void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) -{ - QObject *appletGraphicObject = applet->property("graphicObject").value(); - emit appletRemoved(appletGraphicObject); -} - -void ContainmentInterface::loadWallpaper() -{ - -} - -QString ContainmentInterface::activityId() const -{ - return containment()->activity(); -} - #include "moc_appletinterface.cpp" diff --git a/scriptengines/qml/plasmoid/appletinterface.h b/scriptengines/qml/plasmoid/appletinterface.h index a017d65cd..1908fd46f 100644 --- a/scriptengines/qml/plasmoid/appletinterface.h +++ b/scriptengines/qml/plasmoid/appletinterface.h @@ -27,7 +27,6 @@ #include #include -#include #include #include "declarativeappletscript.h" @@ -240,57 +239,4 @@ private: bool m_expanded : 1; }; - -class ContainmentInterface : public AppletInterface -{ - Q_OBJECT - Q_PROPERTY(QVariantList applets READ applets) - Q_PROPERTY(bool drawWallpaper READ drawWallpaper WRITE setDrawWallpaper) - Q_PROPERTY(Type containmentType READ containmentType WRITE setContainmentType) - Q_PROPERTY(int screen READ screen NOTIFY screenChanged) - Q_PROPERTY(QString activityId READ activityId NOTIFY activityIdChanged) - Q_ENUMS(Type) - -public: - enum Type { - NoContainmentType = -1, /**< @internal */ - DesktopContainment = 0, /**< A desktop containment */ - PanelContainment, /**< A desktop panel */ - CustomContainment = 127, /**< A containment that is neither a desktop nor a panel - but something application specific */ - CustomPanelContainment = 128 /**< A customized desktop panel */ - }; - ContainmentInterface(DeclarativeAppletScript *parent); - - inline Plasma::Containment *containment() const { return static_cast(m_appletScriptEngine->applet()); } - - QVariantList applets(); - - void setDrawWallpaper(bool drawWallpaper); - bool drawWallpaper(); - Type containmentType() const; - void setContainmentType(Type type); - int screen() const; - - QString activityId() const; - - Q_INVOKABLE QRectF screenGeometry(int id) const; - Q_INVOKABLE QVariantList availableScreenRegion(int id) const; - -Q_SIGNALS: - void appletAdded(QObject *applet, const QPointF &pos); - void appletRemoved(QObject *applet); - void screenChanged(); - void activityIdChanged(); - void availableScreenRegionChanged(); - -protected Q_SLOTS: - void appletAddedForward(Plasma::Applet *applet, const QPointF &pos); - void appletRemovedForward(Plasma::Applet *applet); - void loadWallpaper(); - -private: - bool m_movableApplets; -}; - #endif diff --git a/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/scriptengines/qml/plasmoid/declarativeappletscript.cpp index d4c005c9a..03dc8d36a 100644 --- a/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -44,6 +44,7 @@ #include "plasmoid/declarativeappletscript.h" #include "plasmoid/appletinterface.h" +#include "plasmoid/containmentinterface.h" #include "common/scriptenv.h" #include "declarative/qmlobject.h"