1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Labs Platform module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QQUICKPLATFORMMENU_P_H
38#define QQUICKPLATFORMMENU_P_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include <QtCore/qobject.h>
52#include <QtCore/qurl.h>
53#include <QtGui/qfont.h>
54#include <QtGui/qpa/qplatformmenu.h>
55#include <QtQml/qqmlparserstatus.h>
56#include <QtQml/qqmllist.h>
57#include <QtQml/qqml.h>
58
59#include "qquickplatformicon_p.h"
60
61QT_BEGIN_NAMESPACE
62
63class QIcon;
64class QWindow;
65class QQuickItem;
66class QPlatformMenu;
67class QQmlV4Function;
68class QQuickPlatformMenuBar;
69class QQuickPlatformMenuItem;
70class QQuickPlatformIconLoader;
71class QQuickPlatformSystemTrayIcon;
72
73class QQuickPlatformMenu : public QObject, public QQmlParserStatus
74{
75 Q_OBJECT
76 Q_INTERFACES(QQmlParserStatus)
77 Q_PROPERTY(QQmlListProperty<QObject> data READ data FINAL)
78 Q_PROPERTY(QQmlListProperty<QQuickPlatformMenuItem> items READ items NOTIFY itemsChanged FINAL)
79 Q_PROPERTY(QQuickPlatformMenuBar *menuBar READ menuBar NOTIFY menuBarChanged FINAL)
80 Q_PROPERTY(QQuickPlatformMenu *parentMenu READ parentMenu NOTIFY parentMenuChanged FINAL)
81 Q_PROPERTY(QQuickPlatformSystemTrayIcon *systemTrayIcon READ systemTrayIcon NOTIFY systemTrayIconChanged FINAL)
82 Q_PROPERTY(QQuickPlatformMenuItem *menuItem READ menuItem CONSTANT FINAL)
83 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
84 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
85 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged FINAL)
86 Q_PROPERTY(QPlatformMenu::MenuType type READ type WRITE setType NOTIFY typeChanged FINAL)
87 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL)
88 Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged FINAL)
89 Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged FINAL)
90 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL)
91 Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION 1)
92 Q_ENUMS(QPlatformMenu::MenuType)
93 Q_CLASSINFO("DefaultProperty", "data")
94
95public:
96 explicit QQuickPlatformMenu(QObject *parent = nullptr);
97 ~QQuickPlatformMenu();
98
99 QPlatformMenu *handle() const;
100 QPlatformMenu *create();
101 void destroy();
102 void sync();
103
104 QQmlListProperty<QObject> data();
105 QQmlListProperty<QQuickPlatformMenuItem> items();
106
107 QQuickPlatformMenuBar *menuBar() const;
108 void setMenuBar(QQuickPlatformMenuBar *menuBar);
109
110 QQuickPlatformMenu *parentMenu() const;
111 void setParentMenu(QQuickPlatformMenu *menu);
112
113 QQuickPlatformSystemTrayIcon *systemTrayIcon() const;
114 void setSystemTrayIcon(QQuickPlatformSystemTrayIcon *icon);
115
116 QQuickPlatformMenuItem *menuItem() const;
117
118 bool isEnabled() const;
119 void setEnabled(bool enabled);
120
121 bool isVisible() const;
122 void setVisible(bool visible);
123
124 int minimumWidth() const;
125 void setMinimumWidth(int width);
126
127 QPlatformMenu::MenuType type() const;
128 void setType(QPlatformMenu::MenuType type);
129
130 QString title() const;
131 void setTitle(const QString &title);
132
133 QUrl iconSource() const;
134 void setIconSource(const QUrl &source);
135
136 QString iconName() const;
137 void setIconName(const QString &name);
138
139 QFont font() const;
140 void setFont(const QFont &font);
141
142 QQuickPlatformIcon icon() const;
143 void setIcon(const QQuickPlatformIcon &icon);
144
145 Q_INVOKABLE void addItem(QQuickPlatformMenuItem *item);
146 Q_INVOKABLE void insertItem(int index, QQuickPlatformMenuItem *item);
147 Q_INVOKABLE void removeItem(QQuickPlatformMenuItem *item);
148
149 Q_INVOKABLE void addMenu(QQuickPlatformMenu *menu);
150 Q_INVOKABLE void insertMenu(int index, QQuickPlatformMenu *menu);
151 Q_INVOKABLE void removeMenu(QQuickPlatformMenu *menu);
152
153 Q_INVOKABLE void clear();
154
155public Q_SLOTS:
156 void open(QQmlV4Function *args);
157 void close();
158
159Q_SIGNALS:
160 void aboutToShow();
161 void aboutToHide();
162
163 void itemsChanged();
164 void menuBarChanged();
165 void parentMenuChanged();
166 void systemTrayIconChanged();
167 void titleChanged();
168 void iconSourceChanged();
169 void iconNameChanged();
170 void enabledChanged();
171 void visibleChanged();
172 void minimumWidthChanged();
173 void fontChanged();
174 void typeChanged();
175 Q_REVISION(1) void iconChanged();
176
177protected:
178 void classBegin() override;
179 void componentComplete() override;
180
181 QQuickPlatformIconLoader *iconLoader() const;
182
183 QWindow *findWindow(QQuickItem *target, QPoint *offset) const;
184
185 static void data_append(QQmlListProperty<QObject> *property, QObject *object);
186 static int data_count(QQmlListProperty<QObject> *property);
187 static QObject *data_at(QQmlListProperty<QObject> *property, int index);
188 static void data_clear(QQmlListProperty<QObject> *property);
189
190 static void items_append(QQmlListProperty<QQuickPlatformMenuItem> *property, QQuickPlatformMenuItem *item);
191 static int items_count(QQmlListProperty<QQuickPlatformMenuItem> *property);
192 static QQuickPlatformMenuItem *items_at(QQmlListProperty<QQuickPlatformMenuItem> *property, int index);
193 static void items_clear(QQmlListProperty<QQuickPlatformMenuItem> *property);
194
195private Q_SLOTS:
196 void updateIcon();
197
198private:
199 void unparentSubmenus();
200
201 bool m_complete;
202 bool m_enabled;
203 bool m_visible;
204 int m_minimumWidth;
205 QPlatformMenu::MenuType m_type;
206 QString m_title;
207 QFont m_font;
208 QList<QObject *> m_data;
209 QList<QQuickPlatformMenuItem *> m_items;
210 QQuickPlatformMenuBar *m_menuBar;
211 QQuickPlatformMenu *m_parentMenu;
212 QQuickPlatformSystemTrayIcon *m_systemTrayIcon;
213 mutable QQuickPlatformMenuItem *m_menuItem;
214 mutable QQuickPlatformIconLoader *m_iconLoader;
215 QPlatformMenu *m_handle;
216};
217
218QT_END_NAMESPACE
219
220QML_DECLARE_TYPE(QQuickPlatformMenu)
221Q_DECLARE_METATYPE(QPlatformMenu::MenuType)
222
223#endif // QQUICKPLATFORMMENU_P_H
224

source code of qtquickcontrols2/src/imports/platform/qquickplatformmenu_p.h