diff options
author | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2015-10-27 12:35:15 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2015-11-04 14:00:54 +0000 |
commit | b63160b079a124ce45fb5741c65e9a4393aaa560 (patch) | |
tree | c3f359f4e76a1aff89eb7c147a49cee51e8e6358 /src/gui/kernel | |
parent | c5239ec12d6aca0aa081ea61a3adad715d45d65c (diff) |
iOS: refactor removeMnemonics(const QString &) to QPlatformTheme
This function is needed across several OS', so refactor it out to
a common place.
Change-Id: I35b957029c965672739d03cd2db3e87f5bd0acdf
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qplatformtheme.cpp | 35 | ||||
-rw-r--r-- | src/gui/kernel/qplatformtheme.h | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index ce8548f628..61dacfa076 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -682,6 +682,41 @@ QString QPlatformTheme::defaultStandardButtonText(int button) return QString(); } +QString QPlatformTheme::removeMnemonics(const QString &original) +{ + QString returnText(original.size(), 0); + int finalDest = 0; + int currPos = 0; + int l = original.length(); + while (l) { + if (original.at(currPos) == QLatin1Char('&') + && (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) { + ++currPos; + --l; + if (l == 0) + break; + } else if (original.at(currPos) == QLatin1Char('(') && l >= 4 && + original.at(currPos + 1) == QLatin1Char('&') && + original.at(currPos + 2) != QLatin1Char('&') && + original.at(currPos + 3) == QLatin1Char(')')) { + /* remove mnemonics its format is "\s*(&X)" */ + int n = 0; + while (finalDest > n && returnText.at(finalDest - n - 1).isSpace()) + ++n; + finalDest -= n; + currPos += 4; + l -= 4; + continue; + } + returnText[finalDest] = original.at(currPos); + ++currPos; + ++finalDest; + --l; + } + returnText.truncate(finalDest); + return returnText; +} + unsigned QPlatformThemePrivate::currentKeyPlatforms() { const uint keyboardScheme = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt(); diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 69cc2f90af..9355e83491 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -301,6 +301,7 @@ public: static QVariant defaultThemeHint(ThemeHint hint); static QString defaultStandardButtonText(int button); + static QString removeMnemonics(const QString &original); protected: explicit QPlatformTheme(QPlatformThemePrivate *priv); |