From 89a3e34bd2aa6005b462feaceba9bcc6e4e74759 Mon Sep 17 00:00:00 2001 From: Eike Hein Date: Tue, 4 Oct 2016 21:32:55 +0900 Subject: [PATCH] Move availableScreenRect/Region up to AppletInterface. Summary: Tested with Folder View and Simple Menu, both use cases (desktop containment margins, strut-aware dialog placement) addressed. Reviewers: #plasma, mart Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D2932 --- .../qml/plasmoid/appletinterface.cpp | 43 +++++++++++++++++++ .../qml/plasmoid/appletinterface.h | 18 ++++++++ .../qml/plasmoid/containmentinterface.cpp | 34 --------------- .../qml/plasmoid/containmentinterface.h | 18 -------- 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 466dbd89f..814517fa4 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -656,6 +656,49 @@ void AppletInterface::executeAction(const QString &name) } } +QVariantList AppletInterface::availableScreenRegion() const +{ + QVariantList regVal; + + if (!applet()->containment() || !applet()->containment()->corona()) { + return regVal; + } + + QRegion reg = QRect(0, 0, width(), height()); + int screenId = screen(); + if (screenId > -1) { + reg = applet()->containment()->corona()->availableScreenRegion(screenId); + } + + foreach (QRect rect, reg.rects()) { + //make it relative + QRect geometry = applet()->containment()->corona()->screenGeometry(screenId); + rect.moveTo(rect.topLeft() - geometry.topLeft()); + regVal << QVariant::fromValue(QRectF(rect)); + } + return regVal; +} + +QRect AppletInterface::availableScreenRect() const +{ + if (!applet()->containment() || !applet()->containment()->corona()) { + return QRect(); + } + + QRect rect(0, 0, width(), height()); + + int screenId = screen(); + + if (screenId > -1) { + rect = applet()->containment()->corona()->availableScreenRect(screenId); + //make it relative + QRect geometry = applet()->containment()->corona()->screenGeometry(screenId); + rect.moveTo(rect.topLeft() - geometry.topLeft()); + } + + return rect; +} + bool AppletInterface::event(QEvent *event) { // QAction keyboard shortcuts cannot work with QML2 (and probably newver will diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index a215ddd82..a1e2cd792 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -227,6 +227,18 @@ class AppletInterface : public PlasmaQuick::AppletQuickItem */ Q_PROPERTY(QString configurationRequiredReason READ configurationRequiredReason WRITE setConfigurationRequiredReason NOTIFY configurationRequiredReasonChanged) + /** + * screen area free of panels: the coordinates are relative to the containment, + * it's independent from the screen position + * For more precise available geometry use availableScreenRegion() + */ + Q_PROPERTY(QRect availableScreenRect READ availableScreenRect NOTIFY availableScreenRectChanged) + + /** + * The available region of this screen, panels excluded. It's a list of rectangles + */ + Q_PROPERTY(QVariantList availableScreenRegion READ availableScreenRegion NOTIFY availableScreenRegionChanged) + public: AppletInterface(DeclarativeAppletScript *script, const QVariantList &args = QVariantList(), QQuickItem *parent = 0); ~AppletInterface(); @@ -301,6 +313,10 @@ public: */ Q_INVOKABLE QStringList downloadedFiles() const; + QVariantList availableScreenRegion() const; + + QRect availableScreenRect() const; + static AppletInterface *qmlAttachedProperties(QObject *object) { return qobject_cast(AppletQuickItem::qmlAttachedProperties(object)); @@ -416,6 +432,8 @@ Q_SIGNALS: void hideOnWindowDeactivateChanged(); void associatedApplicationChanged(); void associatedApplicationUrlsChanged(); + void availableScreenRegionChanged(); + void availableScreenRectChanged(); void userConfiguringChanged(); void globalShortcutChanged(); diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 9c14ad8cd..160cdd7b3 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -190,40 +190,6 @@ void ContainmentInterface::setContainmentType(Plasma::Types::ContainmentType typ appletScript()->setContainmentType(type); } -QVariantList ContainmentInterface::availableScreenRegion() const -{ - QRegion reg = QRect(0, 0, width(), height()); - int screenId = screen(); - if (screenId > -1 && m_containment->corona()) { - reg = m_containment->corona()->availableScreenRegion(screenId); - } - - QVariantList regVal; - foreach (QRect rect, reg.rects()) { - //make it relative - QRect geometry = m_containment->corona()->screenGeometry(screenId); - rect.moveTo(rect.topLeft() - geometry.topLeft()); - regVal << QVariant::fromValue(QRectF(rect)); - } - return regVal; -} - -QRect ContainmentInterface::availableScreenRect() const -{ - QRect rect(0, 0, width(), height()); - - int screenId = screen(); - - if (screenId > -1 && m_containment->corona()) { - rect = m_containment->corona()->availableScreenRect(screenId); - //make it relative - QRect geometry = m_containment->corona()->screenGeometry(screenId); - rect.moveTo(rect.topLeft() - geometry.topLeft()); - } - - return rect; -} - Plasma::Applet *ContainmentInterface::createApplet(const QString &plugin, const QVariantList &args, const QPoint &pos) { return createApplet(plugin, args, QRectF(pos, QSize())); diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index 5fe96b8d6..f1d96c1ae 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -76,18 +76,6 @@ class ContainmentInterface : public AppletInterface */ Q_PROPERTY(QList actions READ actions NOTIFY actionsChanged) - /** - * screen area free of panels: the coordinates are relative to the containment, - * it's independent from the screen position - * For more precise available geometry use availableScreenRegion() - */ - Q_PROPERTY(QRect availableScreenRect READ availableScreenRect NOTIFY availableScreenRectChanged) - - /** - * The available region of this screen, panels excluded. It's a list of rectangles - */ - Q_PROPERTY(QVariantList availableScreenRegion READ availableScreenRegion NOTIFY availableScreenRegionChanged) - public: ContainmentInterface(DeclarativeAppletScript *parent, const QVariantList &args = QVariantList()); @@ -113,10 +101,6 @@ public: QList actions() const; - QVariantList availableScreenRegion() const; - - QRect availableScreenRect() const; - /** * Process the mime data arrived to a particular coordinate, either with a drag and drop or paste with middle mouse button */ @@ -189,8 +173,6 @@ Q_SIGNALS: //Property notifiers void activityChanged(); void activityNameChanged(); - void availableScreenRegionChanged(); - void availableScreenRectChanged(); void appletsChanged(); void drawWallpaperChanged(); void containmentTypeChanged();