From 5fa25fcf132f33238d6162d276607669527191dc Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Tue, 22 May 2018 21:30:36 +0200 Subject: [PATCH 1/7] citra-qt: Add base support for hotkey reconfiguration + UI (whole of PR citra-emu/citra#3786) * Adds a new Hotkeys tab in the Controls group. * Right click to reconfigure. * See the original PR for more details & screenshots. --- src/citra_qt/CMakeLists.txt | 8 +- src/citra_qt/configuration/config.cpp | 62 ++++-- src/citra_qt/configuration/configure.ui | 11 ++ .../configuration/configure_dialog.cpp | 30 ++- src/citra_qt/configuration/configure_dialog.h | 3 +- .../configuration/configure_general.cpp | 5 - .../configuration/configure_general.h | 1 - .../configuration/configure_general.ui | 176 +++++++----------- .../configuration/configure_hotkeys.cpp | 130 +++++++++++++ .../configuration/configure_hotkeys.h | 48 +++++ .../configuration/configure_hotkeys.ui | 35 ++++ .../configuration/configure_input.cpp | 41 +++- src/citra_qt/configuration/configure_input.h | 17 ++ src/citra_qt/hotkeys.cpp | 77 +++----- src/citra_qt/hotkeys.h | 42 ++--- src/citra_qt/hotkeys.ui | 46 ----- src/citra_qt/main.cpp | 64 +++---- src/citra_qt/main.h | 2 +- src/citra_qt/ui_settings.cpp | 1 - src/citra_qt/ui_settings.h | 7 +- .../util/sequence_dialog/sequence_dialog.cpp | 35 ++++ .../util/sequence_dialog/sequence_dialog.h | 24 +++ 22 files changed, 559 insertions(+), 306 deletions(-) create mode 100644 src/citra_qt/configuration/configure_hotkeys.cpp create mode 100644 src/citra_qt/configuration/configure_hotkeys.h create mode 100644 src/citra_qt/configuration/configure_hotkeys.ui delete mode 100644 src/citra_qt/hotkeys.ui create mode 100644 src/citra_qt/util/sequence_dialog/sequence_dialog.cpp create mode 100644 src/citra_qt/util/sequence_dialog/sequence_dialog.h diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 9eab29b3e..0cc4d1c68 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -41,6 +41,8 @@ add_executable(citra-qt configuration/configure_general.h configuration/configure_graphics.cpp configuration/configure_graphics.h + configuration/configure_hotkeys.cpp + configuration/configure_hotkeys.h configuration/configure_input.cpp configuration/configure_input.h configuration/configure_motion_touch.cpp @@ -109,8 +111,10 @@ add_executable(citra-qt updater/updater.cpp updater/updater.h updater/updater_p.h - util/clickable_label.h util/clickable_label.cpp + util/clickable_label.h + util/sequence_dialog/sequence_dialog.cpp + util/sequence_dialog/sequence_dialog.h util/spinbox.cpp util/spinbox.h util/util.cpp @@ -126,6 +130,7 @@ set(UIS configuration/configure_debug.ui configuration/configure_general.ui configuration/configure_graphics.ui + configuration/configure_hotkeys.ui configuration/configure_input.ui configuration/configure_motion_touch.ui configuration/configure_system.ui @@ -140,7 +145,6 @@ set(UIS multiplayer/moderation_dialog.ui aboutdialog.ui cheats.ui - hotkeys.ui main.ui compatdb.ui ) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 19e94715c..878defdda 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -3,7 +3,9 @@ // Refer to the license.txt file included. #include +#include #include +#include #include #include "citra_qt/configuration/config.h" #include "citra_qt/ui_settings.h" @@ -318,20 +320,46 @@ void Config::ReadValues() { qt_config->endGroup(); qt_config->beginGroup("Shortcuts"); - QStringList groups = qt_config->childGroups(); - for (auto group : groups) { - qt_config->beginGroup(group); - - QStringList hotkeys = qt_config->childGroups(); - for (auto hotkey : hotkeys) { - qt_config->beginGroup(hotkey); - UISettings::values.shortcuts.emplace_back(UISettings::Shortcut( - group + "/" + hotkey, - UISettings::ContextualShortcut(ReadSetting("KeySeq").toString(), - ReadSetting("Context").toInt()))); - qt_config->endGroup(); - } + const std::array default_hotkeys{ + {{"Load File", "Main Window", + UISettings::ContextualShortcut(QKeySequence(QKeySequence::Open).toString(), + Qt::WindowShortcut)}, + {"Exit Citra", "Main Window", + UISettings::ContextualShortcut("Ctrl+Q", Qt::WindowShortcut)}, + {"Continue/Pause Emulation", "Main Window", + UISettings::ContextualShortcut("F4", Qt::WindowShortcut)}, + {"Stop Emulation", "Main Window", + UISettings::ContextualShortcut("F5", Qt::WindowShortcut)}, + {"Restart Emulation", "Main Window", + UISettings::ContextualShortcut("F6", Qt::WindowShortcut)}, + {"Swap Screens", "Main Window", UISettings::ContextualShortcut("F9", Qt::WindowShortcut)}, + {"Toggle Screen Layout", "Main Window", + UISettings::ContextualShortcut("F10", Qt::WindowShortcut)}, + {"Toggle Filter Bar", "Main Window", + UISettings::ContextualShortcut("Ctrl+F", Qt::WindowShortcut)}, + {"Toggle Status Bar", "Main Window", + UISettings::ContextualShortcut("Ctrl+S", Qt::WindowShortcut)}, + {"Fullscreen", "Main Window", + UISettings::ContextualShortcut(QKeySequence(QKeySequence::FullScreen).toString(), + Qt::WindowShortcut)}, + {"Exit Fullscreen", "Main Window", + UISettings::ContextualShortcut("Escape", Qt::WindowShortcut)}, + {"Toggle Speed Limit", "Main Window", + UISettings::ContextualShortcut("Ctrl+Z", Qt::ApplicationShortcut)}, + {"Increase Speed Limit", "Main Window", + UISettings::ContextualShortcut("+", Qt::ApplicationShortcut)}, + {"Decrease Speed Limit", "Main Window", + UISettings::ContextualShortcut("-", Qt::ApplicationShortcut)}}}; + for (int i = 0; i < default_hotkeys.size(); i++) { + qt_config->beginGroup(default_hotkeys[i].group); + qt_config->beginGroup(default_hotkeys[i].name); + UISettings::values.shortcuts.push_back( + {default_hotkeys[i].name, default_hotkeys[i].group, + UISettings::ContextualShortcut( + qt_config->value("KeySeq", default_hotkeys[i].shortcut.first).toString(), + qt_config->value("Context", default_hotkeys[i].shortcut.second).toInt())}); + qt_config->endGroup(); qt_config->endGroup(); } qt_config->endGroup(); @@ -564,8 +592,12 @@ void Config::SaveValues() { qt_config->beginGroup("Shortcuts"); for (auto shortcut : UISettings::values.shortcuts) { - WriteSetting(shortcut.first + "/KeySeq", shortcut.second.first); - WriteSetting(shortcut.first + "/Context", shortcut.second.second); + qt_config->beginGroup(shortcut.group); + qt_config->beginGroup(shortcut.name); + WriteSetting("KeySeq", shortcut.shortcut.first); + WriteSetting("Context", shortcut.shortcut.second); + qt_config->endGroup(); + qt_config->endGroup(); } qt_config->endGroup(); diff --git a/src/citra_qt/configuration/configure.ui b/src/citra_qt/configuration/configure.ui index 70796a035..8b625d8c3 100644 --- a/src/citra_qt/configuration/configure.ui +++ b/src/citra_qt/configuration/configure.ui @@ -38,6 +38,11 @@ Input + + + Hotkeys + + Graphics @@ -118,6 +123,12 @@
configuration/configure_input.h
1 + + ConfigureHotkeys + QWidget +
configuration/configure_hotkeys.h
+ 1 +
ConfigureGraphics QWidget diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index 3527b8589..a62082229 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -13,15 +13,25 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry) : QDialog(parent), ui(new Ui::ConfigureDialog) { ui->setupUi(this); - ui->generalTab->PopulateHotkeyList(registry); + ui->hotkeysTab->Populate(registry); + this->PopulateSelectionList(); connect(ui->uiTab, &ConfigureUi::languageChanged, this, &ConfigureDialog::onLanguageChanged); connect(ui->selectorList, &QListWidget::itemSelectionChanged, this, &ConfigureDialog::UpdateVisibleTabs); - adjustSize(); - ui->selectorList->setCurrentRow(0); + + connect(ui->inputTab, &ConfigureInput::InputKeysChanged, ui->hotkeysTab, + &ConfigureHotkeys::OnInputKeysChanged); + connect(ui->hotkeysTab, &ConfigureHotkeys::HotkeysChanged, ui->inputTab, + &ConfigureInput::OnHotkeysChanged); + connect(ui->hotkeysTab, &ConfigureHotkeys::HotkeysChanged, this, + [this]() { emit UpdateHotkeys(); }); + + // Synchronise lists upon initialisation + ui->inputTab->EmitInputKeysChanged(); + ui->hotkeysTab->EmitHotkeysChanged(); } ConfigureDialog::~ConfigureDialog() = default; @@ -38,11 +48,12 @@ void ConfigureDialog::setConfiguration() { ui->uiTab->setConfiguration(); } -void ConfigureDialog::applyConfiguration() { +void ConfigureDialog::applyConfiguration(HotkeyRegistry& registry) { ui->generalTab->applyConfiguration(); ui->systemTab->applyConfiguration(); ui->inputTab->applyConfiguration(); ui->inputTab->ApplyProfile(); + ui->hotkeysTab->applyConfiguration(registry); ui->graphicsTab->applyConfiguration(); ui->audioTab->applyConfiguration(); ui->cameraTab->applyConfiguration(); @@ -61,7 +72,7 @@ void ConfigureDialog::PopulateSelectionList() { {QT_TR_NOOP("General"), QT_TR_NOOP("Web"), QT_TR_NOOP("Debug"), QT_TR_NOOP("UI")}}, {tr("System"), {QT_TR_NOOP("System"), QT_TR_NOOP("Audio"), QT_TR_NOOP("Camera")}}, {tr("Graphics"), {QT_TR_NOOP("Graphics")}}, - {tr("Controls"), {QT_TR_NOOP("Input")}}}}; + {tr("Controls"), {QT_TR_NOOP("Input"), QT_TR_NOOP("Hotkeys")}}}}; for (const auto& entry : items) { auto* item = new QListWidgetItem(entry.first); @@ -91,6 +102,7 @@ void ConfigureDialog::retranslateUi() { ui->generalTab->retranslateUi(); ui->systemTab->retranslateUi(); ui->inputTab->retranslateUi(); + ui->hotkeysTab->retranslateUi(); ui->graphicsTab->retranslateUi(); ui->audioTab->retranslateUi(); ui->cameraTab->retranslateUi(); @@ -105,9 +117,11 @@ void ConfigureDialog::UpdateVisibleTabs() { return; const QHash widgets = { - {"General", ui->generalTab}, {"System", ui->systemTab}, {"Input", ui->inputTab}, - {"Graphics", ui->graphicsTab}, {"Audio", ui->audioTab}, {"Camera", ui->cameraTab}, - {"Debug", ui->debugTab}, {"Web", ui->webTab}, {"UI", ui->uiTab}}; + {tr("General"), ui->generalTab}, {tr("System"), ui->systemTab}, + {tr("Input"), ui->inputTab}, {tr("Hotkeys"), ui->hotkeysTab}, + {tr("Graphics"), ui->graphicsTab}, {tr("Audio"), ui->audioTab}, + {tr("Camera"), ui->cameraTab}, {tr("Debug"), ui->debugTab}, + {tr("Web"), ui->webTab}, {tr("UI"), ui->uiTab}}; ui->tabWidget->clear(); diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index b60b4207b..c10572692 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -20,15 +20,16 @@ public: explicit ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry); ~ConfigureDialog() override; - void applyConfiguration(); void UpdateVisibleTabs(); void PopulateSelectionList(); + void applyConfiguration(HotkeyRegistry& registry); private slots: void onLanguageChanged(const QString& locale); signals: void languageChanged(const QString& locale); + void UpdateHotkeys(); private: void setConfiguration(); diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index cd47b135e..98cd8f97f 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -32,10 +32,6 @@ void ConfigureGeneral::setConfiguration() { ui->region_combobox->setCurrentIndex(Settings::values.region_value + 1); } -void ConfigureGeneral::PopulateHotkeyList(const HotkeyRegistry& registry) { - ui->hotkeysDialog->Populate(registry); -} - void ConfigureGeneral::ResetDefaults() { QMessageBox::StandardButton answer = QMessageBox::question( this, tr("Citra"), @@ -60,5 +56,4 @@ void ConfigureGeneral::applyConfiguration() { void ConfigureGeneral::retranslateUi() { ui->retranslateUi(this); - ui->hotkeysDialog->retranslateUi(); } diff --git a/src/citra_qt/configuration/configure_general.h b/src/citra_qt/configuration/configure_general.h index 9f518155b..f7b2209b0 100644 --- a/src/citra_qt/configuration/configure_general.h +++ b/src/citra_qt/configuration/configure_general.h @@ -20,7 +20,6 @@ public: explicit ConfigureGeneral(QWidget* parent = nullptr); ~ConfigureGeneral() override; - void PopulateHotkeyList(const HotkeyRegistry& registry); void ResetDefaults(); void applyConfiguration(); void retranslateUi(); diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 5979dd95b..3879e6b77 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -7,7 +7,7 @@ 0 0 345 - 504 + 357 @@ -21,17 +21,13 @@ General - + - - - - - Confirm exit while emulation is running - - - - + + + Confirm exit while emulation is running + +
@@ -41,24 +37,20 @@ Updates - + - - - - - Check for updates on start - - - - - - - Silently auto update after closing - - - - + + + Check for updates on start + + + + + + + Silently auto update after closing + + @@ -68,81 +60,57 @@ Emulation - - - - - - - - - Region: - - - - - - - - Auto-select - - - - - JPN - - - - - USA - - - - - EUR - - - - - AUS - - - - - CHN - - - - - KOR - - - - - TWN - - - - - - - + + + + + Region: + + - - - - - - - Hotkeys - - - - + + - + + Auto-select + - + + + JPN + + + + + USA + + + + + EUR + + + + + AUS + + + + + CHN + + + + + KOR + + + + + TWN + + + @@ -158,14 +126,6 @@ - - - GHotkeysDialog - QWidget -
hotkeys.h
- 1 -
-
diff --git a/src/citra_qt/configuration/configure_hotkeys.cpp b/src/citra_qt/configuration/configure_hotkeys.cpp new file mode 100644 index 000000000..1d961c5f0 --- /dev/null +++ b/src/citra_qt/configuration/configure_hotkeys.cpp @@ -0,0 +1,130 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include "citra_qt/configuration/configure_hotkeys.h" +#include "citra_qt/hotkeys.h" +#include "citra_qt/util/sequence_dialog/sequence_dialog.h" +#include "core/settings.h" +#include "ui_configure_hotkeys.h" + +ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) + : QWidget(parent), ui(std::make_unique()) { + ui->setupUi(this); + setFocusPolicy(Qt::ClickFocus); + + model = new QStandardItemModel(this); + model->setColumnCount(3); + model->setHorizontalHeaderLabels({tr("Action"), tr("Hotkey"), tr("Context")}); + + ui->hotkey_list->setSelectionMode(QTreeView::SingleSelection); + connect(ui->hotkey_list, &QTreeView::doubleClicked, this, &ConfigureHotkeys::Configure); + ui->hotkey_list->setModel(model); + + // TODO(Kloen): Make context configurable as well (hiding the column for now) + ui->hotkey_list->hideColumn(2); + + ui->hotkey_list->setColumnWidth(0, 200); + ui->hotkey_list->resizeColumnToContents(1); + ui->hotkey_list->setEditTriggers(QTreeView::NoEditTriggers); +} + +ConfigureHotkeys::~ConfigureHotkeys() {} + +void ConfigureHotkeys::EmitHotkeysChanged() { + emit HotkeysChanged(GetUsedKeyList()); +} + +QList ConfigureHotkeys::GetUsedKeyList() { + QList list; + for (int r = 0; r < model->rowCount(); r++) { + QStandardItem* parent = model->item(r, 0); + for (int r2 = 0; r2 < parent->rowCount(); r2++) { + QStandardItem* keyseq = parent->child(r2, 1); + list << QKeySequence::fromString(keyseq->text(), QKeySequence::NativeText); + } + } + return list; +} + +void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) { + for (const auto& group : registry.hotkey_groups) { + QStandardItem* parent_item = new QStandardItem(group.first); + parent_item->setEditable(false); + for (const auto& hotkey : group.second) { + QStandardItem* action = new QStandardItem(hotkey.first); + QStandardItem* keyseq = + new QStandardItem(hotkey.second.keyseq.toString(QKeySequence::NativeText)); + action->setEditable(false); + keyseq->setEditable(false); + parent_item->appendRow({action, keyseq}); + } + model->appendRow(parent_item); + } + + ui->hotkey_list->expandAll(); +} + +void ConfigureHotkeys::OnInputKeysChanged(QList new_key_list) { + input_keys_list = new_key_list; +} + +void ConfigureHotkeys::Configure(QModelIndex index) { + if (index.parent() == QModelIndex()) + return; + + index = index.sibling(index.row(), 1); + auto* model = ui->hotkey_list->model(); + auto previous_key = model->data(index); + + auto* hotkey_dialog = new SequenceDialog; + int return_code = hotkey_dialog->exec(); + + auto key_sequence = hotkey_dialog->GetSequence(); + + if (return_code == QDialog::Rejected || key_sequence.isEmpty()) + return; + + if (IsUsedKey(key_sequence) && + key_sequence != QKeySequence(previous_key.toString(), QKeySequence::NativeText)) { + model->setData(index, previous_key); + QMessageBox::critical(this, tr("Error in inputted key"), + tr("You're using a key that's already bound.")); + } else { + model->setData(index, key_sequence.toString(QKeySequence::NativeText)); + EmitHotkeysChanged(); + } +} + +bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) { + return input_keys_list.contains(key_sequence) || GetUsedKeyList().contains(key_sequence); +} + +void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) { + for (int key_id = 0; key_id < model->rowCount(); key_id++) { + QStandardItem* parent = model->item(key_id, 0); + for (int key_column_id = 0; key_column_id < parent->rowCount(); key_column_id++) { + QStandardItem* action = parent->child(key_column_id, 0); + QStandardItem* keyseq = parent->child(key_column_id, 1); + for (auto key_iterator = registry.hotkey_groups.begin(); + key_iterator != registry.hotkey_groups.end(); ++key_iterator) { + if (key_iterator->first == parent->text()) { + for (auto it2 = key_iterator->second.begin(); it2 != key_iterator->second.end(); + ++it2) { + if (it2->first == action->text()) { + it2->second.keyseq = QKeySequence(keyseq->text()); + } + } + } + } + } + } + + registry.SaveHotkeys(); + Settings::Apply(); +} + +void ConfigureHotkeys::retranslateUi() { + ui->retranslateUi(this); +} diff --git a/src/citra_qt/configuration/configure_hotkeys.h b/src/citra_qt/configuration/configure_hotkeys.h new file mode 100644 index 000000000..431d53fb2 --- /dev/null +++ b/src/citra_qt/configuration/configure_hotkeys.h @@ -0,0 +1,48 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include "common/param_package.h" +#include "core/settings.h" + +namespace Ui { +class ConfigureHotkeys; +} + +class HotkeyRegistry; + +class ConfigureHotkeys : public QWidget { + Q_OBJECT + +public: + explicit ConfigureHotkeys(QWidget* parent = nullptr); + ~ConfigureHotkeys(); + + void applyConfiguration(HotkeyRegistry& registry); + void retranslateUi(); + + void EmitHotkeysChanged(); + + void Populate(const HotkeyRegistry& registry); + +public slots: + void OnInputKeysChanged(QList new_key_list); + +signals: + void HotkeysChanged(QList new_key_list); + +private: + void Configure(QModelIndex index); + bool IsUsedKey(QKeySequence key_sequence); + QList GetUsedKeyList(); + + std::unique_ptr ui; + + QList input_keys_list; + QStandardItemModel* model; +}; diff --git a/src/citra_qt/configuration/configure_hotkeys.ui b/src/citra_qt/configuration/configure_hotkeys.ui new file mode 100644 index 000000000..d6ca3c47b --- /dev/null +++ b/src/citra_qt/configuration/configure_hotkeys.ui @@ -0,0 +1,35 @@ + + + ConfigureHotkeys + + + + 0 + 0 + 363 + 388 + + + + Hotkey Settings + + + + + + + + Double-click on a binding to change it. + + + + + + + + + + + + + diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index c0df64bc9..f6f90385c 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -276,6 +276,30 @@ void ConfigureInput::ApplyProfile() { Settings::values.current_input_profile_index = ui->profile->currentIndex(); } +void ConfigureInput::EmitInputKeysChanged() { + emit InputKeysChanged(GetUsedKeyboardKeys()); +} + +void ConfigureInput::OnHotkeysChanged(QList new_key_list) { + hotkey_list = new_key_list; +} + +QList ConfigureInput::GetUsedKeyboardKeys() { + QList list; + for (int button = 0; button < Settings::NativeButton::NumButtons; button++) { + auto button_param = buttons_param[button]; + + if (button_param.Get("engine", "") == "keyboard") { + list << QKeySequence(button_param.Get("code", 0)); + } + } + + // TODO(adityaruplaha): Add home button to list when we finally emulate it + // Button ID of home button is 14: Reffered from citra_qt/configuration/config.cpp + list.removeOne(list.indexOf(QKeySequence(buttons_param[14].Get("code", 0)))); + return list; +} + void ConfigureInput::loadConfiguration() { std::transform(Settings::values.current_input_profile.buttons.begin(), Settings::values.current_input_profile.buttons.end(), buttons_param.begin(), @@ -332,11 +356,14 @@ void ConfigureInput::updateButtonLabels() { } analog_map_stick[analog_id]->setText(tr("Set Analog Stick")); } + + EmitInputKeysChanged(); } void ConfigureInput::handleClick(QPushButton* button, std::function new_input_setter, InputCommon::Polling::DeviceType type) { + previous_key_code = QKeySequence(button->text())[0]; button->setText(tr("[press key]")); button->setFocus(); @@ -378,16 +405,26 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) { if (!input_setter || !event) return; - if (event->key() != Qt::Key_Escape) { + if (event->key() != Qt::Key_Escape && event->key() != previous_key_code) { if (want_keyboard_keys) { + // Check if key is already bound + if (hotkey_list.contains(QKeySequence(event->key())) || + GetUsedKeyboardKeys().contains(QKeySequence(event->key()))) { + setPollingResult({}, true); + QMessageBox::critical(this, tr("Error!"), + tr("You're using a key that's already bound.")); + return; + } setPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())}, false); } else { - // Escape key wasn't pressed and we don't want any keyboard keys, so don't stop polling + // Escape key wasn't pressed and we don't want any keyboard keys, so don't stop + // polling return; } } setPollingResult({}, true); + previous_key_code = 0; } void ConfigureInput::retranslateUi() { diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h index 1e55fd272..410415990 100644 --- a/src/citra_qt/configuration/configure_input.h +++ b/src/citra_qt/configuration/configure_input.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "common/param_package.h" #include "core/settings.h" @@ -38,6 +39,13 @@ public: /// Load configuration settings. void loadConfiguration(); + void EmitInputKeysChanged(); + +public slots: + void OnHotkeysChanged(QList new_key_list); + +signals: + void InputKeysChanged(QList new_key_list); // Save the current input profile index void ApplyProfile(); @@ -72,10 +80,16 @@ private: std::vector> device_pollers; + /// Keys currently registered as hotkeys + QList hotkey_list; + /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, /// keyboard events are ignored. bool want_keyboard_keys = false; + /// Generates list of all used keys + QList GetUsedKeyboardKeys(); + /// Restore all buttons to their default values. void restoreDefaults(); /// Clear all input configuration @@ -89,6 +103,9 @@ private: std::function new_input_setter, InputCommon::Polling::DeviceType type); + /// The key code of the previous state of the key being currently bound. + int previous_key_code; + /// Finish polling and configure input using the input_setter void setPollingResult(const Common::ParamPackage& params, bool abort); diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp index 5c74f694f..b4038ba54 100644 --- a/src/citra_qt/hotkeys.cpp +++ b/src/citra_qt/hotkeys.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include #include #include #include @@ -12,47 +11,30 @@ HotkeyRegistry::HotkeyRegistry() = default; HotkeyRegistry::~HotkeyRegistry() = default; -void HotkeyRegistry::LoadHotkeys() { - // Make sure NOT to use a reference here because it would become invalid once we call - // beginGroup() - for (auto shortcut : UISettings::values.shortcuts) { - const QStringList cat = shortcut.first.split('/'); - Q_ASSERT(cat.size() >= 2); - - // RegisterHotkey assigns default keybindings, so use old values as default parameters - Hotkey& hk = hotkey_groups[cat[0]][cat[1]]; - if (!shortcut.second.first.isEmpty()) { - hk.keyseq = QKeySequence::fromString(shortcut.second.first); - hk.context = static_cast(shortcut.second.second); - } - if (hk.shortcut) - hk.shortcut->setKey(hk.keyseq); - } -} - void HotkeyRegistry::SaveHotkeys() { UISettings::values.shortcuts.clear(); for (const auto& group : hotkey_groups) { for (const auto& hotkey : group.second) { - UISettings::values.shortcuts.emplace_back( - UISettings::Shortcut(group.first + '/' + hotkey.first, - UISettings::ContextualShortcut(hotkey.second.keyseq.toString(), - hotkey.second.context))); + UISettings::values.shortcuts.push_back( + {hotkey.first, group.first, + UISettings::ContextualShortcut(hotkey.second.keyseq.toString(), + hotkey.second.context)}); } } } -void HotkeyRegistry::RegisterHotkey(const QString& group, const QString& action, - const QKeySequence& default_keyseq, - Qt::ShortcutContext default_context) { - auto& hotkey_group = hotkey_groups[group]; - if (hotkey_group.find(action) != hotkey_group.end()) { - return; +void HotkeyRegistry::LoadHotkeys() { + // Make sure NOT to use a reference here because it would become invalid once we call + // beginGroup() + for (auto shortcut : UISettings::values.shortcuts) { + Hotkey& hk = hotkey_groups[shortcut.group][shortcut.name]; + if (!shortcut.shortcut.first.isEmpty()) { + hk.keyseq = QKeySequence::fromString(shortcut.shortcut.first, QKeySequence::NativeText); + hk.context = (Qt::ShortcutContext)shortcut.shortcut.second; + } + if (hk.shortcut) + hk.shortcut->setKey(hk.keyseq); } - - auto& hotkey_action = hotkey_groups[group][action]; - hotkey_action.keyseq = default_keyseq; - hotkey_action.context = default_context; } QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action, QWidget* widget) { @@ -64,28 +46,13 @@ QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action return hk.shortcut; } -GHotkeysDialog::GHotkeysDialog(QWidget* parent) : QWidget(parent) { - ui.setupUi(this); +QKeySequence HotkeyRegistry::GetKeySequence(const QString& group, const QString& action) { + Hotkey& hk = hotkey_groups[group][action]; + return hk.keyseq; } -void GHotkeysDialog::Populate(const HotkeyRegistry& registry) { - for (const auto& group : registry.hotkey_groups) { - QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first)); - for (const auto& hotkey : group.second) { - QStringList columns; - columns << hotkey.first << hotkey.second.keyseq.toString(); - QTreeWidgetItem* item = new QTreeWidgetItem(columns); - toplevel_item->addChild(item); - } - ui.treeWidget->addTopLevelItem(toplevel_item); - } - // TODO: Make context configurable as well (hiding the column for now) - ui.treeWidget->setColumnCount(2); - - ui.treeWidget->resizeColumnToContents(0); - ui.treeWidget->resizeColumnToContents(1); -} - -void GHotkeysDialog::retranslateUi() { - ui.retranslateUi(this); +Qt::ShortcutContext HotkeyRegistry::GetShortcutContext(const QString& group, + const QString& action) { + Hotkey& hk = hotkey_groups[group][action]; + return hk.context; } diff --git a/src/citra_qt/hotkeys.h b/src/citra_qt/hotkeys.h index 045cb98c6..e8fed0ca6 100644 --- a/src/citra_qt/hotkeys.h +++ b/src/citra_qt/hotkeys.h @@ -5,7 +5,6 @@ #pragma once #include -#include "ui_hotkeys.h" class QDialog; class QKeySequence; @@ -14,7 +13,7 @@ class QShortcut; class HotkeyRegistry final { public: - friend class GHotkeysDialog; + friend class ConfigureHotkeys; explicit HotkeyRegistry(); ~HotkeyRegistry(); @@ -49,22 +48,26 @@ public: QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget); /** - * Register a hotkey. + * Returns a QKeySequence object who signal can be connected to QAction->SetShortcut. * - * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger") - * @param action Name of the action (e.g. "Start Emulation", "Load Image") - * @param default_keyseq Default key sequence to assign if the hotkey wasn't present in the - * settings file before - * @param default_context Default context to assign if the hotkey wasn't present in the settings - * file before - * @warning Both the group and action strings will be displayed in the hotkey settings dialog + * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger"). + * @param action Name of the action (e.g. "Start Emulation", "Load Image"). */ - void RegisterHotkey(const QString& group, const QString& action, - const QKeySequence& default_keyseq = {}, - Qt::ShortcutContext default_context = Qt::WindowShortcut); + QKeySequence GetKeySequence(const QString& group, const QString& action); + + /** + * Returns a Qt::ShortcutContext object who can be connected to other + * QAction->SetShortcutContext. + * + * @param group General group this shortcutcontext belongs to (e.g. "Main Window", "Debugger"). + * @param action Name of the action (e.g. "Start Emulation", "Load Image"). + */ + Qt::ShortcutContext GetShortcutContext(const QString& group, const QString& action); private: struct Hotkey { + Hotkey() : shortcut(nullptr), context(Qt::WindowShortcut) {} + QKeySequence keyseq; QShortcut* shortcut = nullptr; Qt::ShortcutContext context = Qt::WindowShortcut; @@ -75,16 +78,3 @@ private: HotkeyGroupMap hotkey_groups; }; - -class GHotkeysDialog : public QWidget { - Q_OBJECT - -public: - explicit GHotkeysDialog(QWidget* parent = nullptr); - void retranslateUi(); - - void Populate(const HotkeyRegistry& registry); - -private: - Ui::hotkeys ui; -}; diff --git a/src/citra_qt/hotkeys.ui b/src/citra_qt/hotkeys.ui deleted file mode 100644 index 050fe064e..000000000 --- a/src/citra_qt/hotkeys.ui +++ /dev/null @@ -1,46 +0,0 @@ - - - hotkeys - - - - 0 - 0 - 363 - 388 - - - - Hotkey Settings - - - - - - QAbstractItemView::SelectItems - - - false - - - - Action - - - - - Hotkey - - - - - Context - - - - - - - - - diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index a62e23260..dff565b38 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -344,40 +344,35 @@ void GMainWindow::InitializeRecentFileMenuActions() { } void GMainWindow::InitializeHotkeys() { - hotkey_registry.RegisterHotkey("Main Window", "Load File", QKeySequence::Open); - hotkey_registry.RegisterHotkey("Main Window", "Start Emulation"); - hotkey_registry.RegisterHotkey("Main Window", "Continue/Pause", QKeySequence(Qt::Key_F4)); - hotkey_registry.RegisterHotkey("Main Window", "Restart", QKeySequence(Qt::Key_F5)); - hotkey_registry.RegisterHotkey("Main Window", "Swap Screens", QKeySequence(Qt::Key_F9)); - hotkey_registry.RegisterHotkey("Main Window", "Toggle Screen Layout", - QKeySequence(Qt::Key_F10)); - hotkey_registry.RegisterHotkey("Main Window", "Fullscreen", QKeySequence::FullScreen); - hotkey_registry.RegisterHotkey("Main Window", "Exit Fullscreen", QKeySequence(Qt::Key_Escape), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Increase Speed Limit", QKeySequence("+"), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Decrease Speed Limit", QKeySequence("-"), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Toggle Frame Advancing", QKeySequence("CTRL+A"), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Advance Frame", QKeySequence(Qt::Key_Backslash), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Load Amiibo", QKeySequence(Qt::Key_F2), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Remove Amiibo", QKeySequence(Qt::Key_F3), - Qt::ApplicationShortcut); - hotkey_registry.RegisterHotkey("Main Window", "Capture Screenshot", QKeySequence(tr("CTRL+P"))); - hotkey_registry.LoadHotkeys(); + ui.action_Load_File->setShortcut(hotkey_registry.GetKeySequence("Main Window", "Load File")); + ui.action_Load_File->setShortcutContext( + hotkey_registry.GetShortcutContext("Main Window", "Load File")); + + ui.action_Exit->setShortcut(hotkey_registry.GetKeySequence("Main Window", "Exit Citra")); + ui.action_Exit->setShortcutContext( + hotkey_registry.GetShortcutContext("Main Window", "Exit Citra")); + + ui.action_Stop->setShortcut(hotkey_registry.GetKeySequence("Main Window", "Stop Emulation")); + ui.action_Stop->setShortcutContext( + hotkey_registry.GetShortcutContext("Main Window", "Stop Emulation")); + + ui.action_Show_Filter_Bar->setShortcut( + hotkey_registry.GetKeySequence("Main Window", "Toggle Filter Bar")); + ui.action_Show_Filter_Bar->setShortcutContext( + hotkey_registry.GetShortcutContext("Main Window", "Toggle Filter Bar")); + + ui.action_Show_Status_Bar->setShortcut( + hotkey_registry.GetKeySequence("Main Window", "Toggle Status Bar")); + ui.action_Show_Status_Bar->setShortcutContext( + hotkey_registry.GetShortcutContext("Main Window", "Toggle Status Bar")); + connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated, this, &GMainWindow::OnMenuLoadFile); - connect(hotkey_registry.GetHotkey("Main Window", "Start Emulation", this), - &QShortcut::activated, this, &GMainWindow::OnStartGame); - connect(hotkey_registry.GetHotkey("Main Window", "Continue/Pause", this), &QShortcut::activated, - this, [&] { + + connect(hotkey_registry.GetHotkey("Main Window", "Continue/Pause Emulation", this), + &QShortcut::activated, this, [&] { if (emulation_running) { if (emu_thread->IsRunning()) { OnPauseGame(); @@ -386,8 +381,8 @@ void GMainWindow::InitializeHotkeys() { } } }); - connect(hotkey_registry.GetHotkey("Main Window", "Restart", this), &QShortcut::activated, this, - [this] { + connect(hotkey_registry.GetHotkey("Main Window", "Restart Emulation", this), + &QShortcut::activated, this, [this] { if (!Core::System::GetInstance().IsPoweredOn()) return; BootGame(QString(game_path)); @@ -546,7 +541,6 @@ void GMainWindow::ConnectMenuEvents() { &GMainWindow::ToggleWindowMode); connect(ui.action_Display_Dock_Widget_Headers, &QAction::triggered, this, &GMainWindow::OnDisplayTitleBars); - ui.action_Show_Filter_Bar->setShortcut(tr("CTRL+F")); connect(ui.action_Show_Filter_Bar, &QAction::triggered, this, &GMainWindow::OnToggleFilterBar); connect(ui.action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible); @@ -1325,13 +1319,15 @@ void GMainWindow::OnConfigure() { ConfigureDialog configureDialog(this, hotkey_registry); connect(&configureDialog, &ConfigureDialog::languageChanged, this, &GMainWindow::OnLanguageChanged); + connect(&configureDialog, &ConfigureDialog::UpdateHotkeys, this, + [this]() { InitializeHotkeys(); }); auto old_theme = UISettings::values.theme; const int old_input_profile_index = Settings::values.current_input_profile_index; const auto old_input_profiles = Settings::values.input_profiles; const bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); if (result == QDialog::Accepted) { - configureDialog.applyConfiguration(); + configureDialog.applyConfiguration(hotkey_registry); if (UISettings::values.theme != old_theme) UpdateUITheme(); if (UISettings::values.enable_discord_presence != old_discord_presence) diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 0d561508a..720bdedb6 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -96,7 +96,6 @@ private: void InitializeWidgets(); void InitializeDebugWidgets(); void InitializeRecentFileMenuActions(); - void InitializeHotkeys(); void SetDefaultUIGeometry(); void SyncMenuUISettings(); @@ -171,6 +170,7 @@ private slots: void OnOpenCitraFolder(); void OnToggleFilterBar(); void OnDisplayTitleBars(bool); + void InitializeHotkeys(); void ToggleFullscreen(); void ChangeScreenLayout(); void ToggleScreenLayout(); diff --git a/src/citra_qt/ui_settings.cpp b/src/citra_qt/ui_settings.cpp index b27fc7661..39156fb73 100644 --- a/src/citra_qt/ui_settings.cpp +++ b/src/citra_qt/ui_settings.cpp @@ -14,5 +14,4 @@ const Themes themes{{ }}; Values values = {}; - } // namespace UISettings diff --git a/src/citra_qt/ui_settings.h b/src/citra_qt/ui_settings.h index d623b14da..47e4b1b32 100644 --- a/src/citra_qt/ui_settings.h +++ b/src/citra_qt/ui_settings.h @@ -17,7 +17,12 @@ namespace UISettings { using ContextualShortcut = std::pair; -using Shortcut = std::pair; + +struct Shortcut { + QString name; + QString group; + ContextualShortcut shortcut; +}; using Themes = std::array, 4>; extern const Themes themes; diff --git a/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp b/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp new file mode 100644 index 000000000..5a4cfb03f --- /dev/null +++ b/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp @@ -0,0 +1,35 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "citra_qt/util/sequence_dialog/sequence_dialog.h" + +SequenceDialog::SequenceDialog(QWidget* parent) : QDialog(parent) { + setWindowTitle(tr("Enter a hotkey")); + auto* layout = new QVBoxLayout(this); + key_sequence = new QKeySequenceEdit; + layout->addWidget(key_sequence); + auto* buttons = + new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal); + buttons->setCenterButtons(true); + layout->addWidget(buttons); + connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); +} + +SequenceDialog::~SequenceDialog() = default; + +QKeySequence SequenceDialog::GetSequence() { + return QKeySequence(key_sequence->keySequence()[0]); +} + +bool SequenceDialog::focusNextPrevChild(bool next) { + return false; +} + +void SequenceDialog::closeEvent(QCloseEvent*) { + reject(); +} diff --git a/src/citra_qt/util/sequence_dialog/sequence_dialog.h b/src/citra_qt/util/sequence_dialog/sequence_dialog.h new file mode 100644 index 000000000..1dca4ddf2 --- /dev/null +++ b/src/citra_qt/util/sequence_dialog/sequence_dialog.h @@ -0,0 +1,24 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +class SequenceDialog : public QDialog { + Q_OBJECT + +public: + explicit SequenceDialog(QWidget* parent = nullptr); + ~SequenceDialog(); + + QKeySequence GetSequence(); + void closeEvent(QCloseEvent*) override; + +private: + QKeySequenceEdit* key_sequence; + bool focusNextPrevChild(bool next) override; +}; From 9615acb5500355a00f73f008452459da97a81683 Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Fri, 16 Nov 2018 21:19:43 +0530 Subject: [PATCH 2/7] citra-qt: Fixed reloading hotkeys on-the fly. --- src/citra_qt/configuration/configure_dialog.cpp | 2 -- src/citra_qt/configuration/configure_dialog.h | 1 - src/citra_qt/main.cpp | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index a62082229..08c60ec8a 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -26,8 +26,6 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry &ConfigureHotkeys::OnInputKeysChanged); connect(ui->hotkeysTab, &ConfigureHotkeys::HotkeysChanged, ui->inputTab, &ConfigureInput::OnHotkeysChanged); - connect(ui->hotkeysTab, &ConfigureHotkeys::HotkeysChanged, this, - [this]() { emit UpdateHotkeys(); }); // Synchronise lists upon initialisation ui->inputTab->EmitInputKeysChanged(); diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index c10572692..40bc94e76 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -29,7 +29,6 @@ private slots: signals: void languageChanged(const QString& locale); - void UpdateHotkeys(); private: void setConfiguration(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index dff565b38..7da699b98 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1319,8 +1319,6 @@ void GMainWindow::OnConfigure() { ConfigureDialog configureDialog(this, hotkey_registry); connect(&configureDialog, &ConfigureDialog::languageChanged, this, &GMainWindow::OnLanguageChanged); - connect(&configureDialog, &ConfigureDialog::UpdateHotkeys, this, - [this]() { InitializeHotkeys(); }); auto old_theme = UISettings::values.theme; const int old_input_profile_index = Settings::values.current_input_profile_index; const auto old_input_profiles = Settings::values.input_profiles; @@ -1328,6 +1326,7 @@ void GMainWindow::OnConfigure() { auto result = configureDialog.exec(); if (result == QDialog::Accepted) { configureDialog.applyConfiguration(hotkey_registry); + InitializeHotkeys(); if (UISettings::values.theme != old_theme) UpdateUITheme(); if (UISettings::values.enable_discord_presence != old_discord_presence) From 4309585623e67f38e3c6113d6435f128069748d2 Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Fri, 16 Nov 2018 22:04:00 +0530 Subject: [PATCH 3/7] citra-qt: Commented & documented code related to hotkeys as & when required. --- src/citra_qt/configuration/configure_dialog.cpp | 1 + src/citra_qt/configuration/configure_hotkeys.h | 11 +++++++++++ src/citra_qt/configuration/configure_input.h | 6 +++++- src/citra_qt/util/sequence_dialog/sequence_dialog.cpp | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index 08c60ec8a..8d0d89c3b 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -22,6 +22,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry adjustSize(); ui->selectorList->setCurrentRow(0); + // Set up used key list synchronisation connect(ui->inputTab, &ConfigureInput::InputKeysChanged, ui->hotkeysTab, &ConfigureHotkeys::OnInputKeysChanged); connect(ui->hotkeysTab, &ConfigureHotkeys::HotkeysChanged, ui->inputTab, diff --git a/src/citra_qt/configuration/configure_hotkeys.h b/src/citra_qt/configuration/configure_hotkeys.h index 431d53fb2..960d9d572 100644 --- a/src/citra_qt/configuration/configure_hotkeys.h +++ b/src/citra_qt/configuration/configure_hotkeys.h @@ -28,6 +28,11 @@ public: void EmitHotkeysChanged(); + /** + * Populates the hotkey list widget using data from the provided registry. + * Called everytime the Configure dialog is opened. + * @param registry The HotkeyRegistry whose data is used to populate the list. + */ void Populate(const HotkeyRegistry& registry); public slots: @@ -43,6 +48,12 @@ private: std::unique_ptr ui; + /** + * List of keyboard keys currently registered to any of the 3DS inputs. + * These can't be bound to any hotkey. + * Synchronised with ConfigureInput via signal-slot. + */ QList input_keys_list; + QStandardItemModel* model; }; diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h index 410415990..a122402aa 100644 --- a/src/citra_qt/configuration/configure_input.h +++ b/src/citra_qt/configuration/configure_input.h @@ -80,7 +80,11 @@ private: std::vector> device_pollers; - /// Keys currently registered as hotkeys + /** + * List of keys currently registered to hotkeys. + * These can't be bound to any input key. + * Synchronised with ConfigureHotkeys via signal-slot. + */ QList hotkey_list; /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, diff --git a/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp b/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp index 5a4cfb03f..48e7a82a7 100644 --- a/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp +++ b/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp @@ -23,6 +23,7 @@ SequenceDialog::SequenceDialog(QWidget* parent) : QDialog(parent) { SequenceDialog::~SequenceDialog() = default; QKeySequence SequenceDialog::GetSequence() { + // Only the first key is returned. The other 3, if present, are ignored. return QKeySequence(key_sequence->keySequence()[0]); } From 988acf588a01367389b7e86de772066473fb0fce Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Sat, 17 Nov 2018 16:55:05 +0530 Subject: [PATCH 4/7] citra-qt: Add back missing hotkeys & conflict fixes. * Also fixed a missing spacer in ConfigureGeneral. --- src/citra_qt/configuration/config.cpp | 14 ++++++++++++-- src/citra_qt/configuration/configure_dialog.cpp | 6 +++--- src/citra_qt/configuration/configure_dialog.h | 3 ++- src/citra_qt/configuration/configure_general.ui | 13 +++++++++++++ src/citra_qt/main.cpp | 2 +- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 878defdda..c12c90507 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -320,7 +320,7 @@ void Config::ReadValues() { qt_config->endGroup(); qt_config->beginGroup("Shortcuts"); - const std::array default_hotkeys{ + const std::array default_hotkeys{ {{"Load File", "Main Window", UISettings::ContextualShortcut(QKeySequence(QKeySequence::Open).toString(), Qt::WindowShortcut)}, @@ -349,7 +349,17 @@ void Config::ReadValues() { {"Increase Speed Limit", "Main Window", UISettings::ContextualShortcut("+", Qt::ApplicationShortcut)}, {"Decrease Speed Limit", "Main Window", - UISettings::ContextualShortcut("-", Qt::ApplicationShortcut)}}}; + UISettings::ContextualShortcut("-", Qt::ApplicationShortcut)}, + {"Advance Frame", "Main Window", + UISettings::ContextualShortcut("\\", Qt::ApplicationShortcut)}, + {"Toggle Frame Advancing", "Main Window", + UISettings::ContextualShortcut("Ctrl+A", Qt::ApplicationShortcut)}, + {"Load Amiibo", "Main Window", + UISettings::ContextualShortcut("F2", Qt::ApplicationShortcut)}, + {"Remove Amiibo", "Main Window", + UISettings::ContextualShortcut("F3", Qt::ApplicationShortcut)}, + {"Capture Screenshot", "Main Window", + UISettings::ContextualShortcut("Ctrl+P", Qt::ApplicationShortcut)}}}; for (int i = 0; i < default_hotkeys.size(); i++) { qt_config->beginGroup(default_hotkeys[i].group); diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index 8d0d89c3b..a5d3d4fe9 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -10,8 +10,8 @@ #include "core/settings.h" #include "ui_configure.h" -ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry) - : QDialog(parent), ui(new Ui::ConfigureDialog) { +ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry) + : QDialog(parent), registry(registry), ui(new Ui::ConfigureDialog) { ui->setupUi(this); ui->hotkeysTab->Populate(registry); @@ -47,7 +47,7 @@ void ConfigureDialog::setConfiguration() { ui->uiTab->setConfiguration(); } -void ConfigureDialog::applyConfiguration(HotkeyRegistry& registry) { +void ConfigureDialog::applyConfiguration() { ui->generalTab->applyConfiguration(); ui->systemTab->applyConfiguration(); ui->inputTab->applyConfiguration(); diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index 40bc94e76..39ece2847 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -22,7 +22,7 @@ public: void UpdateVisibleTabs(); void PopulateSelectionList(); - void applyConfiguration(HotkeyRegistry& registry); + void applyConfiguration(); private slots: void onLanguageChanged(const QString& locale); @@ -35,4 +35,5 @@ private: void retranslateUi(); std::unique_ptr ui; + HotkeyRegistry& registry; }; diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 3879e6b77..f33fb9d98 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -122,6 +122,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 7da699b98..6ff7e3b2b 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1325,7 +1325,7 @@ void GMainWindow::OnConfigure() { const bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); if (result == QDialog::Accepted) { - configureDialog.applyConfiguration(hotkey_registry); + configureDialog.applyConfiguration(); InitializeHotkeys(); if (UISettings::values.theme != old_theme) UpdateUITheme(); From dccd1664adca2f8774912f3267afdbe2d8b028f3 Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Sun, 9 Dec 2018 17:43:14 +0530 Subject: [PATCH 5/7] citra-qt/configuration: Fix a weird issue where the tab UI disappears when language is changed. --- src/citra_qt/configuration/configure_dialog.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index a5d3d4fe9..a0ef52d2e 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -116,11 +116,11 @@ void ConfigureDialog::UpdateVisibleTabs() { return; const QHash widgets = { - {tr("General"), ui->generalTab}, {tr("System"), ui->systemTab}, - {tr("Input"), ui->inputTab}, {tr("Hotkeys"), ui->hotkeysTab}, - {tr("Graphics"), ui->graphicsTab}, {tr("Audio"), ui->audioTab}, - {tr("Camera"), ui->cameraTab}, {tr("Debug"), ui->debugTab}, - {tr("Web"), ui->webTab}, {tr("UI"), ui->uiTab}}; + {"General", ui->generalTab}, {"System", ui->systemTab}, + {"Input", ui->inputTab}, {"Hotkeys", ui->hotkeysTab}, + {"Graphics", ui->graphicsTab}, {"Audio", ui->audioTab}, + {"Camera", ui->cameraTab}, {"Debug", ui->debugTab}, + {"Web", ui->webTab}, {"UI", ui->uiTab}}; ui->tabWidget->clear(); From 71f36efd273a40ae44380c04058d1159c504f13f Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Wed, 12 Dec 2018 21:14:27 +0530 Subject: [PATCH 6/7] citra-qt: Use structured bindings where applicable in `ConfigureHotkeys::applyConfiguration`. Fix a few minor issues. * Address https://github.com/citra-emu/citra/pull/4437#discussion_r241380912 --- src/citra_qt/configuration/configure_dialog.h | 2 +- src/citra_qt/configuration/configure_hotkeys.cpp | 16 +++++++--------- src/citra_qt/hotkeys.cpp | 4 +++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index 39ece2847..5abd28543 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -17,7 +17,7 @@ class ConfigureDialog : public QDialog { Q_OBJECT public: - explicit ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry); + explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry); ~ConfigureDialog() override; void UpdateVisibleTabs(); diff --git a/src/citra_qt/configuration/configure_hotkeys.cpp b/src/citra_qt/configuration/configure_hotkeys.cpp index 1d961c5f0..cf4ae1034 100644 --- a/src/citra_qt/configuration/configure_hotkeys.cpp +++ b/src/citra_qt/configuration/configure_hotkeys.cpp @@ -107,15 +107,13 @@ void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) { for (int key_column_id = 0; key_column_id < parent->rowCount(); key_column_id++) { QStandardItem* action = parent->child(key_column_id, 0); QStandardItem* keyseq = parent->child(key_column_id, 1); - for (auto key_iterator = registry.hotkey_groups.begin(); - key_iterator != registry.hotkey_groups.end(); ++key_iterator) { - if (key_iterator->first == parent->text()) { - for (auto it2 = key_iterator->second.begin(); it2 != key_iterator->second.end(); - ++it2) { - if (it2->first == action->text()) { - it2->second.keyseq = QKeySequence(keyseq->text()); - } - } + for (auto& [group, sub_actions] : registry.hotkey_groups) { + if (group != parent->text()) + continue; + for (auto& [action_name, hotkey] : sub_actions) { + if (action_name != action->text()) + continue; + hotkey.keyseq = QKeySequence(keyseq->text()); } } } diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp index b4038ba54..0939bcf49 100644 --- a/src/citra_qt/hotkeys.cpp +++ b/src/citra_qt/hotkeys.cpp @@ -32,8 +32,10 @@ void HotkeyRegistry::LoadHotkeys() { hk.keyseq = QKeySequence::fromString(shortcut.shortcut.first, QKeySequence::NativeText); hk.context = (Qt::ShortcutContext)shortcut.shortcut.second; } - if (hk.shortcut) + if (hk.shortcut) { + hk.shortcut->disconnect(); hk.shortcut->setKey(hk.keyseq); + } } } From 80ebd75285369fba45dcc771c2d45881eed704eb Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Sun, 30 Dec 2018 15:39:16 +0530 Subject: [PATCH 7/7] citra-qt: Add /default parsing for hotkeys. Also minor code cleanups. --- src/citra_qt/configuration/config.cpp | 95 ++++++++----------- src/citra_qt/configuration/config.h | 3 + src/citra_qt/configuration/configure_dialog.h | 2 +- .../configuration/configure_hotkeys.cpp | 9 +- .../configuration/configure_hotkeys.h | 3 +- .../configuration/configure_hotkeys.ui | 9 +- .../configuration/configure_input.cpp | 2 +- src/citra_qt/configuration/configure_input.h | 5 +- src/citra_qt/hotkeys.cpp | 2 +- src/citra_qt/hotkeys.h | 7 +- .../util/sequence_dialog/sequence_dialog.cpp | 1 + .../util/sequence_dialog/sequence_dialog.h | 3 +- 12 files changed, 67 insertions(+), 74 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index c12c90507..b0a6323ac 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -8,7 +8,6 @@ #include #include #include "citra_qt/configuration/config.h" -#include "citra_qt/ui_settings.h" #include "common/file_util.h" #include "core/hle/service/service.h" #include "input_common/main.h" @@ -21,7 +20,6 @@ Config::Config() { FileUtil::CreateFullPath(qt_config_loc); qt_config = std::make_unique(QString::fromStdString(qt_config_loc), QSettings::IniFormat); - Reload(); } @@ -52,6 +50,31 @@ const std::array, Settings::NativeAnalog::NumAnalogs> Config: }, }}; +// This shouldn't have anything except static initializers (no functions). So +// QKeySequnce(...).toString() is NOT ALLOWED HERE. +// This must be in alphabetical order according to action name as it must have the same order as +// UISetting::values.shortcuts, which is alphabetically ordered. +const std::array Config::default_hotkeys{ + {{"Advance Frame", "Main Window", {"\\", Qt::ApplicationShortcut}}, + {"Capture Screenshot", "Main Window", {"Ctrl+P", Qt::ApplicationShortcut}}, + {"Continue/Pause Emulation", "Main Window", {"F4", Qt::WindowShortcut}}, + {"Decrease Speed Limit", "Main Window", {"-", Qt::ApplicationShortcut}}, + {"Exit Citra", "Main Window", {"Ctrl+Q", Qt::WindowShortcut}}, + {"Exit Fullscreen", "Main Window", {"Esc", Qt::WindowShortcut}}, + {"Fullscreen", "Main Window", {"F11", Qt::WindowShortcut}}, + {"Increase Speed Limit", "Main Window", {"+", Qt::ApplicationShortcut}}, + {"Load Amiibo", "Main Window", {"F2", Qt::ApplicationShortcut}}, + {"Load File", "Main Window", {"Ctrl+O", Qt::WindowShortcut}}, + {"Remove Amiibo", "Main Window", {"F3", Qt::ApplicationShortcut}}, + {"Restart Emulation", "Main Window", {"F6", Qt::WindowShortcut}}, + {"Stop Emulation", "Main Window", {"F5", Qt::WindowShortcut}}, + {"Swap Screens", "Main Window", {"F9", Qt::WindowShortcut}}, + {"Toggle Filter Bar", "Main Window", {"Ctrl+F", Qt::WindowShortcut}}, + {"Toggle Frame Advancing", "Main Window", {"Ctrl+A", Qt::ApplicationShortcut}}, + {"Toggle Screen Layout", "Main Window", {"F10", Qt::WindowShortcut}}, + {"Toggle Speed Limit", "Main Window", {"Ctrl+Z", Qt::ApplicationShortcut}}, + {"Toggle Status Bar", "Main Window", {"Ctrl+S", Qt::WindowShortcut}}}}; + void Config::ReadValues() { qt_config->beginGroup("Controls"); @@ -320,55 +343,14 @@ void Config::ReadValues() { qt_config->endGroup(); qt_config->beginGroup("Shortcuts"); - const std::array default_hotkeys{ - {{"Load File", "Main Window", - UISettings::ContextualShortcut(QKeySequence(QKeySequence::Open).toString(), - Qt::WindowShortcut)}, - {"Exit Citra", "Main Window", - UISettings::ContextualShortcut("Ctrl+Q", Qt::WindowShortcut)}, - {"Continue/Pause Emulation", "Main Window", - UISettings::ContextualShortcut("F4", Qt::WindowShortcut)}, - {"Stop Emulation", "Main Window", - UISettings::ContextualShortcut("F5", Qt::WindowShortcut)}, - {"Restart Emulation", "Main Window", - UISettings::ContextualShortcut("F6", Qt::WindowShortcut)}, - {"Swap Screens", "Main Window", UISettings::ContextualShortcut("F9", Qt::WindowShortcut)}, - {"Toggle Screen Layout", "Main Window", - UISettings::ContextualShortcut("F10", Qt::WindowShortcut)}, - {"Toggle Filter Bar", "Main Window", - UISettings::ContextualShortcut("Ctrl+F", Qt::WindowShortcut)}, - {"Toggle Status Bar", "Main Window", - UISettings::ContextualShortcut("Ctrl+S", Qt::WindowShortcut)}, - {"Fullscreen", "Main Window", - UISettings::ContextualShortcut(QKeySequence(QKeySequence::FullScreen).toString(), - Qt::WindowShortcut)}, - {"Exit Fullscreen", "Main Window", - UISettings::ContextualShortcut("Escape", Qt::WindowShortcut)}, - {"Toggle Speed Limit", "Main Window", - UISettings::ContextualShortcut("Ctrl+Z", Qt::ApplicationShortcut)}, - {"Increase Speed Limit", "Main Window", - UISettings::ContextualShortcut("+", Qt::ApplicationShortcut)}, - {"Decrease Speed Limit", "Main Window", - UISettings::ContextualShortcut("-", Qt::ApplicationShortcut)}, - {"Advance Frame", "Main Window", - UISettings::ContextualShortcut("\\", Qt::ApplicationShortcut)}, - {"Toggle Frame Advancing", "Main Window", - UISettings::ContextualShortcut("Ctrl+A", Qt::ApplicationShortcut)}, - {"Load Amiibo", "Main Window", - UISettings::ContextualShortcut("F2", Qt::ApplicationShortcut)}, - {"Remove Amiibo", "Main Window", - UISettings::ContextualShortcut("F3", Qt::ApplicationShortcut)}, - {"Capture Screenshot", "Main Window", - UISettings::ContextualShortcut("Ctrl+P", Qt::ApplicationShortcut)}}}; - - for (int i = 0; i < default_hotkeys.size(); i++) { - qt_config->beginGroup(default_hotkeys[i].group); - qt_config->beginGroup(default_hotkeys[i].name); + for (auto [name, group, shortcut] : default_hotkeys) { + auto [keyseq, context] = shortcut; + qt_config->beginGroup(group); + qt_config->beginGroup(name); UISettings::values.shortcuts.push_back( - {default_hotkeys[i].name, default_hotkeys[i].group, - UISettings::ContextualShortcut( - qt_config->value("KeySeq", default_hotkeys[i].shortcut.first).toString(), - qt_config->value("Context", default_hotkeys[i].shortcut.second).toInt())}); + {name, + group, + {ReadSetting("KeySeq", keyseq).toString(), ReadSetting("Context", context).toInt()}}); qt_config->endGroup(); qt_config->endGroup(); } @@ -601,11 +583,14 @@ void Config::SaveValues() { qt_config->endGroup(); qt_config->beginGroup("Shortcuts"); - for (auto shortcut : UISettings::values.shortcuts) { - qt_config->beginGroup(shortcut.group); - qt_config->beginGroup(shortcut.name); - WriteSetting("KeySeq", shortcut.shortcut.first); - WriteSetting("Context", shortcut.shortcut.second); + // Lengths of UISettings::values.shortcuts & default_hotkeys are same. + // However, their ordering must also be the same. + for (std::size_t i = 0; i < default_hotkeys.size(); i++) { + auto [name, group, shortcut] = UISettings::values.shortcuts[i]; + qt_config->beginGroup(group); + qt_config->beginGroup(name); + WriteSetting("KeySeq", shortcut.first, default_hotkeys[i].shortcut.first); + WriteSetting("Context", shortcut.second, default_hotkeys[i].shortcut.second); qt_config->endGroup(); qt_config->endGroup(); } diff --git a/src/citra_qt/configuration/config.h b/src/citra_qt/configuration/config.h index fdb161c23..70aab4f8c 100644 --- a/src/citra_qt/configuration/config.h +++ b/src/citra_qt/configuration/config.h @@ -8,6 +8,7 @@ #include #include #include +#include "citra_qt/ui_settings.h" #include "core/settings.h" class QSettings; @@ -31,6 +32,8 @@ private: void WriteSetting(const QString& name, const QVariant& value); void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value); + static const std::array default_hotkeys; + std::unique_ptr qt_config; std::string qt_config_loc; }; diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index 5abd28543..c902bf702 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -20,9 +20,9 @@ public: explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry); ~ConfigureDialog() override; + void applyConfiguration(); void UpdateVisibleTabs(); void PopulateSelectionList(); - void applyConfiguration(); private slots: void onLanguageChanged(const QString& locale); diff --git a/src/citra_qt/configuration/configure_hotkeys.cpp b/src/citra_qt/configuration/configure_hotkeys.cpp index cf4ae1034..aae212b5d 100644 --- a/src/citra_qt/configuration/configure_hotkeys.cpp +++ b/src/citra_qt/configuration/configure_hotkeys.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "citra_qt/configuration/configure_hotkeys.h" #include "citra_qt/hotkeys.h" #include "citra_qt/util/sequence_dialog/sequence_dialog.h" @@ -18,7 +19,6 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) model->setColumnCount(3); model->setHorizontalHeaderLabels({tr("Action"), tr("Hotkey"), tr("Context")}); - ui->hotkey_list->setSelectionMode(QTreeView::SingleSelection); connect(ui->hotkey_list, &QTreeView::doubleClicked, this, &ConfigureHotkeys::Configure); ui->hotkey_list->setModel(model); @@ -27,10 +27,9 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) ui->hotkey_list->setColumnWidth(0, 200); ui->hotkey_list->resizeColumnToContents(1); - ui->hotkey_list->setEditTriggers(QTreeView::NoEditTriggers); } -ConfigureHotkeys::~ConfigureHotkeys() {} +ConfigureHotkeys::~ConfigureHotkeys() = default; void ConfigureHotkeys::EmitHotkeysChanged() { emit HotkeysChanged(GetUsedKeyList()); @@ -86,9 +85,7 @@ void ConfigureHotkeys::Configure(QModelIndex index) { if (return_code == QDialog::Rejected || key_sequence.isEmpty()) return; - if (IsUsedKey(key_sequence) && - key_sequence != QKeySequence(previous_key.toString(), QKeySequence::NativeText)) { - model->setData(index, previous_key); + if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) { QMessageBox::critical(this, tr("Error in inputted key"), tr("You're using a key that's already bound.")); } else { diff --git a/src/citra_qt/configuration/configure_hotkeys.h b/src/citra_qt/configuration/configure_hotkeys.h index 960d9d572..bd2c1542c 100644 --- a/src/citra_qt/configuration/configure_hotkeys.h +++ b/src/citra_qt/configuration/configure_hotkeys.h @@ -5,9 +5,7 @@ #pragma once #include -#include #include -#include "common/param_package.h" #include "core/settings.h" namespace Ui { @@ -15,6 +13,7 @@ class ConfigureHotkeys; } class HotkeyRegistry; +class QStandardItemModel; class ConfigureHotkeys : public QWidget { Q_OBJECT diff --git a/src/citra_qt/configuration/configure_hotkeys.ui b/src/citra_qt/configuration/configure_hotkeys.ui index d6ca3c47b..56a2e53fa 100644 --- a/src/citra_qt/configuration/configure_hotkeys.ui +++ b/src/citra_qt/configuration/configure_hotkeys.ui @@ -24,7 +24,14 @@ - + + + QAbstractItemView::NoEditTriggers + + + false + + diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index f6f90385c..da5f64271 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -295,7 +295,7 @@ QList ConfigureInput::GetUsedKeyboardKeys() { } // TODO(adityaruplaha): Add home button to list when we finally emulate it - // Button ID of home button is 14: Reffered from citra_qt/configuration/config.cpp + // Button ID of home button is 14: Referred from citra_qt/configuration/config.cpp list.removeOne(list.indexOf(QKeySequence(buttons_param[14].Get("code", 0)))); return list; } diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h index a122402aa..36e44d52b 100644 --- a/src/citra_qt/configuration/configure_input.h +++ b/src/citra_qt/configuration/configure_input.h @@ -41,15 +41,14 @@ public: void loadConfiguration(); void EmitInputKeysChanged(); + /// Save the current input profile index + void ApplyProfile(); public slots: void OnHotkeysChanged(QList new_key_list); signals: void InputKeysChanged(QList new_key_list); - // Save the current input profile index - void ApplyProfile(); - private: std::unique_ptr ui; diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp index 0939bcf49..5542f6dd4 100644 --- a/src/citra_qt/hotkeys.cpp +++ b/src/citra_qt/hotkeys.cpp @@ -30,7 +30,7 @@ void HotkeyRegistry::LoadHotkeys() { Hotkey& hk = hotkey_groups[shortcut.group][shortcut.name]; if (!shortcut.shortcut.first.isEmpty()) { hk.keyseq = QKeySequence::fromString(shortcut.shortcut.first, QKeySequence::NativeText); - hk.context = (Qt::ShortcutContext)shortcut.shortcut.second; + hk.context = static_cast(shortcut.shortcut.second); } if (hk.shortcut) { hk.shortcut->disconnect(); diff --git a/src/citra_qt/hotkeys.h b/src/citra_qt/hotkeys.h index e8fed0ca6..4f526dc7e 100644 --- a/src/citra_qt/hotkeys.h +++ b/src/citra_qt/hotkeys.h @@ -48,7 +48,7 @@ public: QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget); /** - * Returns a QKeySequence object who signal can be connected to QAction->SetShortcut. + * Returns a QKeySequence object whose signal can be connected to QAction::setShortcut. * * @param group General group this hotkey belongs to (e.g. "Main Window", "Debugger"). * @param action Name of the action (e.g. "Start Emulation", "Load Image"). @@ -57,9 +57,10 @@ public: /** * Returns a Qt::ShortcutContext object who can be connected to other - * QAction->SetShortcutContext. + * QAction::setShortcutContext. * - * @param group General group this shortcutcontext belongs to (e.g. "Main Window", "Debugger"). + * @param group General group this shortcut context belongs to (e.g. "Main Window", + * "Debugger"). * @param action Name of the action (e.g. "Start Emulation", "Load Image"). */ Qt::ShortcutContext GetShortcutContext(const QString& group, const QString& action); diff --git a/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp b/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp index 48e7a82a7..8eff35621 100644 --- a/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp +++ b/src/citra_qt/util/sequence_dialog/sequence_dialog.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include "citra_qt/util/sequence_dialog/sequence_dialog.h" diff --git a/src/citra_qt/util/sequence_dialog/sequence_dialog.h b/src/citra_qt/util/sequence_dialog/sequence_dialog.h index 1dca4ddf2..ba8843d92 100644 --- a/src/citra_qt/util/sequence_dialog/sequence_dialog.h +++ b/src/citra_qt/util/sequence_dialog/sequence_dialog.h @@ -6,7 +6,8 @@ #include #include -#include + +class QKeySequenceEdit; class SequenceDialog : public QDialog { Q_OBJECT