give corona its own action collection.

this is a place for things which shouldn't be duplicated over every single containment, like "lock" and "new activity".
for now we still add the lock action to every containment, so that none of the code lower down notices the change - but we only have one action behind it all :)

svn path=/trunk/KDE/kdelibs/; revision=937923
This commit is contained in:
Chani Armitage 2009-03-10 19:52:50 +00:00
parent 324b6f11d4
commit aa34398a80
5 changed files with 72 additions and 48 deletions

View File

@ -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<Applet*, AppletHandle*> 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<Applet*, AppletHandle*> h = handles;
handles.clear();
foreach (AppletHandle *handle, h) {
handle->disconnect(q);
handle->deleteLater();
}
}
}
if (constraints & Plasma::FormFactorConstraint) {

View File

@ -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;

View File

@ -35,6 +35,8 @@
#include <kglobal.h>
#include <klocale.h>
#include <kmimetype.h>
#include <kactioncollection.h>
#include <kaction.h>
#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<Containment*> containments;
QHash<uint, QGraphicsWidget*> offscreenWidgets;
KActionCollection actions;
};
Corona::Corona(QObject *parent)
@ -569,6 +591,21 @@ QList<Plasma::Location> 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<QAction*> Corona::actions() const
{
return d->actions.actions();
}
} // namespace Plasma
#include "corona.moc"

View File

@ -28,6 +28,7 @@
#include <plasma/plasma_export.h>
class QGraphicsGridLayout;
class QAction;
namespace Plasma
{
@ -155,6 +156,21 @@ public:
*/
QList<Plasma::Location> 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<QAction*> 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;
};

View File

@ -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);