From ce0cc37045b2afa6953b35444054ca4ef2c2edad Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Sun, 12 Jun 2016 08:54:41 -0500 Subject: [PATCH] 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();