From a8dc93d4b4797e285e25eae164c8f69a731659b6 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 8 Aug 2022 12:11:16 +0800 Subject: [PATCH] - fix: can't set shortcut that contains shift and non-alphabet characters --- NEWS.md | 1 + RedPandaIDE/widgets/shortcutinputedit.cpp | 25 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7f7ec521..1b5db1a4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ Red Panda C++ Version 1.2 - change: reorganization templates in subfolders - enhancement: create template from project - fix: can't correctly set project icon + - fix: can't set shortcut that contains shift and non-alphabet characters Red Panda C++ Version 1.1.6 diff --git a/RedPandaIDE/widgets/shortcutinputedit.cpp b/RedPandaIDE/widgets/shortcutinputedit.cpp index e7a594d3..252568b2 100644 --- a/RedPandaIDE/widgets/shortcutinputedit.cpp +++ b/RedPandaIDE/widgets/shortcutinputedit.cpp @@ -40,14 +40,33 @@ void ShortcutInputEdit::keyPressEvent(QKeyEvent *event) event->key()==Qt::Key_Shift || event->key()==Qt::Key_Meta ) { - QKeySequence seq(event->modifiers()); - setText(""); + //setText(""); + return; + } else if (event->modifiers()==Qt::ShiftModifier + && !event->text().isEmpty() + && event->text().at(0).unicode()>32 + && event->text().at(0).unicode()<127){ + //setText(""); + return; + } else if (event->modifiers()==Qt::NoModifier + && !event->text().isEmpty() + && event->text().at(0).unicode()>32 + && event->text().at(0).unicode()<127){ + //setText(""); + return; } else { int key = event->key(); if (key==Qt::Key_Backtab) key = Qt::Key_Tab; QKeySequence seq(event->modifiers()|key); - setText(seq.toString()); + QString s=seq.toString(); + if (event->modifiers().testFlag(Qt::ShiftModifier) + && !event->text().isEmpty() + && event->text().at(0).unicode()>32 + && event->text().at(0).unicode()<127) { + s = s.mid(0,s.lastIndexOf('+')+1) + event->text().at(0); + } + setText(s); if (key!=Qt::Key_Tab && key!=Qt::Key_Enter && key!=Qt::Key_Return)