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 QQUICKPLATFORMMENUITEM_P_H
38#define QQUICKPLATFORMMENUITEM_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/qqml.h>
57
58#include "qquickplatformicon_p.h"
59
60QT_BEGIN_NAMESPACE
61
62class QPlatformMenuItem;
63class QQuickPlatformMenu;
64class QQuickPlatformIconLoader;
65class QQuickPlatformMenuItemGroup;
66
67class QQuickPlatformMenuItem : public QObject, public QQmlParserStatus
68{
69 Q_OBJECT
70 Q_INTERFACES(QQmlParserStatus)
71 Q_PROPERTY(QQuickPlatformMenu *menu READ menu NOTIFY menuChanged FINAL)
72 Q_PROPERTY(QQuickPlatformMenu *subMenu READ subMenu NOTIFY subMenuChanged FINAL)
73 Q_PROPERTY(QQuickPlatformMenuItemGroup *group READ group WRITE setGroup NOTIFY groupChanged FINAL)
74 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
75 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
76 Q_PROPERTY(bool separator READ isSeparator WRITE setSeparator NOTIFY separatorChanged FINAL)
77 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL)
78 Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL)
79 Q_PROPERTY(QPlatformMenuItem::MenuRole role READ role WRITE setRole NOTIFY roleChanged FINAL)
80 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
81 Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged FINAL)
82 Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged FINAL)
83 Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged FINAL)
84 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL)
85 Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION 1)
86 Q_ENUMS(QPlatformMenuItem::MenuRole)
87
88public:
89 explicit QQuickPlatformMenuItem(QObject *parent = nullptr);
90 ~QQuickPlatformMenuItem();
91
92 QPlatformMenuItem *handle() const;
93 QPlatformMenuItem *create();
94 void sync();
95
96 QQuickPlatformMenu *menu() const;
97 void setMenu(QQuickPlatformMenu* menu);
98
99 QQuickPlatformMenu *subMenu() const;
100 void setSubMenu(QQuickPlatformMenu *menu);
101
102 QQuickPlatformMenuItemGroup *group() const;
103 void setGroup(QQuickPlatformMenuItemGroup *group);
104
105 bool isEnabled() const;
106 void setEnabled(bool enabled);
107
108 bool isVisible() const;
109 void setVisible(bool visible);
110
111 bool isSeparator() const;
112 void setSeparator(bool separator);
113
114 bool isCheckable() const;
115 void setCheckable(bool checkable);
116
117 bool isChecked() const;
118 void setChecked(bool checked);
119
120 QPlatformMenuItem::MenuRole role() const;
121 void setRole(QPlatformMenuItem::MenuRole role);
122
123 QString text() const;
124 void setText(const QString &text);
125
126 QUrl iconSource() const;
127 void setIconSource(const QUrl &source);
128
129 QString iconName() const;
130 void setIconName(const QString &name);
131
132 QVariant shortcut() const;
133 void setShortcut(const QVariant& shortcut);
134
135 QFont font() const;
136 void setFont(const QFont &font);
137
138 QQuickPlatformIcon icon() const;
139 void setIcon(const QQuickPlatformIcon &icon);
140
141public Q_SLOTS:
142 void toggle();
143
144Q_SIGNALS:
145 void triggered();
146 void hovered();
147
148 void menuChanged();
149 void subMenuChanged();
150 void groupChanged();
151 void enabledChanged();
152 void visibleChanged();
153 void separatorChanged();
154 void checkableChanged();
155 void checkedChanged();
156 void roleChanged();
157 void textChanged();
158 void iconSourceChanged();
159 void iconNameChanged();
160 void shortcutChanged();
161 void fontChanged();
162 Q_REVISION(1) void iconChanged();
163
164protected:
165 void classBegin() override;
166 void componentComplete() override;
167
168 QQuickPlatformIconLoader *iconLoader() const;
169
170 bool event(QEvent *e) override;
171private Q_SLOTS:
172 void activate();
173 void updateIcon();
174
175private:
176 bool m_complete;
177 bool m_enabled;
178 bool m_visible;
179 bool m_separator;
180 bool m_checkable;
181 bool m_checked;
182 QPlatformMenuItem::MenuRole m_role;
183 QString m_text;
184 QVariant m_shortcut;
185 QFont m_font;
186 QQuickPlatformMenu *m_menu;
187 QQuickPlatformMenu *m_subMenu;
188 QQuickPlatformMenuItemGroup *m_group;
189 mutable QQuickPlatformIconLoader *m_iconLoader;
190 QPlatformMenuItem *m_handle;
191 int m_shortcutId = -1;
192
193 friend class QQuickPlatformMenu;
194 friend class QQuickPlatformMenuItemGroup;
195};
196
197QT_END_NAMESPACE
198
199QML_DECLARE_TYPE(QQuickPlatformMenuItem)
200
201#endif // QQUICKPLATFORMMENUITEM_P_H
202

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