summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2012-01-19 12:40:52 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-24 15:27:17 +0100
commit6efefb3fe5c7c392bc4857d979dee51042a4f043 (patch)
tree66f8c1d0b3281c59c9c05608238d586f6e40ad5e /src/gui
parent84bdb7b61f79402b238e903fc18fd62e565e1563 (diff)
QKeySequence: add tests, fix handling of '+' as key or separator.
Change-Id: I3c471dff9b46025aab762d36bb3a3adc64ced561 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qkeysequence.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index 34457a9cee..83796bb550 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -1255,10 +1255,21 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
int lastI = 0;
while ((i = sl.indexOf(QLatin1Char('+'), i + 1)) != -1) {
const QString sub = sl.mid(lastI, i - lastI + 1);
- // Just shortcut the check here if we only have one character.
- // Rational: A modifier will contain the name AND +, so longer than 1, a length of 1 is just
- // the remaining part of the shortcut (ei. The 'C' in "Ctrl+C"), so no need to check that.
- if (sub.length() > 1) {
+ // If we get here the shortcuts contains at least one '+'. We break up
+ // along the following strategy:
+ // Meta+Ctrl++ ( "Meta+", "Ctrl+", "+" )
+ // Super+Shift+A ( "Super+", "Shift+" )
+ // 4+3+2=1 ( "4+", "3+" )
+ // In other words, everything we try to handle HAS to be a modifier
+ // except for a single '+' at the end of the string.
+
+ // Only '+' can have length 1.
+ if (sub.length() == 1) {
+ // Make sure we only encounter a single '+' at the end of the accel
+ if (accel.lastIndexOf(QLatin1Char('+')) != accel.length()-1)
+ return Qt::Key_unknown;
+ } else {
+ // Identify the modifier
bool validModifier = false;
for (int j = 0; j < modifs.size(); ++j) {
const QModifKeyName &mkf = modifs.at(j);
@@ -1268,9 +1279,7 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
break; // Shortcut, since if we find an other it would/should just be a dup
}
}
- // We couldn't match the string with a modifier. This is only
- // possible if this part is the key. The key is never followed by a
- // '+'. And if the key is '+' the if() above would have skipped it.
+
if (!validModifier)
return Qt::Key_unknown;
}