summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakumi Asaki <asaki@sra.co.jp>2014-04-25 17:14:31 +0900
committerOswald Buddenhagen <oswald.buddenhagen@digia.com>2014-08-08 10:44:29 +0200
commit8e3aacf61bcfe036acdba8fac4d07d68ff0f5ab3 (patch)
treefedd2a572282210d37a1f68f525ca1030e1d28c5
parentbb760d9514ed617ee8e7344152b3fa697b2c4171 (diff)
OS X: Remove mnemonics in parentheses
In some language, mnemonics put after label text within parentheses. e.g. "&Open" is translated to "開く(&O)" in Japanese. OS X doesn't use mnemonics and '&' in label text is removed. Mnemonics in parentheses (and spaces before them) also should be removed. Change-Id: I88c0a1f60af7e148b3cf24a4e215ce807d62bce3 Reviewed-by: Tasuku Suzuki <stasuku@gmail.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
-rw-r--r--src/gui/painting/qpainter.cpp14
-rw-r--r--src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm4
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm11
-rw-r--r--src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm4
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.mm23
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm12
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp8
7 files changed, 51 insertions, 25 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 8b2c315e58..0e03a0194a 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -7438,6 +7438,7 @@ start_lengthVariant:
underlinePositions.resize(maxUnderlines + 1);
QChar *cout = text.data() + old_offset;
+ QChar *cout0 = cout;
QChar *cin = cout;
int l = length;
while (l) {
@@ -7448,7 +7449,18 @@ start_lengthVariant:
if (!l)
break;
if (*cin != QLatin1Char('&') && !hidemnmemonic)
- underlinePositions[numUnderlines++] = cout - text.data() - old_offset;
+ underlinePositions[numUnderlines++] = cout - cout0;
+ } else if (hidemnmemonic && *cin == QLatin1Char('(') && l >= 4 &&
+ cin[1] == QLatin1Char('&') && cin[2] != QLatin1Char('&') &&
+ cin[3] == QLatin1Char(')')) {
+ int n = 0;
+ while ((cout - n) > cout0 && (cout - n - 1)->isSpace())
+ ++n;
+ cout -= n;
+ cin += 4;
+ length -= n + 4;
+ l -= 4;
+ continue;
}
*cout = *cin;
++cout;
diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
index be2bab8ce7..5a7cdec83e 100644
--- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
@@ -59,8 +59,8 @@ static NSButton *macCreateButton(const char *text, NSView *superview)
NSButton *button = [[NSButton alloc] initWithFrame:buttonFrameRect];
[button setButtonType:NSMomentaryLightButton];
[button setBezelStyle:NSRoundedBezelStyle];
- [button setTitle:(NSString*)(CFStringRef)QCFString(QCoreApplication::translate("QDialogButtonBox", text)
- .remove(QLatin1Char('&')))];
+ [button setTitle:(NSString*)(CFStringRef)QCFString(
+ qt_mac_removeMnemonics(QCoreApplication::translate("QDialogButtonBox", text)))];
[[button cell] setFont:[NSFont systemFontOfSize:
[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
[superview addSubview:button];
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index 2b7b8109ad..f021446438 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -191,16 +191,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate);
static QString strippedText(QString s)
{
s.remove( QString::fromLatin1("...") );
- int i = 0;
- while (i < s.size()) {
- ++i;
- if (s.at(i-1) != QLatin1Char('&'))
- continue;
- if (i < s.size() && s.at(i) == QLatin1Char('&'))
- ++i;
- s.remove(i-1,1);
- }
- return s.trimmed();
+ return qt_mac_removeMnemonics(s).trimmed();
}
- (NSString *)strip:(const QString &)label
diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
index a18f721e04..c37bb63916 100644
--- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
@@ -79,8 +79,8 @@ static NSButton *macCreateButton(const char *text, NSView *superview)
NSButton *button = [[NSButton alloc] initWithFrame:buttonFrameRect];
[button setButtonType:NSMomentaryLightButton];
[button setBezelStyle:NSRoundedBezelStyle];
- [button setTitle:(NSString*)(CFStringRef)QCFString(QCoreApplication::translate("QDialogButtonBox", text)
- .remove(QLatin1Char('&')))];
+ [button setTitle:(NSString*)(CFStringRef)QCFString(
+ qt_mac_removeMnemonics(QCoreApplication::translate("QDialogButtonBox", text)))];
[[button cell] setFont:[NSFont systemFontOfSize:
[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
[superview addSubview:button];
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm
index 526204a414..e3916ea787 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.mm
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm
@@ -503,6 +503,18 @@ QString qt_mac_removeMnemonics(const QString &original)
--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;
@@ -761,16 +773,7 @@ bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret)
QString qt_mac_removeAmpersandEscapes(QString s)
{
- int i = 0;
- while (i < s.size()) {
- ++i;
- if (s.at(i-1) != QLatin1Char('&'))
- continue;
- if (i < s.size() && s.at(i) == QLatin1Char('&'))
- ++i;
- s.remove(i-1,1);
- }
- return s.trimmed();
+ return qt_mac_removeMnemonics(s).trimmed();
}
/*! \internal
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 531f538820..242a1c1c9e 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -494,6 +494,18 @@ static QString qt_mac_removeMnemonics(const QString &original)
--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;
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index 3b891152b1..6c63d1ee90 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -1047,6 +1047,14 @@ void tst_QMenu::QTBUG_37933_ampersands_data()
QTest::newRow("simple") << QString("Test") << QString("Test");
QTest::newRow("ampersand") << QString("&Test") << QString("Test");
QTest::newRow("double_ampersand") << QString("&Test && more") << QString("Test & more");
+ QTest::newRow("ampersand_in_parentheses") << QString("Test(&T) (&&) more") << QString("Test (&) more");
+ QTest::newRow("ampersand_in_parentheses_after_space") << QString("Test (&T)") << QString("Test");
+ QTest::newRow("ampersand_in_parentheses_after_spaces") << QString("Test (&T)") << QString("Test");
+ QTest::newRow("ampersand_in_parentheses_before_space") << QString("Test(&T) ") << QString("Test ");
+ QTest::newRow("only_ampersand_in_parentheses") << QString("(&T)") << QString("");
+ QTest::newRow("only_ampersand_in_parentheses_after_space") << QString(" (&T)") << QString("");
+ QTest::newRow("parentheses_after_space") << QString(" (Dummy)") << QString(" (Dummy)");
+ QTest::newRow("ampersand_after_space") << QString("About &Qt Project") << QString("About Qt Project");
}
void tst_qmenu_QTBUG_37933_ampersands();