diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index e5b12bf57..bfae90681 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -21,7 +21,7 @@ set(SRCS bootmanager.cpp hotkeys.cpp inputs.cpp - KeyPressEater.cpp + QLineEditKeyConfig.cpp main.cpp citra-qt.rc ) @@ -47,7 +47,7 @@ set(HEADERS bootmanager.h hotkeys.h inputs.h - KeyPressEater.h + QLineEditKeyConfig.h main.h version.h ) diff --git a/src/citra_qt/KeyPressEater.cpp b/src/citra_qt/KeyPressEater.cpp deleted file mode 100644 index d9c930948..000000000 --- a/src/citra_qt/KeyPressEater.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include -#include - -KeyPressEater::KeyPressEater(QObject* parent) : QObject(parent) {} - -bool KeyPressEater::eventFilter(QObject* obj, QEvent* event) { - if (event->type() == QEvent::KeyPress) { - QKeyEvent* key_event = static_cast(event); - QLineEdit* line_edit = static_cast(obj); - Button button_modified = GInputsDialog::edit_input_map[line_edit->objectName()]; - - QString key_name = GInputsDialog::getKeyName(key_event->key()); - line_edit->setText(key_name); - - int key = key_event->key(); - switch (button_modified) { - case Button::A: - GInputsDialog::temp_settings.pad_a_key = key; - break; - case Button::B: - GInputsDialog::temp_settings.pad_b_key = key; - break; - case Button::X: - GInputsDialog::temp_settings.pad_x_key = key; - break; - case Button::Y: - GInputsDialog::temp_settings.pad_y_key = key; - break; - case Button::L: - GInputsDialog::temp_settings.pad_l_key = key; - break; - case Button::R: - GInputsDialog::temp_settings.pad_r_key = key; - break; - case Button::Start: - GInputsDialog::temp_settings.pad_start_key = key; - break; - case Button::Select: - GInputsDialog::temp_settings.pad_select_key = key; - break; - case Button::Home: - GInputsDialog::temp_settings.pad_home_key = key; - break; - case Button::DUp: - GInputsDialog::temp_settings.pad_dup_key = key; - break; - case Button::DDown: - GInputsDialog::temp_settings.pad_ddown_key = key; - break; - case Button::DLeft: - GInputsDialog::temp_settings.pad_dleft_key = key; - break; - case Button::DRight: - GInputsDialog::temp_settings.pad_dright_key = key; - break; - case Button::SUp: - GInputsDialog::temp_settings.pad_sup_key = key; - break; - case Button::SDown: - GInputsDialog::temp_settings.pad_sdown_key = key; - break; - case Button::SLeft: - GInputsDialog::temp_settings.pad_sleft_key = key; - break; - case Button::SRight: - GInputsDialog::temp_settings.pad_sright_key = key; - break; - default: - break; - } - - return true; - } - else { - // standard event processing - return QObject::eventFilter(obj, event); - } -} \ No newline at end of file diff --git a/src/citra_qt/KeyPressEater.h b/src/citra_qt/KeyPressEater.h deleted file mode 100644 index 493bc7376..000000000 --- a/src/citra_qt/KeyPressEater.h +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -/// The event filter used for LineEdits to handle key presses -class KeyPressEater : public QObject { - Q_OBJECT -public: - KeyPressEater(QObject* parent); - bool eventFilter(QObject *obj, QEvent *event); -}; \ No newline at end of file diff --git a/src/citra_qt/QLineEditKeyConfig.cpp b/src/citra_qt/QLineEditKeyConfig.cpp new file mode 100644 index 000000000..cbda42f34 --- /dev/null +++ b/src/citra_qt/QLineEditKeyConfig.cpp @@ -0,0 +1,72 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#include + +QLineEditKeyConfig::QLineEditKeyConfig(QWidget* parent) : QLineEdit(parent) {} + +void QLineEditKeyConfig::keyPressEvent(QKeyEvent* event) { + QString key_name = GInputsDialog::getKeyName(event->key()); + this->setText(key_name); + + int key = event->key(); + switch (this->button) { + case Button::A: + GInputsDialog::temp_settings.pad_a_key = key; + break; + case Button::B: + GInputsDialog::temp_settings.pad_b_key = key; + break; + case Button::X: + GInputsDialog::temp_settings.pad_x_key = key; + break; + case Button::Y: + GInputsDialog::temp_settings.pad_y_key = key; + break; + case Button::L: + GInputsDialog::temp_settings.pad_l_key = key; + break; + case Button::R: + GInputsDialog::temp_settings.pad_r_key = key; + break; + case Button::Start: + GInputsDialog::temp_settings.pad_start_key = key; + break; + case Button::Select: + GInputsDialog::temp_settings.pad_select_key = key; + break; + case Button::Home: + GInputsDialog::temp_settings.pad_home_key = key; + break; + case Button::DUp: + GInputsDialog::temp_settings.pad_dup_key = key; + break; + case Button::DDown: + GInputsDialog::temp_settings.pad_ddown_key = key; + break; + case Button::DLeft: + GInputsDialog::temp_settings.pad_dleft_key = key; + break; + case Button::DRight: + GInputsDialog::temp_settings.pad_dright_key = key; + break; + case Button::SUp: + GInputsDialog::temp_settings.pad_sup_key = key; + break; + case Button::SDown: + GInputsDialog::temp_settings.pad_sdown_key = key; + break; + case Button::SLeft: + GInputsDialog::temp_settings.pad_sleft_key = key; + break; + case Button::SRight: + GInputsDialog::temp_settings.pad_sright_key = key; + break; + default: + break; + } +} \ No newline at end of file diff --git a/src/citra_qt/QLineEditKeyConfig.h b/src/citra_qt/QLineEditKeyConfig.h new file mode 100644 index 000000000..c22270475 --- /dev/null +++ b/src/citra_qt/QLineEditKeyConfig.h @@ -0,0 +1,26 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +class QKeyEvent; + +/// An enum for the buttons on the 3DS +enum Button { + A, B, X, Y, L, R, Start, Select, Home, + DUp, DDown, DLeft, DRight, + SUp, SDown, SLeft, SRight +}; + +/// The LineEdits used for button configuration +class QLineEditKeyConfig : public QLineEdit { + Q_OBJECT + +public: + Button button; + QLineEditKeyConfig(QWidget* parent); + void keyPressEvent(QKeyEvent* event) override; +}; diff --git a/src/citra_qt/inputs.cpp b/src/citra_qt/inputs.cpp index 05aaf76b3..575ff33f5 100644 --- a/src/citra_qt/inputs.cpp +++ b/src/citra_qt/inputs.cpp @@ -2,50 +2,45 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include -#include -#include -#include "inputs.h" -#include "KeyPressEater.h" -#include "config.h" #include "common/log.h" -std::map GInputsDialog::edit_input_map; -bool GInputsDialog::edit_input_map_initialized = false; +#include +#include +#include + +#include "config.h" +#include "inputs.h" +#include "QLineEditKeyConfig.h" + Settings::Values GInputsDialog::temp_settings; GInputsDialog::GInputsDialog(QWidget* parent) : QDialog(parent) { ui.setupUi(this); - // initialize the edit_input_map - if (!edit_input_map_initialized) { - GInputsDialog::edit_input_map = std::map { - { this->ui.lineEdit_A->objectName(), Button::A}, - { this->ui.lineEdit_B->objectName(), Button::B }, - { this->ui.lineEdit_X->objectName(), Button::X }, - { this->ui.lineEdit_Y->objectName(), Button::Y }, - { this->ui.lineEdit_L->objectName(), Button::L }, - { this->ui.lineEdit_R->objectName(), Button::R }, - { this->ui.lineEdit_Start->objectName(), Button::Start }, - { this->ui.lineEdit_Select->objectName(), Button::Select }, - { this->ui.lineEdit_Home->objectName(), Button::Home }, - { this->ui.lineEdit_dUp->objectName(), Button::DUp }, - { this->ui.lineEdit_dDown->objectName(), Button::DDown }, - { this->ui.lineEdit_dLeft->objectName(), Button::DLeft }, - { this->ui.lineEdit_dRight->objectName(), Button::DRight }, - { this->ui.lineEdit_sUp->objectName(), Button::SUp }, - { this->ui.lineEdit_sDown->objectName(), Button::SDown }, - { this->ui.lineEdit_sLeft->objectName(), Button::SLeft }, - { this->ui.lineEdit_sRight->objectName(), Button::SRight }, - }; - edit_input_map_initialized = true; - } + // setup the LineEdits + this->ui.lineEdit_A->button = Button::A; + this->ui.lineEdit_B->button = Button::B; + this->ui.lineEdit_X->button = Button::X; + this->ui.lineEdit_Y->button = Button::Y; + this->ui.lineEdit_L->button = Button::L; + this->ui.lineEdit_R->button = Button::R; + this->ui.lineEdit_Start->button = Button::Start; + this->ui.lineEdit_Select->button = Button::Select; + this->ui.lineEdit_Home->button = Button::Home; + this->ui.lineEdit_dUp->button = Button::DUp; + this->ui.lineEdit_dDown->button = Button::DDown; + this->ui.lineEdit_dLeft->button = Button::DLeft; + this->ui.lineEdit_dRight->button = Button::DRight; + this->ui.lineEdit_sUp->button = Button::SUp; + this->ui.lineEdit_sDown->button = Button::SDown; + this->ui.lineEdit_sLeft->button = Button::SLeft; + this->ui.lineEdit_sRight->button = Button::SRight; // set up event handlers for the buttons - QPushButton *resetButton = this->ui.buttonBox->button(QDialogButtonBox::Reset); - connect(resetButton, SIGNAL(clicked()), this, SLOT(OnResetClicked())); + QPushButton* defaultButton = this->ui.buttonBox->button(QDialogButtonBox::RestoreDefaults); + connect(defaultButton, SIGNAL(clicked()), this, SLOT(OnDefaultClicked())); - QPushButton *okButton = this->ui.buttonBox->button(QDialogButtonBox::Ok); + QPushButton* okButton = this->ui.buttonBox->button(QDialogButtonBox::Ok); connect(okButton, SIGNAL(clicked()), this, SLOT(OnOkClicked())); // create a copy of the current settings @@ -53,29 +48,9 @@ GInputsDialog::GInputsDialog(QWidget* parent) : QDialog(parent) { // display current key settings this->displayButtonSettings(Settings::values); - - // setup event filters for the LineEdits - KeyPressEater* keyPressEater = new KeyPressEater(this); - this->ui.lineEdit_A->installEventFilter(keyPressEater); - this->ui.lineEdit_B->installEventFilter(keyPressEater); - this->ui.lineEdit_X->installEventFilter(keyPressEater); - this->ui.lineEdit_Y->installEventFilter(keyPressEater); - this->ui.lineEdit_L->installEventFilter(keyPressEater); - this->ui.lineEdit_R->installEventFilter(keyPressEater); - this->ui.lineEdit_Start->installEventFilter(keyPressEater); - this->ui.lineEdit_Select->installEventFilter(keyPressEater); - this->ui.lineEdit_Home->installEventFilter(keyPressEater); - this->ui.lineEdit_dUp->installEventFilter(keyPressEater); - this->ui.lineEdit_dDown->installEventFilter(keyPressEater); - this->ui.lineEdit_dLeft->installEventFilter(keyPressEater); - this->ui.lineEdit_dRight->installEventFilter(keyPressEater); - this->ui.lineEdit_sUp->installEventFilter(keyPressEater); - this->ui.lineEdit_sDown->installEventFilter(keyPressEater); - this->ui.lineEdit_sLeft->installEventFilter(keyPressEater); - this->ui.lineEdit_sRight->installEventFilter(keyPressEater); } -void GInputsDialog::displayButtonSettings(Settings::Values values) { +void GInputsDialog::displayButtonSettings(const Settings::Values& values) { this->ui.lineEdit_A->setText(GInputsDialog::getKeyName(values.pad_a_key)); this->ui.lineEdit_B->setText(GInputsDialog::getKeyName(values.pad_b_key)); this->ui.lineEdit_X->setText(GInputsDialog::getKeyName(values.pad_x_key)); @@ -96,14 +71,22 @@ void GInputsDialog::displayButtonSettings(Settings::Values values) { } QString GInputsDialog::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 tr("Meta"); } - else return QKeySequence(key_code).toString(); + 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 tr("Meta"); + + return QKeySequence(key_code).toString(); } -void GInputsDialog::OnResetClicked() { +void GInputsDialog::OnDefaultClicked() { // load the default button settings into temp_settings GInputsDialog::temp_settings.pad_a_key = Qt::Key_A; GInputsDialog::temp_settings.pad_b_key = Qt::Key_S; diff --git a/src/citra_qt/inputs.h b/src/citra_qt/inputs.h index 880d2a2dd..e0c43594c 100644 --- a/src/citra_qt/inputs.h +++ b/src/citra_qt/inputs.h @@ -3,30 +3,18 @@ // Refer to the license.txt file included. #pragma once + #include -#include + #include "core/settings.h" #include "ui_inputs.h" -/// An enum for the buttons on the 3DS -enum Button { - A, B, X, Y, L, R, Start, Select, Home, - DUp, DDown, DLeft, DRight, - SUp, SDown, SLeft, SRight -}; - /// The input configuration dialog class GInputsDialog : public QDialog { Q_OBJECT public: - GInputsDialog(QWidget* parent = NULL); - - /// A map between the name of a LineEdit and the button that it modifies - static std::map edit_input_map; - - /// true if edit_input_map is initialized - static bool edit_input_map_initialized; + GInputsDialog(QWidget* parent = nullptr); /// Temporary settings used when configuration is changed but not saved yet static Settings::Values temp_settings; @@ -38,9 +26,9 @@ private: Ui::inputs ui; /// Display the button settings on the LineEdits from the given values - void displayButtonSettings(Settings::Values values); + void displayButtonSettings(const Settings::Values& values); private slots: - void OnResetClicked(); + void OnDefaultClicked(); void OnOkClicked(); }; diff --git a/src/citra_qt/inputs.ui b/src/citra_qt/inputs.ui index b8b4d69f4..ae9edd78b 100644 --- a/src/citra_qt/inputs.ui +++ b/src/citra_qt/inputs.ui @@ -11,7 +11,7 @@ - Input setting + Input Settings @@ -26,7 +26,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults @@ -39,9 +39,9 @@ - C-Pad + Circle Pad - + 160 @@ -67,7 +67,7 @@ Left - + 110 @@ -80,7 +80,7 @@ Qt::AlignCenter - + 40 @@ -119,7 +119,7 @@ Right - + 110 @@ -158,7 +158,7 @@ D-Pad - + 110 @@ -171,7 +171,7 @@ Qt::AlignCenter - + 40 @@ -197,7 +197,7 @@ Up - + 160 @@ -226,7 +226,7 @@ Down - + 110 @@ -276,9 +276,9 @@ - Main + Main Buttons - + 90 @@ -291,7 +291,7 @@ Qt::AlignCenter - + 20 @@ -317,7 +317,7 @@ Y - + 140 @@ -369,7 +369,7 @@ A - + 90 @@ -382,22 +382,6 @@ Qt::AlignCenter - lineEdit_B - label_Y - lineEdit_Y - lineEdit_A - label_X - label_B - label_A - lineEdit_X - lineEdit_B - lineEdit_Y - label_Y - lineEdit_A - label_B - label_X - label_A - lineEdit_X @@ -409,9 +393,9 @@ - Others + Other Buttons - + 360 @@ -450,7 +434,7 @@ Select - + 90 @@ -463,7 +447,7 @@ Qt::AlignCenter - + 230 @@ -500,9 +484,9 @@ - Shoulder + Bumpers - + 340 @@ -515,7 +499,7 @@ Qt::AlignCenter - + 110 @@ -556,6 +540,13 @@ + + + QLineEditKeyConfig + QLineEdit +
QLineEditKeyConfig.h
+
+
diff --git a/src/citra_qt/main.ui b/src/citra_qt/main.ui index ff4942318..c9a600ba9 100644 --- a/src/citra_qt/main.ui +++ b/src/citra_qt/main.ui @@ -171,9 +171,6 @@ Configure &Inputs - - Configure Inputs -