1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Controls module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKMENUITEM_P_H
41#define QQUICKMENUITEM_P_H
42
43#include <QtCore/qobject.h>
44#include <QtCore/qvariant.h>
45#include <QtCore/qpointer.h>
46#include <QtCore/qurl.h>
47#include <QtGui/qicon.h>
48#include <QtQml/QQmlListProperty>
49
50QT_BEGIN_NAMESPACE
51
52class QUrl;
53class QPlatformMenuItem;
54class QQuickItem;
55class QQuickAction1;
56class QQuickExclusiveGroup1;
57class QQuickMenu1;
58class QQuickMenuItemContainer1;
59
60class QQuickMenuItemType1
61{
62 Q_GADGET
63 Q_ENUMS(MenuItemType)
64
65public:
66 enum MenuItemType {
67 Separator = 0,
68 Item,
69 Menu,
70 ScrollIndicator
71 };
72};
73
74class QQuickMenuBase1: public QObject
75{
76 Q_OBJECT
77 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
78 Q_PROPERTY(QQuickMenuItemType1::MenuItemType type READ type CONSTANT)
79
80 Q_PROPERTY(QObject *__parentMenu READ parentMenuOrMenuBar CONSTANT)
81 Q_PROPERTY(bool __isNative READ isNative CONSTANT)
82 Q_PROPERTY(QQuickItem *__visualItem READ visualItem WRITE setVisualItem)
83
84Q_SIGNALS:
85 void visibleChanged();
86
87public:
88 QQuickMenuBase1(QObject *parent, int type);
89 ~QQuickMenuBase1();
90
91 bool visible() const { return m_visible; }
92 virtual void setVisible(bool);
93
94 QQuickMenu1 *parentMenu() const;
95 QObject *parentMenuOrMenuBar() const;
96 virtual void setParentMenu(QQuickMenu1 *parentMenu);
97
98 QQuickMenuItemContainer1 *container() const;
99 void setContainer(QQuickMenuItemContainer1 *);
100
101 inline QPlatformMenuItem *platformItem() { return m_platformItem; }
102 void syncWithPlatformMenu();
103
104 QQuickItem *visualItem() const;
105 void setVisualItem(QQuickItem *item);
106
107 QQuickMenuItemType1::MenuItemType type() { return m_type; }
108 virtual bool isNative() { return m_platformItem != 0; }
109
110private:
111 bool m_visible;
112 QQuickMenuItemType1::MenuItemType m_type;
113 QQuickMenu1 *m_parentMenu;
114 QQuickMenuItemContainer1 *m_container;
115 QPlatformMenuItem *m_platformItem;
116 QPointer<QQuickItem> m_visualItem;
117};
118
119class QQuickMenuSeparator1 : public QQuickMenuBase1
120{
121 Q_OBJECT
122public:
123 QQuickMenuSeparator1(QObject *parent = 0);
124};
125
126class QQuickMenuText1 : public QQuickMenuBase1
127{
128 Q_OBJECT
129 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
130 Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged)
131 Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged)
132
133 Q_PROPERTY(QVariant __icon READ iconVariant NOTIFY __iconChanged)
134
135Q_SIGNALS:
136 void enabledChanged();
137 void iconSourceChanged();
138 void iconNameChanged();
139
140 void __textChanged();
141 void __iconChanged();
142
143public:
144 QQuickMenuText1(QObject *parent, QQuickMenuItemType1::MenuItemType type);
145 ~QQuickMenuText1();
146
147 bool enabled() const;
148 virtual void setEnabled(bool enabled);
149
150 virtual QString text() const;
151 void setText(const QString &text);
152
153 virtual QUrl iconSource() const;
154 void setIconSource(const QUrl &icon);
155 virtual QString iconName() const;
156 void setIconName(const QString &icon);
157
158 QVariant iconVariant() const { return QVariant(icon()); }
159
160protected:
161 virtual QIcon icon() const;
162 virtual QQuickAction1 *action() const { return m_action; }
163
164protected Q_SLOTS:
165 virtual void updateText();
166 void updateEnabled();
167 void updateIcon();
168
169private:
170 QQuickAction1 *m_action;
171};
172
173class QQuickMenuItem1 : public QQuickMenuText1
174{
175 Q_OBJECT
176 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
177 Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged)
178 Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY toggled)
179 Q_PROPERTY(QQuickExclusiveGroup1 *exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup NOTIFY exclusiveGroupChanged)
180 Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged)
181 Q_PROPERTY(QQuickAction1 *action READ boundAction WRITE setBoundAction NOTIFY actionChanged)
182
183public Q_SLOTS:
184 void trigger();
185
186Q_SIGNALS:
187 void triggered();
188 void toggled(bool checked);
189
190 void textChanged();
191 void checkableChanged();
192 void exclusiveGroupChanged();
193 void shortcutChanged();
194 void actionChanged();
195
196public:
197 QQuickMenuItem1(QObject *parent = 0);
198 ~QQuickMenuItem1();
199
200 void setEnabled(bool enabled) override;
201
202 QString text() const override;
203
204 QUrl iconSource() const override;
205 QString iconName() const override;
206
207 QQuickAction1 *boundAction() { return m_boundAction; }
208 void setBoundAction(QQuickAction1 *a);
209
210 QVariant shortcut() const;
211 void setShortcut(const QVariant &shortcut);
212
213 bool checkable() const;
214 void setCheckable(bool checkable);
215
216 bool checked() const;
217 void setChecked(bool checked);
218
219 QQuickExclusiveGroup1 *exclusiveGroup() const;
220 void setExclusiveGroup(QQuickExclusiveGroup1 *);
221
222 void setParentMenu(QQuickMenu1 *parentMenu) override;
223
224protected Q_SLOTS:
225 void updateShortcut();
226 void updateCheckable();
227 void updateChecked();
228 void bindToAction(QQuickAction1 *action);
229 void unbindFromAction(QObject *action);
230
231protected:
232 QIcon icon() const override;
233 QQuickAction1 *action() const override;
234
235private:
236 QQuickAction1 *m_boundAction;
237};
238
239QT_END_NAMESPACE
240
241#endif // QQUICKMENUITEM_P_H
242

source code of qtquickcontrols/src/controls/qquickmenuitem_p.h