From 2e5677e22a3805334d4cc1b5528326c974b02ac9 Mon Sep 17 00:00:00 2001 From: Chin Date: Sun, 1 Feb 2015 22:27:18 -0500 Subject: [PATCH] Settings: Handle modifier keys name correctly. --- src/citra_qt/KeyPressEater.cpp | 47 +++++++++++++++++----------------- src/citra_qt/inputs.cpp | 42 ++++++++++++++++++------------ src/citra_qt/inputs.h | 3 +++ 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/citra_qt/KeyPressEater.cpp b/src/citra_qt/KeyPressEater.cpp index a8242b0e7..d9c930948 100644 --- a/src/citra_qt/KeyPressEater.cpp +++ b/src/citra_qt/KeyPressEater.cpp @@ -5,71 +5,72 @@ KeyPressEater::KeyPressEater(QObject* parent) : QObject(parent) {} -bool KeyPressEater::eventFilter(QObject *obj, QEvent *event) { +bool KeyPressEater::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::KeyPress) { - QKeyEvent *keyEvent = static_cast(event); - auto keyName = QKeySequence(keyEvent->key()).toString(); + QKeyEvent* key_event = static_cast(event); + QLineEdit* line_edit = static_cast(obj); + Button button_modified = GInputsDialog::edit_input_map[line_edit->objectName()]; - QLineEdit* lineEdit = static_cast(obj); - Button button_modified = GInputsDialog::edit_input_map[lineEdit->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 = keyEvent->key(); + GInputsDialog::temp_settings.pad_a_key = key; break; case Button::B: - GInputsDialog::temp_settings.pad_b_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_b_key = key; break; case Button::X: - GInputsDialog::temp_settings.pad_x_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_x_key = key; break; case Button::Y: - GInputsDialog::temp_settings.pad_y_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_y_key = key; break; case Button::L: - GInputsDialog::temp_settings.pad_l_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_l_key = key; break; case Button::R: - GInputsDialog::temp_settings.pad_r_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_r_key = key; break; case Button::Start: - GInputsDialog::temp_settings.pad_start_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_start_key = key; break; case Button::Select: - GInputsDialog::temp_settings.pad_select_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_select_key = key; break; case Button::Home: - GInputsDialog::temp_settings.pad_home_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_home_key = key; break; case Button::DUp: - GInputsDialog::temp_settings.pad_dup_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_dup_key = key; break; case Button::DDown: - GInputsDialog::temp_settings.pad_ddown_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_ddown_key = key; break; case Button::DLeft: - GInputsDialog::temp_settings.pad_dleft_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_dleft_key = key; break; case Button::DRight: - GInputsDialog::temp_settings.pad_dright_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_dright_key = key; break; case Button::SUp: - GInputsDialog::temp_settings.pad_sup_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_sup_key = key; break; case Button::SDown: - GInputsDialog::temp_settings.pad_sdown_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_sdown_key = key; break; case Button::SLeft: - GInputsDialog::temp_settings.pad_sleft_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_sleft_key = key; break; case Button::SRight: - GInputsDialog::temp_settings.pad_sright_key = keyEvent->key(); + GInputsDialog::temp_settings.pad_sright_key = key; break; default: break; } - lineEdit->setText(keyName); return true; } else { diff --git a/src/citra_qt/inputs.cpp b/src/citra_qt/inputs.cpp index 621ecab14..05aaf76b3 100644 --- a/src/citra_qt/inputs.cpp +++ b/src/citra_qt/inputs.cpp @@ -76,23 +76,31 @@ GInputsDialog::GInputsDialog(QWidget* parent) : QDialog(parent) { } void GInputsDialog::displayButtonSettings(Settings::Values values) { - this->ui.lineEdit_A->setText(QKeySequence(values.pad_a_key).toString()); - this->ui.lineEdit_B->setText(QKeySequence(values.pad_b_key).toString()); - this->ui.lineEdit_X->setText(QKeySequence(values.pad_x_key).toString()); - this->ui.lineEdit_Y->setText(QKeySequence(values.pad_y_key).toString()); - this->ui.lineEdit_L->setText(QKeySequence(values.pad_l_key).toString()); - this->ui.lineEdit_R->setText(QKeySequence(values.pad_r_key).toString()); - this->ui.lineEdit_Start->setText(QKeySequence(values.pad_start_key).toString()); - this->ui.lineEdit_Select->setText(QKeySequence(values.pad_select_key).toString()); - this->ui.lineEdit_Home->setText(QKeySequence(values.pad_home_key).toString()); - this->ui.lineEdit_dUp->setText(QKeySequence(values.pad_dup_key).toString()); - this->ui.lineEdit_dDown->setText(QKeySequence(values.pad_ddown_key).toString()); - this->ui.lineEdit_dLeft->setText(QKeySequence(values.pad_dleft_key).toString()); - this->ui.lineEdit_dRight->setText(QKeySequence(values.pad_dright_key).toString()); - this->ui.lineEdit_sUp->setText(QKeySequence(values.pad_sup_key).toString()); - this->ui.lineEdit_sDown->setText(QKeySequence(values.pad_sdown_key).toString()); - this->ui.lineEdit_sLeft->setText(QKeySequence(values.pad_sleft_key).toString()); - this->ui.lineEdit_sRight->setText(QKeySequence(values.pad_sright_key).toString()); + 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)); + this->ui.lineEdit_Y->setText(GInputsDialog::getKeyName(values.pad_y_key)); + this->ui.lineEdit_L->setText(GInputsDialog::getKeyName(values.pad_l_key)); + this->ui.lineEdit_R->setText(GInputsDialog::getKeyName(values.pad_r_key)); + this->ui.lineEdit_Start->setText(GInputsDialog::getKeyName(values.pad_start_key)); + this->ui.lineEdit_Select->setText(GInputsDialog::getKeyName(values.pad_select_key)); + this->ui.lineEdit_Home->setText(GInputsDialog::getKeyName(values.pad_home_key)); + this->ui.lineEdit_dUp->setText(GInputsDialog::getKeyName(values.pad_dup_key)); + this->ui.lineEdit_dDown->setText(GInputsDialog::getKeyName(values.pad_ddown_key)); + this->ui.lineEdit_dLeft->setText(GInputsDialog::getKeyName(values.pad_dleft_key)); + this->ui.lineEdit_dRight->setText(GInputsDialog::getKeyName(values.pad_dright_key)); + this->ui.lineEdit_sUp->setText(GInputsDialog::getKeyName(values.pad_sup_key)); + this->ui.lineEdit_sDown->setText(GInputsDialog::getKeyName(values.pad_sdown_key)); + this->ui.lineEdit_sLeft->setText(GInputsDialog::getKeyName(values.pad_sleft_key)); + this->ui.lineEdit_sRight->setText(GInputsDialog::getKeyName(values.pad_sright_key)); +} + +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(); } void GInputsDialog::OnResetClicked() { diff --git a/src/citra_qt/inputs.h b/src/citra_qt/inputs.h index 957cb6a84..880d2a2dd 100644 --- a/src/citra_qt/inputs.h +++ b/src/citra_qt/inputs.h @@ -31,6 +31,9 @@ public: /// Temporary settings used when configuration is changed but not saved yet static Settings::Values temp_settings; + /// Given a key code, return the key name. Needed for modifier keys + static QString getKeyName(int key_code); + private: Ui::inputs ui;