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#if QT_CONFIG(shortcut)
56# include <QtGui/QKeySequence>
57#endif
58#include <QtGui/QIcon>
59
60QT_BEGIN_NAMESPACE
61
62class QPlatformMenu;
63class Q_GUI_EXPORT QPlatformMenuItem : public QObject
64{
65Q_OBJECT
66public:
67 QPlatformMenuItem();
68
69 // copied from, and must stay in sync with, QAction menu roles.
70 enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
71 AboutRole, PreferencesRole, QuitRole,
72 // However these roles are private, perhaps temporarily.
73 // They could be added as public QAction roles if necessary.
74 CutRole, CopyRole, PasteRole, SelectAllRole,
75 RoleCount };
76 Q_ENUM(MenuRole)
77
78 virtual void setTag(quintptr tag);
79 virtual quintptr tag() const;
80
81 virtual void setText(const QString &text) = 0;
82 virtual void setIcon(const QIcon &icon) = 0;
83 virtual void setMenu(QPlatformMenu *menu) = 0;
84 virtual void setVisible(bool isVisible) = 0;
85 virtual void setIsSeparator(bool isSeparator) = 0;
86 virtual void setFont(const QFont &font) = 0;
87 virtual void setRole(MenuRole role) = 0;
88 virtual void setCheckable(bool checkable) = 0;
89 virtual void setChecked(bool isChecked) = 0;
90#if QT_CONFIG(shortcut)
91 virtual void setShortcut(const QKeySequence& shortcut) = 0;
92#endif
93 virtual void setEnabled(bool enabled) = 0;
94 virtual void setIconSize(int size) = 0;
95 virtual void setNativeContents(WId item) { Q_UNUSED(item); }
96 virtual void setHasExclusiveGroup(bool hasExclusiveGroup) { Q_UNUSED(hasExclusiveGroup); }
97
98Q_SIGNALS:
99 void activated();
100 void hovered();
101
102private:
103 quintptr m_tag;
104};
105
106class Q_GUI_EXPORT QPlatformMenu : public QObject
107{
108Q_OBJECT
109public:
110 QPlatformMenu();
111
112 enum MenuType { DefaultMenu = 0, EditMenu };
113 Q_ENUM(MenuType)
114
115 virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) = 0;
116 virtual void removeMenuItem(QPlatformMenuItem *menuItem) = 0;
117 virtual void syncMenuItem(QPlatformMenuItem *menuItem) = 0;
118 virtual void syncSeparatorsCollapsible(bool enable) = 0;
119
120 virtual void setTag(quintptr tag);
121 virtual quintptr tag() const;
122
123 virtual void setText(const QString &text) = 0;
124 virtual void setIcon(const QIcon &icon) = 0;
125 virtual void setEnabled(bool enabled) = 0;
126 virtual bool isEnabled() const { return true; }
127 virtual void setVisible(bool visible) = 0;
128 virtual void setMinimumWidth(int width) { Q_UNUSED(width); }
129 virtual void setFont(const QFont &font) { Q_UNUSED(font); }
130 virtual void setMenuType(MenuType type) { Q_UNUSED(type); }
131
132 virtual void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item)
133 {
134 Q_UNUSED(parentWindow);
135 Q_UNUSED(targetRect);
136 Q_UNUSED(item);
137 setVisible(true);
138 }
139
140 virtual void dismiss() { } // Closes this and all its related menu popups
141
142 virtual QPlatformMenuItem *menuItemAt(int position) const = 0;
143 virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const = 0;
144
145 virtual QPlatformMenuItem *createMenuItem() const;
146 virtual QPlatformMenu *createSubMenu() const;
147Q_SIGNALS:
148 void aboutToShow();
149 void aboutToHide();
150
151private:
152 quintptr m_tag;
153};
154
155class Q_GUI_EXPORT QPlatformMenuBar : public QObject
156{
157Q_OBJECT
158public:
159 virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) = 0;
160 virtual void removeMenu(QPlatformMenu *menu) = 0;
161 virtual void syncMenu(QPlatformMenu *menuItem) = 0;
162 virtual void handleReparent(QWindow *newParentWindow) = 0;
163 virtual QWindow *parentWindow() const { return nullptr; }
164
165 virtual QPlatformMenu *menuForTag(quintptr tag) const = 0;
166 virtual QPlatformMenu *createMenu() const;
167};
168
169QT_END_NAMESPACE
170
171#endif
172
173