diff --git a/src/plasma/corona.h b/src/plasma/corona.h --- a/src/plasma/corona.h +++ b/src/plasma/corona.h @@ -257,6 +257,21 @@ */ 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 @@ */ 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/corona.cpp b/src/plasma/corona.cpp --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -380,6 +380,26 @@ 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/private/corona_p.h b/src/plasma/private/corona_p.h --- a/src/plasma/private/corona_p.h +++ b/src/plasma/private/corona_p.h @@ -60,6 +60,7 @@ QList containments; KActionCollection actions; int containmentsStarting; + bool editMode = false; }; } diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -79,10 +79,11 @@ 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 @@ */ 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 @@ QPointer m_containment; QPointer m_contextMenu; int m_wheelDelta; - bool m_editMode : 1; friend class AppletInterface; }; diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -60,8 +60,7 @@ : 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 @@ 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 @@ 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)