1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKLABSPLATFORMMENU_P_H
5#define QQUICKLABSPLATFORMMENU_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qobject.h>
19#include <QtCore/qurl.h>
20#include <QtGui/qfont.h>
21#include <QtGui/qpa/qplatformmenu.h>
22#include <QtQml/qqmlparserstatus.h>
23#include <QtQml/qqmllist.h>
24#include <QtQml/qqml.h>
25
26#include "qquicklabsplatformicon_p.h"
27
28QT_BEGIN_NAMESPACE
29
30class QIcon;
31class QWindow;
32class QQuickItem;
33class QPlatformMenu;
34class QQmlV4Function;
35class QQuickLabsPlatformMenuBar;
36class QQuickLabsPlatformMenuItem;
37class QQuickLabsPlatformIconLoader;
38class QQuickLabsPlatformSystemTrayIcon;
39
40class QQuickLabsPlatformMenu : public QObject, public QQmlParserStatus
41{
42 Q_OBJECT
43 QML_NAMED_ELEMENT(Menu)
44 QML_EXTENDED_NAMESPACE(QPlatformMenu)
45 Q_INTERFACES(QQmlParserStatus)
46 Q_PROPERTY(QQmlListProperty<QObject> data READ data FINAL)
47 Q_PROPERTY(QQmlListProperty<QQuickLabsPlatformMenuItem> items READ items NOTIFY itemsChanged FINAL)
48 Q_PROPERTY(QQuickLabsPlatformMenuBar *menuBar READ menuBar NOTIFY menuBarChanged FINAL)
49 Q_PROPERTY(QQuickLabsPlatformMenu *parentMenu READ parentMenu NOTIFY parentMenuChanged FINAL)
50#if QT_CONFIG(systemtrayicon)
51 Q_PROPERTY(QQuickLabsPlatformSystemTrayIcon *systemTrayIcon READ systemTrayIcon NOTIFY systemTrayIconChanged FINAL)
52#endif
53 Q_PROPERTY(QQuickLabsPlatformMenuItem *menuItem READ menuItem CONSTANT FINAL)
54 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
55 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
56 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged FINAL)
57 Q_PROPERTY(QPlatformMenu::MenuType type READ type WRITE setType NOTIFY typeChanged FINAL)
58 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL)
59 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL)
60 Q_PROPERTY(QQuickLabsPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(1, 1))
61 Q_CLASSINFO("DefaultProperty", "data")
62
63public:
64 explicit QQuickLabsPlatformMenu(QObject *parent = nullptr);
65 ~QQuickLabsPlatformMenu();
66
67 QPlatformMenu *handle() const;
68 QPlatformMenu *create();
69 void destroy();
70 void sync();
71
72 QQmlListProperty<QObject> data();
73 QQmlListProperty<QQuickLabsPlatformMenuItem> items();
74
75 QQuickLabsPlatformMenuBar *menuBar() const;
76 void setMenuBar(QQuickLabsPlatformMenuBar *menuBar);
77
78 QQuickLabsPlatformMenu *parentMenu() const;
79 void setParentMenu(QQuickLabsPlatformMenu *menu);
80
81#if QT_CONFIG(systemtrayicon)
82 QQuickLabsPlatformSystemTrayIcon *systemTrayIcon() const;
83 void setSystemTrayIcon(QQuickLabsPlatformSystemTrayIcon *icon);
84#endif
85
86 QQuickLabsPlatformMenuItem *menuItem() const;
87
88 bool isEnabled() const;
89 void setEnabled(bool enabled);
90
91 bool isVisible() const;
92 void setVisible(bool visible);
93
94 int minimumWidth() const;
95 void setMinimumWidth(int width);
96
97 QPlatformMenu::MenuType type() const;
98 void setType(QPlatformMenu::MenuType type);
99
100 QString title() const;
101 void setTitle(const QString &title);
102
103 QFont font() const;
104 void setFont(const QFont &font);
105
106 QQuickLabsPlatformIcon icon() const;
107 void setIcon(const QQuickLabsPlatformIcon &icon);
108
109 Q_INVOKABLE void addItem(QQuickLabsPlatformMenuItem *item);
110 Q_INVOKABLE void insertItem(int index, QQuickLabsPlatformMenuItem *item);
111 Q_INVOKABLE void removeItem(QQuickLabsPlatformMenuItem *item);
112
113 Q_INVOKABLE void addMenu(QQuickLabsPlatformMenu *menu);
114 Q_INVOKABLE void insertMenu(int index, QQuickLabsPlatformMenu *menu);
115 Q_INVOKABLE void removeMenu(QQuickLabsPlatformMenu *menu);
116
117 Q_INVOKABLE void clear();
118
119public Q_SLOTS:
120 void open(QQmlV4Function *args);
121 void close();
122
123Q_SIGNALS:
124 void aboutToShow();
125 void aboutToHide();
126
127 void itemsChanged();
128 void menuBarChanged();
129 void parentMenuChanged();
130 void systemTrayIconChanged();
131 void titleChanged();
132 void enabledChanged();
133 void visibleChanged();
134 void minimumWidthChanged();
135 void fontChanged();
136 void typeChanged();
137 Q_REVISION(2, 1) void iconChanged();
138
139protected:
140 void classBegin() override;
141 void componentComplete() override;
142
143 QQuickLabsPlatformIconLoader *iconLoader() const;
144
145 QWindow *findWindow(QQuickItem *target, QPoint *offset) const;
146
147 static void data_append(QQmlListProperty<QObject> *property, QObject *object);
148 static qsizetype data_count(QQmlListProperty<QObject> *property);
149 static QObject *data_at(QQmlListProperty<QObject> *property, qsizetype index);
150 static void data_clear(QQmlListProperty<QObject> *property);
151
152 static void items_append(QQmlListProperty<QQuickLabsPlatformMenuItem> *property, QQuickLabsPlatformMenuItem *item);
153 static qsizetype items_count(QQmlListProperty<QQuickLabsPlatformMenuItem> *property);
154 static QQuickLabsPlatformMenuItem *items_at(QQmlListProperty<QQuickLabsPlatformMenuItem> *property, qsizetype index);
155 static void items_clear(QQmlListProperty<QQuickLabsPlatformMenuItem> *property);
156
157private Q_SLOTS:
158 void updateIcon();
159
160private:
161 void unparentSubmenus();
162
163 bool m_complete;
164 bool m_enabled;
165 bool m_visible;
166 int m_minimumWidth;
167 QPlatformMenu::MenuType m_type;
168 QString m_title;
169 QFont m_font;
170 QList<QObject *> m_data;
171 QList<QQuickLabsPlatformMenuItem *> m_items;
172 QQuickLabsPlatformMenuBar *m_menuBar;
173 QQuickLabsPlatformMenu *m_parentMenu;
174 QQuickLabsPlatformSystemTrayIcon *m_systemTrayIcon;
175 mutable QQuickLabsPlatformMenuItem *m_menuItem;
176 mutable QQuickLabsPlatformIconLoader *m_iconLoader;
177 QPlatformMenu *m_handle;
178};
179
180QT_END_NAMESPACE
181
182QML_DECLARE_TYPE(QQuickLabsPlatformMenu)
183
184#endif // QQUICKLABSPLATFORMMENU_P_H
185

source code of qtdeclarative/src/labs/platform/qquicklabsplatformmenu_p.h