Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickmenu_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKMENU_P_H
6#define QQUICKMENU_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQml/qqmllist.h>
20#include <QtQml/qqml.h>
21#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
22
23#include "qquickpopup_p.h"
24#include <QtQuickTemplates2/private/qquickicon_p.h>
25
26QT_REQUIRE_CONFIG(qml_object_model);
27
28QT_BEGIN_NAMESPACE
29
30class QQuickAction;
31class QQmlComponent;
32class QQuickMenuItem;
33class QQuickMenuPrivate;
34
35class Q_QUICKTEMPLATES2_EXPORT QQuickMenu : public QQuickPopup
36{
37 Q_OBJECT
38 Q_PROPERTY(QVariant contentModel READ contentModel CONSTANT FINAL)
39 Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL)
40 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL)
41 // 2.3 (Qt 5.10)
42 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL REVISION(2, 3))
43 Q_PROPERTY(bool cascade READ cascade WRITE setCascade RESET resetCascade NOTIFY cascadeChanged FINAL REVISION(2, 3))
44 Q_PROPERTY(qreal overlap READ overlap WRITE setOverlap NOTIFY overlapChanged FINAL REVISION(2, 3))
45 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL REVISION(2, 3))
46 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL REVISION(2, 3))
47
48 Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(6, 5))
49 Q_PROPERTY(bool separatorsCollapsible READ separatorsCollapsible WRITE setSeparatorsCollapsible
50 NOTIFY separatorsCollapsibleChanged FINAL REVISION(6, 12))
51
52 Q_CLASSINFO("DefaultProperty", "contentData")
53 QML_NAMED_ELEMENT(Menu)
54 QML_ADDED_IN_VERSION(2, 0)
55
56public:
57 explicit QQuickMenu(QObject *parent = nullptr);
58 ~QQuickMenu();
59
60 Q_INVOKABLE QQuickItem *itemAt(int index) const;
61 Q_INVOKABLE void addItem(QQuickItem *item);
62 Q_INVOKABLE void insertItem(int index, QQuickItem *item);
63 Q_INVOKABLE void moveItem(int from, int to);
64 Q_INVOKABLE void removeItem(QQuickItem *item);
65
66 QVariant contentModel() const;
67 QQmlListProperty<QObject> contentData();
68
69 QString title() const;
70 void setTitle(const QString &title);
71
72 QQuickIcon icon() const;
73 void setIcon(const QQuickIcon &icon);
74
75 bool separatorsCollapsible() const;
76 void setSeparatorsCollapsible(bool collapsible);
77
78 bool cascade() const;
79 void setCascade(bool cascade);
80 void resetCascade();
81
82 qreal overlap() const;
83 void setOverlap(qreal overlap);
84
85 QQmlComponent *delegate() const;
86 void setDelegate(QQmlComponent *delegate);
87
88 int currentIndex() const;
89 void setCurrentIndex(int index);
90
91 // 2.3 (Qt 5.10)
92 int count() const;
93 Q_REVISION(2, 3) Q_INVOKABLE QQuickItem *takeItem(int index);
95 Q_REVISION(2, 3) Q_INVOKABLE QQuickMenu *menuAt(int index) const;
96 Q_REVISION(2, 3) Q_INVOKABLE void addMenu(QQuickMenu *menu);
97 Q_REVISION(2, 3) Q_INVOKABLE void insertMenu(int index, QQuickMenu *menu);
98 Q_REVISION(2, 3) Q_INVOKABLE void removeMenu(QQuickMenu *menu);
99 Q_REVISION(2, 3) Q_INVOKABLE QQuickMenu *takeMenu(int index);
101 Q_REVISION(2, 3) Q_INVOKABLE QQuickAction *actionAt(int index) const;
102 Q_REVISION(2, 3) Q_INVOKABLE void addAction(QQuickAction *action);
103 Q_REVISION(2, 3) Q_INVOKABLE void insertAction(int index, QQuickAction *action);
104 Q_REVISION(2, 3) Q_INVOKABLE void removeAction(QQuickAction *action);
105 Q_REVISION(2, 3) Q_INVOKABLE QQuickAction *takeAction(int index);
106
107 bool isVisible() const override;
108 void setVisible(bool visible) override;
109
110 // overload set with parent item
111 Q_REVISION(2, 3) Q_INVOKABLE void popup(QQuickItem *parent, qreal x, qreal y, QQuickItem *menuItem = nullptr);
112 Q_REVISION(2, 3) Q_INVOKABLE void popup(QQuickItem *parent, const QPointF &position, QQuickItem *menuItem = nullptr);
113 Q_REVISION(2, 3) Q_INVOKABLE void popup(QQuickItem *parent, QQuickItem *menuItem);
114 Q_REVISION(2, 3) Q_INVOKABLE void popup(QQuickItem *parent = nullptr);
115 // overload set without parent item
116 Q_REVISION(2, 3) Q_INVOKABLE void popup(qreal x, qreal y, QQuickItem *menuItem = nullptr);
117 Q_REVISION(2, 3) Q_INVOKABLE void popup(const QPointF &position, QQuickItem *menuItem = nullptr);
118 Q_REVISION(2, 3) Q_INVOKABLE void dismiss();
119
120protected:
121 void componentComplete() override;
122 void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override;
123 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
124 void keyPressEvent(QKeyEvent *event) override;
125
126Q_SIGNALS:
127 void titleChanged(const QString &title);
128 // 2.3 (Qt 5.10)
129 Q_REVISION(2, 3) void countChanged();
130 Q_REVISION(2, 3) void cascadeChanged(bool cascade);
131 Q_REVISION(2, 3) void overlapChanged();
132 Q_REVISION(2, 3) void delegateChanged();
133 Q_REVISION(2, 3) void currentIndexChanged();
135 Q_REVISION(6, 5) void iconChanged(const QQuickIcon &icon);
136 Q_REVISION(6, 12) void separatorsCollapsibleChanged();
137
138protected:
139 void timerEvent(QTimerEvent *event) override;
140
141 QFont defaultFont() const override;
142
143#if QT_CONFIG(accessibility)
144 QAccessible::Role accessibleRole() const override;
145#endif
146
147private:
148 Q_DISABLE_COPY(QQuickMenu)
149 Q_DECLARE_PRIVATE(QQuickMenu)
150};
151
152QT_END_NAMESPACE
153
154#endif // QQUICKMENU_P_H
QQuickMenuPositioner(QQuickMenu *menu)
void reposition() override
Combined button and popup list for selecting options.
static const QQuickPopup::ClosePolicy cascadingSubMenuClosePolicy
Menu popup that can be used as a context menu or popup menu.
static QQuickItem * findParentMenuItem(QQuickMenu *subMenu)
static bool shouldCascade()
static QWindow * effectiveWindow(QWindow *window, QPoint *offset)
QString nativeMenuItemListToString(const QList< QQuickNativeMenuItem * > &nativeItems)