Qt: Allow use of modifier keys as input
Jeffrey Pfau jeffrey@endrift.com
Mon, 07 Dec 2015 20:41:28 -0800
3 files changed,
44 insertions(+),
18 deletions(-)
M
CHANGES
→
CHANGES
@@ -60,6 +60,7 @@ - GBA Memory: Add GBAView* functions for viewing memory directly without bus issues
- 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:
M
src/platform/qt/KeyEditor.cpp
→
src/platform/qt/KeyEditor.cpp
@@ -22,6 +22,7 @@ , m_button(false)
{ setAlignment(Qt::AlignCenter); setFocusPolicy(Qt::ClickFocus); + m_lastKey.setSingleShot(true); } void KeyEditor::setValue(int key) {@@ -77,28 +78,47 @@ }
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();
M
src/platform/qt/KeyEditor.h
→
src/platform/qt/KeyEditor.h
@@ -7,7 +7,9 @@ #ifndef QGBA_KEY_EDITOR
#define QGBA_KEY_EDITOR #include "GamepadAxisEvent.h" + #include <QLineEdit> +#include <QTimer> namespace QGBA {@@ -41,12 +43,15 @@ virtual void keyPressEvent(QKeyEvent* event) override;
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; }; }