allow setting and getting of global shortcuts

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=815050
This commit is contained in:
Aaron J. Seigo 2008-06-01 02:53:50 +00:00
parent e26442e7e4
commit 4878d04cc3
2 changed files with 44 additions and 12 deletions

View File

@ -189,7 +189,9 @@ void Applet::restore(KConfigGroup &group)
Private::s_maxZValue = z; Private::s_maxZValue = z;
} }
setZValue(z); if (z > 0) {
setZValue(z);
}
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable)); setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
@ -201,17 +203,7 @@ void Applet::restore(KConfigGroup &group)
KConfigGroup shortcutConfig(&group, "Shortcuts"); KConfigGroup shortcutConfig(&group, "Shortcuts");
QString shortcutText = shortcutConfig.readEntry("global", QString()); QString shortcutText = shortcutConfig.readEntry("global", QString());
if (!shortcutText.isEmpty()) { if (!shortcutText.isEmpty()) {
if (!d->activationAction) { setGlobalShortcut(KShortcut(shortcutText));
d->activationAction = new KAction(this);
//TODO: add better text when we aren't in a string freeze
d->activationAction->setText(name());
d->activationAction->setObjectName(QString("Activate %1 Widget").arg(name())); // NO I18N
connect(d->activationAction, SIGNAL(triggered()), this, SIGNAL(activate()));
connect(this, SIGNAL(activate()), this, SLOT(setFocus()));
}
KShortcut shortcut(shortcutText);
d->activationAction->setGlobalShortcut(shortcut);
} }
// local shortcut, if any // local shortcut, if any
@ -936,6 +928,34 @@ Containment* Applet::containment() const
return c; return c;
} }
void Applet::setGlobalShortcut(const KShortcut &shortcut)
{
if (!d->activationAction) {
d->activationAction = new KAction(this);
//TODO: add better text when we aren't in a string freeze
d->activationAction->setText(name());
d->activationAction->setObjectName(QString("Activate %1 Widget").arg(name())); // NO I18N
connect(d->activationAction, SIGNAL(triggered()), this, SIGNAL(activate()));
connect(this, SIGNAL(activate()), this, SLOT(setFocus()));
QList<QWidget *> widgets = d->actions.associatedWidgets();
foreach (QWidget *w, widgets) {
w->addAction(d->activationAction);
}
}
d->activationAction->setGlobalShortcut(shortcut);
}
KShortcut Applet::globalShortcut() const
{
if (d->activationAction) {
return d->activationAction->globalShortcut();
}
return KShortcut();
}
void Applet::addAssociatedWidget(QWidget *widget) void Applet::addAssociatedWidget(QWidget *widget)
{ {
d->actions.addAssociatedWidget(widget); d->actions.addAssociatedWidget(widget);

View File

@ -29,6 +29,7 @@
#include <KDE/KConfigGroup> #include <KDE/KConfigGroup>
#include <KDE/KGenericFactory> #include <KDE/KGenericFactory>
#include <KDE/KPluginInfo> #include <KDE/KPluginInfo>
#include <KDE/KShortcut>
#include <plasma/configxml.h> #include <plasma/configxml.h>
#include <plasma/packagestructure.h> #include <plasma/packagestructure.h>
@ -441,6 +442,17 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
**/ **/
Containment* containment() const; Containment* containment() const;
/**
* Sets the global shorcut to associate with this widget.
*/
void setGlobalShortcut(const KShortcut &shortcut);
/**
* @return the global shortcut associated with this wiget, or
* an empty shortcut if no global shortcut is associated.
*/
KShortcut globalShortcut() const;
/** /**
* associate actions with this widget, including ones added after this call. * associate actions with this widget, including ones added after this call.
* needed to make keyboard shortcuts work. * needed to make keyboard shortcuts work.