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

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

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