From c621ebe5726f742fffb2266f0289c6a88decfda1 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 26 Sep 2019 18:20:31 +0200 Subject: [PATCH] make editMode a corona global property Summary: The plans are to switch on/off the whole plasma shell into edit mode. For this it needs to be a global corona property, rather then just containmentInterface. Plasmashell would expose a dbus call to set it from systemsettings Test Plan: plasmoid.editMode=true still works Reviewers: #plasma, #vdg, ngraham Reviewed By: #vdg, ngraham Subscribers: ngraham, GB_2, broulik, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D24239 --- src/plasma/corona.cpp | 20 ++++++++++++++++ src/plasma/corona.h | 22 +++++++++++++++++ src/plasma/private/corona_p.h | 1 + .../qml/plasmoid/containmentinterface.cpp | 24 +++++++++---------- .../qml/plasmoid/containmentinterface.h | 11 ++++++--- 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp index d059c9dc6..f97fa3b63 100644 --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -380,6 +380,26 @@ void Corona::setImmutability(const Types::ImmutabilityType immutable) cg.writeEntry("immutability", (int)d->immutability); requestConfigSync(); } + + if (d->immutability != Types::Mutable) { + d->editMode = false; + emit editModeChanged(); + } +} + +void Corona::setEditMode(bool edit) +{ + if (d->immutability != Plasma::Types::Mutable || edit == d->editMode) { + return; + } + + d->editMode = edit; + emit editModeChanged(); +} + +bool Corona::isEditMode() const +{ + return d->editMode; } QList Corona::freeEdges(int screen) const diff --git a/src/plasma/corona.h b/src/plasma/corona.h index d23a4022d..9eb8163a8 100644 --- a/src/plasma/corona.h +++ b/src/plasma/corona.h @@ -257,6 +257,21 @@ public: */ Types::ImmutabilityType immutability() const; + /** + * Set the Corona globally into "edit mode" + * Only when the corona is of mutable type can be set of edit mode. + * This indicates the UI to make easy for the user to manipulate applets. + * @param edit + * @since 5.63 + */ + void setEditMode(bool edit); + + /** + * @returns true if the corona is in edit mode + * @since 5.63 + */ + bool isEditMode() const; + public Q_SLOTS: /** * Load applet layout from a config file. The results will be added to the @@ -358,6 +373,13 @@ Q_SIGNALS: */ void screenAdded(int id); + /** + * emitted when the editMode state changes + * @see isEditMode() + * @since 5.63 + */ + void editModeChanged(); + #ifndef PLASMA_NO_DEPRECATED /** * Emitted when the package for this corona has been changed. diff --git a/src/plasma/private/corona_p.h b/src/plasma/private/corona_p.h index 36a455e9f..13d5366f0 100644 --- a/src/plasma/private/corona_p.h +++ b/src/plasma/private/corona_p.h @@ -60,6 +60,7 @@ public: QList containments; KActionCollection actions; int containmentsStarting; + bool editMode = false; }; } diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 271700095..0900ddd08 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -60,8 +60,7 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent, cons : AppletInterface(parent, args), m_wallpaperInterface(nullptr), m_activityInfo(nullptr), - m_wheelDelta(0), - m_editMode(false) + m_wheelDelta(0) { m_containment = static_cast(appletScript()->applet()->containment()); @@ -72,6 +71,9 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent, cons connect(m_containment.data(), &Plasma::Containment::appletAdded, this, &ContainmentInterface::appletAddedForward); + connect(m_containment->corona(), &Plasma::Corona::editModeChanged, + this, &ContainmentInterface::editModeChanged); + if (!m_appletInterfaces.isEmpty()) { emit appletsChanged(); } @@ -402,23 +404,19 @@ QPointF ContainmentInterface::adjustToAvailableScreenRegion(int x, int y, int w, return rect.topLeft(); } +QAction *ContainmentInterface::globalAction(QString name) const +{ + return m_containment->corona()->actions()->action(name); +} + bool ContainmentInterface::isEditMode() const { - return m_editMode; + return m_containment->corona()->isEditMode(); } void ContainmentInterface::setEditMode(bool edit) { - if (edit == m_editMode) { - return; - } - - if (m_containment->immutability() != Plasma::Types::Mutable) { - return; - } - - m_editMode = edit; - emit editModeChanged(); + m_containment->corona()->setEditMode(edit); } void ContainmentInterface::processMimeData(QObject *mimeDataProxy, int x, int y, KIO::DropJob *dropJob) diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index ef4e54c6e..e96e4e6cd 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -79,10 +79,11 @@ class ContainmentInterface : public AppletInterface Q_PROPERTY(QList actions READ actions NOTIFY actionsChanged) /** - * True when the containment is in an edit mode that allows to move + * True when the Plasma Shell is in an edit mode that allows to move * things around: it's different from userConfiguring as it's about * editing plasmoids inside the containment, rather than the containment - * settings dialog itself + * settings dialog itself. + * This is global for the whole Plasma process, all containments will have the same value for editMode */ Q_PROPERTY(bool editMode READ isEditMode WRITE setEditMode NOTIFY editModeChanged) @@ -150,6 +151,11 @@ public: */ Q_INVOKABLE QPointF adjustToAvailableScreenRegion(int x, int y, int w, int h) const; + /** + * @returns a named action from global Corona's actions + */ + Q_INVOKABLE QAction *globalAction(QString name) const; + bool isEditMode() const; void setEditMode(bool edit); @@ -220,7 +226,6 @@ private: QPointer m_containment; QPointer m_contextMenu; int m_wheelDelta; - bool m_editMode : 1; friend class AppletInterface; };