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 Quick Templates 2 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 QQUICKMENU_P_H
38#define QQUICKMENU_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 <QtQml/qqmllist.h>
52#include <QtQml/qqml.h>
53
54#include "qquickpopup_p.h"
55
56QT_BEGIN_NAMESPACE
57
58class QQuickAction;
59class QQmlComponent;
60class QQuickMenuItem;
61class QQuickMenuPrivate;
62
63class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenu : public QQuickPopup
64{
65 Q_OBJECT
66 Q_PROPERTY(QVariant contentModel READ contentModel CONSTANT FINAL)
67 Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL)
68 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL)
69 // 2.3 (Qt 5.10)
70 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL REVISION 3)
71 Q_PROPERTY(bool cascade READ cascade WRITE setCascade RESET resetCascade NOTIFY cascadeChanged FINAL REVISION 3)
72 Q_PROPERTY(qreal overlap READ overlap WRITE setOverlap NOTIFY overlapChanged FINAL REVISION 3)
73 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL REVISION 3)
74 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL REVISION 3)
75 Q_CLASSINFO("DefaultProperty", "contentData")
76
77public:
78 explicit QQuickMenu(QObject *parent = nullptr);
79 ~QQuickMenu();
80
81 Q_INVOKABLE QQuickItem *itemAt(int index) const;
82 Q_INVOKABLE void addItem(QQuickItem *item);
83 Q_INVOKABLE void insertItem(int index, QQuickItem *item);
84 Q_INVOKABLE void moveItem(int from, int to);
85 Q_INVOKABLE void removeItem(const QVariant &item); // ### Qt 6: remove
86 void removeItem(QQuickItem *item); // ### Qt 6: Q_INVOKABLE
87
88 QVariant contentModel() const;
89 QQmlListProperty<QObject> contentData();
90
91 QString title() const;
92 void setTitle(QString &title);
93
94 bool cascade() const;
95 void setCascade(bool cascade);
96 void resetCascade();
97
98 qreal overlap() const;
99 void setOverlap(qreal overlap);
100
101 QQmlComponent *delegate() const;
102 void setDelegate(QQmlComponent *delegate);
103
104 int currentIndex() const;
105 void setCurrentIndex(int index);
106
107 // 2.3 (Qt 5.10)
108 int count() const;
109 Q_REVISION(3) Q_INVOKABLE QQuickItem *takeItem(int index);
110
111 Q_REVISION(3) Q_INVOKABLE QQuickMenu *menuAt(int index) const;
112 Q_REVISION(3) Q_INVOKABLE void addMenu(QQuickMenu *menu);
113 Q_REVISION(3) Q_INVOKABLE void insertMenu(int index, QQuickMenu *menu);
114 Q_REVISION(3) Q_INVOKABLE void removeMenu(QQuickMenu *menu);
115 Q_REVISION(3) Q_INVOKABLE QQuickMenu *takeMenu(int index);
116
117 Q_REVISION(3) Q_INVOKABLE QQuickAction *actionAt(int index) const;
118 Q_REVISION(3) Q_INVOKABLE void addAction(QQuickAction *action);
119 Q_REVISION(3) Q_INVOKABLE void insertAction(int index, QQuickAction *action);
120 Q_REVISION(3) Q_INVOKABLE void removeAction(QQuickAction *action);
121 Q_REVISION(3) Q_INVOKABLE QQuickAction *takeAction(int index);
122
123 void popup(QQuickItem *menuItem = nullptr);
124 void popup(const QPointF &pos, QQuickItem *menuItem = nullptr);
125
126 Q_REVISION(3) Q_INVOKABLE void popup(QQmlV4Function *args);
127 Q_REVISION(3) Q_INVOKABLE void dismiss();
128
129protected:
130 void componentComplete() override;
131 void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override;
132 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
133 void keyPressEvent(QKeyEvent *event) override;
134
135Q_SIGNALS:
136 void titleChanged(const QString &title);
137 // 2.3 (Qt 5.10)
138 Q_REVISION(3) void countChanged();
139 Q_REVISION(3) void cascadeChanged(bool cascade);
140 Q_REVISION(3) void overlapChanged();
141 Q_REVISION(3) void delegateChanged();
142 Q_REVISION(3) void currentIndexChanged();
143
144protected:
145 void timerEvent(QTimerEvent *event) override;
146
147 QFont defaultFont() const override;
148 QPalette defaultPalette() const override;
149
150#if QT_CONFIG(accessibility)
151 QAccessible::Role accessibleRole() const override;
152#endif
153
154private:
155 Q_DISABLE_COPY(QQuickMenu)
156 Q_DECLARE_PRIVATE(QQuickMenu)
157};
158
159QT_END_NAMESPACE
160
161QML_DECLARE_TYPE(QQuickMenu)
162
163#endif // QQUICKMENU_P_H
164

source code of qtquickcontrols2/src/quicktemplates2/qquickmenu_p.h