1 | // Copyright (C) 2017 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 QQUICKLABSPLATFORMMENUITEM_P_H |
5 | #define QQUICKLABSPLATFORMMENUITEM_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/qqml.h> |
24 | |
25 | #include "qquicklabsplatformicon_p.h" |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QPlatformMenuItem; |
30 | class QQuickLabsPlatformMenu; |
31 | class QQuickLabsPlatformIconLoader; |
32 | class QQuickLabsPlatformMenuItemGroup; |
33 | |
34 | class QQuickLabsPlatformMenuItem : public QObject, public QQmlParserStatus |
35 | { |
36 | Q_OBJECT |
37 | QML_NAMED_ELEMENT(MenuItem) |
38 | QML_EXTENDED_NAMESPACE(QPlatformMenuItem) |
39 | Q_INTERFACES(QQmlParserStatus) |
40 | Q_PROPERTY(QQuickLabsPlatformMenu *menu READ menu NOTIFY menuChanged FINAL) |
41 | Q_PROPERTY(QQuickLabsPlatformMenu *subMenu READ subMenu NOTIFY subMenuChanged FINAL) |
42 | Q_PROPERTY(QQuickLabsPlatformMenuItemGroup *group READ group WRITE setGroup NOTIFY groupChanged FINAL) |
43 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
44 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) |
45 | Q_PROPERTY(bool separator READ isSeparator WRITE setSeparator NOTIFY separatorChanged FINAL) |
46 | Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL) |
47 | Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL) |
48 | Q_PROPERTY(QPlatformMenuItem::MenuRole role READ role WRITE setRole NOTIFY roleChanged FINAL) |
49 | Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) |
50 | Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged FINAL) |
51 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL) |
52 | Q_PROPERTY(QQuickLabsPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(1, 1)) |
53 | |
54 | public: |
55 | explicit QQuickLabsPlatformMenuItem(QObject *parent = nullptr); |
56 | ~QQuickLabsPlatformMenuItem(); |
57 | |
58 | QPlatformMenuItem *handle() const; |
59 | QPlatformMenuItem *create(); |
60 | void sync(); |
61 | |
62 | QQuickLabsPlatformMenu *menu() const; |
63 | void setMenu(QQuickLabsPlatformMenu* menu); |
64 | |
65 | QQuickLabsPlatformMenu *subMenu() const; |
66 | void setSubMenu(QQuickLabsPlatformMenu *menu); |
67 | |
68 | QQuickLabsPlatformMenuItemGroup *group() const; |
69 | void setGroup(QQuickLabsPlatformMenuItemGroup *group); |
70 | |
71 | bool isEnabled() const; |
72 | void setEnabled(bool enabled); |
73 | |
74 | bool isVisible() const; |
75 | void setVisible(bool visible); |
76 | |
77 | bool isSeparator() const; |
78 | void setSeparator(bool separator); |
79 | |
80 | bool isCheckable() const; |
81 | void setCheckable(bool checkable); |
82 | |
83 | bool isChecked() const; |
84 | void setChecked(bool checked); |
85 | |
86 | QPlatformMenuItem::MenuRole role() const; |
87 | void setRole(QPlatformMenuItem::MenuRole role); |
88 | |
89 | QString text() const; |
90 | void setText(const QString &text); |
91 | |
92 | QVariant shortcut() const; |
93 | void setShortcut(const QVariant& shortcut); |
94 | |
95 | QFont font() const; |
96 | void setFont(const QFont &font); |
97 | |
98 | QQuickLabsPlatformIcon icon() const; |
99 | void setIcon(const QQuickLabsPlatformIcon &icon); |
100 | |
101 | public Q_SLOTS: |
102 | void toggle(); |
103 | |
104 | Q_SIGNALS: |
105 | void triggered(); |
106 | void hovered(); |
107 | |
108 | void menuChanged(); |
109 | void subMenuChanged(); |
110 | void groupChanged(); |
111 | void enabledChanged(); |
112 | void visibleChanged(); |
113 | void separatorChanged(); |
114 | void checkableChanged(); |
115 | void checkedChanged(); |
116 | void roleChanged(); |
117 | void textChanged(); |
118 | void shortcutChanged(); |
119 | void fontChanged(); |
120 | Q_REVISION(2, 1) void iconChanged(); |
121 | |
122 | protected: |
123 | void classBegin() override; |
124 | void componentComplete() override; |
125 | |
126 | QQuickLabsPlatformIconLoader *iconLoader() const; |
127 | |
128 | bool event(QEvent *e) override; |
129 | private Q_SLOTS: |
130 | void activate(); |
131 | void updateIcon(); |
132 | |
133 | private: |
134 | void addShortcut(); |
135 | void removeShortcut(); |
136 | |
137 | bool m_complete; |
138 | bool m_enabled; |
139 | bool m_visible; |
140 | bool m_separator; |
141 | bool m_checkable; |
142 | bool m_checked; |
143 | QPlatformMenuItem::MenuRole m_role; |
144 | QString m_text; |
145 | QVariant m_shortcut; |
146 | QFont m_font; |
147 | QQuickLabsPlatformMenu *m_menu; |
148 | QQuickLabsPlatformMenu *m_subMenu; |
149 | QQuickLabsPlatformMenuItemGroup *m_group; |
150 | mutable QQuickLabsPlatformIconLoader *m_iconLoader; |
151 | QPlatformMenuItem *m_handle; |
152 | int m_shortcutId = -1; |
153 | |
154 | friend class QQuickLabsPlatformMenu; |
155 | friend class QQuickLabsPlatformMenuItemGroup; |
156 | }; |
157 | |
158 | QT_END_NAMESPACE |
159 | |
160 | QML_DECLARE_TYPE(QQuickLabsPlatformMenuItem) |
161 | |
162 | #endif // QQUICKLABSPLATFORMMENUITEM_P_H |
163 |