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 QQUICKMENU_P_H
5#define QQUICKMENU_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 <QtQml/qqmllist.h>
19#include <QtQml/qqml.h>
20#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
21
22#include "qquickpopup_p.h"
23#include <QtQuickTemplates2/private/qquickicon_p.h>
24
25QT_REQUIRE_CONFIG(qml_object_model);
26
27QT_BEGIN_NAMESPACE
28
29class QQuickAction;
30class QQmlComponent;
31class QQuickMenuItem;
32class QQuickMenuPrivate;
33
34class Q_QUICKTEMPLATES2_EXPORT QQuickMenu : public QQuickPopup
35{
36 Q_OBJECT
37 Q_PROPERTY(QVariant contentModel READ contentModel CONSTANT FINAL)
38 Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL)
39 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL)
40 // 2.3 (Qt 5.10)
41 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL REVISION(2, 3))
42 Q_PROPERTY(bool cascade READ cascade WRITE setCascade RESET resetCascade NOTIFY cascadeChanged FINAL REVISION(2, 3))
43 Q_PROPERTY(qreal overlap READ overlap WRITE setOverlap NOTIFY overlapChanged FINAL REVISION(2, 3))
44 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL REVISION(2, 3))
45 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL REVISION(2, 3))
46 // 6.5 (Qt 6.5)
47 Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(6, 5))
48 Q_CLASSINFO("DefaultProperty", "contentData")
49 QML_NAMED_ELEMENT(Menu)
50 QML_ADDED_IN_VERSION(2, 0)
51
52public:
53 explicit QQuickMenu(QObject *parent = nullptr);
54 ~QQuickMenu();
55
56 Q_INVOKABLE QQuickItem *itemAt(int index) const;
57 Q_INVOKABLE void addItem(QQuickItem *item);
58 Q_INVOKABLE void insertItem(int index, QQuickItem *item);
59 Q_INVOKABLE void moveItem(int from, int to);
60 Q_INVOKABLE void removeItem(QQuickItem *item);
61
62 QVariant contentModel() const;
63 QQmlListProperty<QObject> contentData();
64
65 QString title() const;
66 void setTitle(const QString &title);
67
68 QQuickIcon icon() const;
69 void setIcon(const QQuickIcon &icon);
70
71 bool cascade() const;
72 void setCascade(bool cascade);
73 void resetCascade();
74
75 qreal overlap() const;
76 void setOverlap(qreal overlap);
77
78 QQmlComponent *delegate() const;
79 void setDelegate(QQmlComponent *delegate);
80
81 int currentIndex() const;
82 void setCurrentIndex(int index);
83
84 // 2.3 (Qt 5.10)
85 int count() const;
86 Q_REVISION(2, 3) Q_INVOKABLE QQuickItem *takeItem(int index);
87
88 Q_REVISION(2, 3) Q_INVOKABLE QQuickMenu *menuAt(int index) const;
89 Q_REVISION(2, 3) Q_INVOKABLE void addMenu(QQuickMenu *menu);
90 Q_REVISION(2, 3) Q_INVOKABLE void insertMenu(int index, QQuickMenu *menu);
91 Q_REVISION(2, 3) Q_INVOKABLE void removeMenu(QQuickMenu *menu);
92 Q_REVISION(2, 3) Q_INVOKABLE QQuickMenu *takeMenu(int index);
93
94 Q_REVISION(2, 3) Q_INVOKABLE QQuickAction *actionAt(int index) const;
95 Q_REVISION(2, 3) Q_INVOKABLE void addAction(QQuickAction *action);
96 Q_REVISION(2, 3) Q_INVOKABLE void insertAction(int index, QQuickAction *action);
97 Q_REVISION(2, 3) Q_INVOKABLE void removeAction(QQuickAction *action);
98 Q_REVISION(2, 3) Q_INVOKABLE QQuickAction *takeAction(int index);
99
100 bool isVisible() const override;
101 void setVisible(bool visible) override;
102
103 void popup(QQuickItem *menuItem = nullptr);
104 void popup(const QPointF &pos, QQuickItem *menuItem = nullptr);
105
106 Q_REVISION(2, 3) Q_INVOKABLE void popup(QQmlV4FunctionPtr args);
107 Q_REVISION(2, 3) Q_INVOKABLE void dismiss();
108
109protected:
110 void componentComplete() override;
111 void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override;
112 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
113 void keyPressEvent(QKeyEvent *event) override;
114
115Q_SIGNALS:
116 void titleChanged(const QString &title);
117 // 2.3 (Qt 5.10)
118 Q_REVISION(2, 3) void countChanged();
119 Q_REVISION(2, 3) void cascadeChanged(bool cascade);
120 Q_REVISION(2, 3) void overlapChanged();
121 Q_REVISION(2, 3) void delegateChanged();
122 Q_REVISION(2, 3) void currentIndexChanged();
123 // 6.5 (Qt 6.5)
124 Q_REVISION(6, 5) void iconChanged(const QQuickIcon &icon);
125
126protected:
127 void timerEvent(QTimerEvent *event) override;
128
129 QFont defaultFont() const override;
130
131#if QT_CONFIG(accessibility)
132 QAccessible::Role accessibleRole() const override;
133#endif
134
135private:
136 Q_DISABLE_COPY(QQuickMenu)
137 Q_DECLARE_PRIVATE(QQuickMenu)
138};
139
140QT_END_NAMESPACE
141
142#endif // QQUICKMENU_P_H
143

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtdeclarative/src/quicktemplates/qquickmenu_p.h