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

source code of qtbase/src/gui/kernel/qplatformmenu.h