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