Qt: Allow use of modifier keys as input

This commit is contained in:
Jeffrey Pfau 2015-12-07 20:41:28 -08:00
parent 9590b484c7
commit 08a2b24eac
3 changed files with 44 additions and 18 deletions

View File

@ -60,6 +60,7 @@ Misc:
- Util: Add MutexTryLock - Util: Add MutexTryLock
- Qt: Gray out "Skip BIOS intro" while "Use BIOS file" is unchecked - Qt: Gray out "Skip BIOS intro" while "Use BIOS file" is unchecked
- Qt: Add mute option to menu - Qt: Add mute option to menu
- Qt: Allow use of modifier keys as input
0.3.1: (2015-10-24) 0.3.1: (2015-10-24)
Bugfixes: Bugfixes:

View File

@ -22,6 +22,7 @@ KeyEditor::KeyEditor(QWidget* parent)
{ {
setAlignment(Qt::AlignCenter); setAlignment(Qt::AlignCenter);
setFocusPolicy(Qt::ClickFocus); setFocusPolicy(Qt::ClickFocus);
m_lastKey.setSingleShot(true);
} }
void KeyEditor::setValue(int key) { void KeyEditor::setValue(int key) {
@ -77,28 +78,47 @@ QSize KeyEditor::sizeHint() const {
void KeyEditor::keyPressEvent(QKeyEvent* event) { void KeyEditor::keyPressEvent(QKeyEvent* event) {
if (!m_button) { if (!m_button) {
if (m_key < 0) { if (m_key < 0 || !m_lastKey.isActive()) {
m_key = 0; m_key = 0;
} }
if (ShortcutController::isModifierKey(event->key())) { m_lastKey.start(KEY_TIME);
switch (event->key()) { if (m_key) {
case Qt::Key_Shift: if (ShortcutController::isModifierKey(m_key)) {
setValue(m_key | Qt::ShiftModifier); switch (event->key()) {
break; case Qt::Key_Shift:
case Qt::Key_Control: setValue(Qt::ShiftModifier);
setValue(m_key | Qt::ControlModifier); break;
break; case Qt::Key_Control:
case Qt::Key_Alt: setValue(Qt::ControlModifier);
setValue(m_key | Qt::AltModifier); break;
break; case Qt::Key_Alt:
case Qt::Key_Meta: setValue(Qt::AltModifier);
setValue(m_key | Qt::MetaModifier); break;
break; case Qt::Key_Meta:
default: setValue(Qt::MetaModifier);
setValue(m_key); 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 { } else {
setValue(event->key() | (m_key & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))); setValue(event->key());
} }
} }
event->accept(); event->accept();

View File

@ -7,7 +7,9 @@
#define QGBA_KEY_EDITOR #define QGBA_KEY_EDITOR
#include "GamepadAxisEvent.h" #include "GamepadAxisEvent.h"
#include <QLineEdit> #include <QLineEdit>
#include <QTimer>
namespace QGBA { namespace QGBA {
@ -41,12 +43,15 @@ protected:
virtual bool event(QEvent* event) override; virtual bool event(QEvent* event) override;
private: private:
static const int KEY_TIME = 2000;
void updateButtonText(); void updateButtonText();
int m_key; int m_key;
int m_axis; int m_axis;
bool m_button; bool m_button;
GamepadAxisEvent::Direction m_direction; GamepadAxisEvent::Direction m_direction;
QTimer m_lastKey;
}; };
} }