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

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