From 4a28d000cf7b4b0b3406d2badb018568e76130f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 25 Apr 2013 17:21:54 +0200 Subject: [PATCH] Move ShortcutDialog to useractions It's only used from useractions.cpp which means that it's not the best fit in utils. We can see the problems with it given that it was in an ifdef and it included quite some headers into everything. REVIEW: 110189 --- outline.h | 1 + tabbox/tabbox.h | 1 + useractions.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++ useractions.h | 26 ++++++++++++ utils.cpp | 104 ------------------------------------------------ utils.h | 35 ++-------------- workspace.h | 1 + xcbutils.h | 2 + 8 files changed, 134 insertions(+), 135 deletions(-) diff --git a/outline.h b/outline.h index bdb447a301..a342454937 100644 --- a/outline.h +++ b/outline.h @@ -23,6 +23,7 @@ along with this program. If not, see . #include "xcbutils.h" #include #include +#include namespace Plasma { class FrameSvg; diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index 600b37a955..058b202d23 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -30,6 +30,7 @@ along with this program. If not, see . #include "tabbox/tabboxhandler.h" class KActionCollection; +class KConfigGroup; class QKeyEvent; namespace KWin diff --git a/useractions.cpp b/useractions.cpp index 8259e55126..61ffb45672 100755 --- a/useractions.cpp +++ b/useractions.cpp @@ -49,6 +49,7 @@ along with this program. If not, see . #include #endif +#include #include #include @@ -66,9 +67,11 @@ along with this program. If not, see . #include #include #include +#include #include #include #include +#include #include #include #include @@ -822,6 +825,102 @@ void UserActionsMenu::slotToggleOnActivity(QAction *action) #endif } +//**************************************** +// ShortcutDialog +//**************************************** +ShortcutDialog::ShortcutDialog(const QKeySequence& cut) + : _shortcut(cut) +{ + QWidget *vBoxContainer = new QWidget(this); + vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer)); + vBoxContainer->layout()->addWidget(widget = new KKeySequenceWidget(vBoxContainer)); + vBoxContainer->layout()->addWidget(warning = new QLabel(vBoxContainer)); + warning->hide(); + widget->setKeySequence(cut); + + // To not check for conflicting shortcuts. The widget would use a message + // box which brings down kwin. + widget->setCheckForConflictsAgainst(KKeySequenceWidget::None); + // It's a global shortcut so don't allow multikey shortcuts + widget->setMultiKeyShortcutsAllowed(false); + + // Listen to changed shortcuts + connect( + widget, SIGNAL(keySequenceChanged(QKeySequence)), + SLOT(keySequenceChanged(QKeySequence))); + + setMainWidget(vBoxContainer); + widget->setFocus(); + + // make it a popup, so that it has the grab + XSetWindowAttributes attrs; + attrs.override_redirect = True; + XChangeWindowAttributes(display(), winId(), CWOverrideRedirect, &attrs); + setWindowFlags(Qt::Popup); +} + +void ShortcutDialog::accept() +{ + QKeySequence seq = shortcut(); + if (!seq.isEmpty()) { + if (seq[0] == Qt::Key_Escape) { + reject(); + return; + } + if (seq[0] == Qt::Key_Space + || (seq[0] & Qt::KeyboardModifierMask) == 0) { + // clear + widget->clearKeySequence(); + KDialog::accept(); + return; + } + } + KDialog::accept(); +} + +void ShortcutDialog::done(int r) +{ + KDialog::done(r); + emit dialogDone(r == Accepted); +} + +void ShortcutDialog::keySequenceChanged(const QKeySequence &seq) +{ + activateWindow(); // where is the kbd focus lost? cause of popup state? + if (_shortcut == seq) + return; // don't try to update the same + + if (seq.isEmpty()) { // clear + _shortcut = seq; + return; + } + + // Check if the key sequence is used currently + QString sc = seq.toString(); + // NOTICE - seq.toString() & the entries in "conflicting" randomly get invalidated after the next call (if no sc has been set & conflicting isn't empty?!) + QList conflicting = KGlobalAccel::getGlobalShortcutsByKey(seq); + if (!conflicting.isEmpty()) { + const KGlobalShortcutInfo &conflict = conflicting.at(0); + warning->setText(i18nc("'%1' is a keyboard shortcut like 'ctrl+w'", + "%1 is already in use", sc)); + warning->setToolTip(i18nc("keyboard shortcut '%1' is used by action '%2' in application '%3'", + "%1 is used by %2 in %3", sc, conflict.friendlyName(), conflict.componentFriendlyName())); + warning->show(); + widget->setKeySequence(shortcut()); + } else if (seq != _shortcut) { + warning->hide(); + if (KPushButton *ok = button(KDialog::Ok)) + ok->setFocus(); + } + + _shortcut = seq; +} + +QKeySequence ShortcutDialog::shortcut() const +{ + return _shortcut; +} + //**************************************** // Workspace //**************************************** diff --git a/useractions.h b/useractions.h index 33fcc334b0..3c71c4779c 100644 --- a/useractions.h +++ b/useractions.h @@ -20,10 +20,15 @@ along with this program. If not, see . #ifndef KWIN_USERACTIONS_H #define KWIN_USERACTIONS_H +// KDE +#include +// Qt #include #include +class KKeySequenceWidget; class QAction; +class QLabel; class QMenu; class QRect; @@ -254,6 +259,27 @@ private: **/ QWeakPointer m_client; }; + +class ShortcutDialog + : public KDialog +{ + Q_OBJECT +public: + explicit ShortcutDialog(const QKeySequence& cut); + virtual void accept(); + QKeySequence shortcut() const; +public Q_SLOTS: + void keySequenceChanged(const QKeySequence &seq); +signals: + void dialogDone(bool ok); +protected: + virtual void done(int r); +private: + KKeySequenceWidget* widget; + QKeySequence _shortcut; + QLabel *warning; +}; + } // namespace #endif // KWIN_USERACTIONS_H diff --git a/utils.cpp b/utils.cpp index 16c7619606..9c7f31db04 100644 --- a/utils.cpp +++ b/utils.cpp @@ -29,23 +29,15 @@ along with this program. If not, see . #include #include -#include -#include #ifndef KCMRULES -#include -#include #include #include -#include -#include #include -#include #include #include #include -#include #include @@ -407,102 +399,6 @@ Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state) } #endif - -#ifndef KCMRULES -ShortcutDialog::ShortcutDialog(const QKeySequence& cut) - : _shortcut(cut) -{ - QWidget *vBoxContainer = new QWidget(this); - vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer)); - vBoxContainer->layout()->addWidget(widget = new KKeySequenceWidget(vBoxContainer)); - vBoxContainer->layout()->addWidget(warning = new QLabel(vBoxContainer)); - warning->hide(); - widget->setKeySequence(cut); - - // To not check for conflicting shortcuts. The widget would use a message - // box which brings down kwin. - widget->setCheckForConflictsAgainst(KKeySequenceWidget::None); - // It's a global shortcut so don't allow multikey shortcuts - widget->setMultiKeyShortcutsAllowed(false); - - // Listen to changed shortcuts - connect( - widget, SIGNAL(keySequenceChanged(QKeySequence)), - SLOT(keySequenceChanged(QKeySequence))); - - setMainWidget(vBoxContainer); - widget->setFocus(); - - // make it a popup, so that it has the grab - XSetWindowAttributes attrs; - attrs.override_redirect = True; - XChangeWindowAttributes(display(), winId(), CWOverrideRedirect, &attrs); - setWindowFlags(Qt::Popup); -} - -void ShortcutDialog::accept() -{ - QKeySequence seq = shortcut(); - if (!seq.isEmpty()) { - if (seq[0] == Qt::Key_Escape) { - reject(); - return; - } - if (seq[0] == Qt::Key_Space - || (seq[0] & Qt::KeyboardModifierMask) == 0) { - // clear - widget->clearKeySequence(); - KDialog::accept(); - return; - } - } - KDialog::accept(); -} - -void ShortcutDialog::done(int r) -{ - KDialog::done(r); - emit dialogDone(r == Accepted); -} - -void ShortcutDialog::keySequenceChanged(const QKeySequence &seq) -{ - activateWindow(); // where is the kbd focus lost? cause of popup state? - if (_shortcut == seq) - return; // don't try to update the same - - if (seq.isEmpty()) { // clear - _shortcut = seq; - return; - } - - // Check if the key sequence is used currently - QString sc = seq.toString(); - // NOTICE - seq.toString() & the entries in "conflicting" randomly get invalidated after the next call (if no sc has been set & conflicting isn't empty?!) - QList conflicting = KGlobalAccel::getGlobalShortcutsByKey(seq); - if (!conflicting.isEmpty()) { - const KGlobalShortcutInfo &conflict = conflicting.at(0); - warning->setText(i18nc("'%1' is a keyboard shortcut like 'ctrl+w'", - "%1 is already in use", sc)); - warning->setToolTip(i18nc("keyboard shortcut '%1' is used by action '%2' in application '%3'", - "%1 is used by %2 in %3", sc, conflict.friendlyName(), conflict.componentFriendlyName())); - warning->show(); - widget->setKeySequence(shortcut()); - } else if (seq != _shortcut) { - warning->hide(); - if (KPushButton *ok = button(KDialog::Ok)) - ok->setFocus(); - } - - _shortcut = seq; -} - -QKeySequence ShortcutDialog::shortcut() const -{ - return _shortcut; -} - -#endif //KCMRULES } // namespace #ifndef KCMRULES diff --git a/utils.h b/utils.h index 5fa103b166..d24c425ce1 100644 --- a/utils.h +++ b/utils.h @@ -29,10 +29,11 @@ along with this program. If not, see . // kwin #include // KDE -#include #include #include // Qt +#include +#include #include // X #include @@ -40,10 +41,6 @@ along with this program. If not, see . // system #include -// forward declarations -class KKeySequenceWidget; -class QLabel; - namespace KWin { @@ -179,7 +176,7 @@ public: // property. If it explicitly requests that decorations be shown // or hidden, 'got_noborder' is set to true and 'noborder' is set // appropriately. - static void readFlags(WId w, bool& got_noborder, bool& noborder, + static void readFlags(Window w, bool& got_noborder, bool& noborder, bool& resize, bool& move, bool& minimize, bool& maximize, bool& close); struct MwmHints { @@ -244,7 +241,7 @@ public: ScopedCPointer(T *p = 0) : QScopedPointer(p) {} }; -QByteArray getStringProperty(WId w, Atom prop, char separator = 0); +QByteArray getStringProperty(Window w, Atom prop, char separator = 0); void updateXTime(); void grabXServer(); void ungrabXServer(); @@ -340,30 +337,6 @@ Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state); void checkNonExistentClients(); -#ifndef KCMRULES -// Qt dialogs emit no signal when closed :( -class ShortcutDialog - : public KDialog -{ - Q_OBJECT -public: - explicit ShortcutDialog(const QKeySequence& cut); - virtual void accept(); - QKeySequence shortcut() const; -public Q_SLOTS: - void keySequenceChanged(const QKeySequence &seq); -signals: - void dialogDone(bool ok); -protected: - virtual void done(int r); -private: - KKeySequenceWidget* widget; - QKeySequence _shortcut; - QLabel *warning; -}; - -#endif //KCMRULES - } // namespace // Must be outside namespace diff --git a/workspace.h b/workspace.h index 0593865c6d..22f2f0aea2 100644 --- a/workspace.h +++ b/workspace.h @@ -53,6 +53,7 @@ class Client; class KillWindow; class RootInfo; class Rules; +class ShortcutDialog; class UserActionsMenu; class WindowRules; class Compositor; diff --git a/xcbutils.h b/xcbutils.h index 336db9f4fc..51b9357d73 100644 --- a/xcbutils.h +++ b/xcbutils.h @@ -24,6 +24,8 @@ along with this program. If not, see . #include "utils.h" #include +#include +#include #include #include