From 6efefb3fe5c7c392bc4857d979dee51042a4f043 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 19 Jan 2012 12:40:52 +0100 Subject: QKeySequence: add tests, fix handling of '+' as key or separator. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3c471dff9b46025aab762d36bb3a3adc64ced561 Reviewed-by: Morten Johan Sørvig Reviewed-by: Lars Knoll --- src/gui/kernel/qkeysequence.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/gui') 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; } -- cgit v1.2.3