diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoamenuitem.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoamenuitem.mm | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 3979d7169a..b8a64641a8 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -48,17 +48,12 @@ #include "qt_mac_p.h" #include "qcocoaapplication.h" // for custom application category #include "qcocoamenuloader.h" +#include <QtGui/private/qcoregraphics_p.h> #include <QtCore/QDebug> QT_BEGIN_NAMESPACE -static inline QCocoaMenuLoader *getMenuLoader() -{ - return [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)]; -} - - static quint32 constructModifierMask(quint32 accel_key) { quint32 ret = 0; @@ -74,6 +69,7 @@ static quint32 constructModifierMask(quint32 accel_key) return ret; } +#ifndef QT_NO_SHORTCUT // return an autoreleased string given a QKeySequence (currently only looks at the first one). NSString *keySequenceToKeyEqivalent(const QKeySequence &accel) { @@ -92,6 +88,7 @@ NSUInteger keySequenceModifierMask(const QKeySequence &accel) { return constructModifierMask(accel[0]); } +#endif QCocoaMenuItem::QCocoaMenuItem() : m_native(NULL), @@ -189,10 +186,12 @@ void QCocoaMenuItem::setRole(MenuRole role) m_role = role; } +#ifndef QT_NO_SHORTCUT void QCocoaMenuItem::setShortcut(const QKeySequence& shortcut) { m_shortcut = shortcut; } +#endif void QCocoaMenuItem::setChecked(bool isChecked) { @@ -234,7 +233,7 @@ NSMenuItem *QCocoaMenuItem::sync() if ((m_role != NoRole && !m_textSynced) || m_merged) { NSMenuItem *mergeItem = nil; - QCocoaMenuLoader *loader = getMenuLoader(); + QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader]; switch (m_role) { case ApplicationSpecificRole: mergeItem = [loader appSpecificMenuItem:reinterpret_cast<NSInteger>(this)]; @@ -310,7 +309,7 @@ NSMenuItem *QCocoaMenuItem::sync() } if (!m_native) { - m_native = [[NSMenuItem alloc] initWithTitle:QCFString::toNSString(m_text) + m_native = [[NSMenuItem alloc] initWithTitle:m_text.toNSString() action:nil keyEquivalent:@""]; [m_native setTag:reinterpret_cast<NSInteger>(this)]; @@ -320,36 +319,41 @@ NSMenuItem *QCocoaMenuItem::sync() [m_native setView:m_itemView]; QString text = mergeText(); +#ifndef QT_NO_SHORTCUT QKeySequence accel = mergeAccel(); // Show multiple key sequences as part of the menu text. if (accel.count() > 1) text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")"); +#endif QString finalString = QPlatformTheme::removeMnemonics(text); bool useAttributedTitle = false; // Cocoa Font and title if (m_font.resolve()) { - NSFont *customMenuFont = [NSFont fontWithName:QCFString::toNSString(m_font.family()) + NSFont *customMenuFont = [NSFont fontWithName:m_font.family().toNSString() size:m_font.pointSize()]; if (customMenuFont) { NSArray *keys = [NSArray arrayWithObjects:NSFontAttributeName, nil]; NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil]; NSDictionary *attributes = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; - NSAttributedString *str = [[[NSAttributedString alloc] initWithString:QCFString::toNSString(finalString) + NSAttributedString *str = [[[NSAttributedString alloc] initWithString:finalString.toNSString() attributes:attributes] autorelease]; [m_native setAttributedTitle: str]; useAttributedTitle = true; } } if (!useAttributedTitle) { - [m_native setTitle: QCFString::toNSString(finalString)]; + [m_native setTitle:finalString.toNSString()]; } +#ifndef QT_NO_SHORTCUT if (accel.count() == 1) { [m_native setKeyEquivalent:keySequenceToKeyEqivalent(accel)]; [m_native setKeyEquivalentModifierMask:keySequenceModifierMask(accel)]; - } else { + } else +#endif + { [m_native setKeyEquivalent:@""]; [m_native setKeyEquivalentModifierMask:NSCommandKeyMask]; } @@ -372,7 +376,7 @@ QT_END_NAMESPACE QString QCocoaMenuItem::mergeText() { - QCocoaMenuLoader *loader = getMenuLoader(); + QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader]; if (m_native == [loader aboutMenuItem]) { return qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName()); } else if (m_native== [loader aboutQtMenuItem]) { @@ -390,9 +394,10 @@ QString QCocoaMenuItem::mergeText() return m_text; } +#ifndef QT_NO_SHORTCUT QKeySequence QCocoaMenuItem::mergeAccel() { - QCocoaMenuLoader *loader = getMenuLoader(); + QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader]; if (m_native == [loader preferencesMenuItem]) return QKeySequence(QKeySequence::Preferences); else if (m_native == [loader quitMenuItem]) @@ -402,6 +407,7 @@ QKeySequence QCocoaMenuItem::mergeAccel() return m_shortcut; } +#endif void QCocoaMenuItem::syncMerged() { |