From 93308de8ec81a4e68bd3bad984297a5e63311425 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sat, 11 Jun 2016 10:46:36 -0500 Subject: [PATCH 01/16] Input GUI: Add tab to remap controls --- src/citra_qt/CMakeLists.txt | 3 + src/citra_qt/config.cpp | 7 +- src/citra_qt/config.h | 5 + src/citra_qt/configure.ui | 8 +- src/citra_qt/configure_dialog.cpp | 1 + src/citra_qt/configure_input.cpp | 178 ++++++ src/citra_qt/configure_input.h | 45 ++ src/citra_qt/configure_input.ui | 975 ++++++++++++++++++++++++++++++ src/citra_qt/main.cpp | 1 + 9 files changed, 1217 insertions(+), 6 deletions(-) create mode 100644 src/citra_qt/configure_input.cpp create mode 100644 src/citra_qt/configure_input.h create mode 100644 src/citra_qt/configure_input.ui diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 43a766053..29e02d9ce 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -22,6 +22,7 @@ set(SRCS configure_debug.cpp configure_dialog.cpp configure_general.cpp + configure_input.cpp game_list.cpp hotkeys.cpp main.cpp @@ -52,6 +53,7 @@ set(HEADERS configure_debug.h configure_dialog.h configure_general.h + configure_input.h game_list.h game_list_p.h hotkeys.h @@ -69,6 +71,7 @@ set(UIS configure_audio.ui configure_debug.ui configure_general.ui + configure_input.ui hotkeys.ui main.ui ) diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index ba7edaff9..aa6c120e3 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -2,15 +2,12 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include -#include -#include + #include "citra_qt/config.h" #include "citra_qt/ui_settings.h" #include "common/file_util.h" -#include "core/settings.h" Config::Config() { // TODO: Don't hardcode the path; let the frontend decide where to put the config files. @@ -21,7 +18,7 @@ Config::Config() { Reload(); } -static const std::array defaults = { +const std::array defaults = { // directly mapped keys Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index dd0b2ef0b..2f5724d4d 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -5,6 +5,10 @@ #pragma once #include +#include "core/settings.h" +#include +#include +#include class QSettings; @@ -21,3 +25,4 @@ public: void Reload(); void Save(); }; +extern const std::array defaults; diff --git a/src/citra_qt/configure.ui b/src/citra_qt/configure.ui index e1624bbef..09c2026de 100644 --- a/src/citra_qt/configure.ui +++ b/src/citra_qt/configure.ui @@ -24,7 +24,7 @@ General - + Input @@ -69,6 +69,12 @@
configure_debug.h
1 + + ConfigureInput + QWidget +
configure_input.h
+ 1 +
diff --git a/src/citra_qt/configure_dialog.cpp b/src/citra_qt/configure_dialog.cpp index 2f0317fe0..e6b6d45e0 100644 --- a/src/citra_qt/configure_dialog.cpp +++ b/src/citra_qt/configure_dialog.cpp @@ -27,4 +27,5 @@ void ConfigureDialog::applyConfiguration() { ui->generalTab->applyConfiguration(); ui->audioTab->applyConfiguration(); ui->debugTab->applyConfiguration(); + ui->inputTab->applyConfiguration(); } diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp new file mode 100644 index 000000000..76b0ee45e --- /dev/null +++ b/src/citra_qt/configure_input.cpp @@ -0,0 +1,178 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. +#include "configure_input.h" + +ConfigureInput::ConfigureInput(QWidget *parent) : + QWidget(parent), + ui(new Ui::ConfigureInput) +{ + ui->setupUi(this); + + //Initialize mapping of input enum to UI button. + input_mapping = { + { std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) }, + { std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) }, + { std::make_pair(Settings::NativeInput::Values::X, ui->btnFaceX) }, + { std::make_pair(Settings::NativeInput::Values::Y, ui->btnFaceY) }, + { std::make_pair(Settings::NativeInput::Values::L, ui->btnShdrL) }, + { std::make_pair(Settings::NativeInput::Values::R, ui->btnShdrR) }, + { std::make_pair(Settings::NativeInput::Values::ZL, ui->btnShdrZL) }, + { std::make_pair(Settings::NativeInput::Values::ZR, ui->btnShdrZR) }, + { std::make_pair(Settings::NativeInput::Values::START, ui->btnStart) }, + { std::make_pair(Settings::NativeInput::Values::SELECT, ui->btnSelect) }, + { std::make_pair(Settings::NativeInput::Values::HOME, ui->btnHome) }, + { std::make_pair(Settings::NativeInput::Values::DUP, ui->btnDirUp) }, + { std::make_pair(Settings::NativeInput::Values::DDOWN, ui->btnDirDown) }, + { std::make_pair(Settings::NativeInput::Values::DLEFT, ui->btnDirLeft) }, + { std::make_pair(Settings::NativeInput::Values::DRIGHT, ui->btnDirRight) }, + { std::make_pair(Settings::NativeInput::Values::CUP, ui->btnStickUp) }, + { std::make_pair(Settings::NativeInput::Values::CDOWN, ui->btnStickDown) }, + { std::make_pair(Settings::NativeInput::Values::CLEFT, ui->btnStickLeft) }, + { std::make_pair(Settings::NativeInput::Values::CRIGHT, ui->btnStickRight) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_UP, ui->btnCircleUp) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_DOWN, ui->btnCircleDown) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_LEFT, ui->btnCircleLeft) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) }, + }; + + //Attach handle click method to each button click. + for (auto &ent1 : input_mapping) { + connect(ent1.second, &QPushButton::released, this, &ConfigureInput::HandleClick); + } + connect(ui->btnRestoreDefaults, &QPushButton::released, this, &ConfigureInput::RestoreDefaults); + setFocusPolicy(Qt::ClickFocus); + this->setConfiguration(); +} + +ConfigureInput::~ConfigureInput() +{ +} + +///Event handler for all button released() event. +void ConfigureInput::HandleClick() +{ + QPushButton* sender = qobject_cast(QObject::sender()); + sender->setText("[waiting]"); + sender->setFocus(); + grabKeyboard(); + grabMouse(); + changingButton = sender; +} + +///Save all button configurations to settings file +void ConfigureInput::applyConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + int value = GetKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); + Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; + } + Settings::Apply(); +} + +///Load configuration settings into button text +void ConfigureInput::setConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + QString keyValue = GetKeyName(Settings::values.input_mappings[i]); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } +} + +///Handle key press event for input tab when a button is 'waiting'. +void ConfigureInput::keyPressEvent(QKeyEvent *event) +{ + if (changingButton != nullptr && event->key() > 0) + { + keysPressed.push_back(event->key()); + + //Can't save Modifier + Keys yet as input. Will re-enable after settings refactor + /*if (event->key() == Qt::Key_Shift) + return; + + else if (event->key() == Qt::Key_Control) + return; + + else if (event->key() == Qt::Key_Alt) + return; + + else if (event->key() == Qt::Key_Meta) + return; + else*/ + SetKey(); + } +} + +///Set button text to name of key pressed. +void ConfigureInput::SetKey() +{ + QString keyValue = ""; + for (int i : keysPressed) // Will only contain one key until settings refactor + { + keyValue += GetKeyName(i); + } + //RemoveDuplicates(keyValue); + changingButton->setText(keyValue); + + keysPressed.clear(); + releaseKeyboard(); + releaseMouse(); + changingButton = nullptr; +} + +///Convert key ASCII value to its' letter/name +QString ConfigureInput::GetKeyName(int key_code) +{ + if (key_code == Qt::Key_Shift) + return tr("Shift"); + + else if (key_code == Qt::Key_Control) + return tr("Ctrl"); + + else if (key_code == Qt::Key_Alt) + return tr("Alt"); + + else if (key_code == Qt::Key_Meta) + return ""; + else if (key_code == -1) + return ""; + + return QKeySequence(key_code).toString(); +} + +///Convert letter/name of key to its ASCII value. +int ConfigureInput::GetKeyValue(QString text) +{ + if (text == "Shift") + return Qt::Key_Shift; + else if (text == "Ctrl") + return Qt::Key_Control; + else if (text == "Alt") + return Qt::Key_Alt; + else if (text == "Meta") + return -1; + else if (text == "") + return -1; + return QKeySequence(text)[0]; +} + +///Check all inputs for duplicate keys. Clears out any other button with same key as new button. +void ConfigureInput::RemoveDuplicates(QString newValue) +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + if (changingButton != input_mapping[Settings::NativeInput::Values(i)]) { + QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text(); + if (newValue == oldValue) + input_mapping[Settings::NativeInput::Values(i)]->setText(""); + } + } +} + +///Restore all buttons to their default values. +void ConfigureInput::RestoreDefaults() { + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) + { + QString keyValue = GetKeyName(defaults[i].toInt()); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } +} \ No newline at end of file diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h new file mode 100644 index 000000000..5e66b04d9 --- /dev/null +++ b/src/citra_qt/configure_input.h @@ -0,0 +1,45 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. +#pragma once +#include + +#include +#include +#include +#include +#include +#include + +#include "citra_qt/config.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +namespace Ui { + class ConfigureInput; +} + +class ConfigureInput : public QWidget +{ + Q_OBJECT + +public: + explicit ConfigureInput(QWidget *parent = 0); + ~ConfigureInput(); + void applyConfiguration(); + +private: + std::unique_ptr ui; + std::map input_mapping; + std::vector keysPressed; + QPushButton* changingButton = nullptr; /// button currently waiting for key press. + + void HandleClick(); + void setConfiguration(); + void SetKey(); + void RemoveDuplicates(QString newValue); + void RestoreDefaults(); + virtual void keyPressEvent(QKeyEvent *event); + QString GetKeyName(int key_code); + int GetKeyValue(QString text); +}; diff --git a/src/citra_qt/configure_input.ui b/src/citra_qt/configure_input.ui new file mode 100644 index 000000000..0324f9396 --- /dev/null +++ b/src/citra_qt/configure_input.ui @@ -0,0 +1,975 @@ + + + ConfigureInput + + + + 0 + 0 + 390 + 457 + + + + ConfigureInput + + + + + 10 + 0 + 181 + 130 + + + + Face Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + A: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + B: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + X: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Y: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + 200 + 0 + 181 + 130 + + + + Directional Pad + + + false + + + false + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + 10 + 140 + 181 + 130 + + + + Shoulder Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + L: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZR: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + R: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZL: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + 200 + 140 + 181 + 130 + + + + Circle Pad + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + 10 + 280 + 181 + 130 + + + + C-Stick + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + 200 + 280 + 181 + 130 + + + + System Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Start: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Select: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Home: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + 270 + 420 + 110 + 28 + + + + Restore Defaults + + + + + + + \ No newline at end of file diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0ed1ffa5a..0398989d0 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -513,6 +513,7 @@ void GMainWindow::OnConfigure() { if (result == QDialog::Accepted) { configureDialog.applyConfiguration(); + render_window->ReloadSetKeymaps(); config->Save(); } } From 61144d2ab171ae9fc285f9cb6423010865c19a96 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sat, 11 Jun 2016 23:14:57 -0500 Subject: [PATCH 02/16] Input-GUI: Fix most PR issues --- src/citra_qt/config.cpp | 436 +++---- src/citra_qt/config.h | 53 +- src/citra_qt/configure_input.cpp | 353 +++--- src/citra_qt/configure_input.h | 91 +- src/citra_qt/configure_input.ui | 1979 +++++++++++++++--------------- 5 files changed, 1469 insertions(+), 1443 deletions(-) diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index aa6c120e3..08ec191b8 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -1,218 +1,218 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - - - -#include "citra_qt/config.h" -#include "citra_qt/ui_settings.h" - -#include "common/file_util.h" - -Config::Config() { - // TODO: Don't hardcode the path; let the frontend decide where to put the config files. - qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini"; - FileUtil::CreateFullPath(qt_config_loc); - qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat); - - Reload(); -} - -const std::array defaults = { - // directly mapped keys - Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, - Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, - Qt::Key_M, Qt::Key_N, Qt::Key_B, - Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, - Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, - - // indirectly mapped keys - Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, - Qt::Key_D, -}; - -void Config::ReadValues() { - qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { - Settings::values.input_mappings[Settings::NativeInput::All[i]] = - qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]).toInt(); - } - Settings::values.pad_circle_modifier_scale = qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); - qt_config->endGroup(); - - qt_config->beginGroup("Core"); - Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("Renderer"); - Settings::values.use_hw_renderer = qt_config->value("use_hw_renderer", false).toBool(); - Settings::values.use_shader_jit = qt_config->value("use_shader_jit", true).toBool(); - Settings::values.use_scaled_resolution = qt_config->value("use_scaled_resolution", false).toBool(); - - Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat(); - Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat(); - Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat(); - qt_config->endGroup(); - - qt_config->beginGroup("Audio"); - Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); - qt_config->endGroup(); - - qt_config->beginGroup("System"); - Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); - Settings::values.region_value = qt_config->value("region_value", 1).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); - qt_config->endGroup(); - - qt_config->beginGroup("Debugging"); - Settings::values.use_gdbstub = qt_config->value("use_gdbstub", false).toBool(); - Settings::values.gdbstub_port = qt_config->value("gdbstub_port", 24689).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("UI"); - - qt_config->beginGroup("UILayout"); - UISettings::values.geometry = qt_config->value("geometry").toByteArray(); - UISettings::values.state = qt_config->value("state").toByteArray(); - UISettings::values.renderwindow_geometry = qt_config->value("geometryRenderWindow").toByteArray(); - UISettings::values.gamelist_header_state = qt_config->value("gameListHeaderState").toByteArray(); - UISettings::values.microprofile_geometry = qt_config->value("microProfileDialogGeometry").toByteArray(); - UISettings::values.microprofile_visible = qt_config->value("microProfileDialogVisible", false).toBool(); - qt_config->endGroup(); - - qt_config->beginGroup("Paths"); - UISettings::values.roms_path = qt_config->value("romsPath").toString(); - UISettings::values.symbols_path = qt_config->value("symbolsPath").toString(); - UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); - UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); - UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); - 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(qt_config->value("KeySeq").toString(), - qt_config->value("Context").toInt()))); - qt_config->endGroup(); - } - - qt_config->endGroup(); - } - qt_config->endGroup(); - - UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); - UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); - UISettings::values.confirm_before_closing = qt_config->value("confirmClose",true).toBool(); - UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); - - qt_config->endGroup(); -} - -void Config::SaveValues() { - qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { - qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), - Settings::values.input_mappings[Settings::NativeInput::All[i]]); - } - qt_config->setValue("pad_circle_modifier_scale", (double)Settings::values.pad_circle_modifier_scale); - qt_config->endGroup(); - - qt_config->beginGroup("Core"); - qt_config->setValue("frame_skip", Settings::values.frame_skip); - qt_config->endGroup(); - - qt_config->beginGroup("Renderer"); - qt_config->setValue("use_hw_renderer", Settings::values.use_hw_renderer); - qt_config->setValue("use_shader_jit", Settings::values.use_shader_jit); - qt_config->setValue("use_scaled_resolution", Settings::values.use_scaled_resolution); - - // Cast to double because Qt's written float values are not human-readable - qt_config->setValue("bg_red", (double)Settings::values.bg_red); - qt_config->setValue("bg_green", (double)Settings::values.bg_green); - qt_config->setValue("bg_blue", (double)Settings::values.bg_blue); - qt_config->endGroup(); - - qt_config->beginGroup("Audio"); - qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); - qt_config->endGroup(); - - qt_config->beginGroup("System"); - qt_config->setValue("is_new_3ds", Settings::values.is_new_3ds); - qt_config->setValue("region_value", Settings::values.region_value); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); - qt_config->endGroup(); - - qt_config->beginGroup("Debugging"); - qt_config->setValue("use_gdbstub", Settings::values.use_gdbstub); - qt_config->setValue("gdbstub_port", Settings::values.gdbstub_port); - qt_config->endGroup(); - - qt_config->beginGroup("UI"); - - qt_config->beginGroup("UILayout"); - qt_config->setValue("geometry", UISettings::values.geometry); - qt_config->setValue("state", UISettings::values.state); - qt_config->setValue("geometryRenderWindow", UISettings::values.renderwindow_geometry); - qt_config->setValue("gameListHeaderState", UISettings::values.gamelist_header_state); - qt_config->setValue("microProfileDialogGeometry", UISettings::values.microprofile_geometry); - qt_config->setValue("microProfileDialogVisible", UISettings::values.microprofile_visible); - qt_config->endGroup(); - - qt_config->beginGroup("Paths"); - qt_config->setValue("romsPath", UISettings::values.roms_path); - qt_config->setValue("symbolsPath", UISettings::values.symbols_path); - qt_config->setValue("gameListRootDir", UISettings::values.gamedir); - qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); - qt_config->setValue("recentFiles", UISettings::values.recent_files); - qt_config->endGroup(); - - qt_config->beginGroup("Shortcuts"); - for (auto shortcut : UISettings::values.shortcuts ) { - qt_config->setValue(shortcut.first + "/KeySeq", shortcut.second.first); - qt_config->setValue(shortcut.first + "/Context", shortcut.second.second); - } - qt_config->endGroup(); - - qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); - qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); - qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); - qt_config->setValue("firstStart", UISettings::values.first_start); - - qt_config->endGroup(); -} - -void Config::Reload() { - ReadValues(); - Settings::Apply(); -} - -void Config::Save() { - SaveValues(); -} - -Config::~Config() { - Save(); - - delete qt_config; -} +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "citra_qt/config.h" +#include "citra_qt/ui_settings.h" + +#include "common/file_util.h" + +Config::Config() { + // TODO: Don't hardcode the path; let the frontend decide where to put the config files. + qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini"; + FileUtil::CreateFullPath(qt_config_loc); + qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat); + + Reload(); +} + +const std::array defaults = { + // directly mapped keys + Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, + Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, + Qt::Key_M, Qt::Key_N, Qt::Key_B, + Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, + Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, + + // indirectly mapped keys + Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, + Qt::Key_D, +}; + +void Config::ReadValues() { + qt_config->beginGroup("Controls"); + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { + Settings::values.input_mappings[Settings::NativeInput::All[i]] = + qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]).toInt(); + } + Settings::values.pad_circle_modifier_scale = qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); + qt_config->endGroup(); + + qt_config->beginGroup("Core"); + Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("Renderer"); + Settings::values.use_hw_renderer = qt_config->value("use_hw_renderer", false).toBool(); + Settings::values.use_shader_jit = qt_config->value("use_shader_jit", true).toBool(); + Settings::values.use_scaled_resolution = qt_config->value("use_scaled_resolution", false).toBool(); + + Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat(); + Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat(); + Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat(); + qt_config->endGroup(); + + qt_config->beginGroup("Audio"); + Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); + qt_config->endGroup(); + + qt_config->beginGroup("Data Storage"); + Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); + qt_config->endGroup(); + + qt_config->beginGroup("System"); + Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); + Settings::values.region_value = qt_config->value("region_value", 1).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("Miscellaneous"); + Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); + qt_config->endGroup(); + + qt_config->beginGroup("Debugging"); + Settings::values.use_gdbstub = qt_config->value("use_gdbstub", false).toBool(); + Settings::values.gdbstub_port = qt_config->value("gdbstub_port", 24689).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("UI"); + + qt_config->beginGroup("UILayout"); + UISettings::values.geometry = qt_config->value("geometry").toByteArray(); + UISettings::values.state = qt_config->value("state").toByteArray(); + UISettings::values.renderwindow_geometry = qt_config->value("geometryRenderWindow").toByteArray(); + UISettings::values.gamelist_header_state = qt_config->value("gameListHeaderState").toByteArray(); + UISettings::values.microprofile_geometry = qt_config->value("microProfileDialogGeometry").toByteArray(); + UISettings::values.microprofile_visible = qt_config->value("microProfileDialogVisible", false).toBool(); + qt_config->endGroup(); + + qt_config->beginGroup("Paths"); + UISettings::values.roms_path = qt_config->value("romsPath").toString(); + UISettings::values.symbols_path = qt_config->value("symbolsPath").toString(); + UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); + UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); + UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); + 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(qt_config->value("KeySeq").toString(), + qt_config->value("Context").toInt()))); + qt_config->endGroup(); + } + + qt_config->endGroup(); + } + qt_config->endGroup(); + + UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); + UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); + UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool(); + UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); + + qt_config->endGroup(); +} + +void Config::SaveValues() { + qt_config->beginGroup("Controls"); + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { + qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), + Settings::values.input_mappings[Settings::NativeInput::All[i]]); + } + qt_config->setValue("pad_circle_modifier_scale", (double)Settings::values.pad_circle_modifier_scale); + qt_config->endGroup(); + + qt_config->beginGroup("Core"); + qt_config->setValue("frame_skip", Settings::values.frame_skip); + qt_config->endGroup(); + + qt_config->beginGroup("Renderer"); + qt_config->setValue("use_hw_renderer", Settings::values.use_hw_renderer); + qt_config->setValue("use_shader_jit", Settings::values.use_shader_jit); + qt_config->setValue("use_scaled_resolution", Settings::values.use_scaled_resolution); + + // Cast to double because Qt's written float values are not human-readable + qt_config->setValue("bg_red", (double)Settings::values.bg_red); + qt_config->setValue("bg_green", (double)Settings::values.bg_green); + qt_config->setValue("bg_blue", (double)Settings::values.bg_blue); + qt_config->endGroup(); + + qt_config->beginGroup("Audio"); + qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); + qt_config->endGroup(); + + qt_config->beginGroup("Data Storage"); + qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); + qt_config->endGroup(); + + qt_config->beginGroup("System"); + qt_config->setValue("is_new_3ds", Settings::values.is_new_3ds); + qt_config->setValue("region_value", Settings::values.region_value); + qt_config->endGroup(); + + qt_config->beginGroup("Miscellaneous"); + qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); + qt_config->endGroup(); + + qt_config->beginGroup("Debugging"); + qt_config->setValue("use_gdbstub", Settings::values.use_gdbstub); + qt_config->setValue("gdbstub_port", Settings::values.gdbstub_port); + qt_config->endGroup(); + + qt_config->beginGroup("UI"); + + qt_config->beginGroup("UILayout"); + qt_config->setValue("geometry", UISettings::values.geometry); + qt_config->setValue("state", UISettings::values.state); + qt_config->setValue("geometryRenderWindow", UISettings::values.renderwindow_geometry); + qt_config->setValue("gameListHeaderState", UISettings::values.gamelist_header_state); + qt_config->setValue("microProfileDialogGeometry", UISettings::values.microprofile_geometry); + qt_config->setValue("microProfileDialogVisible", UISettings::values.microprofile_visible); + qt_config->endGroup(); + + qt_config->beginGroup("Paths"); + qt_config->setValue("romsPath", UISettings::values.roms_path); + qt_config->setValue("symbolsPath", UISettings::values.symbols_path); + qt_config->setValue("gameListRootDir", UISettings::values.gamedir); + qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); + qt_config->setValue("recentFiles", UISettings::values.recent_files); + qt_config->endGroup(); + + qt_config->beginGroup("Shortcuts"); + for (auto shortcut : UISettings::values.shortcuts) { + qt_config->setValue(shortcut.first + "/KeySeq", shortcut.second.first); + qt_config->setValue(shortcut.first + "/Context", shortcut.second.second); + } + qt_config->endGroup(); + + qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); + qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); + qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); + qt_config->setValue("firstStart", UISettings::values.first_start); + + qt_config->endGroup(); +} + +void Config::Reload() { + ReadValues(); + Settings::Apply(); +} + +void Config::Save() { + SaveValues(); +} + +Config::~Config() { + Save(); + + delete qt_config; +} \ No newline at end of file diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index 2f5724d4d..7c6217ec1 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -1,28 +1,25 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include "core/settings.h" -#include -#include -#include - -class QSettings; - -class Config { - QSettings* qt_config; - std::string qt_config_loc; - - void ReadValues(); - void SaveValues(); -public: - Config(); - ~Config(); - - void Reload(); - void Save(); -}; -extern const std::array defaults; +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/settings.h" +#include + +class QSettings; + +class Config { + QSettings* qt_config; + std::string qt_config_loc; + + void ReadValues(); + void SaveValues(); +public: + Config(); + ~Config(); + + void Reload(); + void Save(); +}; +extern const std::array defaults; diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 76b0ee45e..7c20b995a 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -1,178 +1,177 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. -#include "configure_input.h" - -ConfigureInput::ConfigureInput(QWidget *parent) : - QWidget(parent), - ui(new Ui::ConfigureInput) -{ - ui->setupUi(this); - - //Initialize mapping of input enum to UI button. - input_mapping = { - { std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) }, - { std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) }, - { std::make_pair(Settings::NativeInput::Values::X, ui->btnFaceX) }, - { std::make_pair(Settings::NativeInput::Values::Y, ui->btnFaceY) }, - { std::make_pair(Settings::NativeInput::Values::L, ui->btnShdrL) }, - { std::make_pair(Settings::NativeInput::Values::R, ui->btnShdrR) }, - { std::make_pair(Settings::NativeInput::Values::ZL, ui->btnShdrZL) }, - { std::make_pair(Settings::NativeInput::Values::ZR, ui->btnShdrZR) }, - { std::make_pair(Settings::NativeInput::Values::START, ui->btnStart) }, - { std::make_pair(Settings::NativeInput::Values::SELECT, ui->btnSelect) }, - { std::make_pair(Settings::NativeInput::Values::HOME, ui->btnHome) }, - { std::make_pair(Settings::NativeInput::Values::DUP, ui->btnDirUp) }, - { std::make_pair(Settings::NativeInput::Values::DDOWN, ui->btnDirDown) }, - { std::make_pair(Settings::NativeInput::Values::DLEFT, ui->btnDirLeft) }, - { std::make_pair(Settings::NativeInput::Values::DRIGHT, ui->btnDirRight) }, - { std::make_pair(Settings::NativeInput::Values::CUP, ui->btnStickUp) }, - { std::make_pair(Settings::NativeInput::Values::CDOWN, ui->btnStickDown) }, - { std::make_pair(Settings::NativeInput::Values::CLEFT, ui->btnStickLeft) }, - { std::make_pair(Settings::NativeInput::Values::CRIGHT, ui->btnStickRight) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_UP, ui->btnCircleUp) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_DOWN, ui->btnCircleDown) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_LEFT, ui->btnCircleLeft) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) }, - }; - - //Attach handle click method to each button click. - for (auto &ent1 : input_mapping) { - connect(ent1.second, &QPushButton::released, this, &ConfigureInput::HandleClick); - } - connect(ui->btnRestoreDefaults, &QPushButton::released, this, &ConfigureInput::RestoreDefaults); - setFocusPolicy(Qt::ClickFocus); - this->setConfiguration(); -} - -ConfigureInput::~ConfigureInput() -{ -} - -///Event handler for all button released() event. -void ConfigureInput::HandleClick() -{ - QPushButton* sender = qobject_cast(QObject::sender()); - sender->setText("[waiting]"); - sender->setFocus(); - grabKeyboard(); - grabMouse(); - changingButton = sender; -} - -///Save all button configurations to settings file -void ConfigureInput::applyConfiguration() -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - int value = GetKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); - Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; - } - Settings::Apply(); -} - -///Load configuration settings into button text -void ConfigureInput::setConfiguration() -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - QString keyValue = GetKeyName(Settings::values.input_mappings[i]); - input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); - } -} - -///Handle key press event for input tab when a button is 'waiting'. -void ConfigureInput::keyPressEvent(QKeyEvent *event) -{ - if (changingButton != nullptr && event->key() > 0) - { - keysPressed.push_back(event->key()); - - //Can't save Modifier + Keys yet as input. Will re-enable after settings refactor - /*if (event->key() == Qt::Key_Shift) - return; - - else if (event->key() == Qt::Key_Control) - return; - - else if (event->key() == Qt::Key_Alt) - return; - - else if (event->key() == Qt::Key_Meta) - return; - else*/ - SetKey(); - } -} - -///Set button text to name of key pressed. -void ConfigureInput::SetKey() -{ - QString keyValue = ""; - for (int i : keysPressed) // Will only contain one key until settings refactor - { - keyValue += GetKeyName(i); - } - //RemoveDuplicates(keyValue); - changingButton->setText(keyValue); - - keysPressed.clear(); - releaseKeyboard(); - releaseMouse(); - changingButton = nullptr; -} - -///Convert key ASCII value to its' letter/name -QString ConfigureInput::GetKeyName(int key_code) -{ - if (key_code == Qt::Key_Shift) - return tr("Shift"); - - else if (key_code == Qt::Key_Control) - return tr("Ctrl"); - - else if (key_code == Qt::Key_Alt) - return tr("Alt"); - - else if (key_code == Qt::Key_Meta) - return ""; - else if (key_code == -1) - return ""; - - return QKeySequence(key_code).toString(); -} - -///Convert letter/name of key to its ASCII value. -int ConfigureInput::GetKeyValue(QString text) -{ - if (text == "Shift") - return Qt::Key_Shift; - else if (text == "Ctrl") - return Qt::Key_Control; - else if (text == "Alt") - return Qt::Key_Alt; - else if (text == "Meta") - return -1; - else if (text == "") - return -1; - return QKeySequence(text)[0]; -} - -///Check all inputs for duplicate keys. Clears out any other button with same key as new button. -void ConfigureInput::RemoveDuplicates(QString newValue) -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - if (changingButton != input_mapping[Settings::NativeInput::Values(i)]) { - QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text(); - if (newValue == oldValue) - input_mapping[Settings::NativeInput::Values(i)]->setText(""); - } - } -} - -///Restore all buttons to their default values. -void ConfigureInput::RestoreDefaults() { - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) - { - QString keyValue = GetKeyName(defaults[i].toInt()); - input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); - } +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. +#include "configure_input.h" + +ConfigureInput::ConfigureInput(QWidget* parent) : + QWidget(parent), + ui(new Ui::ConfigureInput) +{ + ui->setupUi(this); + + // Initialize mapping of input enum to UI button. + input_mapping = { + { std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) }, + { std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) }, + { std::make_pair(Settings::NativeInput::Values::X, ui->btnFaceX) }, + { std::make_pair(Settings::NativeInput::Values::Y, ui->btnFaceY) }, + { std::make_pair(Settings::NativeInput::Values::L, ui->btnShdrL) }, + { std::make_pair(Settings::NativeInput::Values::R, ui->btnShdrR) }, + { std::make_pair(Settings::NativeInput::Values::ZL, ui->btnShdrZL) }, + { std::make_pair(Settings::NativeInput::Values::ZR, ui->btnShdrZR) }, + { std::make_pair(Settings::NativeInput::Values::START, ui->btnStart) }, + { std::make_pair(Settings::NativeInput::Values::SELECT, ui->btnSelect) }, + { std::make_pair(Settings::NativeInput::Values::HOME, ui->btnHome) }, + { std::make_pair(Settings::NativeInput::Values::DUP, ui->btnDirUp) }, + { std::make_pair(Settings::NativeInput::Values::DDOWN, ui->btnDirDown) }, + { std::make_pair(Settings::NativeInput::Values::DLEFT, ui->btnDirLeft) }, + { std::make_pair(Settings::NativeInput::Values::DRIGHT, ui->btnDirRight) }, + { std::make_pair(Settings::NativeInput::Values::CUP, ui->btnStickUp) }, + { std::make_pair(Settings::NativeInput::Values::CDOWN, ui->btnStickDown) }, + { std::make_pair(Settings::NativeInput::Values::CLEFT, ui->btnStickLeft) }, + { std::make_pair(Settings::NativeInput::Values::CRIGHT, ui->btnStickRight) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_UP, ui->btnCircleUp) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_DOWN, ui->btnCircleDown) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_LEFT, ui->btnCircleLeft) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) }, + }; + + // Attach handle click method to each button click. + for (const auto& entry : input_mapping) { + connect(entry.second, SIGNAL(released()), this, SLOT(handleClick())); + } + connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); + setFocusPolicy(Qt::ClickFocus); + this->setConfiguration(); +} + +ConfigureInput::~ConfigureInput() +{ +} + +/// Event handler for all button released() event. +void ConfigureInput::handleClick() +{ + QPushButton* sender = qobject_cast(QObject::sender()); + sender->setText(tr("[waiting]")); + sender->setFocus(); + grabKeyboard(); + grabMouse(); + changing_button = sender; +} + +/// Save all button configurations to settings file +void ConfigureInput::applyConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); + Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; + } + Settings::Apply(); +} + +/// Load configuration settings into button text +void ConfigureInput::setConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + QString keyValue = getKeyName(Settings::values.input_mappings[i]); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } +} + +/// Handle key press event for input tab when a button is 'waiting'. +void ConfigureInput::keyPressEvent(QKeyEvent* event) +{ + if (changing_button != nullptr && event->key() != Qt::Key_unknown) + { + keys_pressed.push_back(event->key()); + + // Can't save Modifier + Keys yet as input. Will re-enable after settings refactor + /*if (event->key() == Qt::Key_Shift) + return; + + else if (event->key() == Qt::Key_Control) + return; + + else if (event->key() == Qt::Key_Alt) + return; + + else if (event->key() == Qt::Key_Meta) + return; + else*/ + setKey(); + } +} + +/// Set button text to name of key pressed. +void ConfigureInput::setKey() +{ + QString key_value = ""; + for (int i : keys_pressed) // Will only contain one key until settings refactor + { + key_value += getKeyName(i); + } + // RemoveDuplicates(keyValue); + changing_button->setText(key_value); + + keys_pressed.clear(); + releaseKeyboard(); + releaseMouse(); + changing_button = nullptr; +} + +/// Convert key ASCII value to its' letter/name +QString ConfigureInput::getKeyName(int key_code) const +{ + if (key_code == Qt::Key_Shift) + return tr("Shift"); + + if (key_code == Qt::Key_Control) + return tr("Ctrl"); + + if (key_code == Qt::Key_Alt) + return tr("Alt"); + + if (key_code == Qt::Key_Meta) + return ""; + if (key_code == -1) + return ""; + + return QKeySequence(key_code).toString(); +} + +/// Convert letter/name of key to its ASCII value. +Qt::Key ConfigureInput::getKeyValue(const QString& text) const +{ + if (text == "Shift") + return Qt::Key_Shift; + if (text == "Ctrl") + return Qt::Key_Control; + if (text == "Alt") + return Qt::Key_Alt; + if (text == "Meta") + return Qt::Key_unknown; + if (text == "") + return Qt::Key_unknown; + return Qt::Key(QKeySequence(text)[0]); +} + +/// Check all inputs for duplicate keys. Clears out any other button with same key as new button. +void ConfigureInput::removeDuplicates(const QString& newValue) +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + if (changing_button != input_mapping[Settings::NativeInput::Values(i)]) { + QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text(); + if (newValue == oldValue) + input_mapping[Settings::NativeInput::Values(i)]->setText(""); + } + } +} + +/// Restore all buttons to their default values. +void ConfigureInput::restoreDefaults() { + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + QString keyValue = getKeyName(defaults[i].toInt()); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } } \ No newline at end of file diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index 5e66b04d9..d6745c69d 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -1,45 +1,46 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. -#pragma once -#include - -#include -#include -#include -#include -#include -#include - -#include "citra_qt/config.h" -#include "core/settings.h" -#include "ui_configure_input.h" - -namespace Ui { - class ConfigureInput; -} - -class ConfigureInput : public QWidget -{ - Q_OBJECT - -public: - explicit ConfigureInput(QWidget *parent = 0); - ~ConfigureInput(); - void applyConfiguration(); - -private: - std::unique_ptr ui; - std::map input_mapping; - std::vector keysPressed; - QPushButton* changingButton = nullptr; /// button currently waiting for key press. - - void HandleClick(); - void setConfiguration(); - void SetKey(); - void RemoveDuplicates(QString newValue); - void RestoreDefaults(); - virtual void keyPressEvent(QKeyEvent *event); - QString GetKeyName(int key_code); - int GetKeyValue(QString text); -}; +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once +#include +#include + +#include "citra_qt/config.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +class QObject; +class QPushButton; +class QString; +class QWidget; + +namespace Ui { + class ConfigureInput; +} + +class ConfigureInput : public QWidget +{ + Q_OBJECT + +public: + explicit ConfigureInput(QWidget* parent = nullptr); + ~ConfigureInput(); + void applyConfiguration(); + + public Q_SLOTS: + void handleClick(); + void restoreDefaults(); +private: + std::unique_ptr ui; + std::map input_mapping; + std::vector keys_pressed; + QPushButton* changing_button = nullptr; /// button currently waiting for key press. + + void setConfiguration(); + void setKey(); + void removeDuplicates(const QString& newValue); + void keyPressEvent(QKeyEvent* event) override; + QString getKeyName(int key_code) const; + Qt::Key ConfigureInput::getKeyValue(const QString& text) const; +}; diff --git a/src/citra_qt/configure_input.ui b/src/citra_qt/configure_input.ui index 0324f9396..5b7c568d1 100644 --- a/src/citra_qt/configure_input.ui +++ b/src/citra_qt/configure_input.ui @@ -1,975 +1,1004 @@ - - - ConfigureInput - - - - 0 - 0 - 390 - 457 - - - - ConfigureInput - - - - - 10 - 0 - 181 - 130 - - - - Face Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - A: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - B: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - X: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Y: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - 200 - 0 - 181 - 130 - - - - Directional Pad - - - false - - - false - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - 10 - 140 - 181 - 130 - - - - Shoulder Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - L: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZR: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - R: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZL: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - 200 - 140 - 181 - 130 - - - - Circle Pad - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - 10 - 280 - 181 - 130 - - - - C-Stick - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - 200 - 280 - 181 - 130 - - - - System Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Start: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Select: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Home: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - 270 - 420 - 110 - 28 - - - - Restore Defaults - - - - - - - \ No newline at end of file + + + ConfigureInput + + + + 0 + 0 + 390 + 445 + + + + ConfigureInput + + + + + + 2 + + + + + Face Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + A: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + B: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + X: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Y: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + Directional Pad + + + false + + + false + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + 2 + + + + + Shoulder Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + L: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZR: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + R: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZL: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + Circle Pad + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + 2 + + + + + C-Stick + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + System Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Start: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Select: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Home: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + + 0 + 50 + + + + + 0 + 26 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 260 + 0 + 110 + 26 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Restore Defaults + + + + + + + + + From ce0cc37045b2afa6953b35444054ca4ef2c2edad Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 12 Jun 2016 08:54:41 -0500 Subject: [PATCH 03/16] Input-GUI: More cleanup --- src/citra_qt/config.cpp | 7 +++- src/citra_qt/config.h | 7 +++- src/citra_qt/configure_dialog.cpp | 62 +++++++++++++++---------------- src/citra_qt/configure_input.cpp | 40 ++++++++------------ src/citra_qt/configure_input.h | 7 ++-- 5 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 08ec191b8..4c03bbb95 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -18,7 +18,7 @@ Config::Config() { Reload(); } -const std::array defaults = { +const std::array Config::defaults = { // directly mapped keys Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, @@ -31,6 +31,11 @@ const std::array defaults = { Qt::Key_D, }; +const std::array& Config::getDefaultInput() +{ + return defaults; +} + void Config::ReadValues() { qt_config->beginGroup("Controls"); for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index 7c6217ec1..d98ed5468 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -3,9 +3,10 @@ // Refer to the license.txt file included. #pragma once +#include +#include #include "core/settings.h" -#include class QSettings; @@ -13,6 +14,8 @@ class Config { QSettings* qt_config; std::string qt_config_loc; + static const std::array defaults; + void ReadValues(); void SaveValues(); public: @@ -21,5 +24,5 @@ public: void Reload(); void Save(); + static const std::array& getDefaultInput(); }; -extern const std::array defaults; diff --git a/src/citra_qt/configure_dialog.cpp b/src/citra_qt/configure_dialog.cpp index e6b6d45e0..47a06d756 100644 --- a/src/citra_qt/configure_dialog.cpp +++ b/src/citra_qt/configure_dialog.cpp @@ -1,31 +1,31 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "citra_qt/config.h" -#include "citra_qt/configure_dialog.h" -#include "ui_configure.h" - - -#include "core/settings.h" - -ConfigureDialog::ConfigureDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::ConfigureDialog) -{ - ui->setupUi(this); - this->setConfiguration(); -} - -ConfigureDialog::~ConfigureDialog() { -} - -void ConfigureDialog::setConfiguration() { -} - -void ConfigureDialog::applyConfiguration() { - ui->generalTab->applyConfiguration(); - ui->audioTab->applyConfiguration(); - ui->debugTab->applyConfiguration(); - ui->inputTab->applyConfiguration(); -} +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "citra_qt/config.h" +#include "citra_qt/configure_dialog.h" +#include "ui_configure.h" + + +#include "core/settings.h" + +ConfigureDialog::ConfigureDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ConfigureDialog) +{ + ui->setupUi(this); + this->setConfiguration(); +} + +ConfigureDialog::~ConfigureDialog() { +} + +void ConfigureDialog::setConfiguration() { +} + +void ConfigureDialog::applyConfiguration() { + ui->generalTab->applyConfiguration(); + ui->inputTab->applyConfiguration(); + ui->audioTab->applyConfiguration(); + ui->debugTab->applyConfiguration(); +} diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 7c20b995a..5e925dfc1 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -1,7 +1,10 @@ // Copyright 2016 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "configure_input.h" + +#include + +#include "citra_qt/configure_input.h" ConfigureInput::ConfigureInput(QWidget* parent) : QWidget(parent), @@ -53,6 +56,7 @@ ConfigureInput::~ConfigureInput() void ConfigureInput::handleClick() { QPushButton* sender = qobject_cast(QObject::sender()); + previous_mapping = sender->text(); sender->setText(tr("[waiting]")); sender->setFocus(); grabKeyboard(); @@ -84,21 +88,7 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) { if (changing_button != nullptr && event->key() != Qt::Key_unknown) { - keys_pressed.push_back(event->key()); - - // Can't save Modifier + Keys yet as input. Will re-enable after settings refactor - /*if (event->key() == Qt::Key_Shift) - return; - - else if (event->key() == Qt::Key_Control) - return; - - else if (event->key() == Qt::Key_Alt) - return; - - else if (event->key() == Qt::Key_Meta) - return; - else*/ + key_pressed = event->key(); setKey(); } } @@ -106,18 +96,17 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) /// Set button text to name of key pressed. void ConfigureInput::setKey() { - QString key_value = ""; - for (int i : keys_pressed) // Will only contain one key until settings refactor - { - key_value += getKeyName(i); - } - // RemoveDuplicates(keyValue); - changing_button->setText(key_value); + QString key_value = getKeyName(key_pressed); + if (key_pressed == Qt::Key_Escape) + changing_button->setText(previous_mapping); + else + changing_button->setText(key_value); - keys_pressed.clear(); + key_pressed = Qt::Key_unknown; releaseKeyboard(); releaseMouse(); changing_button = nullptr; + previous_mapping = nullptr; } /// Convert key ASCII value to its' letter/name @@ -134,6 +123,7 @@ QString ConfigureInput::getKeyName(int key_code) const if (key_code == Qt::Key_Meta) return ""; + if (key_code == -1) return ""; @@ -171,7 +161,7 @@ void ConfigureInput::removeDuplicates(const QString& newValue) /// Restore all buttons to their default values. void ConfigureInput::restoreDefaults() { for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - QString keyValue = getKeyName(defaults[i].toInt()); + QString keyValue = getKeyName(Config::getDefaultInput()[i].toInt()); input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); } } \ No newline at end of file diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index d6745c69d..823b31580 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -3,17 +3,17 @@ // Refer to the license.txt file included. #pragma once + #include +#include #include #include "citra_qt/config.h" #include "core/settings.h" #include "ui_configure_input.h" -class QObject; class QPushButton; class QString; -class QWidget; namespace Ui { class ConfigureInput; @@ -34,8 +34,9 @@ public: private: std::unique_ptr ui; std::map input_mapping; - std::vector keys_pressed; + int key_pressed; QPushButton* changing_button = nullptr; /// button currently waiting for key press. + QString previous_mapping; void setConfiguration(); void setKey(); From 0a49094fd530920ff11f500f16c66f790502428f Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 12 Jun 2016 16:26:21 -0500 Subject: [PATCH 04/16] Possible fix to trailing white space. Change line endings to Unix, from Windows --- src/citra_qt/config.cpp | 446 +++---- src/citra_qt/config.h | 56 +- src/citra_qt/configure_input.cpp | 334 ++--- src/citra_qt/configure_input.h | 94 +- src/citra_qt/configure_input.ui | 2008 +++++++++++++++--------------- 5 files changed, 1469 insertions(+), 1469 deletions(-) diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 4c03bbb95..0c47ef899 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -1,223 +1,223 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include - -#include "citra_qt/config.h" -#include "citra_qt/ui_settings.h" - -#include "common/file_util.h" - -Config::Config() { - // TODO: Don't hardcode the path; let the frontend decide where to put the config files. - qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini"; - FileUtil::CreateFullPath(qt_config_loc); - qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat); - - Reload(); -} - -const std::array Config::defaults = { - // directly mapped keys - Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, - Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, - Qt::Key_M, Qt::Key_N, Qt::Key_B, - Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, - Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, - - // indirectly mapped keys - Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, - Qt::Key_D, -}; - -const std::array& Config::getDefaultInput() -{ - return defaults; -} - -void Config::ReadValues() { - qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { - Settings::values.input_mappings[Settings::NativeInput::All[i]] = - qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]).toInt(); - } - Settings::values.pad_circle_modifier_scale = qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); - qt_config->endGroup(); - - qt_config->beginGroup("Core"); - Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("Renderer"); - Settings::values.use_hw_renderer = qt_config->value("use_hw_renderer", false).toBool(); - Settings::values.use_shader_jit = qt_config->value("use_shader_jit", true).toBool(); - Settings::values.use_scaled_resolution = qt_config->value("use_scaled_resolution", false).toBool(); - - Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat(); - Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat(); - Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat(); - qt_config->endGroup(); - - qt_config->beginGroup("Audio"); - Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); - qt_config->endGroup(); - - qt_config->beginGroup("System"); - Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); - Settings::values.region_value = qt_config->value("region_value", 1).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); - qt_config->endGroup(); - - qt_config->beginGroup("Debugging"); - Settings::values.use_gdbstub = qt_config->value("use_gdbstub", false).toBool(); - Settings::values.gdbstub_port = qt_config->value("gdbstub_port", 24689).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("UI"); - - qt_config->beginGroup("UILayout"); - UISettings::values.geometry = qt_config->value("geometry").toByteArray(); - UISettings::values.state = qt_config->value("state").toByteArray(); - UISettings::values.renderwindow_geometry = qt_config->value("geometryRenderWindow").toByteArray(); - UISettings::values.gamelist_header_state = qt_config->value("gameListHeaderState").toByteArray(); - UISettings::values.microprofile_geometry = qt_config->value("microProfileDialogGeometry").toByteArray(); - UISettings::values.microprofile_visible = qt_config->value("microProfileDialogVisible", false).toBool(); - qt_config->endGroup(); - - qt_config->beginGroup("Paths"); - UISettings::values.roms_path = qt_config->value("romsPath").toString(); - UISettings::values.symbols_path = qt_config->value("symbolsPath").toString(); - UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); - UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); - UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); - 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(qt_config->value("KeySeq").toString(), - qt_config->value("Context").toInt()))); - qt_config->endGroup(); - } - - qt_config->endGroup(); - } - qt_config->endGroup(); - - UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); - UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); - UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool(); - UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); - - qt_config->endGroup(); -} - -void Config::SaveValues() { - qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { - qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), - Settings::values.input_mappings[Settings::NativeInput::All[i]]); - } - qt_config->setValue("pad_circle_modifier_scale", (double)Settings::values.pad_circle_modifier_scale); - qt_config->endGroup(); - - qt_config->beginGroup("Core"); - qt_config->setValue("frame_skip", Settings::values.frame_skip); - qt_config->endGroup(); - - qt_config->beginGroup("Renderer"); - qt_config->setValue("use_hw_renderer", Settings::values.use_hw_renderer); - qt_config->setValue("use_shader_jit", Settings::values.use_shader_jit); - qt_config->setValue("use_scaled_resolution", Settings::values.use_scaled_resolution); - - // Cast to double because Qt's written float values are not human-readable - qt_config->setValue("bg_red", (double)Settings::values.bg_red); - qt_config->setValue("bg_green", (double)Settings::values.bg_green); - qt_config->setValue("bg_blue", (double)Settings::values.bg_blue); - qt_config->endGroup(); - - qt_config->beginGroup("Audio"); - qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); - qt_config->endGroup(); - - qt_config->beginGroup("System"); - qt_config->setValue("is_new_3ds", Settings::values.is_new_3ds); - qt_config->setValue("region_value", Settings::values.region_value); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); - qt_config->endGroup(); - - qt_config->beginGroup("Debugging"); - qt_config->setValue("use_gdbstub", Settings::values.use_gdbstub); - qt_config->setValue("gdbstub_port", Settings::values.gdbstub_port); - qt_config->endGroup(); - - qt_config->beginGroup("UI"); - - qt_config->beginGroup("UILayout"); - qt_config->setValue("geometry", UISettings::values.geometry); - qt_config->setValue("state", UISettings::values.state); - qt_config->setValue("geometryRenderWindow", UISettings::values.renderwindow_geometry); - qt_config->setValue("gameListHeaderState", UISettings::values.gamelist_header_state); - qt_config->setValue("microProfileDialogGeometry", UISettings::values.microprofile_geometry); - qt_config->setValue("microProfileDialogVisible", UISettings::values.microprofile_visible); - qt_config->endGroup(); - - qt_config->beginGroup("Paths"); - qt_config->setValue("romsPath", UISettings::values.roms_path); - qt_config->setValue("symbolsPath", UISettings::values.symbols_path); - qt_config->setValue("gameListRootDir", UISettings::values.gamedir); - qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); - qt_config->setValue("recentFiles", UISettings::values.recent_files); - qt_config->endGroup(); - - qt_config->beginGroup("Shortcuts"); - for (auto shortcut : UISettings::values.shortcuts) { - qt_config->setValue(shortcut.first + "/KeySeq", shortcut.second.first); - qt_config->setValue(shortcut.first + "/Context", shortcut.second.second); - } - qt_config->endGroup(); - - qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); - qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); - qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); - qt_config->setValue("firstStart", UISettings::values.first_start); - - qt_config->endGroup(); -} - -void Config::Reload() { - ReadValues(); - Settings::Apply(); -} - -void Config::Save() { - SaveValues(); -} - -Config::~Config() { - Save(); - - delete qt_config; -} \ No newline at end of file +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "citra_qt/config.h" +#include "citra_qt/ui_settings.h" + +#include "common/file_util.h" + +Config::Config() { + // TODO: Don't hardcode the path; let the frontend decide where to put the config files. + qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini"; + FileUtil::CreateFullPath(qt_config_loc); + qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat); + + Reload(); +} + +const std::array Config::defaults = { + // directly mapped keys + Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, + Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, + Qt::Key_M, Qt::Key_N, Qt::Key_B, + Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, + Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, + + // indirectly mapped keys + Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, + Qt::Key_D, +}; + +const std::array& Config::getDefaultInput() +{ + return defaults; +} + +void Config::ReadValues() { + qt_config->beginGroup("Controls"); + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { + Settings::values.input_mappings[Settings::NativeInput::All[i]] = + qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]).toInt(); + } + Settings::values.pad_circle_modifier_scale = qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); + qt_config->endGroup(); + + qt_config->beginGroup("Core"); + Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("Renderer"); + Settings::values.use_hw_renderer = qt_config->value("use_hw_renderer", false).toBool(); + Settings::values.use_shader_jit = qt_config->value("use_shader_jit", true).toBool(); + Settings::values.use_scaled_resolution = qt_config->value("use_scaled_resolution", false).toBool(); + + Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat(); + Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat(); + Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat(); + qt_config->endGroup(); + + qt_config->beginGroup("Audio"); + Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); + qt_config->endGroup(); + + qt_config->beginGroup("Data Storage"); + Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); + qt_config->endGroup(); + + qt_config->beginGroup("System"); + Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); + Settings::values.region_value = qt_config->value("region_value", 1).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("Miscellaneous"); + Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); + qt_config->endGroup(); + + qt_config->beginGroup("Debugging"); + Settings::values.use_gdbstub = qt_config->value("use_gdbstub", false).toBool(); + Settings::values.gdbstub_port = qt_config->value("gdbstub_port", 24689).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("UI"); + + qt_config->beginGroup("UILayout"); + UISettings::values.geometry = qt_config->value("geometry").toByteArray(); + UISettings::values.state = qt_config->value("state").toByteArray(); + UISettings::values.renderwindow_geometry = qt_config->value("geometryRenderWindow").toByteArray(); + UISettings::values.gamelist_header_state = qt_config->value("gameListHeaderState").toByteArray(); + UISettings::values.microprofile_geometry = qt_config->value("microProfileDialogGeometry").toByteArray(); + UISettings::values.microprofile_visible = qt_config->value("microProfileDialogVisible", false).toBool(); + qt_config->endGroup(); + + qt_config->beginGroup("Paths"); + UISettings::values.roms_path = qt_config->value("romsPath").toString(); + UISettings::values.symbols_path = qt_config->value("symbolsPath").toString(); + UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); + UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); + UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); + 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(qt_config->value("KeySeq").toString(), + qt_config->value("Context").toInt()))); + qt_config->endGroup(); + } + + qt_config->endGroup(); + } + qt_config->endGroup(); + + UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); + UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); + UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool(); + UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); + + qt_config->endGroup(); +} + +void Config::SaveValues() { + qt_config->beginGroup("Controls"); + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { + qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), + Settings::values.input_mappings[Settings::NativeInput::All[i]]); + } + qt_config->setValue("pad_circle_modifier_scale", (double)Settings::values.pad_circle_modifier_scale); + qt_config->endGroup(); + + qt_config->beginGroup("Core"); + qt_config->setValue("frame_skip", Settings::values.frame_skip); + qt_config->endGroup(); + + qt_config->beginGroup("Renderer"); + qt_config->setValue("use_hw_renderer", Settings::values.use_hw_renderer); + qt_config->setValue("use_shader_jit", Settings::values.use_shader_jit); + qt_config->setValue("use_scaled_resolution", Settings::values.use_scaled_resolution); + + // Cast to double because Qt's written float values are not human-readable + qt_config->setValue("bg_red", (double)Settings::values.bg_red); + qt_config->setValue("bg_green", (double)Settings::values.bg_green); + qt_config->setValue("bg_blue", (double)Settings::values.bg_blue); + qt_config->endGroup(); + + qt_config->beginGroup("Audio"); + qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); + qt_config->endGroup(); + + qt_config->beginGroup("Data Storage"); + qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); + qt_config->endGroup(); + + qt_config->beginGroup("System"); + qt_config->setValue("is_new_3ds", Settings::values.is_new_3ds); + qt_config->setValue("region_value", Settings::values.region_value); + qt_config->endGroup(); + + qt_config->beginGroup("Miscellaneous"); + qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); + qt_config->endGroup(); + + qt_config->beginGroup("Debugging"); + qt_config->setValue("use_gdbstub", Settings::values.use_gdbstub); + qt_config->setValue("gdbstub_port", Settings::values.gdbstub_port); + qt_config->endGroup(); + + qt_config->beginGroup("UI"); + + qt_config->beginGroup("UILayout"); + qt_config->setValue("geometry", UISettings::values.geometry); + qt_config->setValue("state", UISettings::values.state); + qt_config->setValue("geometryRenderWindow", UISettings::values.renderwindow_geometry); + qt_config->setValue("gameListHeaderState", UISettings::values.gamelist_header_state); + qt_config->setValue("microProfileDialogGeometry", UISettings::values.microprofile_geometry); + qt_config->setValue("microProfileDialogVisible", UISettings::values.microprofile_visible); + qt_config->endGroup(); + + qt_config->beginGroup("Paths"); + qt_config->setValue("romsPath", UISettings::values.roms_path); + qt_config->setValue("symbolsPath", UISettings::values.symbols_path); + qt_config->setValue("gameListRootDir", UISettings::values.gamedir); + qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); + qt_config->setValue("recentFiles", UISettings::values.recent_files); + qt_config->endGroup(); + + qt_config->beginGroup("Shortcuts"); + for (auto shortcut : UISettings::values.shortcuts) { + qt_config->setValue(shortcut.first + "/KeySeq", shortcut.second.first); + qt_config->setValue(shortcut.first + "/Context", shortcut.second.second); + } + qt_config->endGroup(); + + qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); + qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); + qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); + qt_config->setValue("firstStart", UISettings::values.first_start); + + qt_config->endGroup(); +} + +void Config::Reload() { + ReadValues(); + Settings::Apply(); +} + +void Config::Save() { + SaveValues(); +} + +Config::~Config() { + Save(); + + delete qt_config; +} diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index d98ed5468..d56d10658 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -1,28 +1,28 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once -#include -#include - -#include "core/settings.h" - -class QSettings; - -class Config { - QSettings* qt_config; - std::string qt_config_loc; - - static const std::array defaults; - - void ReadValues(); - void SaveValues(); -public: - Config(); - ~Config(); - - void Reload(); - void Save(); - static const std::array& getDefaultInput(); -}; +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once +#include +#include + +#include "core/settings.h" + +class QSettings; + +class Config { + QSettings* qt_config; + std::string qt_config_loc; + + static const std::array defaults; + + void ReadValues(); + void SaveValues(); +public: + Config(); + ~Config(); + + void Reload(); + void Save(); + static const std::array& getDefaultInput(); +}; diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 5e925dfc1..6046f527c 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -1,167 +1,167 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include - -#include "citra_qt/configure_input.h" - -ConfigureInput::ConfigureInput(QWidget* parent) : - QWidget(parent), - ui(new Ui::ConfigureInput) -{ - ui->setupUi(this); - - // Initialize mapping of input enum to UI button. - input_mapping = { - { std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) }, - { std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) }, - { std::make_pair(Settings::NativeInput::Values::X, ui->btnFaceX) }, - { std::make_pair(Settings::NativeInput::Values::Y, ui->btnFaceY) }, - { std::make_pair(Settings::NativeInput::Values::L, ui->btnShdrL) }, - { std::make_pair(Settings::NativeInput::Values::R, ui->btnShdrR) }, - { std::make_pair(Settings::NativeInput::Values::ZL, ui->btnShdrZL) }, - { std::make_pair(Settings::NativeInput::Values::ZR, ui->btnShdrZR) }, - { std::make_pair(Settings::NativeInput::Values::START, ui->btnStart) }, - { std::make_pair(Settings::NativeInput::Values::SELECT, ui->btnSelect) }, - { std::make_pair(Settings::NativeInput::Values::HOME, ui->btnHome) }, - { std::make_pair(Settings::NativeInput::Values::DUP, ui->btnDirUp) }, - { std::make_pair(Settings::NativeInput::Values::DDOWN, ui->btnDirDown) }, - { std::make_pair(Settings::NativeInput::Values::DLEFT, ui->btnDirLeft) }, - { std::make_pair(Settings::NativeInput::Values::DRIGHT, ui->btnDirRight) }, - { std::make_pair(Settings::NativeInput::Values::CUP, ui->btnStickUp) }, - { std::make_pair(Settings::NativeInput::Values::CDOWN, ui->btnStickDown) }, - { std::make_pair(Settings::NativeInput::Values::CLEFT, ui->btnStickLeft) }, - { std::make_pair(Settings::NativeInput::Values::CRIGHT, ui->btnStickRight) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_UP, ui->btnCircleUp) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_DOWN, ui->btnCircleDown) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_LEFT, ui->btnCircleLeft) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) }, - }; - - // Attach handle click method to each button click. - for (const auto& entry : input_mapping) { - connect(entry.second, SIGNAL(released()), this, SLOT(handleClick())); - } - connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); - setFocusPolicy(Qt::ClickFocus); - this->setConfiguration(); -} - -ConfigureInput::~ConfigureInput() -{ -} - -/// Event handler for all button released() event. -void ConfigureInput::handleClick() -{ - QPushButton* sender = qobject_cast(QObject::sender()); - previous_mapping = sender->text(); - sender->setText(tr("[waiting]")); - sender->setFocus(); - grabKeyboard(); - grabMouse(); - changing_button = sender; -} - -/// Save all button configurations to settings file -void ConfigureInput::applyConfiguration() -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); - Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; - } - Settings::Apply(); -} - -/// Load configuration settings into button text -void ConfigureInput::setConfiguration() -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - QString keyValue = getKeyName(Settings::values.input_mappings[i]); - input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); - } -} - -/// Handle key press event for input tab when a button is 'waiting'. -void ConfigureInput::keyPressEvent(QKeyEvent* event) -{ - if (changing_button != nullptr && event->key() != Qt::Key_unknown) - { - key_pressed = event->key(); - setKey(); - } -} - -/// Set button text to name of key pressed. -void ConfigureInput::setKey() -{ - QString key_value = getKeyName(key_pressed); - if (key_pressed == Qt::Key_Escape) - changing_button->setText(previous_mapping); - else - changing_button->setText(key_value); - - key_pressed = Qt::Key_unknown; - releaseKeyboard(); - releaseMouse(); - changing_button = nullptr; - previous_mapping = nullptr; -} - -/// Convert key ASCII value to its' letter/name -QString ConfigureInput::getKeyName(int key_code) const -{ - if (key_code == Qt::Key_Shift) - return tr("Shift"); - - if (key_code == Qt::Key_Control) - return tr("Ctrl"); - - if (key_code == Qt::Key_Alt) - return tr("Alt"); - - if (key_code == Qt::Key_Meta) - return ""; - - if (key_code == -1) - return ""; - - return QKeySequence(key_code).toString(); -} - -/// Convert letter/name of key to its ASCII value. -Qt::Key ConfigureInput::getKeyValue(const QString& text) const -{ - if (text == "Shift") - return Qt::Key_Shift; - if (text == "Ctrl") - return Qt::Key_Control; - if (text == "Alt") - return Qt::Key_Alt; - if (text == "Meta") - return Qt::Key_unknown; - if (text == "") - return Qt::Key_unknown; - return Qt::Key(QKeySequence(text)[0]); -} - -/// Check all inputs for duplicate keys. Clears out any other button with same key as new button. -void ConfigureInput::removeDuplicates(const QString& newValue) -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - if (changing_button != input_mapping[Settings::NativeInput::Values(i)]) { - QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text(); - if (newValue == oldValue) - input_mapping[Settings::NativeInput::Values(i)]->setText(""); - } - } -} - -/// Restore all buttons to their default values. -void ConfigureInput::restoreDefaults() { - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - QString keyValue = getKeyName(Config::getDefaultInput()[i].toInt()); - input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); - } -} \ No newline at end of file +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "citra_qt/configure_input.h" + +ConfigureInput::ConfigureInput(QWidget* parent) : + QWidget(parent), + ui(new Ui::ConfigureInput) +{ + ui->setupUi(this); + + // Initialize mapping of input enum to UI button. + input_mapping = { + { std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) }, + { std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) }, + { std::make_pair(Settings::NativeInput::Values::X, ui->btnFaceX) }, + { std::make_pair(Settings::NativeInput::Values::Y, ui->btnFaceY) }, + { std::make_pair(Settings::NativeInput::Values::L, ui->btnShdrL) }, + { std::make_pair(Settings::NativeInput::Values::R, ui->btnShdrR) }, + { std::make_pair(Settings::NativeInput::Values::ZL, ui->btnShdrZL) }, + { std::make_pair(Settings::NativeInput::Values::ZR, ui->btnShdrZR) }, + { std::make_pair(Settings::NativeInput::Values::START, ui->btnStart) }, + { std::make_pair(Settings::NativeInput::Values::SELECT, ui->btnSelect) }, + { std::make_pair(Settings::NativeInput::Values::HOME, ui->btnHome) }, + { std::make_pair(Settings::NativeInput::Values::DUP, ui->btnDirUp) }, + { std::make_pair(Settings::NativeInput::Values::DDOWN, ui->btnDirDown) }, + { std::make_pair(Settings::NativeInput::Values::DLEFT, ui->btnDirLeft) }, + { std::make_pair(Settings::NativeInput::Values::DRIGHT, ui->btnDirRight) }, + { std::make_pair(Settings::NativeInput::Values::CUP, ui->btnStickUp) }, + { std::make_pair(Settings::NativeInput::Values::CDOWN, ui->btnStickDown) }, + { std::make_pair(Settings::NativeInput::Values::CLEFT, ui->btnStickLeft) }, + { std::make_pair(Settings::NativeInput::Values::CRIGHT, ui->btnStickRight) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_UP, ui->btnCircleUp) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_DOWN, ui->btnCircleDown) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_LEFT, ui->btnCircleLeft) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) }, + }; + + // Attach handle click method to each button click. + for (const auto& entry : input_mapping) { + connect(entry.second, SIGNAL(released()), this, SLOT(handleClick())); + } + connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); + setFocusPolicy(Qt::ClickFocus); + this->setConfiguration(); +} + +ConfigureInput::~ConfigureInput() +{ +} + +/// Event handler for all button released() event. +void ConfigureInput::handleClick() +{ + QPushButton* sender = qobject_cast(QObject::sender()); + previous_mapping = sender->text(); + sender->setText(tr("[waiting]")); + sender->setFocus(); + grabKeyboard(); + grabMouse(); + changing_button = sender; +} + +/// Save all button configurations to settings file +void ConfigureInput::applyConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); + Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; + } + Settings::Apply(); +} + +/// Load configuration settings into button text +void ConfigureInput::setConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + QString keyValue = getKeyName(Settings::values.input_mappings[i]); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } +} + +/// Handle key press event for input tab when a button is 'waiting'. +void ConfigureInput::keyPressEvent(QKeyEvent* event) +{ + if (changing_button != nullptr && event->key() != Qt::Key_unknown) + { + key_pressed = event->key(); + setKey(); + } +} + +/// Set button text to name of key pressed. +void ConfigureInput::setKey() +{ + QString key_value = getKeyName(key_pressed); + if (key_pressed == Qt::Key_Escape) + changing_button->setText(previous_mapping); + else + changing_button->setText(key_value); + + key_pressed = Qt::Key_unknown; + releaseKeyboard(); + releaseMouse(); + changing_button = nullptr; + previous_mapping = nullptr; +} + +/// Convert key ASCII value to its' letter/name +QString ConfigureInput::getKeyName(int key_code) const +{ + if (key_code == Qt::Key_Shift) + return tr("Shift"); + + if (key_code == Qt::Key_Control) + return tr("Ctrl"); + + if (key_code == Qt::Key_Alt) + return tr("Alt"); + + if (key_code == Qt::Key_Meta) + return ""; + + if (key_code == -1) + return ""; + + return QKeySequence(key_code).toString(); +} + +/// Convert letter/name of key to its ASCII value. +Qt::Key ConfigureInput::getKeyValue(const QString& text) const +{ + if (text == "Shift") + return Qt::Key_Shift; + if (text == "Ctrl") + return Qt::Key_Control; + if (text == "Alt") + return Qt::Key_Alt; + if (text == "Meta") + return Qt::Key_unknown; + if (text == "") + return Qt::Key_unknown; + return Qt::Key(QKeySequence(text)[0]); +} + +/// Check all inputs for duplicate keys. Clears out any other button with same key as new button. +void ConfigureInput::removeDuplicates(const QString& newValue) +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + if (changing_button != input_mapping[Settings::NativeInput::Values(i)]) { + QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text(); + if (newValue == oldValue) + input_mapping[Settings::NativeInput::Values(i)]->setText(""); + } + } +} + +/// Restore all buttons to their default values. +void ConfigureInput::restoreDefaults() { + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + QString keyValue = getKeyName(Config::getDefaultInput()[i].toInt()); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } +} diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index 823b31580..cfa4a5163 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -1,47 +1,47 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include "citra_qt/config.h" -#include "core/settings.h" -#include "ui_configure_input.h" - -class QPushButton; -class QString; - -namespace Ui { - class ConfigureInput; -} - -class ConfigureInput : public QWidget -{ - Q_OBJECT - -public: - explicit ConfigureInput(QWidget* parent = nullptr); - ~ConfigureInput(); - void applyConfiguration(); - - public Q_SLOTS: - void handleClick(); - void restoreDefaults(); -private: - std::unique_ptr ui; - std::map input_mapping; - int key_pressed; - QPushButton* changing_button = nullptr; /// button currently waiting for key press. - QString previous_mapping; - - void setConfiguration(); - void setKey(); - void removeDuplicates(const QString& newValue); - void keyPressEvent(QKeyEvent* event) override; - QString getKeyName(int key_code) const; - Qt::Key ConfigureInput::getKeyValue(const QString& text) const; -}; +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include "citra_qt/config.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +class QPushButton; +class QString; + +namespace Ui { + class ConfigureInput; +} + +class ConfigureInput : public QWidget +{ + Q_OBJECT + +public: + explicit ConfigureInput(QWidget* parent = nullptr); + ~ConfigureInput(); + void applyConfiguration(); + + public Q_SLOTS: + void handleClick(); + void restoreDefaults(); +private: + std::unique_ptr ui; + std::map input_mapping; + int key_pressed; + QPushButton* changing_button = nullptr; /// button currently waiting for key press. + QString previous_mapping; + + void setConfiguration(); + void setKey(); + void removeDuplicates(const QString& newValue); + void keyPressEvent(QKeyEvent* event) override; + QString getKeyName(int key_code) const; + Qt::Key ConfigureInput::getKeyValue(const QString& text) const; +}; diff --git a/src/citra_qt/configure_input.ui b/src/citra_qt/configure_input.ui index 5b7c568d1..fef62cb10 100644 --- a/src/citra_qt/configure_input.ui +++ b/src/citra_qt/configure_input.ui @@ -1,1004 +1,1004 @@ - - - ConfigureInput - - - - 0 - 0 - 390 - 445 - - - - ConfigureInput - - - - - - 2 - - - - - Face Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - A: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - B: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - X: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Y: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - Directional Pad - - - false - - - false - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - 2 - - - - - Shoulder Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - L: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZR: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - R: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZL: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - Circle Pad - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - 2 - - - - - C-Stick - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - System Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Start: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Select: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Home: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - - 0 - 50 - - - - - 0 - 26 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 260 - 0 - 110 - 26 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Restore Defaults - - - - - - - - - + + + ConfigureInput + + + + 0 + 0 + 390 + 445 + + + + ConfigureInput + + + + + + 2 + + + + + Face Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + A: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + B: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + X: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Y: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + Directional Pad + + + false + + + false + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + 2 + + + + + Shoulder Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + L: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZR: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + R: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZL: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + Circle Pad + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + 2 + + + + + C-Stick + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + System Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Start: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Select: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Home: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + + 0 + 50 + + + + + 0 + 26 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 260 + 0 + 110 + 26 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Restore Defaults + + + + + + + + + From 323b3e94e197605cf5a933100677cf208c09a703 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 12 Jun 2016 16:33:56 -0500 Subject: [PATCH 05/16] Change line endings --- src/citra_qt/configure_dialog.cpp | 62 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/citra_qt/configure_dialog.cpp b/src/citra_qt/configure_dialog.cpp index 47a06d756..441334f4c 100644 --- a/src/citra_qt/configure_dialog.cpp +++ b/src/citra_qt/configure_dialog.cpp @@ -1,31 +1,31 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "citra_qt/config.h" -#include "citra_qt/configure_dialog.h" -#include "ui_configure.h" - - -#include "core/settings.h" - -ConfigureDialog::ConfigureDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::ConfigureDialog) -{ - ui->setupUi(this); - this->setConfiguration(); -} - -ConfigureDialog::~ConfigureDialog() { -} - -void ConfigureDialog::setConfiguration() { -} - -void ConfigureDialog::applyConfiguration() { - ui->generalTab->applyConfiguration(); - ui->inputTab->applyConfiguration(); - ui->audioTab->applyConfiguration(); - ui->debugTab->applyConfiguration(); -} +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "citra_qt/config.h" +#include "citra_qt/configure_dialog.h" +#include "ui_configure.h" + + +#include "core/settings.h" + +ConfigureDialog::ConfigureDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ConfigureDialog) +{ + ui->setupUi(this); + this->setConfiguration(); +} + +ConfigureDialog::~ConfigureDialog() { +} + +void ConfigureDialog::setConfiguration() { +} + +void ConfigureDialog::applyConfiguration() { + ui->generalTab->applyConfiguration(); + ui->inputTab->applyConfiguration(); + ui->audioTab->applyConfiguration(); + ui->debugTab->applyConfiguration(); +} From edb155f9e562efd26d3fa945bbea5464ce54e028 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 12 Jun 2016 16:53:51 -0500 Subject: [PATCH 06/16] Fix build --- src/citra_qt/configure_input.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index cfa4a5163..a3df7fc97 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -43,5 +43,5 @@ private: void removeDuplicates(const QString& newValue); void keyPressEvent(QKeyEvent* event) override; QString getKeyName(int key_code) const; - Qt::Key ConfigureInput::getKeyValue(const QString& text) const; + Qt::Key getKeyValue(const QString& text) const; }; From e07e3d38e32318290cde3e9bd373f6110c2bb665 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 12 Jun 2016 21:12:45 -0500 Subject: [PATCH 07/16] Clean up --- src/citra_qt/config.cpp | 2 +- src/citra_qt/config.h | 2 +- src/citra_qt/configure_input.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 0c47ef899..a1ab80cd9 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -31,7 +31,7 @@ const std::array Config::defaults = Qt::Key_D, }; -const std::array& Config::getDefaultInput() +const std::array& Config::GetDefaultInput() { return defaults; } diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index d56d10658..0ef55b28a 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -24,5 +24,5 @@ public: void Reload(); void Save(); - static const std::array& getDefaultInput(); + static const std::array& GetDefaultInput(); }; diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 6046f527c..9cb704d7d 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -161,7 +161,7 @@ void ConfigureInput::removeDuplicates(const QString& newValue) /// Restore all buttons to their default values. void ConfigureInput::restoreDefaults() { for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - QString keyValue = getKeyName(Config::getDefaultInput()[i].toInt()); + QString keyValue = getKeyName(Config::GetDefaultInput()[i].toInt()); input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); } } From 1988f6320d696274248c429dc8827663b9e6d8c5 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Thu, 16 Jun 2016 18:37:09 -0500 Subject: [PATCH 08/16] Fix layout. Fix duplicate keys. --- src/citra_qt/configure.ui | 8 +++++++- src/citra_qt/configure_input.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/citra_qt/configure.ui b/src/citra_qt/configure.ui index 09c2026de..847605c44 100644 --- a/src/citra_qt/configure.ui +++ b/src/citra_qt/configure.ui @@ -1,4 +1,4 @@ - + ConfigureDialog @@ -10,6 +10,12 @@ 501 + + + 441 + 0 + + Citra Configuration diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 9cb704d7d..9922f45a9 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -101,7 +101,7 @@ void ConfigureInput::setKey() changing_button->setText(previous_mapping); else changing_button->setText(key_value); - + removeDuplicates(key_value); key_pressed = Qt::Key_unknown; releaseKeyboard(); releaseMouse(); From e7abf0f32c64c32761d606f46f231161ccf1f6d1 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 19 Jun 2016 16:11:56 -0500 Subject: [PATCH 09/16] Input GUI: Fix UI Layout --- src/citra_qt/configure_input.ui | 1579 +++++++++++-------------------- 1 file changed, 575 insertions(+), 1004 deletions(-) diff --git a/src/citra_qt/configure_input.ui b/src/citra_qt/configure_input.ui index fef62cb10..c6b83c67a 100644 --- a/src/citra_qt/configure_input.ui +++ b/src/citra_qt/configure_input.ui @@ -1,1004 +1,575 @@ - - - ConfigureInput - - - - 0 - 0 - 390 - 445 - - - - ConfigureInput - - - - - - 2 - - - - - Face Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - A: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - B: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - X: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Y: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - Directional Pad - - - false - - - false - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - 2 - - - - - Shoulder Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - L: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZR: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - R: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZL: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - Circle Pad - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - 2 - - - - - C-Stick - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - System Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Start: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Select: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Home: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - - 0 - 50 - - - - - 0 - 26 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 260 - 0 - 110 - 26 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Restore Defaults - - - - - - - - - + + + ConfigureInput + + + + 0 + 0 + 370 + 435 + + + + ConfigureInput + + + + + + + + Face Buttons + + + false + + + false + + + + + + + + A: + + + + + + + + + + + + + + + + + + B: + + + + + + + + + + + + + + + + + + X: + + + + + + + + + + + + + + + + + + Y: + + + + + + + + + + + + + + + + + + + Directional Pad + + + false + + + false + + + + + + + + Up: + + + + + + + + + + + + + + + + + + Down: + + + + + + + + + + + + + + + + + + Left: + + + + + + + + + + + + + + + + + + Right: + + + + + + + + + + + + + + + + + + + Shoulder Buttons + + + false + + + false + + + + + + + + L: + + + + + + + + + + + + + + + + + + R: + + + + + + + + + + + + + + + + + + ZL: + + + + + + + + + + + + + + + + + + ZR: + + + + + + + + + + + + + + + + + + + + Circle Pad + + + false + + + false + + + + + + + + Left: + + + + + + + + + + + + + + + + + + Right: + + + + + + + + + + + + + + + + + + Up: + + + + + + + + + + + + + + + + + + Down: + + + + + + + + + + + + + + + + + + + C-Stick + + + false + + + false + + + + + + + + Left: + + + + + + + + + + + + + + + + + + Right: + + + + + + + + + + + + + + + + + + Up: + + + + + + + + + + + + + + + + + + Down: + + + + + + + + + + + + + + + + + + + System Buttons + + + false + + + false + + + + + + + + Start: + + + + + + + + + + + + + + + + + + Select: + + + + + + + + + + + + + + + + + + Home: + + + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Restore Defaults + + + + + + + + + + From d137ccca5837514a97565a87e2848a28254d0b60 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 19 Jun 2016 18:51:59 -0500 Subject: [PATCH 10/16] Fix build --- src/citra_qt/configure_input.ui | 1150 +++++++++++++++---------------- 1 file changed, 575 insertions(+), 575 deletions(-) diff --git a/src/citra_qt/configure_input.ui b/src/citra_qt/configure_input.ui index c6b83c67a..505db1f77 100644 --- a/src/citra_qt/configure_input.ui +++ b/src/citra_qt/configure_input.ui @@ -1,575 +1,575 @@ - - - ConfigureInput - - - - 0 - 0 - 370 - 435 - - - - ConfigureInput - - - - - - - - Face Buttons - - - false - - - false - - - - - - - - A: - - - - - - - - - - - - - - - - - - B: - - - - - - - - - - - - - - - - - - X: - - - - - - - - - - - - - - - - - - Y: - - - - - - - - - - - - - - - - - - - Directional Pad - - - false - - - false - - - - - - - - Up: - - - - - - - - - - - - - - - - - - Down: - - - - - - - - - - - - - - - - - - Left: - - - - - - - - - - - - - - - - - - Right: - - - - - - - - - - - - - - - - - - - Shoulder Buttons - - - false - - - false - - - - - - - - L: - - - - - - - - - - - - - - - - - - R: - - - - - - - - - - - - - - - - - - ZL: - - - - - - - - - - - - - - - - - - ZR: - - - - - - - - - - - - - - - - - - - - Circle Pad - - - false - - - false - - - - - - - - Left: - - - - - - - - - - - - - - - - - - Right: - - - - - - - - - - - - - - - - - - Up: - - - - - - - - - - - - - - - - - - Down: - - - - - - - - - - - - - - - - - - - C-Stick - - - false - - - false - - - - - - - - Left: - - - - - - - - - - - - - - - - - - Right: - - - - - - - - - - - - - - - - - - Up: - - - - - - - - - - - - - - - - - - Down: - - - - - - - - - - - - - - - - - - - System Buttons - - - false - - - false - - - - - - - - Start: - - - - - - - - - - - - - - - - - - Select: - - - - - - - - - - - - - - - - - - Home: - - - - - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Restore Defaults - - - - - - - - - - + + + ConfigureInput + + + + 0 + 0 + 370 + 435 + + + + ConfigureInput + + + + + + + + Face Buttons + + + false + + + false + + + + + + + + A: + + + + + + + + + + + + + + + + + + B: + + + + + + + + + + + + + + + + + + X: + + + + + + + + + + + + + + + + + + Y: + + + + + + + + + + + + + + + + + + + Directional Pad + + + false + + + false + + + + + + + + Up: + + + + + + + + + + + + + + + + + + Down: + + + + + + + + + + + + + + + + + + Left: + + + + + + + + + + + + + + + + + + Right: + + + + + + + + + + + + + + + + + + + Shoulder Buttons + + + false + + + false + + + + + + + + L: + + + + + + + + + + + + + + + + + + R: + + + + + + + + + + + + + + + + + + ZL: + + + + + + + + + + + + + + + + + + ZR: + + + + + + + + + + + + + + + + + + + + Circle Pad + + + false + + + false + + + + + + + + Left: + + + + + + + + + + + + + + + + + + Right: + + + + + + + + + + + + + + + + + + Up: + + + + + + + + + + + + + + + + + + Down: + + + + + + + + + + + + + + + + + + + C-Stick + + + false + + + false + + + + + + + + Left: + + + + + + + + + + + + + + + + + + Right: + + + + + + + + + + + + + + + + + + Up: + + + + + + + + + + + + + + + + + + Down: + + + + + + + + + + + + + + + + + + + System Buttons + + + false + + + false + + + + + + + + Start: + + + + + + + + + + + + + + + + + + Select: + + + + + + + + + + + + + + + + + + Home: + + + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Restore Defaults + + + + + + + + + + \ No newline at end of file From cacc5b439e9354aa65617df63c4d39b31a94cbd0 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Tue, 21 Jun 2016 20:09:34 -0500 Subject: [PATCH 11/16] Input GUI: Add 5 second timeout to button click. --- src/citra_qt/configure_input.cpp | 7 ++- src/citra_qt/configure_input.h | 97 ++++++++++++++++---------------- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 9922f45a9..64e16d0b5 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -45,11 +45,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) : } connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); setFocusPolicy(Qt::ClickFocus); + timer->setSingleShot(true); + connect(timer, &QTimer::timeout, this, [&]() { key_pressed = Qt::Key_Escape; setKey(); }); this->setConfiguration(); } ConfigureInput::~ConfigureInput() { + delete timer; } /// Event handler for all button released() event. @@ -62,6 +65,7 @@ void ConfigureInput::handleClick() grabKeyboard(); grabMouse(); changing_button = sender; + timer->start(5000); //Cancel after 5 seconds } /// Save all button configurations to settings file @@ -89,6 +93,7 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) if (changing_button != nullptr && event->key() != Qt::Key_unknown) { key_pressed = event->key(); + timer->stop(); setKey(); } } @@ -164,4 +169,4 @@ void ConfigureInput::restoreDefaults() { QString keyValue = getKeyName(Config::GetDefaultInput()[i].toInt()); input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); } -} +} \ No newline at end of file diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index a3df7fc97..1718d69e8 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -1,47 +1,50 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include "citra_qt/config.h" -#include "core/settings.h" -#include "ui_configure_input.h" - -class QPushButton; -class QString; - -namespace Ui { - class ConfigureInput; -} - -class ConfigureInput : public QWidget -{ - Q_OBJECT - -public: - explicit ConfigureInput(QWidget* parent = nullptr); - ~ConfigureInput(); - void applyConfiguration(); - - public Q_SLOTS: - void handleClick(); - void restoreDefaults(); -private: - std::unique_ptr ui; - std::map input_mapping; - int key_pressed; - QPushButton* changing_button = nullptr; /// button currently waiting for key press. - QString previous_mapping; - - void setConfiguration(); - void setKey(); - void removeDuplicates(const QString& newValue); - void keyPressEvent(QKeyEvent* event) override; - QString getKeyName(int key_code) const; - Qt::Key getKeyValue(const QString& text) const; -}; +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include + +#include "citra_qt/config.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +class QPushButton; +class QString; + +namespace Ui { + class ConfigureInput; +} + +class ConfigureInput : public QWidget +{ + Q_OBJECT + +public: + explicit ConfigureInput(QWidget* parent = nullptr); + ~ConfigureInput(); + void applyConfiguration(); + + public Q_SLOTS: + void handleClick(); + void restoreDefaults(); +private: + std::unique_ptr ui; + std::map input_mapping; + int key_pressed; + QPushButton* changing_button = nullptr; /// button currently waiting for key press. + QString previous_mapping; + QTimer* timer = new QTimer(); + + void setConfiguration(); + void removeDuplicates(const QString& newValue); + void keyPressEvent(QKeyEvent* event) override; + QString getKeyName(int key_code) const; + Qt::Key getKeyValue(const QString& text) const; + private Q_SLOTS: + void setKey(); +}; From 57cb68f47df5fbdfd59d9d2935c1f5f30cedb866 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Tue, 21 Jun 2016 22:22:22 -0500 Subject: [PATCH 12/16] Fix build. Again. --- src/citra_qt/configure_input.h | 100 ++++++++++++++++----------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index 1718d69e8..8aa27fa18 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -1,50 +1,50 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include -#include - -#include "citra_qt/config.h" -#include "core/settings.h" -#include "ui_configure_input.h" - -class QPushButton; -class QString; - -namespace Ui { - class ConfigureInput; -} - -class ConfigureInput : public QWidget -{ - Q_OBJECT - -public: - explicit ConfigureInput(QWidget* parent = nullptr); - ~ConfigureInput(); - void applyConfiguration(); - - public Q_SLOTS: - void handleClick(); - void restoreDefaults(); -private: - std::unique_ptr ui; - std::map input_mapping; - int key_pressed; - QPushButton* changing_button = nullptr; /// button currently waiting for key press. - QString previous_mapping; - QTimer* timer = new QTimer(); - - void setConfiguration(); - void removeDuplicates(const QString& newValue); - void keyPressEvent(QKeyEvent* event) override; - QString getKeyName(int key_code) const; - Qt::Key getKeyValue(const QString& text) const; - private Q_SLOTS: - void setKey(); -}; +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include + +#include "citra_qt/config.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +class QPushButton; +class QString; + +namespace Ui { + class ConfigureInput; +} + +class ConfigureInput : public QWidget +{ + Q_OBJECT + +public: + explicit ConfigureInput(QWidget* parent = nullptr); + ~ConfigureInput(); + void applyConfiguration(); + + public Q_SLOTS: + void handleClick(); + void restoreDefaults(); +private: + std::unique_ptr ui; + std::map input_mapping; + int key_pressed; + QPushButton* changing_button = nullptr; /// button currently waiting for key press. + QString previous_mapping; + QTimer* timer = new QTimer(); + + void setConfiguration(); + void removeDuplicates(const QString& newValue); + void keyPressEvent(QKeyEvent* event) override; + QString getKeyName(int key_code) const; + Qt::Key getKeyValue(const QString& text) const; + private Q_SLOTS: + void setKey(); +}; From 071d0325a3e1434936e602cbcc07e4a39067ce34 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Wed, 22 Jun 2016 20:43:49 -0500 Subject: [PATCH 13/16] cleanup code --- src/citra_qt/configure_input.cpp | 1 - src/citra_qt/configure_input.h | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 64e16d0b5..900cbce27 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -52,7 +52,6 @@ ConfigureInput::ConfigureInput(QWidget* parent) : ConfigureInput::~ConfigureInput() { - delete timer; } /// Event handler for all button released() event. diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index 8aa27fa18..bf2780cd3 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -29,22 +29,21 @@ public: ~ConfigureInput(); void applyConfiguration(); - public Q_SLOTS: - void handleClick(); - void restoreDefaults(); private: std::unique_ptr ui; std::map input_mapping; int key_pressed; QPushButton* changing_button = nullptr; /// button currently waiting for key press. QString previous_mapping; - QTimer* timer = new QTimer(); + QTimer* timer = new QTimer(this); void setConfiguration(); void removeDuplicates(const QString& newValue); void keyPressEvent(QKeyEvent* event) override; QString getKeyName(int key_code) const; Qt::Key getKeyValue(const QString& text) const; - private Q_SLOTS: - void setKey(); + void setKey(); +private Q_SLOTS: + void handleClick(); + void restoreDefaults(); }; From 4ba93b819a21b9d98da1bc25607cae94a98652ce Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Thu, 23 Jun 2016 07:00:07 -0500 Subject: [PATCH 14/16] Cleanup --- src/citra_qt/configure_input.cpp | 2 ++ src/citra_qt/configure_input.h | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 900cbce27..dd78c463a 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "citra_qt/configure_input.h" @@ -45,6 +46,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) : } connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); setFocusPolicy(Qt::ClickFocus); + timer = new QTimer(this); timer->setSingleShot(true); connect(timer, &QTimer::timeout, this, [&]() { key_pressed = Qt::Key_Escape; setKey(); }); this->setConfiguration(); diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index bf2780cd3..aa3d9ff4d 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -7,7 +7,6 @@ #include #include #include -#include #include "citra_qt/config.h" #include "core/settings.h" @@ -15,6 +14,7 @@ class QPushButton; class QString; +class QTimer; namespace Ui { class ConfigureInput; @@ -35,15 +35,15 @@ private: int key_pressed; QPushButton* changing_button = nullptr; /// button currently waiting for key press. QString previous_mapping; - QTimer* timer = new QTimer(this); + QTimer* timer; void setConfiguration(); void removeDuplicates(const QString& newValue); void keyPressEvent(QKeyEvent* event) override; QString getKeyName(int key_code) const; Qt::Key getKeyValue(const QString& text) const; - void setKey(); -private Q_SLOTS: + void setKey(); + private Q_SLOTS: void handleClick(); void restoreDefaults(); }; From e4146949a024826487ce259cfd81336912979825 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Thu, 23 Jun 2016 07:01:27 -0500 Subject: [PATCH 15/16] More Cleanup --- src/citra_qt/configure_input.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index aa3d9ff4d..d5650f626 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -43,7 +43,7 @@ private: QString getKeyName(int key_code) const; Qt::Key getKeyValue(const QString& text) const; void setKey(); - private Q_SLOTS: +private slots: void handleClick(); void restoreDefaults(); }; From 2a181dd460e5ef3d861e7101ced97574e29622ac Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Thu, 7 Jul 2016 19:42:35 -0500 Subject: [PATCH 16/16] Cleanup --- src/citra_qt/config.h | 3 ++- src/citra_qt/configure.ui | 6 ------ src/citra_qt/configure_input.cpp | 32 +++++++++++--------------------- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index 0ef55b28a..0f42aaf8b 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -1,8 +1,9 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2014 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once + #include #include diff --git a/src/citra_qt/configure.ui b/src/citra_qt/configure.ui index 847605c44..2f98eb5ba 100644 --- a/src/citra_qt/configure.ui +++ b/src/citra_qt/configure.ui @@ -10,12 +10,6 @@ 501 - - - 441 - 0 - - Citra Configuration diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index dd78c463a..fb69e53a7 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2016 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -9,8 +9,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) : QWidget(parent), - ui(new Ui::ConfigureInput) -{ + ui(new Ui::ConfigureInput){ ui->setupUi(this); // Initialize mapping of input enum to UI button. @@ -52,13 +51,11 @@ ConfigureInput::ConfigureInput(QWidget* parent) : this->setConfiguration(); } -ConfigureInput::~ConfigureInput() -{ +ConfigureInput::~ConfigureInput(){ } /// Event handler for all button released() event. -void ConfigureInput::handleClick() -{ +void ConfigureInput::handleClick(){ QPushButton* sender = qobject_cast(QObject::sender()); previous_mapping = sender->text(); sender->setText(tr("[waiting]")); @@ -70,8 +67,7 @@ void ConfigureInput::handleClick() } /// Save all button configurations to settings file -void ConfigureInput::applyConfiguration() -{ +void ConfigureInput::applyConfiguration(){ for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; @@ -80,8 +76,7 @@ void ConfigureInput::applyConfiguration() } /// Load configuration settings into button text -void ConfigureInput::setConfiguration() -{ +void ConfigureInput::setConfiguration(){ for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { QString keyValue = getKeyName(Settings::values.input_mappings[i]); input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); @@ -89,8 +84,7 @@ void ConfigureInput::setConfiguration() } /// Handle key press event for input tab when a button is 'waiting'. -void ConfigureInput::keyPressEvent(QKeyEvent* event) -{ +void ConfigureInput::keyPressEvent(QKeyEvent* event){ if (changing_button != nullptr && event->key() != Qt::Key_unknown) { key_pressed = event->key(); @@ -100,8 +94,7 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) } /// Set button text to name of key pressed. -void ConfigureInput::setKey() -{ +void ConfigureInput::setKey(){ QString key_value = getKeyName(key_pressed); if (key_pressed == Qt::Key_Escape) changing_button->setText(previous_mapping); @@ -116,8 +109,7 @@ void ConfigureInput::setKey() } /// Convert key ASCII value to its' letter/name -QString ConfigureInput::getKeyName(int key_code) const -{ +QString ConfigureInput::getKeyName(int key_code) const{ if (key_code == Qt::Key_Shift) return tr("Shift"); @@ -137,8 +129,7 @@ QString ConfigureInput::getKeyName(int key_code) const } /// Convert letter/name of key to its ASCII value. -Qt::Key ConfigureInput::getKeyValue(const QString& text) const -{ +Qt::Key ConfigureInput::getKeyValue(const QString& text) const{ if (text == "Shift") return Qt::Key_Shift; if (text == "Ctrl") @@ -153,8 +144,7 @@ Qt::Key ConfigureInput::getKeyValue(const QString& text) const } /// Check all inputs for duplicate keys. Clears out any other button with same key as new button. -void ConfigureInput::removeDuplicates(const QString& newValue) -{ +void ConfigureInput::removeDuplicates(const QString& newValue){ for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { if (changing_button != input_mapping[Settings::NativeInput::Values(i)]) { QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text();