macOS: create application menu as QCocoaNSMenu with delegate

This way we can handle keyboard shortcuts for actions in that menu as
well in our menuHasKeyEquivalent implementation. This allows the focus
widget to accept the override, and e.g. a QKeySequenceEdit to record
Cmd+Q which with a plain NSMenu will just quit the application.

Pick-to: 6.3 6.2
Fixes: QTBUG-103590
Change-Id: I84597307aef8f0ab65d97d78e5aa15e5cf2e707d
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-05-16 21:42:23 +02:00
parent 734c9f2df2
commit 2996ca031e
3 changed files with 9 additions and 1 deletions

View File

@ -56,7 +56,7 @@
NSMenuItem *appItem = [[[NSMenuItem alloc] init] autorelease];
appItem.title = appName;
[theMenu addItem:appItem];
appMenu = [[NSMenu alloc] initWithTitle:appName];
appMenu = [[QCocoaNSMenu alloc] initWithoutPlatformMenu:appName];
appItem.submenu = appMenu;
// About Application

View File

@ -28,6 +28,7 @@ QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QCocoaNSMenuDelegate, NSObject <NSMenuDeleg
QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QCocoaNSMenu, NSMenu
@property (readonly, nonatomic) QCocoaMenu *platformMenu;
- (instancetype)initWithPlatformMenu:(QCocoaMenu *)menu;
- (instancetype)initWithoutPlatformMenu:(NSString *)menu;
)
QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QCocoaNSMenuItem, NSMenuItem

View File

@ -51,6 +51,13 @@ static NSString *qt_mac_removePrivateUnicode(NSString *string)
return self;
}
- (instancetype)initWithoutPlatformMenu:(NSString *)title
{
if (self = [super initWithTitle:title])
self.delegate = [QCocoaNSMenuDelegate sharedMenuDelegate];
return self;
}
- (QCocoaMenu *)platformMenu
{
return _platformMenu.data();