diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index 6adad32f7..35b7a0317 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -253,14 +253,11 @@ void GBAKeyEditor::lookupAxes(const GBAInputMap* map) { void GBAKeyEditor::bindKey(const KeyEditor* keyEditor, GBAKey key) { #ifdef BUILD_SDL - if (keyEditor->direction() != GamepadAxisEvent::NEUTRAL) { - m_controller->bindAxis(m_type, keyEditor->value(), keyEditor->direction(), key); - } else { -#endif - m_controller->bindKey(m_type, keyEditor->value(), key); -#ifdef BUILD_SDL + if (m_type == SDL_BINDING_BUTTON) { + m_controller->bindAxis(m_type, keyEditor->axis(), keyEditor->direction(), key); } #endif + m_controller->bindKey(m_type, keyEditor->value(), key); } bool GBAKeyEditor::findFocus() { diff --git a/src/platform/qt/KeyEditor.cpp b/src/platform/qt/KeyEditor.cpp index fd76b2def..f8323c0a3 100644 --- a/src/platform/qt/KeyEditor.cpp +++ b/src/platform/qt/KeyEditor.cpp @@ -15,22 +15,20 @@ using namespace QGBA; KeyEditor::KeyEditor(QWidget* parent) : QLineEdit(parent) , m_direction(GamepadAxisEvent::NEUTRAL) + , m_key(-1) + , m_axis(-1) , m_button(false) { setAlignment(Qt::AlignCenter); } void KeyEditor::setValue(int key) { + m_key = key; if (m_button) { - if (key < 0) { - clear(); - } else { - setText(QString::number(key)); - } + updateButtonText(); } else { setText(QKeySequence(key).toString(QKeySequence::NativeText)); } - m_key = key; emit valueChanged(key); } @@ -41,15 +39,14 @@ void KeyEditor::setValueKey(int key) { void KeyEditor::setValueButton(int button) { m_button = true; - m_direction = GamepadAxisEvent::NEUTRAL; setValue(button); } void KeyEditor::setValueAxis(int axis, int32_t value) { m_button = true; - m_key = axis; + m_axis = axis; m_direction = value < 0 ? GamepadAxisEvent::NEGATIVE : GamepadAxisEvent::POSITIVE; - setText((value < 0 ? "-" : "+") + QString::number(axis)); + updateButtonText(); emit axisChanged(axis, m_direction); } @@ -85,3 +82,18 @@ bool KeyEditor::event(QEvent* event) { } return QWidget::event(event); } + +void KeyEditor::updateButtonText() { + QStringList text; + if (m_key >= 0) { + text.append(QString::number(m_key)); + } + if (m_direction != GamepadAxisEvent::NEUTRAL) { + text.append((m_direction == GamepadAxisEvent::NEGATIVE ? "-" : "+") + QString::number(m_axis)); + } + if (text.isEmpty()) { + setText(tr("---")); + } else { + setText(text.join("/")); + } +} diff --git a/src/platform/qt/KeyEditor.h b/src/platform/qt/KeyEditor.h index 817c00c1c..66b12bb01 100644 --- a/src/platform/qt/KeyEditor.h +++ b/src/platform/qt/KeyEditor.h @@ -20,6 +20,7 @@ public: int value() const { return m_key; } GamepadAxisEvent::Direction direction() const { return m_direction; } + int axis() const { return m_axis; } virtual QSize sizeHint() const override; @@ -38,7 +39,10 @@ protected: virtual bool event(QEvent* event) override; private: + void updateButtonText(); + int m_key; + int m_axis; bool m_button; GamepadAxisEvent::Direction m_direction; };