1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner <james.turner@kdab.com>
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QPLATFORMMENU_H
42#define QPLATFORMMENU_H
43//
44// W A R N I N G
45// -------------
46//
47// This file is part of the QPA API and is not meant to be used
48// in applications. Usage of this API may make your code
49// source and binary incompatible with future versions of Qt.
50//
51
52#include <QtGui/qtguiglobal.h>
53#include <QtCore/qpointer.h>
54#include <QtGui/QFont>
55#include <QtGui/QKeySequence>
56#include <QtGui/QIcon>
57
58QT_BEGIN_NAMESPACE
59
60class QPlatformMenu;
61class Q_GUI_EXPORT QPlatformMenuItem : public QObject
62{
63Q_OBJECT
64public:
65 QPlatformMenuItem();
66
67 // copied from, and must stay in sync with, QAction menu roles.
68 enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
69 AboutRole, PreferencesRole, QuitRole,
70 // However these roles are private, perhaps temporarily.
71 // They could be added as public QAction roles if necessary.
72 CutRole, CopyRole, PasteRole, SelectAllRole,
73 RoleCount };
74 Q_ENUM(MenuRole)
75
76 virtual void setTag(quintptr tag);
77 virtual quintptr tag() const;
78
79 virtual void setText(const QString &text) = 0;
80 virtual void setIcon(const QIcon &icon) = 0;
81 virtual void setMenu(QPlatformMenu *menu) = 0;
82 virtual void setVisible(bool isVisible) = 0;
83 virtual void setIsSeparator(bool isSeparator) = 0;
84 virtual void setFont(const QFont &font) = 0;
85 virtual void setRole(MenuRole role) = 0;
86 virtual void setCheckable(bool checkable) = 0;
87 virtual void setChecked(bool isChecked) = 0;
88#ifndef QT_NO_SHORTCUT
89 virtual void setShortcut(const QKeySequence& shortcut) = 0;
90#endif
91 virtual void setEnabled(bool enabled) = 0;
92 virtual void setIconSize(int size) = 0;
93 virtual void setNativeContents(WId item) { Q_UNUSED(item); }
94 virtual void setHasExclusiveGroup(bool hasExclusiveGroup) { Q_UNUSED(hasExclusiveGroup); }
95
96Q_SIGNALS:
97 void activated();
98 void hovered();
99
100private:
101 quintptr m_tag;
102};
103
104class Q_GUI_EXPORT QPlatformMenu : public QObject
105{
106Q_OBJECT
107public:
108 QPlatformMenu();
109
110 enum MenuType { DefaultMenu = 0, EditMenu };
111 Q_ENUM(MenuType)
112
113 virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) = 0;
114 virtual void removeMenuItem(QPlatformMenuItem *menuItem) = 0;
115 virtual void syncMenuItem(QPlatformMenuItem *menuItem) = 0;
116 virtual void syncSeparatorsCollapsible(bool enable) = 0;
117
118 virtual void setTag(quintptr tag);
119 virtual quintptr tag() const;
120
121 virtual void setText(const QString &text) = 0;
122 virtual void setIcon(const QIcon &icon) = 0;
123 virtual void setEnabled(bool enabled) = 0;
124 virtual bool isEnabled() const { return true; }
125 virtual void setVisible(bool visible) = 0;
126 virtual void setMinimumWidth(int width) { Q_UNUSED(width); }
127 virtual void setFont(const QFont &font) { Q_UNUSED(font); }
128 virtual void setMenuType(MenuType type) { Q_UNUSED(type); }
129
130 virtual void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item)
131 {
132 Q_UNUSED(parentWindow);
133 Q_UNUSED(targetRect);
134 Q_UNUSED(item);
135 setVisible(true);
136 }
137
138 virtual void dismiss() { } // Closes this and all its related menu popups
139
140 virtual QPlatformMenuItem *menuItemAt(int position) const = 0;
141 virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const = 0;
142
143 virtual QPlatformMenuItem *createMenuItem() const;
144 virtual QPlatformMenu *createSubMenu() const;
145Q_SIGNALS:
146 void aboutToShow();
147 void aboutToHide();
148
149private:
150 quintptr m_tag;
151};
152
153class Q_GUI_EXPORT QPlatformMenuBar : public QObject
154{
155Q_OBJECT
156public:
157 virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) = 0;
158 virtual void removeMenu(QPlatformMenu *menu) = 0;
159 virtual void syncMenu(QPlatformMenu *menuItem) = 0;
160 virtual void handleReparent(QWindow *newParentWindow) = 0;
161 virtual QWindow *parentWindow() const { return nullptr; }
162
163 virtual QPlatformMenu *menuForTag(quintptr tag) const = 0;
164 virtual QPlatformMenu *createMenu() const;
165};
166
167QT_END_NAMESPACE
168
169#endif
170
171

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