From 5207af6f93d187dcd6a21f7d0aaf4e84fd64ddae Mon Sep 17 00:00:00 2001 From: Alexander Bikadorov Date: Mon, 11 Nov 2013 19:22:52 +0100 Subject: [PATCH] Create QShortcuts to catch key bindings from global shorcuts and hide them from widgets Fixes issue 722 --- src/core/globalshortcuts.cpp | 17 ++++++++++++----- src/core/globalshortcuts.h | 8 +++++--- src/ui/globalshortcutssettingspage.cpp | 2 ++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/core/globalshortcuts.cpp b/src/core/globalshortcuts.cpp index c37ed907a..d758fca78 100644 --- a/src/core/globalshortcuts.cpp +++ b/src/core/globalshortcuts.cpp @@ -22,9 +22,10 @@ #include "mac_startup.h" -#include #include +#include #include +#include #ifdef QT_DBUS_LIB # include @@ -32,8 +33,8 @@ const char* GlobalShortcuts::kSettingsGroup = "Shortcuts"; -GlobalShortcuts::GlobalShortcuts(QObject *parent) - : QObject(parent), +GlobalShortcuts::GlobalShortcuts(QWidget *parent) + : QWidget(parent), gnome_backend_(NULL), system_backend_(NULL), use_gnome_(false), @@ -101,11 +102,17 @@ GlobalShortcuts::Shortcut GlobalShortcuts::AddShortcut(const QString& id, const const QKeySequence& default_key) { Shortcut shortcut; shortcut.action = new QAction(name, this); - shortcut.action->setShortcut(QKeySequence::fromString( - settings_.value(id, default_key.toString()).toString())); + QKeySequence key_sequence = QKeySequence::fromString( + settings_.value(id, default_key.toString()).toString()); + shortcut.action->setShortcut(key_sequence); shortcut.id = id; shortcut.default_key = default_key; + // Create application wide QShortcut to hide keyevents mapped to global + // shortcuts from widgets. + shortcut.shortcut = new QShortcut(key_sequence, this); + shortcut.shortcut->setContext(Qt::ApplicationShortcut); + shortcuts_[id] = shortcut; return shortcut; diff --git a/src/core/globalshortcuts.h b/src/core/globalshortcuts.h index 8b9df4342..ff6f97563 100644 --- a/src/core/globalshortcuts.h +++ b/src/core/globalshortcuts.h @@ -18,21 +18,22 @@ #ifndef GLOBALSHORTCUTS_H #define GLOBALSHORTCUTS_H -#include #include #include #include +#include class QAction; +class QShortcut; class GlobalShortcutBackend; class QSignalMapper; -class GlobalShortcuts : public QObject { +class GlobalShortcuts : public QWidget { Q_OBJECT public: - GlobalShortcuts(QObject* parent = 0); + GlobalShortcuts(QWidget* parent = 0); static const char* kSettingsGroup; @@ -40,6 +41,7 @@ public: QString id; QKeySequence default_key; QAction* action; + QShortcut* shortcut; }; QMap shortcuts() const { return shortcuts_; } diff --git a/src/ui/globalshortcutssettingspage.cpp b/src/ui/globalshortcutssettingspage.cpp index c57e25353..45e63ed57 100644 --- a/src/ui/globalshortcutssettingspage.cpp +++ b/src/ui/globalshortcutssettingspage.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog* dialog) @@ -116,6 +117,7 @@ void GlobalShortcutsSettingsPage::SetShortcut(const QString& id, const QKeySeque void GlobalShortcutsSettingsPage::Save() { foreach (const Shortcut& s, shortcuts_.values()) { s.s.action->setShortcut(s.key); + s.s.shortcut->setKey(s.key); settings_.setValue(s.s.id, s.key.toString()); }