summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/accessible/qaccessiblewidget.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/gui/accessible/qaccessiblewidget.cpp b/src/gui/accessible/qaccessiblewidget.cpp
index a03bc34..d6cd966 100644
--- a/src/gui/accessible/qaccessiblewidget.cpp
+++ b/src/gui/accessible/qaccessiblewidget.cpp
@@ -100,16 +100,14 @@ static QString buddyString(const QWidget *widget)
return QString();
}
-QString Q_GUI_EXPORT qt_accStripAmp(const QString &text)
-{
- return QString(text).remove(QLatin1Char('&'));
-}
-
-QString Q_GUI_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;
@@ -121,20 +119,38 @@ QString Q_GUI_EXPORT qt_accHotKey(const QString &text)
++fa;
continue;
} else {
- ac = text.at(fa);
+ return fa - 1;
break;
}
}
}
- if (ac.isNull())
- return QString();
- return (QString)QKeySequence(Qt::ALT) + ac.toUpper();
+
+ return -1;
#else
Q_UNUSED(text);
- return QString();
+ return -1;
#endif
}
+QString Q_GUI_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_GUI_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 QAccessible
{
public: