diff --git a/containment.cpp b/containment.cpp index 7c7f42cf0..74f386988 100644 --- a/containment.cpp +++ b/containment.cpp @@ -160,16 +160,12 @@ void Containment::init() action->setShortcut(QKeySequence("alt+d,p")); d->actions().addAction("previous applet", action); - if (immutability() != SystemImmutable) { - //FIXME I'm not certain this belongs in Containment - //but it sure is nice to have the keyboard shortcut in every containment by default - KAction *lockDesktopAction = - new KAction(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets"), this); - lockDesktopAction->setIcon(KIcon(unlocked ? "object-locked" : "object-unlocked")); - connect(lockDesktopAction, SIGNAL(triggered(bool)), - this, SLOT(toggleDesktopImmutability())); - lockDesktopAction->setShortcut(QKeySequence("alt+d,l")); - d->actions().addAction("lock widgets", lockDesktopAction); + if (immutability() != SystemImmutable && corona()) { + QAction *lockDesktopAction = corona()->action("lock widgets"); + //keep a pointer so nobody notices it moved to corona + if (lockDesktopAction) { + d->actions().addAction("lock widgets", lockDesktopAction); + } } if (d->type != PanelContainment && @@ -1513,35 +1509,6 @@ void Containment::destroy(bool confirm) } } -void ContainmentPrivate::toggleDesktopImmutability() -{ - if (q->corona()) { - if (q->corona()->immutability() == Mutable) { - q->corona()->setImmutability(UserImmutable); - } else if (q->corona()->immutability() == UserImmutable) { - q->corona()->setImmutability(Mutable); - } - } else { - if (q->immutability() == Mutable) { - q->setImmutability(UserImmutable); - } else if (q->immutability() == UserImmutable) { - q->setImmutability(Mutable); - } - } - - if (q->immutability() != Mutable) { - QMap h = handles; - handles.clear(); - - foreach (AppletHandle *handle, h) { - handle->disconnect(q); - handle->deleteLater(); - } - } - - //setLockToolText(); -} - void ContainmentPrivate::zoomIn() { emit q->zoomRequested(q, Plasma::ZoomIn); @@ -1650,6 +1617,17 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra toolBox->setIsMovable(unlocked); } } + + //clear handles on lock + if (!unlocked) { + QMap h = handles; + handles.clear(); + + foreach (AppletHandle *handle, h) { + handle->disconnect(q); + handle->deleteLater(); + } + } } if (constraints & Plasma::FormFactorConstraint) { diff --git a/containment.h b/containment.h index e2343415a..984abe88a 100644 --- a/containment.h +++ b/containment.h @@ -515,7 +515,6 @@ class PLASMA_EXPORT Containment : public Applet Q_PRIVATE_SLOT(d, void positionToolBox()) Q_PRIVATE_SLOT(d, void zoomIn()) Q_PRIVATE_SLOT(d, void zoomOut()) - Q_PRIVATE_SLOT(d, void toggleDesktopImmutability()) Q_PRIVATE_SLOT(d, void requestConfiguration()) friend class Applet; diff --git a/corona.cpp b/corona.cpp index 86f57a401..519879ff8 100644 --- a/corona.cpp +++ b/corona.cpp @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include "containment.h" #include "view.h" @@ -57,7 +59,8 @@ public: : q(corona), immutability(Mutable), mimetype("text/x-plasmoidservicename"), - config(0) + config(0), + actions(corona) { if (KGlobal::hasMainComponent()) { configName = KGlobal::mainComponent().componentName() + "-appletsrc"; @@ -75,6 +78,24 @@ public: { configSyncTimer.setSingleShot(true); QObject::connect(&configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig())); + + //some common actions + KAction *lockAction = new KAction(i18n("Lock Widgets"), q); + lockAction->setIcon(KIcon("object-locked")); + QObject::connect(lockAction, SIGNAL(triggered(bool)), + q, SLOT(toggleImmutability())); + lockAction->setShortcut(QKeySequence("alt+d,l")); + lockAction->setShortcutContext(Qt::ApplicationShortcut); + actions.addAction("lock widgets", lockAction); + } + + void toggleImmutability() + { + if (immutability == Mutable) { + q->setImmutability(UserImmutable); + } else { + q->setImmutability(Mutable); + } } void saveLayout(KSharedConfigPtr cg) const @@ -192,6 +213,7 @@ public: QTimer configSyncTimer; QList containments; QHash offscreenWidgets; + KActionCollection actions; }; Corona::Corona(QObject *parent) @@ -569,6 +591,21 @@ QList Corona::freeEdges(int screen) const return freeEdges; } +QAction *Corona::action(QString name) const +{ + return d->actions.action(name); +} + +void Corona::addAction(QString name, QAction *action) +{ + d->actions.addAction(name, action); +} + +QList Corona::actions() const +{ + return d->actions.actions(); +} + } // namespace Plasma #include "corona.moc" diff --git a/corona.h b/corona.h index c29f4de99..f786c7d11 100644 --- a/corona.h +++ b/corona.h @@ -28,6 +28,7 @@ #include class QGraphicsGridLayout; +class QAction; namespace Plasma { @@ -155,6 +156,21 @@ public: */ QList freeEdges(int screen) const; + /** + * Returns the QAction with the given name from our collection + */ + QAction *action(QString name) const; + + /** + * Adds the action to our collection under the given name + */ + void addAction(QString name, QAction *action); + + /** + * Returns all the actions in our collection + */ + QList actions() const; + public Q_SLOTS: /** * Initializes the layout from a config file. This will first clear any existing @@ -277,6 +293,7 @@ private: Q_PRIVATE_SLOT(d, void containmentDestroyed(QObject*)) Q_PRIVATE_SLOT(d, void offscreenWidgetDestroyed(QObject *)) Q_PRIVATE_SLOT(d, void syncConfig()) + Q_PRIVATE_SLOT(d, void toggleImmutability()) friend class CoronaPrivate; }; diff --git a/private/containment_p.h b/private/containment_p.h index 0a91b981c..57cb57522 100644 --- a/private/containment_p.h +++ b/private/containment_p.h @@ -84,13 +84,6 @@ public: bool showContextMenu(const QPointF &point, const QPoint &screenPos, bool includeApplet); void checkRemoveAction(); - /** - * Locks or unlocks plasma's applets. - * When plasma is locked, applets cannot be transformed, added or deleted - * but they can still be configured. - */ - void toggleDesktopImmutability(); - Applet *addApplet(const QString &name, const QVariantList &args = QVariantList(), const QRectF &geometry = QRectF(-1, -1, -1, -1), uint id = 0, bool delayedInit = false);