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
qplatformmenu.h
Go to the documentation of this file.
1// Copyright (C) 2016 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// Qt-Security score:significant reason:default
5
6#ifndef QPLATFORMMENU_H
7#define QPLATFORMMENU_H
8//
9// W A R N I N G
10// -------------
11//
12// This file is part of the QPA API and is not meant to be used
13// in applications. Usage of this API may make your code
14// source and binary incompatible with future versions of Qt.
15//
16
17#include <QtCore/qobject.h>
18#include <QtGui/qtguiglobal.h>
19#include <QtCore/qpointer.h>
20#include <QtGui/qfont.h>
21#if QT_CONFIG(shortcut)
22# include <QtGui/qkeysequence.h>
23#endif
24#include <QtGui/qicon.h>
25
26QT_BEGIN_NAMESPACE
27
28class QPlatformMenu;
29class Q_GUI_EXPORT QPlatformMenuItem : public QObject
30{
31Q_OBJECT
32public:
33 QPlatformMenuItem();
34
35 // copied from, and must stay in sync with, QAction menu roles.
36 enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
37 AboutRole, PreferencesRole, QuitRole,
38 // However these roles are private, perhaps temporarily.
39 // They could be added as public QAction roles if necessary.
40 CutRole, CopyRole, PasteRole, SelectAllRole,
41 RoleCount };
42 Q_ENUM(MenuRole)
43
44 virtual void setTag(quintptr tag);
45 virtual quintptr tag() const;
46
47 virtual void setText(const QString &text) = 0;
48 virtual void setIcon(const QIcon &icon) = 0;
49 virtual void setMenu(QPlatformMenu *menu) = 0;
50 virtual void setVisible(bool isVisible) = 0;
51 virtual void setIsSeparator(bool isSeparator) = 0;
52 virtual void setFont(const QFont &font) = 0;
53 virtual void setRole(MenuRole role) = 0;
54 virtual void setCheckable(bool checkable) = 0;
55 virtual void setChecked(bool isChecked) = 0;
56#if QT_CONFIG(shortcut)
57 virtual void setShortcut(const QKeySequence& shortcut) = 0;
58#endif
59 virtual void setEnabled(bool enabled) = 0;
60 virtual void setIconSize(int size) = 0;
61 virtual void setNativeContents(WId item) { Q_UNUSED(item); }
62 virtual void setHasExclusiveGroup(bool hasExclusiveGroup) { Q_UNUSED(hasExclusiveGroup); }
63
64Q_SIGNALS:
65 void activated();
66 void hovered();
67
68private:
69 quintptr m_tag;
70};
71
72class Q_GUI_EXPORT QPlatformMenu : public QObject
73{
74Q_OBJECT
75public:
76 QPlatformMenu();
77
78 enum MenuType { DefaultMenu = 0, EditMenu };
79 Q_ENUM(MenuType)
80
81 virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) = 0;
82 virtual void removeMenuItem(QPlatformMenuItem *menuItem) = 0;
83 virtual void syncMenuItem(QPlatformMenuItem *menuItem) = 0;
84 virtual void syncSeparatorsCollapsible(bool enable) = 0;
85
86 virtual void setTag(quintptr tag);
87 virtual quintptr tag() const;
88
89 virtual void setText(const QString &text) = 0;
90 virtual void setIcon(const QIcon &icon) = 0;
91 virtual void setEnabled(bool enabled) = 0;
92 virtual bool isEnabled() const { return true; }
93 virtual void setVisible(bool visible) = 0;
94 virtual void setMinimumWidth(int width) { Q_UNUSED(width); }
95 virtual void setFont(const QFont &font) { Q_UNUSED(font); }
96 virtual void setMenuType(MenuType type) { Q_UNUSED(type); }
97
98 virtual void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item)
99 {
100 Q_UNUSED(parentWindow);
101 Q_UNUSED(targetRect);
102 Q_UNUSED(item);
103 setVisible(true);
104 }
105
106 virtual void dismiss() { } // Closes this and all its related menu popups
107
108 virtual QPlatformMenuItem *menuItemAt(int position) const = 0;
109 virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const = 0;
110
111 virtual QPlatformMenuItem *createMenuItem() const;
112 virtual QPlatformMenu *createSubMenu() const;
113Q_SIGNALS:
114 void aboutToShow();
115 void aboutToHide();
116
117private:
118 quintptr m_tag;
119};
120
121class Q_GUI_EXPORT QPlatformMenuBar : public QObject
122{
123Q_OBJECT
124public:
125 virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) = 0;
126 virtual void removeMenu(QPlatformMenu *menu) = 0;
127 virtual void syncMenu(QPlatformMenu *menuItem) = 0;
128 virtual void handleReparent(QWindow *newParentWindow) = 0;
129 virtual QWindow *parentWindow() const { return nullptr; }
130
131 virtual QPlatformMenu *menuForTag(quintptr tag) const = 0;
132 virtual QPlatformMenu *createMenu() const;
133};
134
135QT_END_NAMESPACE
136
137#endif
Combined button and popup list for selecting options.