diff options
| author | 2018-08-07 14:45:45 -0400 | |
|---|---|---|
| committer | 2018-08-07 14:45:45 -0400 | |
| commit | 3242e7c16402b39ac0e4b7f044600f60a900bbbf (patch) | |
| tree | 59fe3c49811b91299e3be12b3e27d1faa970cea4 | |
| parent | Merge pull request #948 from hcorion/fix-mbedtls-installing-files (diff) | |
| parent | qt/hotkey: Get rid of global hotkey map instance (diff) | |
| download | yuzu-3242e7c16402b39ac0e4b7f044600f60a900bbbf.tar.gz yuzu-3242e7c16402b39ac0e4b7f044600f60a900bbbf.tar.xz yuzu-3242e7c16402b39ac0e4b7f044600f60a900bbbf.zip | |
Merge pull request #950 from lioncash/hotkey
qt/hotkey: Get rid of global hotkey map instance
| -rw-r--r-- | src/yuzu/configuration/configure_dialog.cpp | 5 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_dialog.h | 4 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_general.cpp | 4 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_general.h | 4 | ||||
| -rw-r--r-- | src/yuzu/hotkeys.cpp | 67 | ||||
| -rw-r--r-- | src/yuzu/hotkeys.h | 107 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 84 | ||||
| -rw-r--r-- | src/yuzu/main.h | 3 |
8 files changed, 159 insertions, 119 deletions
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 1ca7e876c..cc4b326ae 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp | |||
| @@ -6,9 +6,12 @@ | |||
| 6 | #include "ui_configure.h" | 6 | #include "ui_configure.h" |
| 7 | #include "yuzu/configuration/config.h" | 7 | #include "yuzu/configuration/config.h" |
| 8 | #include "yuzu/configuration/configure_dialog.h" | 8 | #include "yuzu/configuration/configure_dialog.h" |
| 9 | #include "yuzu/hotkeys.h" | ||
| 9 | 10 | ||
| 10 | ConfigureDialog::ConfigureDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ConfigureDialog) { | 11 | ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry) |
| 12 | : QDialog(parent), ui(new Ui::ConfigureDialog) { | ||
| 11 | ui->setupUi(this); | 13 | ui->setupUi(this); |
| 14 | ui->generalTab->PopulateHotkeyList(registry); | ||
| 12 | this->setConfiguration(); | 15 | this->setConfiguration(); |
| 13 | } | 16 | } |
| 14 | 17 | ||
diff --git a/src/yuzu/configuration/configure_dialog.h b/src/yuzu/configuration/configure_dialog.h index 21fa1f501..bbbdacc29 100644 --- a/src/yuzu/configuration/configure_dialog.h +++ b/src/yuzu/configuration/configure_dialog.h | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <QDialog> | 8 | #include <QDialog> |
| 9 | 9 | ||
| 10 | class HotkeyRegistry; | ||
| 11 | |||
| 10 | namespace Ui { | 12 | namespace Ui { |
| 11 | class ConfigureDialog; | 13 | class ConfigureDialog; |
| 12 | } | 14 | } |
| @@ -15,7 +17,7 @@ class ConfigureDialog : public QDialog { | |||
| 15 | Q_OBJECT | 17 | Q_OBJECT |
| 16 | 18 | ||
| 17 | public: | 19 | public: |
| 18 | explicit ConfigureDialog(QWidget* parent); | 20 | explicit ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry); |
| 19 | ~ConfigureDialog(); | 21 | ~ConfigureDialog(); |
| 20 | 22 | ||
| 21 | void applyConfiguration(); | 23 | void applyConfiguration(); |
diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 04afc8724..d8caee1e8 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp | |||
| @@ -35,6 +35,10 @@ void ConfigureGeneral::setConfiguration() { | |||
| 35 | ui->use_docked_mode->setChecked(Settings::values.use_docked_mode); | 35 | ui->use_docked_mode->setChecked(Settings::values.use_docked_mode); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | void ConfigureGeneral::PopulateHotkeyList(const HotkeyRegistry& registry) { | ||
| 39 | ui->widget->Populate(registry); | ||
| 40 | } | ||
| 41 | |||
| 38 | void ConfigureGeneral::applyConfiguration() { | 42 | void ConfigureGeneral::applyConfiguration() { |
| 39 | UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked(); | 43 | UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked(); |
| 40 | UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); | 44 | UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); |
diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index 447552d8c..4770034cc 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <QWidget> | 8 | #include <QWidget> |
| 9 | 9 | ||
| 10 | class HotkeyRegistry; | ||
| 11 | |||
| 10 | namespace Ui { | 12 | namespace Ui { |
| 11 | class ConfigureGeneral; | 13 | class ConfigureGeneral; |
| 12 | } | 14 | } |
| @@ -18,11 +20,11 @@ public: | |||
| 18 | explicit ConfigureGeneral(QWidget* parent = nullptr); | 20 | explicit ConfigureGeneral(QWidget* parent = nullptr); |
| 19 | ~ConfigureGeneral(); | 21 | ~ConfigureGeneral(); |
| 20 | 22 | ||
| 23 | void PopulateHotkeyList(const HotkeyRegistry& registry); | ||
| 21 | void applyConfiguration(); | 24 | void applyConfiguration(); |
| 22 | 25 | ||
| 23 | private: | 26 | private: |
| 24 | void setConfiguration(); | 27 | void setConfiguration(); |
| 25 | 28 | ||
| 26 | private: | ||
| 27 | std::unique_ptr<Ui::ConfigureGeneral> ui; | 29 | std::unique_ptr<Ui::ConfigureGeneral> ui; |
| 28 | }; | 30 | }; |
diff --git a/src/yuzu/hotkeys.cpp b/src/yuzu/hotkeys.cpp index 61acb38ee..dce399774 100644 --- a/src/yuzu/hotkeys.cpp +++ b/src/yuzu/hotkeys.cpp | |||
| @@ -10,58 +10,53 @@ | |||
| 10 | #include "yuzu/hotkeys.h" | 10 | #include "yuzu/hotkeys.h" |
| 11 | #include "yuzu/ui_settings.h" | 11 | #include "yuzu/ui_settings.h" |
| 12 | 12 | ||
| 13 | struct Hotkey { | 13 | HotkeyRegistry::HotkeyRegistry() = default; |
| 14 | Hotkey() : shortcut(nullptr), context(Qt::WindowShortcut) {} | 14 | HotkeyRegistry::~HotkeyRegistry() = default; |
| 15 | 15 | ||
| 16 | QKeySequence keyseq; | 16 | void HotkeyRegistry::LoadHotkeys() { |
| 17 | QShortcut* shortcut; | ||
| 18 | Qt::ShortcutContext context; | ||
| 19 | }; | ||
| 20 | |||
| 21 | typedef std::map<QString, Hotkey> HotkeyMap; | ||
| 22 | typedef std::map<QString, HotkeyMap> HotkeyGroupMap; | ||
| 23 | |||
| 24 | HotkeyGroupMap hotkey_groups; | ||
| 25 | |||
| 26 | void SaveHotkeys() { | ||
| 27 | UISettings::values.shortcuts.clear(); | ||
| 28 | for (auto group : hotkey_groups) { | ||
| 29 | for (auto hotkey : group.second) { | ||
| 30 | UISettings::values.shortcuts.emplace_back( | ||
| 31 | UISettings::Shortcut(group.first + "/" + hotkey.first, | ||
| 32 | UISettings::ContextualShortcut(hotkey.second.keyseq.toString(), | ||
| 33 | hotkey.second.context))); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | void LoadHotkeys() { | ||
| 39 | // Make sure NOT to use a reference here because it would become invalid once we call | 17 | // Make sure NOT to use a reference here because it would become invalid once we call |
| 40 | // beginGroup() | 18 | // beginGroup() |
| 41 | for (auto shortcut : UISettings::values.shortcuts) { | 19 | for (auto shortcut : UISettings::values.shortcuts) { |
| 42 | QStringList cat = shortcut.first.split("/"); | 20 | const QStringList cat = shortcut.first.split('/'); |
| 43 | Q_ASSERT(cat.size() >= 2); | 21 | Q_ASSERT(cat.size() >= 2); |
| 44 | 22 | ||
| 45 | // RegisterHotkey assigns default keybindings, so use old values as default parameters | 23 | // RegisterHotkey assigns default keybindings, so use old values as default parameters |
| 46 | Hotkey& hk = hotkey_groups[cat[0]][cat[1]]; | 24 | Hotkey& hk = hotkey_groups[cat[0]][cat[1]]; |
| 47 | if (!shortcut.second.first.isEmpty()) { | 25 | if (!shortcut.second.first.isEmpty()) { |
| 48 | hk.keyseq = QKeySequence::fromString(shortcut.second.first); | 26 | hk.keyseq = QKeySequence::fromString(shortcut.second.first); |
| 49 | hk.context = (Qt::ShortcutContext)shortcut.second.second; | 27 | hk.context = static_cast<Qt::ShortcutContext>(shortcut.second.second); |
| 50 | } | 28 | } |
| 51 | if (hk.shortcut) | 29 | if (hk.shortcut) |
| 52 | hk.shortcut->setKey(hk.keyseq); | 30 | hk.shortcut->setKey(hk.keyseq); |
| 53 | } | 31 | } |
| 54 | } | 32 | } |
| 55 | 33 | ||
| 56 | void RegisterHotkey(const QString& group, const QString& action, const QKeySequence& default_keyseq, | 34 | void HotkeyRegistry::SaveHotkeys() { |
| 57 | Qt::ShortcutContext default_context) { | 35 | UISettings::values.shortcuts.clear(); |
| 58 | if (hotkey_groups[group].find(action) == hotkey_groups[group].end()) { | 36 | for (const auto& group : hotkey_groups) { |
| 59 | hotkey_groups[group][action].keyseq = default_keyseq; | 37 | for (const auto& hotkey : group.second) { |
| 60 | hotkey_groups[group][action].context = default_context; | 38 | UISettings::values.shortcuts.emplace_back( |
| 39 | UISettings::Shortcut(group.first + '/' + hotkey.first, | ||
| 40 | UISettings::ContextualShortcut(hotkey.second.keyseq.toString(), | ||
| 41 | hotkey.second.context))); | ||
| 42 | } | ||
| 61 | } | 43 | } |
| 62 | } | 44 | } |
| 63 | 45 | ||
| 64 | QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget) { | 46 | void HotkeyRegistry::RegisterHotkey(const QString& group, const QString& action, |
| 47 | const QKeySequence& default_keyseq, | ||
| 48 | Qt::ShortcutContext default_context) { | ||
| 49 | auto& hotkey_group = hotkey_groups[group]; | ||
| 50 | if (hotkey_group.find(action) != hotkey_group.end()) { | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 54 | auto& hotkey_action = hotkey_groups[group][action]; | ||
| 55 | hotkey_action.keyseq = default_keyseq; | ||
| 56 | hotkey_action.context = default_context; | ||
| 57 | } | ||
| 58 | |||
| 59 | QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action, QWidget* widget) { | ||
| 65 | Hotkey& hk = hotkey_groups[group][action]; | 60 | Hotkey& hk = hotkey_groups[group][action]; |
| 66 | 61 | ||
| 67 | if (!hk.shortcut) | 62 | if (!hk.shortcut) |
| @@ -72,10 +67,12 @@ QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widge | |||
| 72 | 67 | ||
| 73 | GHotkeysDialog::GHotkeysDialog(QWidget* parent) : QWidget(parent) { | 68 | GHotkeysDialog::GHotkeysDialog(QWidget* parent) : QWidget(parent) { |
| 74 | ui.setupUi(this); | 69 | ui.setupUi(this); |
| 70 | } | ||
| 75 | 71 | ||
| 76 | for (auto group : hotkey_groups) { | 72 | void GHotkeysDialog::Populate(const HotkeyRegistry& registry) { |
| 73 | for (const auto& group : registry.hotkey_groups) { | ||
| 77 | QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first)); | 74 | QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first)); |
| 78 | for (auto hotkey : group.second) { | 75 | for (const auto& hotkey : group.second) { |
| 79 | QStringList columns; | 76 | QStringList columns; |
| 80 | columns << hotkey.first << hotkey.second.keyseq.toString(); | 77 | columns << hotkey.first << hotkey.second.keyseq.toString(); |
| 81 | QTreeWidgetItem* item = new QTreeWidgetItem(columns); | 78 | QTreeWidgetItem* item = new QTreeWidgetItem(columns); |
diff --git a/src/yuzu/hotkeys.h b/src/yuzu/hotkeys.h index a4ccc193b..f38e6c002 100644 --- a/src/yuzu/hotkeys.h +++ b/src/yuzu/hotkeys.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <map> | ||
| 7 | #include "ui_hotkeys.h" | 8 | #include "ui_hotkeys.h" |
| 8 | 9 | ||
| 9 | class QDialog; | 10 | class QDialog; |
| @@ -11,47 +12,69 @@ class QKeySequence; | |||
| 11 | class QSettings; | 12 | class QSettings; |
| 12 | class QShortcut; | 13 | class QShortcut; |
| 13 | 14 | ||
| 14 | /** | 15 | class HotkeyRegistry final { |
| 15 | * Register a hotkey. | 16 | public: |
| 16 | * | 17 | friend class GHotkeysDialog; |
| 17 | * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger") | 18 | |
| 18 | * @param action Name of the action (e.g. "Start Emulation", "Load Image") | 19 | explicit HotkeyRegistry(); |
| 19 | * @param default_keyseq Default key sequence to assign if the hotkey wasn't present in the settings | 20 | ~HotkeyRegistry(); |
| 20 | * file before | 21 | |
| 21 | * @param default_context Default context to assign if the hotkey wasn't present in the settings | 22 | /** |
| 22 | * file before | 23 | * Loads hotkeys from the settings file. |
| 23 | * @warning Both the group and action strings will be displayed in the hotkey settings dialog | 24 | * |
| 24 | */ | 25 | * @note Yet unregistered hotkeys which are present in the settings will automatically be |
| 25 | void RegisterHotkey(const QString& group, const QString& action, | 26 | * registered. |
| 26 | const QKeySequence& default_keyseq = QKeySequence(), | 27 | */ |
| 27 | Qt::ShortcutContext default_context = Qt::WindowShortcut); | 28 | void LoadHotkeys(); |
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | * Returns a QShortcut object whose activated() signal can be connected to other QObjects' slots. | 31 | * Saves all registered hotkeys to the settings file. |
| 31 | * | 32 | * |
| 32 | * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger"). | 33 | * @note Each hotkey group will be stored a settings group; For each hotkey inside that group, a |
| 33 | * @param action Name of the action (e.g. "Start Emulation", "Load Image"). | 34 | * settings group will be created to store the key sequence and the hotkey context. |
| 34 | * @param widget Parent widget of the returned QShortcut. | 35 | */ |
| 35 | * @warning If multiple QWidgets' call this function for the same action, the returned QShortcut | 36 | void SaveHotkeys(); |
| 36 | * will be the same. Thus, you shouldn't rely on the caller really being the QShortcut's parent. | 37 | |
| 37 | */ | 38 | /** |
| 38 | QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget); | 39 | * Returns a QShortcut object whose activated() signal can be connected to other QObjects' |
| 39 | 40 | * slots. | |
| 40 | /** | 41 | * |
| 41 | * Saves all registered hotkeys to the settings file. | 42 | * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger"). |
| 42 | * | 43 | * @param action Name of the action (e.g. "Start Emulation", "Load Image"). |
| 43 | * @note Each hotkey group will be stored a settings group; For each hotkey inside that group, a | 44 | * @param widget Parent widget of the returned QShortcut. |
| 44 | * settings group will be created to store the key sequence and the hotkey context. | 45 | * @warning If multiple QWidgets' call this function for the same action, the returned QShortcut |
| 45 | */ | 46 | * will be the same. Thus, you shouldn't rely on the caller really being the |
| 46 | void SaveHotkeys(); | 47 | * QShortcut's parent. |
| 47 | 48 | */ | |
| 48 | /** | 49 | QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget); |
| 49 | * Loads hotkeys from the settings file. | 50 | |
| 50 | * | 51 | /** |
| 51 | * @note Yet unregistered hotkeys which are present in the settings will automatically be | 52 | * Register a hotkey. |
| 52 | * registered. | 53 | * |
| 53 | */ | 54 | * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger") |
| 54 | void LoadHotkeys(); | 55 | * @param action Name of the action (e.g. "Start Emulation", "Load Image") |
| 56 | * @param default_keyseq Default key sequence to assign if the hotkey wasn't present in the | ||
| 57 | * settings file before | ||
| 58 | * @param default_context Default context to assign if the hotkey wasn't present in the settings | ||
| 59 | * file before | ||
| 60 | * @warning Both the group and action strings will be displayed in the hotkey settings dialog | ||
| 61 | */ | ||
| 62 | void RegisterHotkey(const QString& group, const QString& action, | ||
| 63 | const QKeySequence& default_keyseq = {}, | ||
| 64 | Qt::ShortcutContext default_context = Qt::WindowShortcut); | ||
| 65 | |||
| 66 | private: | ||
| 67 | struct Hotkey { | ||
| 68 | QKeySequence keyseq; | ||
| 69 | QShortcut* shortcut = nullptr; | ||
| 70 | Qt::ShortcutContext context = Qt::WindowShortcut; | ||
| 71 | }; | ||
| 72 | |||
| 73 | using HotkeyMap = std::map<QString, Hotkey>; | ||
| 74 | using HotkeyGroupMap = std::map<QString, HotkeyMap>; | ||
| 75 | |||
| 76 | HotkeyGroupMap hotkey_groups; | ||
| 77 | }; | ||
| 55 | 78 | ||
| 56 | class GHotkeysDialog : public QWidget { | 79 | class GHotkeysDialog : public QWidget { |
| 57 | Q_OBJECT | 80 | Q_OBJECT |
| @@ -59,6 +82,8 @@ class GHotkeysDialog : public QWidget { | |||
| 59 | public: | 82 | public: |
| 60 | explicit GHotkeysDialog(QWidget* parent = nullptr); | 83 | explicit GHotkeysDialog(QWidget* parent = nullptr); |
| 61 | 84 | ||
| 85 | void Populate(const HotkeyRegistry& registry); | ||
| 86 | |||
| 62 | private: | 87 | private: |
| 63 | Ui::hotkeys ui; | 88 | Ui::hotkeys ui; |
| 64 | }; | 89 | }; |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index dd71bd763..17ed62c72 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -208,43 +208,46 @@ void GMainWindow::InitializeRecentFileMenuActions() { | |||
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | void GMainWindow::InitializeHotkeys() { | 210 | void GMainWindow::InitializeHotkeys() { |
| 211 | RegisterHotkey("Main Window", "Load File", QKeySequence::Open); | 211 | hotkey_registry.RegisterHotkey("Main Window", "Load File", QKeySequence::Open); |
| 212 | RegisterHotkey("Main Window", "Start Emulation"); | 212 | hotkey_registry.RegisterHotkey("Main Window", "Start Emulation"); |
| 213 | RegisterHotkey("Main Window", "Continue/Pause", QKeySequence(Qt::Key_F4)); | 213 | hotkey_registry.RegisterHotkey("Main Window", "Continue/Pause", QKeySequence(Qt::Key_F4)); |
| 214 | RegisterHotkey("Main Window", "Fullscreen", QKeySequence::FullScreen); | 214 | hotkey_registry.RegisterHotkey("Main Window", "Fullscreen", QKeySequence::FullScreen); |
| 215 | RegisterHotkey("Main Window", "Exit Fullscreen", QKeySequence(Qt::Key_Escape), | 215 | hotkey_registry.RegisterHotkey("Main Window", "Exit Fullscreen", QKeySequence(Qt::Key_Escape), |
| 216 | Qt::ApplicationShortcut); | 216 | Qt::ApplicationShortcut); |
| 217 | RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"), | 217 | hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"), |
| 218 | Qt::ApplicationShortcut); | 218 | Qt::ApplicationShortcut); |
| 219 | LoadHotkeys(); | 219 | hotkey_registry.LoadHotkeys(); |
| 220 | 220 | ||
| 221 | connect(GetHotkey("Main Window", "Load File", this), &QShortcut::activated, this, | 221 | connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated, |
| 222 | &GMainWindow::OnMenuLoadFile); | 222 | this, &GMainWindow::OnMenuLoadFile); |
| 223 | connect(GetHotkey("Main Window", "Start Emulation", this), &QShortcut::activated, this, | 223 | connect(hotkey_registry.GetHotkey("Main Window", "Start Emulation", this), |
| 224 | &GMainWindow::OnStartGame); | 224 | &QShortcut::activated, this, &GMainWindow::OnStartGame); |
| 225 | connect(GetHotkey("Main Window", "Continue/Pause", this), &QShortcut::activated, this, [&] { | 225 | connect(hotkey_registry.GetHotkey("Main Window", "Continue/Pause", this), &QShortcut::activated, |
| 226 | if (emulation_running) { | 226 | this, [&] { |
| 227 | if (emu_thread->IsRunning()) { | 227 | if (emulation_running) { |
| 228 | OnPauseGame(); | 228 | if (emu_thread->IsRunning()) { |
| 229 | } else { | 229 | OnPauseGame(); |
| 230 | OnStartGame(); | 230 | } else { |
| 231 | } | 231 | OnStartGame(); |
| 232 | } | 232 | } |
| 233 | }); | 233 | } |
| 234 | connect(GetHotkey("Main Window", "Fullscreen", render_window), &QShortcut::activated, | 234 | }); |
| 235 | ui.action_Fullscreen, &QAction::trigger); | 235 | connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window), |
| 236 | connect(GetHotkey("Main Window", "Fullscreen", render_window), &QShortcut::activatedAmbiguously, | 236 | &QShortcut::activated, ui.action_Fullscreen, &QAction::trigger); |
| 237 | ui.action_Fullscreen, &QAction::trigger); | 237 | connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window), |
| 238 | connect(GetHotkey("Main Window", "Exit Fullscreen", this), &QShortcut::activated, this, [&] { | 238 | &QShortcut::activatedAmbiguously, ui.action_Fullscreen, &QAction::trigger); |
| 239 | if (emulation_running) { | 239 | connect(hotkey_registry.GetHotkey("Main Window", "Exit Fullscreen", this), |
| 240 | ui.action_Fullscreen->setChecked(false); | 240 | &QShortcut::activated, this, [&] { |
| 241 | ToggleFullscreen(); | 241 | if (emulation_running) { |
| 242 | } | 242 | ui.action_Fullscreen->setChecked(false); |
| 243 | }); | 243 | ToggleFullscreen(); |
| 244 | connect(GetHotkey("Main Window", "Toggle Speed Limit", this), &QShortcut::activated, this, [&] { | 244 | } |
| 245 | Settings::values.toggle_framelimit = !Settings::values.toggle_framelimit; | 245 | }); |
| 246 | UpdateStatusBar(); | 246 | connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this), |
| 247 | }); | 247 | &QShortcut::activated, this, [&] { |
| 248 | Settings::values.toggle_framelimit = !Settings::values.toggle_framelimit; | ||
| 249 | UpdateStatusBar(); | ||
| 250 | }); | ||
| 248 | } | 251 | } |
| 249 | 252 | ||
| 250 | void GMainWindow::SetDefaultUIGeometry() { | 253 | void GMainWindow::SetDefaultUIGeometry() { |
| @@ -323,7 +326,8 @@ void GMainWindow::ConnectMenuEvents() { | |||
| 323 | connect(ui.action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible); | 326 | connect(ui.action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible); |
| 324 | 327 | ||
| 325 | // Fullscreen | 328 | // Fullscreen |
| 326 | ui.action_Fullscreen->setShortcut(GetHotkey("Main Window", "Fullscreen", this)->key()); | 329 | ui.action_Fullscreen->setShortcut( |
| 330 | hotkey_registry.GetHotkey("Main Window", "Fullscreen", this)->key()); | ||
| 327 | connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen); | 331 | connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen); |
| 328 | 332 | ||
| 329 | // Help | 333 | // Help |
| @@ -757,7 +761,7 @@ void GMainWindow::ToggleWindowMode() { | |||
| 757 | } | 761 | } |
| 758 | 762 | ||
| 759 | void GMainWindow::OnConfigure() { | 763 | void GMainWindow::OnConfigure() { |
| 760 | ConfigureDialog configureDialog(this); | 764 | ConfigureDialog configureDialog(this, hotkey_registry); |
| 761 | auto old_theme = UISettings::values.theme; | 765 | auto old_theme = UISettings::values.theme; |
| 762 | auto result = configureDialog.exec(); | 766 | auto result = configureDialog.exec(); |
| 763 | if (result == QDialog::Accepted) { | 767 | if (result == QDialog::Accepted) { |
| @@ -896,7 +900,7 @@ void GMainWindow::closeEvent(QCloseEvent* event) { | |||
| 896 | UISettings::values.first_start = false; | 900 | UISettings::values.first_start = false; |
| 897 | 901 | ||
| 898 | game_list->SaveInterfaceLayout(); | 902 | game_list->SaveInterfaceLayout(); |
| 899 | SaveHotkeys(); | 903 | hotkey_registry.SaveHotkeys(); |
| 900 | 904 | ||
| 901 | // Shutdown session if the emu thread is active... | 905 | // Shutdown session if the emu thread is active... |
| 902 | if (emu_thread != nullptr) | 906 | if (emu_thread != nullptr) |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index a60d831b9..6e335b8f8 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <QTimer> | 9 | #include <QTimer> |
| 10 | #include "core/core.h" | 10 | #include "core/core.h" |
| 11 | #include "ui_main.h" | 11 | #include "ui_main.h" |
| 12 | #include "yuzu/hotkeys.h" | ||
| 12 | 13 | ||
| 13 | class Config; | 14 | class Config; |
| 14 | class EmuThread; | 15 | class EmuThread; |
| @@ -172,6 +173,8 @@ private: | |||
| 172 | // stores default icon theme search paths for the platform | 173 | // stores default icon theme search paths for the platform |
| 173 | QStringList default_theme_paths; | 174 | QStringList default_theme_paths; |
| 174 | 175 | ||
| 176 | HotkeyRegistry hotkey_registry; | ||
| 177 | |||
| 175 | protected: | 178 | protected: |
| 176 | void dropEvent(QDropEvent* event) override; | 179 | void dropEvent(QDropEvent* event) override; |
| 177 | void dragEnterEvent(QDragEnterEvent* event) override; | 180 | void dragEnterEvent(QDragEnterEvent* event) override; |