From 08a2b24eac387539179b81f4c3f44469bbeab9e1 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 7 Dec 2015 20:41:28 -0800 Subject: [PATCH] Qt: Allow use of modifier keys as input --- CHANGES | 1 + src/platform/qt/KeyEditor.cpp | 56 ++++++++++++++++++++++++----------- src/platform/qt/KeyEditor.h | 5 ++++ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index 74299681b..28adc582c 100644 --- a/CHANGES +++ b/CHANGES @@ -60,6 +60,7 @@ Misc: - Util: Add MutexTryLock - Qt: Gray out "Skip BIOS intro" while "Use BIOS file" is unchecked - Qt: Add mute option to menu + - Qt: Allow use of modifier keys as input 0.3.1: (2015-10-24) Bugfixes: diff --git a/src/platform/qt/KeyEditor.cpp b/src/platform/qt/KeyEditor.cpp index e97de168e..34e7cf068 100644 --- a/src/platform/qt/KeyEditor.cpp +++ b/src/platform/qt/KeyEditor.cpp @@ -22,6 +22,7 @@ KeyEditor::KeyEditor(QWidget* parent) { setAlignment(Qt::AlignCenter); setFocusPolicy(Qt::ClickFocus); + m_lastKey.setSingleShot(true); } void KeyEditor::setValue(int key) { @@ -77,28 +78,47 @@ QSize KeyEditor::sizeHint() const { void KeyEditor::keyPressEvent(QKeyEvent* event) { if (!m_button) { - if (m_key < 0) { + if (m_key < 0 || !m_lastKey.isActive()) { m_key = 0; } - if (ShortcutController::isModifierKey(event->key())) { - switch (event->key()) { - case Qt::Key_Shift: - setValue(m_key | Qt::ShiftModifier); - break; - case Qt::Key_Control: - setValue(m_key | Qt::ControlModifier); - break; - case Qt::Key_Alt: - setValue(m_key | Qt::AltModifier); - break; - case Qt::Key_Meta: - setValue(m_key | Qt::MetaModifier); - break; - default: - setValue(m_key); + m_lastKey.start(KEY_TIME); + if (m_key) { + if (ShortcutController::isModifierKey(m_key)) { + switch (event->key()) { + case Qt::Key_Shift: + setValue(Qt::ShiftModifier); + break; + case Qt::Key_Control: + setValue(Qt::ControlModifier); + break; + case Qt::Key_Alt: + setValue(Qt::AltModifier); + break; + case Qt::Key_Meta: + setValue(Qt::MetaModifier); + break; + } + } + if (ShortcutController::isModifierKey(event->key())) { + switch (event->key()) { + case Qt::Key_Shift: + setValue(m_key | Qt::ShiftModifier); + break; + case Qt::Key_Control: + setValue(m_key | Qt::ControlModifier); + break; + case Qt::Key_Alt: + setValue(m_key | Qt::AltModifier); + break; + case Qt::Key_Meta: + setValue(m_key | Qt::MetaModifier); + break; + } + } else { + setValue(event->key() | (m_key & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))); } } else { - setValue(event->key() | (m_key & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))); + setValue(event->key()); } } event->accept(); diff --git a/src/platform/qt/KeyEditor.h b/src/platform/qt/KeyEditor.h index 8fdd04f34..039671c45 100644 --- a/src/platform/qt/KeyEditor.h +++ b/src/platform/qt/KeyEditor.h @@ -7,7 +7,9 @@ #define QGBA_KEY_EDITOR #include "GamepadAxisEvent.h" + #include +#include namespace QGBA { @@ -41,12 +43,15 @@ protected: virtual bool event(QEvent* event) override; private: + static const int KEY_TIME = 2000; + void updateButtonText(); int m_key; int m_axis; bool m_button; GamepadAxisEvent::Direction m_direction; + QTimer m_lastKey; }; }