diff options
| author | 2020-04-23 13:31:16 +0200 | |
|---|---|---|
| committer | 2020-04-24 23:50:26 +0200 | |
| commit | a19c6317ef78de6425944038dfd5b5638170dd79 (patch) | |
| tree | 143d9cdbaa54a28a1e10278196854de1cf895cfc | |
| parent | Merge pull request #3699 from FearlessTobi/port-5185 (diff) | |
| download | yuzu-a19c6317ef78de6425944038dfd5b5638170dd79.tar.gz yuzu-a19c6317ef78de6425944038dfd5b5638170dd79.tar.xz yuzu-a19c6317ef78de6425944038dfd5b5638170dd79.zip | |
Add Restore Defaults and Clear options to hotkeys
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 7 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.h | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.cpp | 80 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.h | 6 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.ui | 39 |
5 files changed, 116 insertions, 18 deletions
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 7f6dfac84..fce86d80a 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -12,7 +12,6 @@ | |||
| 12 | #include "input_common/main.h" | 12 | #include "input_common/main.h" |
| 13 | #include "input_common/udp/client.h" | 13 | #include "input_common/udp/client.h" |
| 14 | #include "yuzu/configuration/config.h" | 14 | #include "yuzu/configuration/config.h" |
| 15 | #include "yuzu/uisettings.h" | ||
| 16 | 15 | ||
| 17 | Config::Config() { | 16 | Config::Config() { |
| 18 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | 17 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. |
| @@ -212,12 +211,13 @@ const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> Config::default | |||
| 212 | // This must be in alphabetical order according to action name as it must have the same order as | 211 | // This must be in alphabetical order according to action name as it must have the same order as |
| 213 | // UISetting::values.shortcuts, which is alphabetically ordered. | 212 | // UISetting::values.shortcuts, which is alphabetically ordered. |
| 214 | // clang-format off | 213 | // clang-format off |
| 215 | const std::array<UISettings::Shortcut, 15> default_hotkeys{{ | 214 | const std::array<UISettings::Shortcut, 15> Config::default_hotkeys{{ |
| 216 | {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}}, | 215 | {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}}, |
| 216 | {QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}}, | ||
| 217 | {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, | 217 | {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, |
| 218 | {QStringLiteral("Decrease Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("-"), Qt::ApplicationShortcut}}, | 218 | {QStringLiteral("Decrease Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("-"), Qt::ApplicationShortcut}}, |
| 219 | {QStringLiteral("Exit yuzu"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Q"), Qt::WindowShortcut}}, | ||
| 220 | {QStringLiteral("Exit Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("Esc"), Qt::WindowShortcut}}, | 219 | {QStringLiteral("Exit Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("Esc"), Qt::WindowShortcut}}, |
| 220 | {QStringLiteral("Exit yuzu"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Q"), Qt::WindowShortcut}}, | ||
| 221 | {QStringLiteral("Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("F11"), Qt::WindowShortcut}}, | 221 | {QStringLiteral("Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("F11"), Qt::WindowShortcut}}, |
| 222 | {QStringLiteral("Increase Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}}, | 222 | {QStringLiteral("Increase Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}}, |
| 223 | {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}}, | 223 | {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}}, |
| @@ -227,7 +227,6 @@ const std::array<UISettings::Shortcut, 15> default_hotkeys{{ | |||
| 227 | {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, | 227 | {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, |
| 228 | {QStringLiteral("Toggle Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, | 228 | {QStringLiteral("Toggle Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, |
| 229 | {QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}}, | 229 | {QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}}, |
| 230 | {QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}}, | ||
| 231 | }}; | 230 | }}; |
| 232 | // clang-format on | 231 | // clang-format on |
| 233 | 232 | ||
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index ba6888004..5cd2a5feb 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include <QVariant> | 10 | #include <QVariant> |
| 11 | #include "core/settings.h" | 11 | #include "core/settings.h" |
| 12 | #include "yuzu/uisettings.h" | ||
| 12 | 13 | ||
| 13 | class QSettings; | 14 | class QSettings; |
| 14 | 15 | ||
| @@ -26,6 +27,7 @@ public: | |||
| 26 | default_mouse_buttons; | 27 | default_mouse_buttons; |
| 27 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys; | 28 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys; |
| 28 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods; | 29 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods; |
| 30 | static const std::array<UISettings::Shortcut, 15> default_hotkeys; | ||
| 29 | 31 | ||
| 30 | private: | 32 | private: |
| 31 | void ReadValues(); | 33 | void ReadValues(); |
diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp index fa9052136..6f7fd4414 100644 --- a/src/yuzu/configuration/configure_hotkeys.cpp +++ b/src/yuzu/configuration/configure_hotkeys.cpp | |||
| @@ -2,10 +2,12 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <QMenu> | ||
| 5 | #include <QMessageBox> | 6 | #include <QMessageBox> |
| 6 | #include <QStandardItemModel> | 7 | #include <QStandardItemModel> |
| 7 | #include "core/settings.h" | 8 | #include "core/settings.h" |
| 8 | #include "ui_configure_hotkeys.h" | 9 | #include "ui_configure_hotkeys.h" |
| 10 | #include "yuzu/configuration/config.h" | ||
| 9 | #include "yuzu/configuration/configure_hotkeys.h" | 11 | #include "yuzu/configuration/configure_hotkeys.h" |
| 10 | #include "yuzu/hotkeys.h" | 12 | #include "yuzu/hotkeys.h" |
| 11 | #include "yuzu/util/sequence_dialog/sequence_dialog.h" | 13 | #include "yuzu/util/sequence_dialog/sequence_dialog.h" |
| @@ -19,6 +21,9 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) | |||
| 19 | model->setColumnCount(3); | 21 | model->setColumnCount(3); |
| 20 | 22 | ||
| 21 | connect(ui->hotkey_list, &QTreeView::doubleClicked, this, &ConfigureHotkeys::Configure); | 23 | connect(ui->hotkey_list, &QTreeView::doubleClicked, this, &ConfigureHotkeys::Configure); |
| 24 | connect(ui->hotkey_list, &QTreeView::customContextMenuRequested, this, | ||
| 25 | &ConfigureHotkeys::PopupContextMenu); | ||
| 26 | ui->hotkey_list->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 22 | ui->hotkey_list->setModel(model); | 27 | ui->hotkey_list->setModel(model); |
| 23 | 28 | ||
| 24 | // TODO(Kloen): Make context configurable as well (hiding the column for now) | 29 | // TODO(Kloen): Make context configurable as well (hiding the column for now) |
| @@ -27,6 +32,10 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) | |||
| 27 | ui->hotkey_list->setColumnWidth(0, 200); | 32 | ui->hotkey_list->setColumnWidth(0, 200); |
| 28 | ui->hotkey_list->resizeColumnToContents(1); | 33 | ui->hotkey_list->resizeColumnToContents(1); |
| 29 | 34 | ||
| 35 | connect(ui->button_restore_defaults, &QPushButton::clicked, this, | ||
| 36 | &ConfigureHotkeys::RestoreDefaults); | ||
| 37 | connect(ui->button_clear_all, &QPushButton::clicked, this, &ConfigureHotkeys::ClearAll); | ||
| 38 | |||
| 30 | RetranslateUI(); | 39 | RetranslateUI(); |
| 31 | } | 40 | } |
| 32 | 41 | ||
| @@ -71,7 +80,6 @@ void ConfigureHotkeys::Configure(QModelIndex index) { | |||
| 71 | } | 80 | } |
| 72 | 81 | ||
| 73 | index = index.sibling(index.row(), 1); | 82 | index = index.sibling(index.row(), 1); |
| 74 | auto* const model = ui->hotkey_list->model(); | ||
| 75 | const auto previous_key = model->data(index); | 83 | const auto previous_key = model->data(index); |
| 76 | 84 | ||
| 77 | SequenceDialog hotkey_dialog{this}; | 85 | SequenceDialog hotkey_dialog{this}; |
| @@ -81,31 +89,33 @@ void ConfigureHotkeys::Configure(QModelIndex index) { | |||
| 81 | if (return_code == QDialog::Rejected || key_sequence.isEmpty()) { | 89 | if (return_code == QDialog::Rejected || key_sequence.isEmpty()) { |
| 82 | return; | 90 | return; |
| 83 | } | 91 | } |
| 92 | const auto [key_sequence_used, used_action] = IsUsedKey(key_sequence); | ||
| 84 | 93 | ||
| 85 | if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) { | 94 | if (key_sequence_used && key_sequence != QKeySequence(previous_key.toString())) { |
| 86 | QMessageBox::warning(this, tr("Conflicting Key Sequence"), | 95 | QMessageBox::warning( |
| 87 | tr("The entered key sequence is already assigned to another hotkey.")); | 96 | this, tr("Conflicting Key Sequence"), |
| 97 | tr("The entered key sequence is already assigned to: %1").arg(used_action)); | ||
| 88 | } else { | 98 | } else { |
| 89 | model->setData(index, key_sequence.toString(QKeySequence::NativeText)); | 99 | model->setData(index, key_sequence.toString(QKeySequence::NativeText)); |
| 90 | } | 100 | } |
| 91 | } | 101 | } |
| 92 | 102 | ||
| 93 | bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { | 103 | std::pair<bool, QString> ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { |
| 94 | for (int r = 0; r < model->rowCount(); r++) { | 104 | for (int r = 0; r < model->rowCount(); ++r) { |
| 95 | const QStandardItem* const parent = model->item(r, 0); | 105 | const QStandardItem* const parent = model->item(r, 0); |
| 96 | 106 | ||
| 97 | for (int r2 = 0; r2 < parent->rowCount(); r2++) { | 107 | for (int r2 = 0; r2 < parent->rowCount(); ++r2) { |
| 98 | const QStandardItem* const key_seq_item = parent->child(r2, 1); | 108 | const QStandardItem* const key_seq_item = parent->child(r2, 1); |
| 99 | const auto key_seq_str = key_seq_item->text(); | 109 | const auto key_seq_str = key_seq_item->text(); |
| 100 | const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText); | 110 | const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText); |
| 101 | 111 | ||
| 102 | if (key_sequence == key_seq) { | 112 | if (key_sequence == key_seq) { |
| 103 | return true; | 113 | return std::make_pair(true, parent->child(r2, 0)->text()); |
| 104 | } | 114 | } |
| 105 | } | 115 | } |
| 106 | } | 116 | } |
| 107 | 117 | ||
| 108 | return false; | 118 | return std::make_pair(false, QString()); |
| 109 | } | 119 | } |
| 110 | 120 | ||
| 111 | void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) { | 121 | void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) { |
| @@ -128,3 +138,55 @@ void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) { | |||
| 128 | 138 | ||
| 129 | registry.SaveHotkeys(); | 139 | registry.SaveHotkeys(); |
| 130 | } | 140 | } |
| 141 | |||
| 142 | void ConfigureHotkeys::RestoreDefaults() { | ||
| 143 | for (int r = 0; r < model->rowCount(); ++r) { | ||
| 144 | const QStandardItem* parent = model->item(r, 0); | ||
| 145 | |||
| 146 | for (int r2 = 0; r2 < parent->rowCount(); ++r2) { | ||
| 147 | model->item(r, 0)->child(r2, 1)->setText(Config::default_hotkeys[r2].shortcut.first); | ||
| 148 | } | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | void ConfigureHotkeys::ClearAll() { | ||
| 153 | for (int r = 0; r < model->rowCount(); ++r) { | ||
| 154 | const QStandardItem* parent = model->item(r, 0); | ||
| 155 | |||
| 156 | for (int r2 = 0; r2 < parent->rowCount(); ++r2) { | ||
| 157 | model->item(r, 0)->child(r2, 1)->setText(tr("")); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | void ConfigureHotkeys::PopupContextMenu(const QPoint& menu_location) { | ||
| 163 | QModelIndex index = ui->hotkey_list->indexAt(menu_location); | ||
| 164 | if (!index.parent().isValid()) { | ||
| 165 | return; | ||
| 166 | } | ||
| 167 | |||
| 168 | const auto selected = index.sibling(index.row(), 1); | ||
| 169 | QMenu context_menu; | ||
| 170 | |||
| 171 | QAction* restore_default = context_menu.addAction(tr("Restore Default")); | ||
| 172 | QAction* clear = context_menu.addAction(tr("Clear")); | ||
| 173 | |||
| 174 | connect(restore_default, &QAction::triggered, [this, selected] { | ||
| 175 | const QKeySequence& default_key_sequence = QKeySequence::fromString( | ||
| 176 | Config::default_hotkeys[selected.row()].shortcut.first, QKeySequence::NativeText); | ||
| 177 | const auto [key_sequence_used, used_action] = IsUsedKey(default_key_sequence); | ||
| 178 | |||
| 179 | if (key_sequence_used && | ||
| 180 | default_key_sequence != QKeySequence(model->data(selected).toString())) { | ||
| 181 | |||
| 182 | QMessageBox::warning( | ||
| 183 | this, tr("Conflicting Key Sequence"), | ||
| 184 | tr("The default key sequence is already assigned to: %1").arg(used_action)); | ||
| 185 | } else { | ||
| 186 | model->setData(selected, default_key_sequence.toString(QKeySequence::NativeText)); | ||
| 187 | } | ||
| 188 | }); | ||
| 189 | connect(clear, &QAction::triggered, [this, selected] { model->setData(selected, tr("")); }); | ||
| 190 | |||
| 191 | context_menu.exec(ui->hotkey_list->viewport()->mapToGlobal(menu_location)); | ||
| 192 | } | ||
diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h index 8f8c6173b..a2ec3323e 100644 --- a/src/yuzu/configuration/configure_hotkeys.h +++ b/src/yuzu/configuration/configure_hotkeys.h | |||
| @@ -35,7 +35,11 @@ private: | |||
| 35 | void RetranslateUI(); | 35 | void RetranslateUI(); |
| 36 | 36 | ||
| 37 | void Configure(QModelIndex index); | 37 | void Configure(QModelIndex index); |
| 38 | bool IsUsedKey(QKeySequence key_sequence) const; | 38 | std::pair<bool, QString> IsUsedKey(QKeySequence key_sequence) const; |
| 39 | |||
| 40 | void RestoreDefaults(); | ||
| 41 | void ClearAll(); | ||
| 42 | void PopupContextMenu(const QPoint& menu_location); | ||
| 39 | 43 | ||
| 40 | std::unique_ptr<Ui::ConfigureHotkeys> ui; | 44 | std::unique_ptr<Ui::ConfigureHotkeys> ui; |
| 41 | 45 | ||
diff --git a/src/yuzu/configuration/configure_hotkeys.ui b/src/yuzu/configuration/configure_hotkeys.ui index 0d0b70f38..6d9f861e3 100644 --- a/src/yuzu/configuration/configure_hotkeys.ui +++ b/src/yuzu/configuration/configure_hotkeys.ui | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>363</width> | 9 | <width>439</width> |
| 10 | <height>388</height> | 10 | <height>510</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
| @@ -15,7 +15,7 @@ | |||
| 15 | </property> | 15 | </property> |
| 16 | <layout class="QVBoxLayout" name="verticalLayout"> | 16 | <layout class="QVBoxLayout" name="verticalLayout"> |
| 17 | <item> | 17 | <item> |
| 18 | <layout class="QVBoxLayout" name="verticalLayout_2"> | 18 | <layout class="QHBoxLayout" name="horizontalLayout"> |
| 19 | <item> | 19 | <item> |
| 20 | <widget class="QLabel" name="label_2"> | 20 | <widget class="QLabel" name="label_2"> |
| 21 | <property name="text"> | 21 | <property name="text"> |
| @@ -24,6 +24,37 @@ | |||
| 24 | </widget> | 24 | </widget> |
| 25 | </item> | 25 | </item> |
| 26 | <item> | 26 | <item> |
| 27 | <spacer name="horizontalSpacer"> | ||
| 28 | <property name="orientation"> | ||
| 29 | <enum>Qt::Horizontal</enum> | ||
| 30 | </property> | ||
| 31 | <property name="sizeHint" stdset="0"> | ||
| 32 | <size> | ||
| 33 | <width>40</width> | ||
| 34 | <height>20</height> | ||
| 35 | </size> | ||
| 36 | </property> | ||
| 37 | </spacer> | ||
| 38 | </item> | ||
| 39 | <item> | ||
| 40 | <widget class="QPushButton" name="button_clear_all"> | ||
| 41 | <property name="text"> | ||
| 42 | <string>Clear All</string> | ||
| 43 | </property> | ||
| 44 | </widget> | ||
| 45 | </item> | ||
| 46 | <item> | ||
| 47 | <widget class="QPushButton" name="button_restore_defaults"> | ||
| 48 | <property name="text"> | ||
| 49 | <string>Restore Defaults</string> | ||
| 50 | </property> | ||
| 51 | </widget> | ||
| 52 | </item> | ||
| 53 | </layout> | ||
| 54 | </item> | ||
| 55 | <item> | ||
| 56 | <layout class="QVBoxLayout" name="verticalLayout_2"> | ||
| 57 | <item> | ||
| 27 | <widget class="QTreeView" name="hotkey_list"> | 58 | <widget class="QTreeView" name="hotkey_list"> |
| 28 | <property name="editTriggers"> | 59 | <property name="editTriggers"> |
| 29 | <set>QAbstractItemView::NoEditTriggers</set> | 60 | <set>QAbstractItemView::NoEditTriggers</set> |
| @@ -39,4 +70,4 @@ | |||
| 39 | </widget> | 70 | </widget> |
| 40 | <resources/> | 71 | <resources/> |
| 41 | <connections/> | 72 | <connections/> |
| 42 | </ui> \ No newline at end of file | 73 | </ui> |