diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index d5b1042b8..26e30fa9d 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -6,6 +6,7 @@ #include "GBAKeyEditor.h" #include +#include #include #include #include @@ -24,6 +25,7 @@ const qreal GBAKeyEditor::DPAD_HEIGHT = 0.1; GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString& profile, QWidget* parent) : QWidget(parent) , m_profileSelect(nullptr) + , m_clear(nullptr) , m_type(type) , m_profile(profile) , m_controller(controller) @@ -65,6 +67,33 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString& m_controller->loadProfile(m_type, m_profile); refresh(); }); + + m_clear = new QWidget(this); + QHBoxLayout* layout = new QHBoxLayout; + m_clear->setLayout(layout); + layout->setSpacing(6); + + QPushButton* clearButton = new QPushButton(tr("Clear Button")); + layout->addWidget(clearButton); + connect(clearButton, &QAbstractButton::pressed, [this]() { + if (!findFocus()) { + return; + } + bool signalsBlocked = (*m_currentKey)->blockSignals(true); + (*m_currentKey)->clearButton(); + (*m_currentKey)->blockSignals(signalsBlocked); + }); + + QPushButton* clearAxis = new QPushButton(tr("Clear Analog")); + layout->addWidget(clearAxis); + connect(clearAxis, &QAbstractButton::pressed, [this]() { + if (!findFocus()) { + return; + } + bool signalsBlocked = (*m_currentKey)->blockSignals(true); + (*m_currentKey)->clearAxis(); + (*m_currentKey)->blockSignals(signalsBlocked); + }); } #endif @@ -125,7 +154,11 @@ void GBAKeyEditor::resizeEvent(QResizeEvent* event) { setLocation(m_keyR, 0.9, 0.1); if (m_profileSelect) { - setLocation(m_profileSelect, 0.5, 0.7); + setLocation(m_profileSelect, 0.5, 0.67); + } + + if (m_clear) { + setLocation(m_clear, 0.5, 0.77); } } diff --git a/src/platform/qt/GBAKeyEditor.h b/src/platform/qt/GBAKeyEditor.h index 65707d4eb..c1ba3229f 100644 --- a/src/platform/qt/GBAKeyEditor.h +++ b/src/platform/qt/GBAKeyEditor.h @@ -66,6 +66,7 @@ private: KeyEditor* keyById(GBAKey); QComboBox* m_profileSelect; + QWidget* m_clear; QWidget* m_buttons; KeyEditor* m_keyDU; KeyEditor* m_keyDD; diff --git a/src/platform/qt/KeyEditor.cpp b/src/platform/qt/KeyEditor.cpp index f8323c0a3..ef06d6e41 100644 --- a/src/platform/qt/KeyEditor.cpp +++ b/src/platform/qt/KeyEditor.cpp @@ -50,6 +50,19 @@ void KeyEditor::setValueAxis(int axis, int32_t value) { emit axisChanged(axis, m_direction); } +void KeyEditor::clearButton() { + m_button = true; + setValue(-1); +} + +void KeyEditor::clearAxis() { + m_button = true; + m_axis = -1; + m_direction = GamepadAxisEvent::NEUTRAL; + updateButtonText(); + emit axisChanged(m_axis, m_direction); +} + QSize KeyEditor::sizeHint() const { QSize hint = QLineEdit::sizeHint(); hint.setWidth(40); diff --git a/src/platform/qt/KeyEditor.h b/src/platform/qt/KeyEditor.h index 66b12bb01..8fdd04f34 100644 --- a/src/platform/qt/KeyEditor.h +++ b/src/platform/qt/KeyEditor.h @@ -29,6 +29,8 @@ public slots: void setValueKey(int key); void setValueButton(int button); void setValueAxis(int axis, int32_t value); + void clearButton(); + void clearAxis(); signals: void valueChanged(int key);