mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-18 04:19:55 +01:00
Create QShortcuts to catch key bindings from global shorcuts and hide them from widgets
Fixes issue 722
This commit is contained in:
parent
186a981614
commit
5207af6f93
@ -22,9 +22,10 @@
|
||||
|
||||
#include "mac_startup.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QAction>
|
||||
#include <QShortcut>
|
||||
#include <QSignalMapper>
|
||||
#include <QtDebug>
|
||||
|
||||
#ifdef QT_DBUS_LIB
|
||||
# include <QtDBus>
|
||||
@ -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;
|
||||
|
@ -18,21 +18,22 @@
|
||||
#ifndef GLOBALSHORTCUTS_H
|
||||
#define GLOBALSHORTCUTS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QKeySequence>
|
||||
#include <QMap>
|
||||
#include <QSettings>
|
||||
#include <QWidget>
|
||||
|
||||
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<QString, Shortcut> shortcuts() const { return shortcuts_; }
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QShortcut>
|
||||
#include <QtDebug>
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user