Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcocoamenuitem.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner <james.turner@kdab.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QCOCOAMENUITEM_H
6#define QCOCOAMENUITEM_H
7
8#include <qpa/qplatformmenu.h>
9#include <QtGui/QImage>
10
11#include <QtCore/qpointer.h>
12
17
18QT_BEGIN_NAMESPACE
19
20enum {
21 AboutAppMenuItem = 0,
22 PreferencesAppMenuItem,
23 ServicesAppMenuItem,
24 HideAppMenuItem,
25 HideOthersAppMenuItem,
26 ShowAllAppMenuItem,
27 QuitAppMenuItem
28};
29
31
32class QCocoaMenu;
33
35{
36public:
37 void setMenuParent(QObject *o)
38 {
39 parent = o;
40 }
41
43 {
44 return parent;
45 }
46
47private:
48 QPointer<QObject> parent;
49};
50
52{
53public:
56
57 void setText(const QString &text) override;
58 void setIcon(const QIcon &icon) override;
59 void setMenu(QPlatformMenu *menu) override;
60 void setVisible(bool isVisible) override;
61 void setIsSeparator(bool isSeparator) override;
62 void setFont(const QFont &font) override;
63 void setRole(MenuRole role) override;
64#ifndef QT_NO_SHORTCUT
65 void setShortcut(const QKeySequence& shortcut) override;
66#endif
67 void setCheckable(bool) override {}
68 void setChecked(bool isChecked) override;
69 void setEnabled(bool isEnabled) override;
70 void setIconSize(int size) override;
71
72 void setNativeContents(WId item) override;
73
74 inline QString text() const { return m_text; }
75 inline NSMenuItem * nsItem() { return m_native; }
77
78 void syncMerged();
79 void setParentEnabled(bool enabled);
80
81 inline bool isMerged() const { return m_merged; }
82 inline bool isEnabled() const { return m_enabled && m_parentEnabled; }
83 inline bool isSeparator() const { return m_isSeparator; }
84 inline bool isVisible() const { return m_isVisible; }
85
86 QCocoaMenu *menu() const { return m_menu; }
87 MenuRole effectiveRole() const;
89
90private:
91 QString mergeText();
92 QKeySequence mergeAccel();
93
94 NSMenuItem *m_native;
95 NSView *m_itemView;
96 QString m_text;
97 QIcon m_icon;
98 QPointer<QCocoaMenu> m_menu;
99 MenuRole m_role;
100 MenuRole m_detectedRole;
101#ifndef QT_NO_SHORTCUT
102 QKeySequence m_shortcut;
103#endif
104 int m_iconSize;
105 bool m_textSynced:1;
106 bool m_isVisible:1;
107 bool m_enabled:1;
108 bool m_parentEnabled:1;
109 bool m_isSeparator:1;
110 bool m_checked:1;
111 bool m_merged:1;
112};
113
114QT_END_NAMESPACE
115
116#endif
static void clearCurrentThreadCocoaEventDispatcherInterruptFlag()
NSOpenGLContext * nativeContext() const override
void swapBuffers(QPlatformSurface *surface) override
Reimplement in subclass to native swap buffers calls.
void doneCurrent() override
friend QDebug operator<<(QDebug debug, const QCocoaGLContext *screen)
QSurfaceFormat format() const override
bool isSharing() const override
void initialize() override
Called after a new instance is constructed.
void beginFrame() override
Called when the RHI begins rendering a new frame in the context.
QFunctionPointer getProcAddress(const char *procName) override
Reimplement in subclass to allow dynamic querying of OpenGL symbols.
QCocoaGLContext(QOpenGLContext *context)
bool makeCurrent(QPlatformSurface *surface) override
bool isValid() const override
void setMenu(QPlatformMenu *menu) override
void setParentEnabled(bool enabled)
void setRole(MenuRole role) override
NSMenuItem * sync()
void setNativeContents(WId item) override
bool isVisible() const
QCocoaMenu * menu() const
void setCheckable(bool) override
bool isSeparator() const
void setIsSeparator(bool isSeparator) override
void setText(const QString &text) override
NSMenuItem * nsItem()
void setIcon(const QIcon &icon) override
void setShortcut(const QKeySequence &shortcut) override
QString text() const
void setFont(const QFont &font) override
void setEnabled(bool isEnabled) override
void setVisible(bool isVisible) override
void setChecked(bool isChecked) override
bool isMerged() const
bool isEnabled() const
void setIconSize(int size) override
MenuRole effectiveRole() const
void setMenuParent(QObject *o)
QObject * menuParent() const
void dismiss() override
bool isVisible() const
Definition qcocoamenu.h:49
QPlatformMenuItem * menuItemForTag(quintptr tag) const override
QList< QCocoaMenuItem * > merged() const
void timerEvent(QTimerEvent *e) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
void setEnabled(bool enabled) override
QList< QCocoaMenuItem * > items() const
void setItemTargetAction(QCocoaMenuItem *item) const
NSMenuItem * attachedItem() const
void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override
Definition qcocoamenu.mm:82
void setIsOpen(bool isOpen)
void setAsDockMenu() const override
Definition qcocoamenu.mm:76
void setText(const QString &text) override
Definition qcocoamenu.mm:50
bool isEnabled() const override
void propagateEnabledState(bool enabled)
void syncSeparatorsCollapsible(bool enable) override
void setIsAboutToShow(bool isAbout)
void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override
void setIcon(const QIcon &) override
Definition qcocoamenu.h:40
bool isAboutToShow() const
void setFont(const QFont &font) override
Definition qcocoamenu.mm:62
bool isOpen() const
QPlatformMenuItem * menuItemAt(int position) const override
void syncMenuItem(QPlatformMenuItem *menuItem) override
void removeMenuItem(QPlatformMenuItem *menuItem) override
void syncMenuItem_helper(QPlatformMenuItem *menuItem, bool menubarUpdate)
void setAttachedItem(NSMenuItem *item)
NSMenu * nsMenu() const override
Definition qcocoamenu.mm:71
void setVisible(bool visible) override
void setMinimumWidth(int width) override
Definition qcocoamenu.mm:57
void * nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) override
NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) override
void handleWindowStateChanged(HandleFlags flags=NoHandleFlags)
static void setupPopupMonitor()
void setContentBorderAreaEnabled(quintptr identifier, bool enable)
bool alwaysShowToolWindow() const
void setMenubar(QCocoaMenuBar *mb)
void toggleMaximized()
QWindow * childWindowAt(QPoint windowPoint)
void setAlertState(bool enabled) override
Reimplement this method to set whether the window demands attention (for example, by flashing the tas...
int m_registerTouchCount
Qt::WindowModality m_windowModality
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
void setWindowCursor(NSCursor *cursor)
bool testContentBorderAreaPosition(int position) const
NSView * view() const
QRect normalGeometry() const override
the geometry of the window as it will appear when shown as a normal (not maximized or full screen) to...
QMacKeyValueObserver m_safeAreaInsetsObserver
bool updatesWithDisplayLink() const
bool m_inSetStyleMask
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
bool isForeignWindow() const override
bool setMouseGrabEnabled(bool grab) override
QCocoaNSWindow * m_nsWindow
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
void setOpacity(qreal level) override
Reimplement to be able to let Qt set the opacity level of a window.
QCocoaNSWindow * createNSWindow(bool shouldBePanel)
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
static id s_globalMouseMonitor
void setMask(const QRegion &region) override
Reimplement to be able to let Qt set the mask of a window.
QHash< quintptr, bool > m_enabledContentBorderAreas
void setFrameStrutEventsEnabled(bool enabled) override
Reimplement this method to set whether frame strut events should be sent to enabled.
void toggleFullScreen()
QCocoaMenuBar * menubar() const
void setWindowFilePath(const QString &filePath) override
Reimplement to set the window file path to filePath.
void setCocoaGeometry(const QRect &rect)
QRect geometry() const override
Returns the current geometry of a window.
NSInteger windowLevel(Qt::WindowFlags flags)
void setContentBorderEnabled(bool enable) override
bool isOpaque() const
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
static void removePopupMonitor()
bool m_frameStrutEventsEnabled
bool setWindowModified(bool modified) override
Reimplement to be able to let Qt indicate that the window has been modified.
NSWindow * nativeWindow() const
void applyContentBorderThickness(NSWindow *window=nullptr)
void setWindowState(Qt::WindowStates state) override
Changes the state of the NSWindow, going in/out of minimize/zoomed/fullscreen.
void updateSafeAreaMarginsIfNeeded()
bool windowShouldClose()
void registerTouch(bool enable)
void updateTitleBarButtons(Qt::WindowFlags flags)
QMargins frameMargins() const override
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void updateNormalGeometry()
bool isFixedSize() const
bool isAlertState() const override
Reimplement this method return whether the window is in an alert state.
bool isExposed() const override
Returns if this window is exposed in the windowing system.
void deliverUpdateRequest() override
Delivers an QEvent::UpdateRequest event to the window.
bool isEmbedded() const override
Returns true if the window is a child of a non-Qt window.
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
bool shouldRefuseKeyWindowAndFirstResponder()
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
static QPointer< QCocoaWindow > s_windowUnderMouse
static void closeAllPopups()
void setWindowIcon(const QIcon &icon) override
Reimplement to set the window icon to icon.
bool isContentView() const
Checks if the window is the content view of its immediate NSWindow.
NSInteger m_alertRequest
QRect m_normalGeometry
void recreateWindowIfNeeded()
Recreates (or removes) the NSWindow for this QWindow, if needed.
void handleGeometryChange()
bool m_drawContentBorderGradient
bool m_resizableTransientParent
NSUInteger windowStyleMask(Qt::WindowFlags flags)
QCocoaMenuBar * m_menubar
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
static const int NoAlertRequest
QRect m_exposedRect
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void windowWillZoom()
bool setKeyboardGrabEnabled(bool grab) override
bool windowIsPopupType(Qt::WindowType type=Qt::Widget) const
void registerContentBorderArea(quintptr identifier, int upper, int lower)
void setEmbeddedInForeignView()
void applyWindowState(Qt::WindowStates newState)
QPoint bottomLeftClippedByNSWindowOffset() const override
bool isTransitioningToFullScreen() const
QHash< quintptr, BorderRange > m_contentBorderAreas
Qt::WindowStates windowState() const
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the window.
void initialize() override
Called as part of QWindow::create(), after constructing the window.
Qt::WindowStates m_lastReportedWindowState
QSurfaceFormat format() const override
Returns the actual surface format of the window.
bool frameStrutEventsEnabled() const override
Reimplement this method to return whether frame strut events are enabled.
static id s_applicationActivationObserver
NSView * m_view
void handleExposeEvent(const QRegion &region)
QMargins m_lastReportedSafeAreaMargins
\inmodule QtCore\reentrant
Definition qpoint.h:229
QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QCocoaWindow)
Combined button and popup list for selecting options.
Q_FORWARD_DECLARE_OBJC_CLASS(NSOpenGLPixelFormat)
Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu)
QString qt_mac_applicationmenu_string(int type)
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject)
QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QCocoaNSMenuDelegate, NSObject< NSMenuDelegate >+(instancetype) sharedMenuDelegate;-(NSMenuItem *) findItemInMenu:(NSMenu *) menu forKey:(NSString *) key modifiers:(NSUInteger) modifiers;) QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QCocoaNSMenu
Q_FORWARD_DECLARE_OBJC_CLASS(NSView)
Q_FORWARD_DECLARE_OBJC_CLASS(NSCursor)
const NSNotificationName QCocoaWindowWillReleaseQNSViewNotification
#define Q_NOTIFICATION_HANDLER(notification)
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject)
bool operator<(BorderRange const &right) const
BorderRange(quintptr i, int u, int l)