summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Millán Soto <fid@gpul.org>2012-01-22 19:48:09 +0100
committerQt by Nokia <qt-info@nokia.com>2012-04-11 01:42:12 +0200
commit784076fccbc7f5644259bff274db371747fecee2 (patch)
treec7a33e6a86b145b9e9f8245539d4b870daf0bcb8 /src
parent50fefebc8403c0f293210c6dc5a98adb19776b76 (diff)
Made qt_accStripAmp handle "&&"
Changed qt_accStripAmp implementation to handle texts which contains pairs of ampersands representing a single ampersand. In order to do that, a new static function called qt_accAmpIndex was created. This function is based on the code of qt_accHotKey, which was changed to use qt_accAmpIndex. Change-Id: Idcc5d07581d7fb3251c30399b189740ca8071104 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com> (cherry picked from commit f864f8f79b88bbc3cc9007d2a92b08ca4b5cb871)
Diffstat (limited to 'src')
-rw-r--r--src/widgets/accessible/qaccessiblewidget.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp
index ae050ac643..796ce42118 100644
--- a/src/widgets/accessible/qaccessiblewidget.cpp
+++ b/src/widgets/accessible/qaccessiblewidget.cpp
@@ -100,16 +100,14 @@ static QString buddyString(const QWidget *widget)
return QString();
}
-QString Q_WIDGETS_EXPORT qt_accStripAmp(const QString &text)
-{
- return QString(text).remove(QLatin1Char('&'));
-}
-
-QString Q_WIDGETS_EXPORT qt_accHotKey(const QString &text)
+/* This function will return the offset of the '&' in the text that would be
+ preceding the accelerator character.
+ If this text does not have an accelerator, -1 will be returned. */
+static int qt_accAmpIndex(const QString &text)
{
#ifndef QT_NO_SHORTCUT
if (text.isEmpty())
- return text;
+ return -1;
int fa = 0;
QChar ac;
@@ -118,23 +116,42 @@ QString Q_WIDGETS_EXPORT qt_accHotKey(const QString &text)
if (fa < text.length()) {
// ignore "&&"
if (text.at(fa) == QLatin1Char('&')) {
+
++fa;
continue;
} else {
- ac = text.at(fa);
+ return fa - 1;
break;
}
}
}
- if (ac.isNull())
- return QString();
- return QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + ac.toUpper();
+
+ return -1;
#else
Q_UNUSED(text);
- return QString();
+ return -1;
#endif
}
+QString Q_WIDGETS_EXPORT qt_accStripAmp(const QString &text)
+{
+ QString newText(text);
+ int ampIndex = qt_accAmpIndex(newText);
+ if (ampIndex != -1)
+ newText.remove(ampIndex, 1);
+
+ return newText.replace(QLatin1String("&&"), QLatin1String("&"));
+}
+
+QString Q_WIDGETS_EXPORT qt_accHotKey(const QString &text)
+{
+ int ampIndex = qt_accAmpIndex(text);
+ if (ampIndex != -1)
+ return (QString)QKeySequence(Qt::ALT) + text.at(ampIndex + 1);
+
+ return QString();
+}
+
class QAccessibleWidgetPrivate
{
public: