From b2c8dfe9d866177344e6cddf0212bae97c398429 Mon Sep 17 00:00:00 2001 From: Shubham Shinde Date: Sat, 28 Sep 2024 12:09:24 +0200 Subject: [PATCH] Add more keys where Shift should not be removed Backport of #24958 and fix clazy warnings --- mscore/shortcutcapturedialog.cpp | 81 ++++++++++++++++++++++++++++---- mscore/shortcutcapturedialog.h | 1 + 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/mscore/shortcutcapturedialog.cpp b/mscore/shortcutcapturedialog.cpp index 7d51bc75ba493..ba3915b5c084d 100644 --- a/mscore/shortcutcapturedialog.cpp +++ b/mscore/shortcutcapturedialog.cpp @@ -18,9 +18,9 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //============================================================================= -#include "shortcutcapturedialog.h" #include "musescore.h" #include "shortcut.h" +#include "shortcutcapturedialog.h" namespace Ms { @@ -97,7 +97,6 @@ bool ShortcutCaptureDialog::eventFilter(QObject* /*o*/, QEvent* e) return false; } - //--------------------------------------------------------- // keyPressEvent //--------------------------------------------------------- @@ -113,11 +112,11 @@ void ShortcutCaptureDialog::keyPress(QKeyEvent* e) || k == Qt::Key_ScrollLock || k == Qt::Key_unknown) return; - k += e->modifiers(); - // remove shift-modifier for keys that don't need it: letters and special keys - if ((k & Qt::ShiftModifier) && ((e->key() < 0x41) || (e->key() > 0x5a) || (e->key() >= 0x01000000))) { + k |= e->modifiers(); + // remove shift-modifier for non-letter keys, except a few keys + if ((k & Qt::ShiftModifier) && !isShiftAllowed(e->key())) { qDebug() << k; - k -= Qt::ShiftModifier; + k &= ~Qt::ShiftModifier; qDebug() << k; } @@ -135,7 +134,7 @@ void ShortcutCaptureDialog::keyPress(QKeyEvent* e) bool conflict = false; QString msgString; - for (Shortcut* ss : localShortcuts) { + for (Shortcut* ss : qAsConst(localShortcuts)) { if (s == ss) continue; if (!(s->state() & ss->state())) // no conflict if states do not overlap @@ -143,7 +142,7 @@ void ShortcutCaptureDialog::keyPress(QKeyEvent* e) QList skeys = QKeySequence::keyBindings(ss->standardKey()); - for (const QKeySequence& ks : skeys) { + for (const QKeySequence& ks : qAsConst(skeys)) { if (ks == key) { msgString = tr("Shortcut conflicts with %1").arg(ss->descr()); conflict = true; @@ -191,6 +190,72 @@ void ShortcutCaptureDialog::keyPress(QKeyEvent* e) ); } +bool ShortcutCaptureDialog::isShiftAllowed(int key) + { + // Letter keys where Shift should not be removed + if (key >= Qt::Key_A && key <= Qt::Key_Z) { + return true; + } + + // non-letter keys where Shift should not be removed + switch (key) { + case Qt::Key_Up: + case Qt::Key_Down: + case Qt::Key_Left: + case Qt::Key_Right: + case Qt::Key_Insert: + case Qt::Key_Delete: + case Qt::Key_Home: + case Qt::Key_End: + case Qt::Key_PageUp: + case Qt::Key_PageDown: + case Qt::Key_Space: + case Qt::Key_Escape: +#if (!defined (_MSCVER) && !defined (_MSC_VER)) + case Qt::Key_F1 ... Qt::Key_F35: // needs gcc or a derived compiler +#else + case Qt::Key_F1: + case Qt::Key_F2: + case Qt::Key_F3: + case Qt::Key_F4: + case Qt::Key_F5: + case Qt::Key_F6: + case Qt::Key_F7: + case Qt::Key_F8: + case Qt::Key_F9: + case Qt::Key_F10: + case Qt::Key_F11: + case Qt::Key_F12: + case Qt::Key_F13: + case Qt::Key_F14: + case Qt::Key_F15: + case Qt::Key_F16: + case Qt::Key_F17: + case Qt::Key_F18: + case Qt::Key_F19: + case Qt::Key_F20: + case Qt::Key_F21: + case Qt::Key_F22: + case Qt::Key_F23: + case Qt::Key_F24: + case Qt::Key_F25: + case Qt::Key_F26: + case Qt::Key_F27: + case Qt::Key_F28: + case Qt::Key_F29: + case Qt::Key_F30: + case Qt::Key_F31: + case Qt::Key_F32: + case Qt::Key_F33: + case Qt::Key_F34: + case Qt::Key_F35: +#endif + return true; + default: + return false; + } + } + //--------------------------------------------------------- // clearClicked //--------------------------------------------------------- diff --git a/mscore/shortcutcapturedialog.h b/mscore/shortcutcapturedialog.h index 84fa5b5d8500e..9c4f50cbd9257 100644 --- a/mscore/shortcutcapturedialog.h +++ b/mscore/shortcutcapturedialog.h @@ -41,6 +41,7 @@ class ShortcutCaptureDialog : public QDialog, public Ui::ShortcutCaptureDialogBa Shortcut* s; void keyPress(QKeyEvent* e); + bool isShiftAllowed(int key); virtual bool eventFilter(QObject* o, QEvent* e); QKeySequence key; QMap localShortcuts;