diff options
Diffstat (limited to 'src/citra_qt/hotkeys.cpp')
| -rw-r--r-- | src/citra_qt/hotkeys.cpp | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp index 41f95c63d..6301259d8 100644 --- a/src/citra_qt/hotkeys.cpp +++ b/src/citra_qt/hotkeys.cpp | |||
| @@ -4,16 +4,16 @@ | |||
| 4 | 4 | ||
| 5 | #include <map> | 5 | #include <map> |
| 6 | 6 | ||
| 7 | #include <QtGlobal> | ||
| 8 | #include <QKeySequence> | 7 | #include <QKeySequence> |
| 9 | #include <QShortcut> | 8 | #include <QShortcut> |
| 9 | #include <QtGlobal> | ||
| 10 | 10 | ||
| 11 | #include "citra_qt/hotkeys.h" | 11 | #include "citra_qt/hotkeys.h" |
| 12 | #include "citra_qt/ui_settings.h" | 12 | #include "citra_qt/ui_settings.h" |
| 13 | 13 | ||
| 14 | struct Hotkey | 14 | struct Hotkey { |
| 15 | { | 15 | Hotkey() : shortcut(nullptr), context(Qt::WindowShortcut) { |
| 16 | Hotkey() : shortcut(nullptr), context(Qt::WindowShortcut) {} | 16 | } |
| 17 | 17 | ||
| 18 | QKeySequence keyseq; | 18 | QKeySequence keyseq; |
| 19 | QShortcut* shortcut; | 19 | QShortcut* shortcut; |
| @@ -25,33 +25,28 @@ typedef std::map<QString, HotkeyMap> HotkeyGroupMap; | |||
| 25 | 25 | ||
| 26 | HotkeyGroupMap hotkey_groups; | 26 | HotkeyGroupMap hotkey_groups; |
| 27 | 27 | ||
| 28 | void SaveHotkeys() | 28 | void SaveHotkeys() { |
| 29 | { | ||
| 30 | UISettings::values.shortcuts.clear(); | 29 | UISettings::values.shortcuts.clear(); |
| 31 | for (auto group : hotkey_groups) | 30 | for (auto group : hotkey_groups) { |
| 32 | { | 31 | for (auto hotkey : group.second) { |
| 33 | for (auto hotkey : group.second) | ||
| 34 | { | ||
| 35 | UISettings::values.shortcuts.emplace_back( | 32 | UISettings::values.shortcuts.emplace_back( |
| 36 | UISettings::Shortcut(group.first + "/" + hotkey.first, | 33 | UISettings::Shortcut(group.first + "/" + hotkey.first, |
| 37 | UISettings::ContextualShortcut(hotkey.second.keyseq.toString(), | 34 | UISettings::ContextualShortcut(hotkey.second.keyseq.toString(), |
| 38 | hotkey.second.context))); | 35 | hotkey.second.context))); |
| 39 | } | 36 | } |
| 40 | } | 37 | } |
| 41 | } | 38 | } |
| 42 | 39 | ||
| 43 | void LoadHotkeys() | 40 | void LoadHotkeys() { |
| 44 | { | 41 | // Make sure NOT to use a reference here because it would become invalid once we call |
| 45 | // Make sure NOT to use a reference here because it would become invalid once we call beginGroup() | 42 | // beginGroup() |
| 46 | for (auto shortcut : UISettings::values.shortcuts) | 43 | for (auto shortcut : UISettings::values.shortcuts) { |
| 47 | { | ||
| 48 | QStringList cat = shortcut.first.split("/"); | 44 | QStringList cat = shortcut.first.split("/"); |
| 49 | Q_ASSERT(cat.size() >= 2); | 45 | Q_ASSERT(cat.size() >= 2); |
| 50 | 46 | ||
| 51 | // RegisterHotkey assigns default keybindings, so use old values as default parameters | 47 | // RegisterHotkey assigns default keybindings, so use old values as default parameters |
| 52 | Hotkey& hk = hotkey_groups[cat[0]][cat[1]]; | 48 | Hotkey& hk = hotkey_groups[cat[0]][cat[1]]; |
| 53 | if (!shortcut.second.first.isEmpty()) | 49 | if (!shortcut.second.first.isEmpty()) { |
| 54 | { | ||
| 55 | hk.keyseq = QKeySequence::fromString(shortcut.second.first); | 50 | hk.keyseq = QKeySequence::fromString(shortcut.second.first); |
| 56 | hk.context = (Qt::ShortcutContext)shortcut.second.second; | 51 | hk.context = (Qt::ShortcutContext)shortcut.second.second; |
| 57 | } | 52 | } |
| @@ -60,17 +55,15 @@ void LoadHotkeys() | |||
| 60 | } | 55 | } |
| 61 | } | 56 | } |
| 62 | 57 | ||
| 63 | void RegisterHotkey(const QString& group, const QString& action, const QKeySequence& default_keyseq, Qt::ShortcutContext default_context) | 58 | void RegisterHotkey(const QString& group, const QString& action, const QKeySequence& default_keyseq, |
| 64 | { | 59 | Qt::ShortcutContext default_context) { |
| 65 | if (hotkey_groups[group].find(action) == hotkey_groups[group].end()) | 60 | if (hotkey_groups[group].find(action) == hotkey_groups[group].end()) { |
| 66 | { | ||
| 67 | hotkey_groups[group][action].keyseq = default_keyseq; | 61 | hotkey_groups[group][action].keyseq = default_keyseq; |
| 68 | hotkey_groups[group][action].context = default_context; | 62 | hotkey_groups[group][action].context = default_context; |
| 69 | } | 63 | } |
| 70 | } | 64 | } |
| 71 | 65 | ||
| 72 | QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget) | 66 | QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget) { |
| 73 | { | ||
| 74 | Hotkey& hk = hotkey_groups[group][action]; | 67 | Hotkey& hk = hotkey_groups[group][action]; |
| 75 | 68 | ||
| 76 | if (!hk.shortcut) | 69 | if (!hk.shortcut) |
| @@ -79,16 +72,12 @@ QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widge | |||
| 79 | return hk.shortcut; | 72 | return hk.shortcut; |
| 80 | } | 73 | } |
| 81 | 74 | ||
| 82 | 75 | GHotkeysDialog::GHotkeysDialog(QWidget* parent) : QWidget(parent) { | |
| 83 | GHotkeysDialog::GHotkeysDialog(QWidget* parent): QWidget(parent) | ||
| 84 | { | ||
| 85 | ui.setupUi(this); | 76 | ui.setupUi(this); |
| 86 | 77 | ||
| 87 | for (auto group : hotkey_groups) | 78 | for (auto group : hotkey_groups) { |
| 88 | { | ||
| 89 | QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first)); | 79 | QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first)); |
| 90 | for (auto hotkey : group.second) | 80 | for (auto hotkey : group.second) { |
| 91 | { | ||
| 92 | QStringList columns; | 81 | QStringList columns; |
| 93 | columns << hotkey.first << hotkey.second.keyseq.toString(); | 82 | columns << hotkey.first << hotkey.second.keyseq.toString(); |
| 94 | QTreeWidgetItem* item = new QTreeWidgetItem(columns); | 83 | QTreeWidgetItem* item = new QTreeWidgetItem(columns); |