summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-01-12 14:10:53 +0100
committerAndy Shaw <andy.shaw@qt.io>2017-01-27 01:56:52 +0000
commit02cc57f4edbae450ecfa8368052afa44f8aeee19 (patch)
tree9ad7edbad185944ca1d4b711fa9599d14474652b /src/widgets
parent9febc58d07cc19a7393b98fdafbc38ac25e52d6a (diff)
QKeySequenceEdit: Allow for the case where pressing SHIFT+letter gives a different letter
On some keyboard layouts it is possible that pressing SHIFT+letter does not give the upper case version of the character. So we depend on QKeyMapper here to give us the right keysequence as then it will compare against a shortcut created with this combination then. Task-number: QTBUG-57928 Task-number: QTBUG-57931 Change-Id: I9421f3ab4d3f8d1ee42f9680200d4b017d551057 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qkeysequenceedit.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/widgets/widgets/qkeysequenceedit.cpp b/src/widgets/widgets/qkeysequenceedit.cpp
index 3252ce5941..4d86c7cfc7 100644
--- a/src/widgets/widgets/qkeysequenceedit.cpp
+++ b/src/widgets/widgets/qkeysequenceedit.cpp
@@ -43,6 +43,7 @@
#include "qboxlayout.h"
#include "qlineedit.h"
+#include <private/qkeymapper_p.h>
QT_BEGIN_NAMESPACE
@@ -80,15 +81,8 @@ void QKeySequenceEditPrivate::init()
int QKeySequenceEditPrivate::translateModifiers(Qt::KeyboardModifiers state, const QString &text)
{
+ Q_UNUSED(text);
int result = 0;
- // The shift modifier only counts when it is not used to type a symbol
- // that is only reachable using the shift key anyway
- if ((state & Qt::ShiftModifier) && (text.isEmpty() ||
- !text.at(0).isPrint() ||
- text.at(0).isLetterOrNumber() ||
- text.at(0).isSpace()))
- result |= Qt::SHIFT;
-
if (state & Qt::ControlModifier)
result |= Qt::CTRL;
if (state & Qt::MetaModifier)
@@ -272,7 +266,27 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
if (d->keyNum >= QKeySequencePrivate::MaxKeyCount)
return;
- nextKey |= d->translateModifiers(e->modifiers(), e->text());
+ if (e->modifiers() & Qt::ShiftModifier) {
+ QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
+ int pkTotal = possibleKeys.count();
+ if (!pkTotal)
+ return;
+ bool found = false;
+ for (int i = 0; i < possibleKeys.size(); ++i) {
+ if (possibleKeys.at(i) - nextKey == int(e->modifiers())
+ || (possibleKeys.at(i) == nextKey && e->modifiers() == Qt::ShiftModifier)) {
+ nextKey = possibleKeys.at(i);
+ found = true;
+ break;
+ }
+ }
+ // Use as fallback
+ if (!found)
+ nextKey = possibleKeys.first();
+ } else {
+ nextKey |= d->translateModifiers(e->modifiers(), e->text());
+ }
+
d->key[d->keyNum] = nextKey;
d->keyNum++;