Skip to content

Commit

Permalink
Add more keys where Shift should not be removed
Browse files Browse the repository at this point in the history
Backport of musescore#24958 and fix clazy warnings
  • Loading branch information
shubham-shinde-442 authored and Jojo-Schmitz committed Oct 12, 2024
1 parent ba6d337 commit b2c8dfe
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
81 changes: 73 additions & 8 deletions mscore/shortcutcapturedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -97,7 +97,6 @@ bool ShortcutCaptureDialog::eventFilter(QObject* /*o*/, QEvent* e)
return false;
}


//---------------------------------------------------------
// keyPressEvent
//---------------------------------------------------------
Expand All @@ -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;
}

Expand All @@ -135,15 +134,15 @@ 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
continue;

QList<QKeySequence> 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;
Expand Down Expand Up @@ -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
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions mscore/shortcutcapturedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, Shortcut*> localShortcuts;
Expand Down

0 comments on commit b2c8dfe

Please sign in to comment.