From 5558e469e03b62eeb34c44123f64d64ce5782b3e Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 9 Feb 2023 19:59:55 -0800 Subject: [PATCH] Qt: Fix modifier key names in shortcut editor (fixes #2817) --- CHANGES | 1 + src/platform/qt/KeyEditor.cpp | 31 ++----------------------------- src/platform/qt/ShortcutModel.cpp | 5 +++-- src/platform/qt/utils.cpp | 25 +++++++++++++++++++++++++ src/platform/qt/utils.h | 2 ++ 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/CHANGES b/CHANGES index f99a6a9cb..d85734302 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ Other fixes: - Qt: Disable sync while running scripts from main thread (fixes mgba.io/i/2738) - Qt: Properly cap number of attached players by platform (fixes mgba.io/i/2807) - Qt: Disable attempted linking betwen incompatible platforms (fixes mgba.io/i/2702) + - Qt: Fix modifier key names in shortcut editor (fixes mgba.io/i/2817) Misc: - Qt: Include wayland QPA in AppImage (fixes mgba.io/i/2796) - Qt: Stop eating boolean action key events (fixes mgba.io/i/2636) diff --git a/src/platform/qt/KeyEditor.cpp b/src/platform/qt/KeyEditor.cpp index 95b83a9e8..fb87656b1 100644 --- a/src/platform/qt/KeyEditor.cpp +++ b/src/platform/qt/KeyEditor.cpp @@ -8,6 +8,7 @@ #include "GamepadAxisEvent.h" #include "GamepadButtonEvent.h" #include "ShortcutController.h" +#include "utils.h" #include #include @@ -33,35 +34,7 @@ void KeyEditor::setValue(int key) { if (key < 0) { setText(tr("---")); } else { - QKeySequence seq(key); - switch (key) { -#ifndef Q_OS_MAC - case Qt::Key_Shift: - setText(QCoreApplication::translate("QShortcut", "Shift")); - break; - case Qt::Key_Control: - setText(QCoreApplication::translate("QShortcut", "Control")); - break; - case Qt::Key_Alt: - setText(QCoreApplication::translate("QShortcut", "Alt")); - break; - case Qt::Key_Meta: - setText(QCoreApplication::translate("QShortcut", "Meta")); - break; -#endif - case Qt::Key_Super_L: - setText(tr("Super (L)")); - break; - case Qt::Key_Super_R: - setText(tr("Super (R)")); - break; - case Qt::Key_Menu: - setText(tr("Menu")); - break; - default: - setText(QKeySequence(key).toString(QKeySequence::NativeText)); - break; - } + setText(keyName(key)); } } emit valueChanged(key); diff --git a/src/platform/qt/ShortcutModel.cpp b/src/platform/qt/ShortcutModel.cpp index 54fa83fcf..b73982cad 100644 --- a/src/platform/qt/ShortcutModel.cpp +++ b/src/platform/qt/ShortcutModel.cpp @@ -6,6 +6,7 @@ #include "ShortcutModel.h" #include "ShortcutController.h" +#include "utils.h" using namespace QGBA; @@ -33,7 +34,7 @@ QVariant ShortcutModel::data(const QModelIndex& index, int role) const { case 0: return m_controller->visibleName(item->name); case 1: - return shortcut ? QKeySequence(shortcut->shortcut()).toString(QKeySequence::NativeText) : QVariant(); + return shortcut ? keyName(shortcut->shortcut()) : QVariant(); case 2: if (!shortcut) { return QVariant(); @@ -134,4 +135,4 @@ void ShortcutModel::clearMenu(const QString&) { // TODO beginResetModel(); endResetModel(); -} \ No newline at end of file +} diff --git a/src/platform/qt/utils.cpp b/src/platform/qt/utils.cpp index 8b273cb6d..bf4582cda 100644 --- a/src/platform/qt/utils.cpp +++ b/src/platform/qt/utils.cpp @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "utils.h" +#include +#include #include namespace QGBA { @@ -59,4 +61,27 @@ bool convertAddress(const QHostAddress* input, Address* output) { return true; } +QString keyName(int key) { + switch (key) { +#ifndef Q_OS_MAC + case Qt::Key_Shift: + return QCoreApplication::translate("QShortcut", "Shift"); + case Qt::Key_Control: + return QCoreApplication::translate("QShortcut", "Control"); + case Qt::Key_Alt: + return QCoreApplication::translate("QShortcut", "Alt"); + case Qt::Key_Meta: + return QCoreApplication::translate("QShortcut", "Meta"); +#endif + case Qt::Key_Super_L: + return QObject::tr("Super (L)"); + case Qt::Key_Super_R: + return QObject::tr("Super (R)"); + case Qt::Key_Menu: + return QObject::tr("Menu"); + default: + return QKeySequence(key).toString(QKeySequence::NativeText); + } +} + } diff --git a/src/platform/qt/utils.h b/src/platform/qt/utils.h index ca9ef027f..36f819d92 100644 --- a/src/platform/qt/utils.h +++ b/src/platform/qt/utils.h @@ -67,4 +67,6 @@ constexpr const T& clamp(const T& v, const T& lo, const T& hi) { } #endif +QString keyName(int key); + }