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

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