From 1d213e165638f072302df51fe91f504f9c252b00 Mon Sep 17 00:00:00 2001 From: Chin Date: Tue, 16 Jun 2015 17:19:30 -0400 Subject: [PATCH] Settings: Emit ValueChanged signal from QLineEditKeyConfig and connect to UpdateValue slot on GInputsDialog --- src/citra_qt/config/QLineEditKeyConfig.cpp | 82 +------------ src/citra_qt/config/QLineEditKeyConfig.h | 10 +- src/citra_qt/config/inputs.cpp | 129 ++++++++++++++++----- src/citra_qt/config/inputs.h | 1 + 4 files changed, 114 insertions(+), 108 deletions(-) diff --git a/src/citra_qt/config/QLineEditKeyConfig.cpp b/src/citra_qt/config/QLineEditKeyConfig.cpp index f9b2779cc..1c0978359 100644 --- a/src/citra_qt/config/QLineEditKeyConfig.cpp +++ b/src/citra_qt/config/QLineEditKeyConfig.cpp @@ -2,9 +2,10 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include + #include "QLineEditKeyConfig.h" #include "inputs.h" -#include std::map ButtonNameMap({ { Button::A, "A" }, { Button::B, "B" }, { Button::X, "X" }, { Button::Y, "Y" }, @@ -15,85 +16,12 @@ std::map ButtonNameMap({ { Button::Start, "Start" }, { Button::Select, "Select" }, { Button::Home, "Home" } } ); -QLineEditKeyConfig::QLineEditKeyConfig(Settings::Values& temp_settings, Button button, QWidget* parent) - : button(button), temp_settings(temp_settings), QLineEdit(parent) {} +QLineEditKeyConfig::QLineEditKeyConfig(Button button, QWidget* parent) + : button(button), QLineEdit(parent) {} void QLineEditKeyConfig::keyPressEvent(QKeyEvent* event) { QString key_name = GInputsDialog::GetKeyName(event->key()); setText(key_name); - int key = event->key(); - switch (button) { - case Button::A: - temp_settings.pad_a_key = key; - break; - case Button::B: - temp_settings.pad_b_key = key; - break; - case Button::X: - temp_settings.pad_x_key = key; - break; - case Button::Y: - temp_settings.pad_y_key = key; - break; - case Button::L: - temp_settings.pad_l_key = key; - break; - case Button::R: - temp_settings.pad_r_key = key; - break; - case Button::ZL: - temp_settings.pad_zl_key = key; - break; - case Button::ZR: - temp_settings.pad_zr_key = key; - break; - case Button::DUp: - temp_settings.pad_dup_key = key; - break; - case Button::DDown: - temp_settings.pad_ddown_key = key; - break; - case Button::DLeft: - temp_settings.pad_dleft_key = key; - break; - case Button::DRight: - temp_settings.pad_dright_key = key; - break; - case Button::SUp: - temp_settings.pad_sup_key = key; - break; - case Button::SDown: - temp_settings.pad_sdown_key = key; - break; - case Button::SLeft: - temp_settings.pad_sleft_key = key; - break; - case Button::SRight: - temp_settings.pad_sright_key = key; - break; - case Button::CUp: - temp_settings.pad_cup_key = key; - break; - case Button::CDown: - temp_settings.pad_cdown_key = key; - break; - case Button::CLeft: - temp_settings.pad_cleft_key = key; - break; - case Button::CRight: - temp_settings.pad_cright_key = key; - break; - case Button::Home: - temp_settings.pad_home_key = key; - break; - case Button::Start: - temp_settings.pad_start_key = key; - break; - case Button::Select: - temp_settings.pad_select_key = key; - break; - default: - break; - } + ValueChanged(button, event->key()); } diff --git a/src/citra_qt/config/QLineEditKeyConfig.h b/src/citra_qt/config/QLineEditKeyConfig.h index 7a68d7469..9170a7fc7 100644 --- a/src/citra_qt/config/QLineEditKeyConfig.h +++ b/src/citra_qt/config/QLineEditKeyConfig.h @@ -4,9 +4,9 @@ #pragma once -#include #include -#include "../core/settings.h" + +#include class QKeyEvent; @@ -28,9 +28,9 @@ class QLineEditKeyConfig : public QLineEdit { public: Button button; - QLineEditKeyConfig(Settings::Values& temp_settings, Button button, QWidget* parent = nullptr); + QLineEditKeyConfig(Button button, QWidget* parent = nullptr); void keyPressEvent(QKeyEvent* event) override; -private: - Settings::Values& temp_settings; +signals: + void ValueChanged(Button, int); }; diff --git a/src/citra_qt/config/inputs.cpp b/src/citra_qt/config/inputs.cpp index 0fa74438b..73d60545b 100644 --- a/src/citra_qt/config/inputs.cpp +++ b/src/citra_qt/config/inputs.cpp @@ -2,8 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "common/logging/log.h" - #include #include #include @@ -11,6 +9,7 @@ #include #include +#include "common/logging/log.h" #include "config.h" #include "inputs.h" @@ -19,29 +18,29 @@ GInputsDialog::GInputsDialog(QWidget* parent) : QDialog(parent) { temp_settings = Settings::Values(Settings::values); // create the lineEdits - lineEdit_A = new QLineEditKeyConfig(temp_settings, Button::A); - lineEdit_B = new QLineEditKeyConfig(temp_settings, Button::B); - lineEdit_X = new QLineEditKeyConfig(temp_settings, Button::X); - lineEdit_Y = new QLineEditKeyConfig(temp_settings, Button::Y); - lineEdit_L = new QLineEditKeyConfig(temp_settings, Button::L); - lineEdit_R = new QLineEditKeyConfig(temp_settings, Button::R); - lineEdit_ZL = new QLineEditKeyConfig(temp_settings, Button::ZL); - lineEdit_ZR = new QLineEditKeyConfig(temp_settings, Button::ZR); - lineEdit_dUp = new QLineEditKeyConfig(temp_settings, Button::DUp); - lineEdit_dDown = new QLineEditKeyConfig(temp_settings, Button::DDown); - lineEdit_dLeft = new QLineEditKeyConfig(temp_settings, Button::DLeft); - lineEdit_dRight = new QLineEditKeyConfig(temp_settings, Button::DRight); - lineEdit_sUp = new QLineEditKeyConfig(temp_settings, Button::SUp); - lineEdit_sDown = new QLineEditKeyConfig(temp_settings, Button::SDown); - lineEdit_sLeft = new QLineEditKeyConfig(temp_settings, Button::SLeft); - lineEdit_sRight = new QLineEditKeyConfig(temp_settings, Button::SRight); - lineEdit_cUp = new QLineEditKeyConfig(temp_settings, Button::CUp); - lineEdit_cDown = new QLineEditKeyConfig(temp_settings, Button::CDown); - lineEdit_cLeft = new QLineEditKeyConfig(temp_settings, Button::CLeft); - lineEdit_cRight = new QLineEditKeyConfig(temp_settings, Button::CRight); - lineEdit_Home = new QLineEditKeyConfig(temp_settings, Button::Home); - lineEdit_Start = new QLineEditKeyConfig(temp_settings, Button::Start); - lineEdit_Select = new QLineEditKeyConfig(temp_settings, Button::Select); + lineEdit_A = new QLineEditKeyConfig(Button::A); + lineEdit_B = new QLineEditKeyConfig(Button::B); + lineEdit_X = new QLineEditKeyConfig(Button::X); + lineEdit_Y = new QLineEditKeyConfig(Button::Y); + lineEdit_L = new QLineEditKeyConfig(Button::L); + lineEdit_R = new QLineEditKeyConfig(Button::R); + lineEdit_ZL = new QLineEditKeyConfig(Button::ZL); + lineEdit_ZR = new QLineEditKeyConfig(Button::ZR); + lineEdit_dUp = new QLineEditKeyConfig(Button::DUp); + lineEdit_dDown = new QLineEditKeyConfig(Button::DDown); + lineEdit_dLeft = new QLineEditKeyConfig(Button::DLeft); + lineEdit_dRight = new QLineEditKeyConfig(Button::DRight); + lineEdit_sUp = new QLineEditKeyConfig(Button::SUp); + lineEdit_sDown = new QLineEditKeyConfig(Button::SDown); + lineEdit_sLeft = new QLineEditKeyConfig(Button::SLeft); + lineEdit_sRight = new QLineEditKeyConfig(Button::SRight); + lineEdit_cUp = new QLineEditKeyConfig(Button::CUp); + lineEdit_cDown = new QLineEditKeyConfig(Button::CDown); + lineEdit_cLeft = new QLineEditKeyConfig(Button::CLeft); + lineEdit_cRight = new QLineEditKeyConfig(Button::CRight); + lineEdit_Home = new QLineEditKeyConfig(Button::Home); + lineEdit_Start = new QLineEditKeyConfig(Button::Start); + lineEdit_Select = new QLineEditKeyConfig(Button::Select); lineEdits = {{ lineEdit_A, lineEdit_B, lineEdit_X, lineEdit_Y, lineEdit_L, lineEdit_R, lineEdit_ZL, lineEdit_ZR, @@ -59,9 +58,11 @@ GInputsDialog::GInputsDialog(QWidget* parent) : QDialog(parent) { int row = i % numRow; int labelColumn = i / numRow * 2; QLineEditKeyConfig *lineEdit = lineEdits[i]; - QLabel *label = new QLabel(QString::fromStdString(ButtonNameMap[lineEdit->button])); + QLabel *label = new QLabel(tr(ButtonNameMap[lineEdit->button].c_str())); grid->addWidget(label, row, labelColumn); grid->addWidget(lineEdit, row, labelColumn + 1); + + QObject::connect(lineEdit, SIGNAL(ValueChanged(Button, int)), this, SLOT(UpdateValue(Button, int))); } // the button box that contains the restore default/ok/cancel buttons @@ -91,6 +92,82 @@ GInputsDialog::GInputsDialog(QWidget* parent) : QDialog(parent) { UpdateKeyLabels(); } +void GInputsDialog::UpdateValue(Button button, int key) { + switch (button) { + case Button::A: + temp_settings.pad_a_key = key; + break; + case Button::B: + temp_settings.pad_b_key = key; + break; + case Button::X: + temp_settings.pad_x_key = key; + break; + case Button::Y: + temp_settings.pad_y_key = key; + break; + case Button::L: + temp_settings.pad_l_key = key; + break; + case Button::R: + temp_settings.pad_r_key = key; + break; + case Button::ZL: + temp_settings.pad_zl_key = key; + break; + case Button::ZR: + temp_settings.pad_zr_key = key; + break; + case Button::DUp: + temp_settings.pad_dup_key = key; + break; + case Button::DDown: + temp_settings.pad_ddown_key = key; + break; + case Button::DLeft: + temp_settings.pad_dleft_key = key; + break; + case Button::DRight: + temp_settings.pad_dright_key = key; + break; + case Button::SUp: + temp_settings.pad_sup_key = key; + break; + case Button::SDown: + temp_settings.pad_sdown_key = key; + break; + case Button::SLeft: + temp_settings.pad_sleft_key = key; + break; + case Button::SRight: + temp_settings.pad_sright_key = key; + break; + case Button::CUp: + temp_settings.pad_cup_key = key; + break; + case Button::CDown: + temp_settings.pad_cdown_key = key; + break; + case Button::CLeft: + temp_settings.pad_cleft_key = key; + break; + case Button::CRight: + temp_settings.pad_cright_key = key; + break; + case Button::Home: + temp_settings.pad_home_key = key; + break; + case Button::Start: + temp_settings.pad_start_key = key; + break; + case Button::Select: + temp_settings.pad_select_key = key; + break; + default: + break; + } +} + void GInputsDialog::UpdateKeyLabels() { lineEdit_A->setText(GetKeyName(temp_settings.pad_a_key)); lineEdit_B->setText(GetKeyName(temp_settings.pad_b_key)); diff --git a/src/citra_qt/config/inputs.h b/src/citra_qt/config/inputs.h index dcb725af6..71735d070 100644 --- a/src/citra_qt/config/inputs.h +++ b/src/citra_qt/config/inputs.h @@ -58,4 +58,5 @@ private: private slots: void SaveSettings(); void RestoreDefaultSettings(); + void UpdateValue(Button button, int key); };