1// Copyright (C) 2020 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_P_H
5#define QQUICKMENU_P_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 <QtCore/qlist.h>
19#include <QtCore/qpointer.h>
20
21#include <QtQuickTemplates2/private/qquickmenu_p.h>
22#include <QtQuickTemplates2/private/qquickpopup_p_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class QQuickAction;
27class QQmlComponent;
28class QQmlObjectModel;
29class QQuickMenuItem;
30
31class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuPrivate : public QQuickPopupPrivate
32{
33public:
34 Q_DECLARE_PUBLIC(QQuickMenu)
35
36 QQuickMenuPrivate();
37
38 static QQuickMenuPrivate *get(QQuickMenu *menu)
39 {
40 return menu->d_func();
41 }
42
43 void init();
44
45 QQuickItem *itemAt(int index) const;
46 void insertItem(int index, QQuickItem *item);
47 void moveItem(int from, int to);
48 void removeItem(int index, QQuickItem *item);
49
50 QQuickItem *beginCreateItem();
51 void completeCreateItem();
52
53 QQuickItem *createItem(QQuickMenu *menu);
54 QQuickItem *createItem(QQuickAction *action);
55
56 void resizeItem(QQuickItem *item);
57 void resizeItems();
58
59 void itemChildAdded(QQuickItem *item, QQuickItem *child) override;
60 void itemSiblingOrderChanged(QQuickItem *item) override;
61 void itemParentChanged(QQuickItem *item, QQuickItem *parent) override;
62 void itemDestroyed(QQuickItem *item) override;
63 void itemGeometryChanged(QQuickItem *, QQuickGeometryChange change, const QRectF &diff) override;
64
65 QQuickPopupPositioner *getPositioner() override;
66 bool prepareEnterTransition() override;
67 bool prepareExitTransition() override;
68 bool blockInput(QQuickItem *item, const QPointF &point) const override;
69
70 void onItemHovered();
71 void onItemTriggered();
72 void onItemActiveFocusChanged();
73
74 QQuickMenu *currentSubMenu() const;
75 void setParentMenu(QQuickMenu *parent);
76 void resolveParentItem();
77
78 void propagateKeyEvent(QKeyEvent *event);
79
80 void startHoverTimer();
81 void stopHoverTimer();
82
83 void setCurrentIndex(int index, Qt::FocusReason reason);
84 bool activateNextItem();
85 bool activatePreviousItem();
86
87 QQuickMenuItem *firstEnabledMenuItem() const;
88
89 static void contentData_append(QQmlListProperty<QObject> *prop, QObject *obj);
90 static qsizetype contentData_count(QQmlListProperty<QObject> *prop);
91 static QObject *contentData_at(QQmlListProperty<QObject> *prop, qsizetype index);
92 static void contentData_clear(QQmlListProperty<QObject> *prop);
93
94 QPalette defaultPalette() const override;
95
96 bool cascade = false;
97 int hoverTimer = 0;
98 int currentIndex = -1;
99 qreal overlap = 0;
100 QPointer<QQuickMenu> parentMenu;
101 QPointer<QQuickMenuItem> currentItem;
102 QQuickItem *contentItem = nullptr; // TODO: cleanup
103 QList<QObject *> contentData;
104 QQmlObjectModel *contentModel;
105 QQmlComponent *delegate = nullptr;
106 QString title;
107 QQuickIcon icon;
108};
109
110QT_END_NAMESPACE
111
112#endif // QQUICKMENU_P_P_H
113

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