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 "mac_startup.h"
|
||||||
|
|
||||||
#include <QtDebug>
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QShortcut>
|
||||||
#include <QSignalMapper>
|
#include <QSignalMapper>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
#ifdef QT_DBUS_LIB
|
#ifdef QT_DBUS_LIB
|
||||||
# include <QtDBus>
|
# include <QtDBus>
|
||||||
@ -32,8 +33,8 @@
|
|||||||
|
|
||||||
const char* GlobalShortcuts::kSettingsGroup = "Shortcuts";
|
const char* GlobalShortcuts::kSettingsGroup = "Shortcuts";
|
||||||
|
|
||||||
GlobalShortcuts::GlobalShortcuts(QObject *parent)
|
GlobalShortcuts::GlobalShortcuts(QWidget *parent)
|
||||||
: QObject(parent),
|
: QWidget(parent),
|
||||||
gnome_backend_(NULL),
|
gnome_backend_(NULL),
|
||||||
system_backend_(NULL),
|
system_backend_(NULL),
|
||||||
use_gnome_(false),
|
use_gnome_(false),
|
||||||
@ -101,11 +102,17 @@ GlobalShortcuts::Shortcut GlobalShortcuts::AddShortcut(const QString& id, const
|
|||||||
const QKeySequence& default_key) {
|
const QKeySequence& default_key) {
|
||||||
Shortcut shortcut;
|
Shortcut shortcut;
|
||||||
shortcut.action = new QAction(name, this);
|
shortcut.action = new QAction(name, this);
|
||||||
shortcut.action->setShortcut(QKeySequence::fromString(
|
QKeySequence key_sequence = QKeySequence::fromString(
|
||||||
settings_.value(id, default_key.toString()).toString()));
|
settings_.value(id, default_key.toString()).toString());
|
||||||
|
shortcut.action->setShortcut(key_sequence);
|
||||||
shortcut.id = id;
|
shortcut.id = id;
|
||||||
shortcut.default_key = default_key;
|
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;
|
shortcuts_[id] = shortcut;
|
||||||
|
|
||||||
return shortcut;
|
return shortcut;
|
||||||
|
@ -18,21 +18,22 @@
|
|||||||
#ifndef GLOBALSHORTCUTS_H
|
#ifndef GLOBALSHORTCUTS_H
|
||||||
#define GLOBALSHORTCUTS_H
|
#define GLOBALSHORTCUTS_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
|
class QShortcut;
|
||||||
|
|
||||||
class GlobalShortcutBackend;
|
class GlobalShortcutBackend;
|
||||||
class QSignalMapper;
|
class QSignalMapper;
|
||||||
|
|
||||||
class GlobalShortcuts : public QObject {
|
class GlobalShortcuts : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlobalShortcuts(QObject* parent = 0);
|
GlobalShortcuts(QWidget* parent = 0);
|
||||||
|
|
||||||
static const char* kSettingsGroup;
|
static const char* kSettingsGroup;
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ public:
|
|||||||
QString id;
|
QString id;
|
||||||
QKeySequence default_key;
|
QKeySequence default_key;
|
||||||
QAction* action;
|
QAction* action;
|
||||||
|
QShortcut* shortcut;
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<QString, Shortcut> shortcuts() const { return shortcuts_; }
|
QMap<QString, Shortcut> shortcuts() const { return shortcuts_; }
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QShortcut>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog* dialog)
|
GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog* dialog)
|
||||||
@ -116,6 +117,7 @@ void GlobalShortcutsSettingsPage::SetShortcut(const QString& id, const QKeySeque
|
|||||||
void GlobalShortcutsSettingsPage::Save() {
|
void GlobalShortcutsSettingsPage::Save() {
|
||||||
foreach (const Shortcut& s, shortcuts_.values()) {
|
foreach (const Shortcut& s, shortcuts_.values()) {
|
||||||
s.s.action->setShortcut(s.key);
|
s.s.action->setShortcut(s.key);
|
||||||
|
s.s.shortcut->setKey(s.key);
|
||||||
settings_.setValue(s.s.id, s.key.toString());
|
settings_.setValue(s.s.id, s.key.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user