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
- 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:

View File

@ -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();

View File

@ -7,7 +7,9 @@
#define QGBA_KEY_EDITOR
#include "GamepadAxisEvent.h"
#include <QLineEdit>
#include <QTimer>
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;
};
}