Cocoa QPA: Code clean up, make some bits more readable

Change-Id: I7f37c1b0f7f72a79bb2ac5828ba54111a90a0a00
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Gabriel de Dietrich 2017-10-20 11:07:59 +07:00 committed by Liang Qi
parent 4f9b2cb026
commit 37a1478787
4 changed files with 22 additions and 21 deletions

View File

@ -75,7 +75,7 @@ QString qt_mac_applicationmenu_string(int type)
QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption)
{
QString captionNoAmpersand(caption);
captionNoAmpersand.remove(QChar('&'));
captionNoAmpersand.remove(QLatin1Char('&'));
const QString aboutString = QCoreApplication::translate("QCocoaMenuItem", "About");
if (captionNoAmpersand.startsWith(aboutString, Qt::CaseInsensitive) || caption.endsWith(aboutString, Qt::CaseInsensitive))
return QPlatformMenuItem::AboutRole;

View File

@ -45,6 +45,17 @@
QT_BEGIN_NAMESPACE
enum {
ServicesAppMenuItem = 0,
HideAppMenuItem,
HideOthersAppMenuItem,
ShowAllAppMenuItem,
PreferencesAppMenuItem,
QuitAppMenuItem,
AboutAppMenuItem
};
QString msgAboutQt();
QString qt_mac_applicationmenu_string(int type);

View File

@ -370,24 +370,20 @@ NSMenuItem *QCocoaMenuItem::sync()
return m_native;
}
QT_BEGIN_NAMESPACE
extern QString qt_mac_applicationmenu_string(int type);
QT_END_NAMESPACE
QString QCocoaMenuItem::mergeText()
{
QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader];
if (m_native == [loader aboutMenuItem]) {
return qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName());
return qt_mac_applicationmenu_string(AboutAppMenuItem).arg(qt_mac_applicationName());
} else if (m_native== [loader aboutQtMenuItem]) {
if (m_text == QString("About Qt"))
return msgAboutQt();
else
return m_text;
} else if (m_native == [loader preferencesMenuItem]) {
return qt_mac_applicationmenu_string(4);
return qt_mac_applicationmenu_string(PreferencesAppMenuItem);
} else if (m_native == [loader quitMenuItem]) {
return qt_mac_applicationmenu_string(5).arg(qt_mac_applicationName());
return qt_mac_applicationmenu_string(QuitAppMenuItem).arg(qt_mac_applicationName());
} else if (m_text.contains('\t')) {
return m_text.left(m_text.indexOf('\t'));
}

View File

@ -47,14 +47,8 @@
#include <QtCore/private/qcore_mac_p.h>
#include <QtCore/private/qthread_p.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qdir.h>
#include <QtCore/qstring.h>
#include <QtCore/qdebug.h>
#include <QtGui/private/qguiapplication_p.h>
QT_FORWARD_DECLARE_CLASS(QCFString)
QT_FORWARD_DECLARE_CLASS(QString)
@implementation QCocoaMenuLoader
+ (instancetype)sharedMenuLoader
@ -314,13 +308,13 @@ QT_FORWARD_DECLARE_CLASS(QString)
{
#ifndef QT_NO_TRANSLATION
[servicesItem setTitle:qt_mac_applicationmenu_string(0).toNSString()];
[hideItem setTitle:qt_mac_applicationmenu_string(1).arg(qt_mac_applicationName()).toNSString()];
[hideAllOthersItem setTitle:qt_mac_applicationmenu_string(2).toNSString()];
[showAllItem setTitle:qt_mac_applicationmenu_string(3).toNSString()];
[preferencesItem setTitle:qt_mac_applicationmenu_string(4).toNSString()];
[quitItem setTitle:qt_mac_applicationmenu_string(5).arg(qt_mac_applicationName()).toNSString()];
[aboutItem setTitle:qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName()).toNSString()];
[servicesItem setTitle:qt_mac_applicationmenu_string(ServicesAppMenuItem).toNSString()];
[hideItem setTitle:qt_mac_applicationmenu_string(HideAppMenuItem).arg(qt_mac_applicationName()).toNSString()];
[hideAllOthersItem setTitle:qt_mac_applicationmenu_string(HideOthersAppMenuItem).toNSString()];
[showAllItem setTitle:qt_mac_applicationmenu_string(ShowAllAppMenuItem).toNSString()];
[preferencesItem setTitle:qt_mac_applicationmenu_string(PreferencesAppMenuItem).toNSString()];
[quitItem setTitle:qt_mac_applicationmenu_string(QuitAppMenuItem).arg(qt_mac_applicationName()).toNSString()];
[aboutItem setTitle:qt_mac_applicationmenu_string(AboutAppMenuItem).arg(qt_mac_applicationName()).toNSString()];
#endif
}