Android: Don't show '&' character in menus

Strip out shortcut indicator before showing the text.

Task-number: QTBUG-30507

Change-Id: I8fa2ef8a2052f4c43d14b3babfd5aca0a08e29d5
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
Paul Olav Tvete 2013-04-04 11:58:34 +02:00 committed by The Qt Project
parent 87f890295b
commit d9170e650c

View File

@ -177,6 +177,20 @@ namespace QtAndroidMenu
resetMenuBar();
}
static QString 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();
}
static void fillMenuItem(JNIEnv *env, jobject menuItem, bool checkable, bool checked, bool enabled, bool visible, const QIcon &icon=QIcon())
{
env->CallObjectMethod(menuItem, setCheckableMenuItemMethodID, checkable);
@ -204,8 +218,9 @@ namespace QtAndroidMenu
foreach (QAndroidPlatformMenuItem *item, platformMenu->menuItems()) {
if (item->isSeparator())
continue;
jstring jtext = env->NewString(reinterpret_cast<const jchar *>(item->text().data()),
item->text().length());
QString itemText = removeAmpersandEscapes(item->text());
jstring jtext = env->NewString(reinterpret_cast<const jchar *>(itemText.data()),
itemText.length());
jobject menuItem = env->CallObjectMethod(menu,
addMenuItemMethodID,
menuNoneValue,
@ -239,8 +254,9 @@ namespace QtAndroidMenu
order = addAllMenuItemsToMenu(env, menu, static_cast<QAndroidPlatformMenu *>(menus.front()));
} else {
foreach (QAndroidPlatformMenu *item, menus) {
jstring jtext = env->NewString(reinterpret_cast<const jchar *>(item->text().data()),
item->text().length());
QString itemText = removeAmpersandEscapes(item->text());
jstring jtext = env->NewString(reinterpret_cast<const jchar *>(itemText.data()),
itemText.length());
jobject menuItem = env->CallObjectMethod(menu,
addMenuItemMethodID,
menuNoneValue,
@ -299,8 +315,9 @@ namespace QtAndroidMenu
if (!visibleMenu)
return;
jstring jtext = env->NewString(reinterpret_cast<const jchar*>(visibleMenu->text().data()),
visibleMenu->text().length());
QString menuText = removeAmpersandEscapes(visibleMenu->text());
jstring jtext = env->NewString(reinterpret_cast<const jchar*>(menuText.data()),
menuText.length());
env->CallObjectMethod(menu, setHeaderTitleContextMenuMethodID, jtext);
env->DeleteLocalRef(jtext);
addAllMenuItemsToMenu(env, menu, visibleMenu);