From a824989e5a1ecf32775d7d33a0ae47a86b28c7f4 Mon Sep 17 00:00:00 2001 From: oltolm Date: Tue, 30 Apr 2024 19:01:52 +0200 Subject: [PATCH] fix shortcuts --- src/platform/qt/KeyEditor.cpp | 49 +++++------------------------------ src/platform/qt/KeyEditor.h | 2 +- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/platform/qt/KeyEditor.cpp b/src/platform/qt/KeyEditor.cpp index 50702da73..818b6c703 100644 --- a/src/platform/qt/KeyEditor.cpp +++ b/src/platform/qt/KeyEditor.cpp @@ -41,7 +41,7 @@ void KeyEditor::setValue(int key) { if (m_button) { updateButtonText(); } else { - if (key < 0) { + if (key == Qt::Key_unknown) { setText(tr("---")); } else { setText(keyName(key)); @@ -78,7 +78,7 @@ void KeyEditor::setValueHat(int hat, GamepadHatEvent::Direction direction) { void KeyEditor::clearButton() { m_button = true; - setValue(-1); + setValue(Qt::Key_unknown); } void KeyEditor::clearAxis() { @@ -106,48 +106,11 @@ QSize KeyEditor::sizeHint() const { void KeyEditor::keyPressEvent(QKeyEvent* event) { if (!m_button) { - if (m_key < 0 || !m_lastKey.isActive()) { - m_key = 0; + if (!m_lastKey.isActive()) { + m_key = Qt::Key_unknown; } 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()); - } + setValue(ShortcutController::isModifierKey(event->key()) ? event->modifiers() : event->key() | event->modifiers()); } event->accept(); } @@ -213,7 +176,7 @@ void KeyEditor::updateButtonText() { break; } } - if (m_key >= 0) { + if (m_key != Qt::Key_unknown) { std::shared_ptr gamepad; if (m_controller && m_controller->gamepadDriver()) { gamepad = m_controller->gamepadDriver()->activeGamepad(); diff --git a/src/platform/qt/KeyEditor.h b/src/platform/qt/KeyEditor.h index 93af927ac..66599ad60 100644 --- a/src/platform/qt/KeyEditor.h +++ b/src/platform/qt/KeyEditor.h @@ -57,7 +57,7 @@ private: void updateButtonText(); - int m_key = -1; + int m_key = Qt::Key_unknown; int m_axis = -1; int m_hat = -1; bool m_button = false;