From 34ab711509be2df97a0edcd39b34300667e648a0 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sat, 15 Nov 2008 21:23:56 +0000 Subject: [PATCH] global shortcut configuration for all applets =) svn path=/trunk/KDE/kdelibs/; revision=884810 --- applet.cpp | 41 +++++++++++++++++++++++++++++++++++++---- private/applet_p.h | 4 ++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/applet.cpp b/applet.cpp index 193dec24c..47fff2ca9 100644 --- a/applet.cpp +++ b/applet.cpp @@ -40,22 +40,24 @@ #include #include #include +#include #include #include -#include +#include +#include #include #include #include +#include #include +#include #include #include #include #include #include #include -#include -#include #include @@ -1366,8 +1368,12 @@ void Applet::showConfigurationInterface() f.close(); dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name())); + d->addGlobalShortcutsPage(dialog); + connect(dialog, SIGNAL(applyClicked()), this, SLOT(configChanged())); + connect(dialog, SIGNAL(okClicked()), this, SLOT(configChanged())); dialog->show(); } else if (d->script) { + //FIXME: global shorcuts? d->script->showConfigurationInterface(); } else { KConfigSkeleton *nullManager = new KConfigSkeleton(0); @@ -1376,7 +1382,7 @@ void Applet::showConfigurationInterface() dialog->setWindowTitle(windowTitle); dialog->setAttribute(Qt::WA_DeleteOnClose, true); createConfigurationInterface(dialog); - //TODO: would be nice to not show dialog if there are no pages added? + d->addGlobalShortcutsPage(dialog); connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater())); //TODO: Apply button does not correctly work for now, so do not show it dialog->showButton(KDialog::Apply, false); @@ -1388,11 +1394,37 @@ void Applet::showConfigurationInterface() emit releaseVisualFocus(); } +void AppletPrivate::addGlobalShortcutsPage(KConfigDialog *dialog) +{ + QWidget *page = new QWidget; + QVBoxLayout *layout = new QVBoxLayout(page); + + if (!shortcutEditor) { + shortcutEditor = new KKeySequenceWidget(page); + } + + shortcutEditor->setKeySequence(q->globalShortcut().primary()); + layout->addWidget(shortcutEditor); + layout->addStretch(); + dialog->addPage(page, i18n("Keyboard Shortcut"), "preferences-desktop-keyboard"); +} + void Applet::configChanged() { if (d->script) { d->script->configChanged(); } + + if (d->shortcutEditor) { + QKeySequence sequence = d->shortcutEditor->keySequence(); + if (sequence != globalShortcut().primary()) { + setGlobalShortcut(KShortcut(sequence)); + emit configNeedsSaving(); + } + + delete d->shortcutEditor; + d->shortcutEditor = 0; + } } void Applet::createConfigurationInterface(KConfigDialog *parent) @@ -1730,6 +1762,7 @@ AppletPrivate::AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet immutability(Mutable), actions(applet), activationAction(0), + shortcutEditor(0), constraintsTimerId(0), modificationsTimerId(-1), hasConfigurationInterface(false), diff --git a/private/applet_p.h b/private/applet_p.h index 63df74bef..8594d5bfd 100644 --- a/private/applet_p.h +++ b/private/applet_p.h @@ -24,6 +24,8 @@ #include +class KKeySequenceWidget; + namespace Plasma { @@ -73,6 +75,7 @@ public: void cleanUpAndDelete(); void createMessageOverlay(); void destroyMessageOverlay(); + void addGlobalShortcutsPage(KConfigDialog *dialog); static uint s_maxAppletId; static uint s_maxZValue; @@ -101,6 +104,7 @@ public: ImmutabilityType immutability; KActionCollection actions; KAction *activationAction; + KKeySequenceWidget *shortcutEditor; //TODO: subclass KConfigDialog and encapsulate this in there int constraintsTimerId; int modificationsTimerId; bool hasConfigurationInterface : 1;