From f4b44451b012ead55e5cc7ed93672ed2cb1231fb Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 27 Oct 2015 22:22:15 -0700 Subject: [PATCH] Qt: Fix clear button/analog buttons in gamepad mapper on some platforms --- CHANGES | 1 + src/platform/qt/GBAKeyEditor.cpp | 17 ++++++++++++----- src/platform/qt/GBAKeyEditor.h | 3 ++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 5f6650c16..f8cd5f391 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,7 @@ Bugfixes: - GBA Memory: Fix DMAs from BIOS while not in BIOS - GBA: Fix idle skip state being retained between games - Qt: Fix a race condition in PainterGL that could lead to a crash + - Qt: Fix clear button/analog buttons in gamepad mapper on some platforms Misc: - Qt: Window size command line options are now supported - Qt: Increase usability of key mapper diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index 73e0f6ac6..7acae67a3 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -126,6 +126,7 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString& for (auto& key : m_keyOrder) { connect(key, SIGNAL(valueChanged(int)), this, SLOT(setNext())); connect(key, SIGNAL(axisChanged(int, int)), this, SLOT(setNext())); + key->installEventFilter(this); } m_currentKey = m_keyOrder.end(); @@ -181,9 +182,15 @@ bool GBAKeyEditor::event(QEvent* event) { return QWidget::event(event); } -void GBAKeyEditor::setNext() { - findFocus(); +bool GBAKeyEditor::eventFilter(QObject* obj, QEvent* event) { + if (event->type() != QEvent::FocusIn) { + return false; + } + findFocus(static_cast(obj)); + return true; +} +void GBAKeyEditor::setNext() { if (m_currentKey == m_keyOrder.end()) { return; } @@ -280,18 +287,18 @@ void GBAKeyEditor::bindKey(const KeyEditor* keyEditor, GBAKey key) { m_controller->bindKey(m_type, keyEditor->value(), key); } -bool GBAKeyEditor::findFocus() { +bool GBAKeyEditor::findFocus(KeyEditor* needle) { if (m_currentKey != m_keyOrder.end() && (*m_currentKey)->hasFocus()) { return true; } for (auto key = m_keyOrder.begin(); key != m_keyOrder.end(); ++key) { - if ((*key)->hasFocus()) { + if ((*key)->hasFocus() || needle == *key) { m_currentKey = key; return true; } } - return false; + return m_currentKey != m_keyOrder.end(); } #ifdef BUILD_SDL diff --git a/src/platform/qt/GBAKeyEditor.h b/src/platform/qt/GBAKeyEditor.h index c1ba3229f..8ab83442d 100644 --- a/src/platform/qt/GBAKeyEditor.h +++ b/src/platform/qt/GBAKeyEditor.h @@ -37,6 +37,7 @@ protected: virtual void paintEvent(QPaintEvent*) override; virtual bool event(QEvent*) override; virtual void closeEvent(QCloseEvent*) override; + virtual bool eventFilter(QObject* obj, QEvent* event) override; private slots: void setNext(); @@ -57,7 +58,7 @@ private: void lookupBinding(const GBAInputMap*, KeyEditor*, GBAKey); void bindKey(const KeyEditor*, GBAKey); - bool findFocus(); + bool findFocus(KeyEditor* needle = nullptr); #ifdef BUILD_SDL void lookupAxes(const GBAInputMap*);