Settings: Handle modifier keys name correctly.

This commit is contained in:
Chin 2015-02-01 22:27:18 -05:00 committed by chinhodado
parent b8a727da08
commit 2e5677e22a
3 changed files with 52 additions and 40 deletions

View file

@ -7,69 +7,70 @@ KeyPressEater::KeyPressEater(QObject* parent) : QObject(parent) {}
bool KeyPressEater::eventFilter(QObject* obj, QEvent* event) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
auto keyName = QKeySequence(keyEvent->key()).toString();
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
QLineEdit* line_edit = static_cast<QLineEdit*>(obj);
Button button_modified = GInputsDialog::edit_input_map[line_edit->objectName()];
QLineEdit* lineEdit = static_cast<QLineEdit*>(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 {

View file

@ -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() {

View file

@ -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;