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 <QtGui/qpa/qplatformmenu.h>
22
23#include <QtQuickTemplates2/private/qquickmenu_p.h>
24#include <QtQuickTemplates2/private/qquickpopup_p_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QQuickAction;
29class QQmlComponent;
30class QQmlObjectModel;
31class QQuickMenuItem;
32class QQuickNativeMenuItem;
33class QQuickMenuBar;
34
35class Q_QUICKTEMPLATES2_EXPORT QQuickMenuPrivate : public QQuickPopupPrivate
36{
37public:
38 Q_DECLARE_PUBLIC(QQuickMenu)
39
40 QQuickMenuPrivate();
41
42 static QQuickMenuPrivate *get(QQuickMenu *menu)
43 {
44 return menu->d_func();
45 }
46
47 void init();
48
49 QPlatformMenu *nativeHandle();
50 QPlatformMenu *maybeNativeHandle() const;
51 QQuickMenu *rootMenu() const;
52 bool useNativeMenu() const;
53 bool createNativeMenu();
54 void removeNativeMenu();
55 void syncWithNativeMenu();
56 void syncWithUseNativeMenu();
57 static void recursivelyDestroyNativeSubMenus(QQuickMenu *menu);
58 void setNativeMenuVisible(bool visible);
59
60 QQuickItem *itemAt(int index) const;
61 void insertItem(int index, QQuickItem *item);
62 void maybeCreateAndInsertNativeItem(int index, QQuickItem *item);
63 void moveItem(int from, int to);
64 enum class DestructionPolicy {
65 Destroy,
66 DoNotDestroy
67 };
68 void removeItem(int index, QQuickItem *item,
69 DestructionPolicy destructionPolicy = DestructionPolicy::DoNotDestroy);
70 void removeNativeItem(int index);
71 void resetNativeData();
72
73 static void recursivelyCreateNativeMenuItems(QQuickMenu *menu);
74
75 void printContentModelItems() const;
76
77 QQuickItem *beginCreateItem();
78 void completeCreateItem();
79
80 QQuickItem *createItem(QQuickMenu *menu);
81 QQuickItem *createItem(QQuickAction *action);
82
83 void resizeItem(QQuickItem *item);
84 void resizeItems();
85
86 void itemChildAdded(QQuickItem *item, QQuickItem *child) override;
87 void itemSiblingOrderChanged(QQuickItem *item) override;
88 void itemParentChanged(QQuickItem *item, QQuickItem *parent) override;
89 void itemDestroyed(QQuickItem *item) override;
90 void itemGeometryChanged(QQuickItem *, QQuickGeometryChange change, const QRectF &diff) override;
91
92 QQuickPopupPositioner *getPositioner() override;
93 bool prepareEnterTransition() override;
94 bool prepareExitTransition() override;
95 bool blockInput(QQuickItem *item, const QPointF &point) const override;
96 bool handlePress(QQuickItem *item, const QPointF &point, ulong timestamp) override;
97 bool handleReleaseWithoutGrab(const QEventPoint &eventPoint) override;
98
99 void onItemHovered();
100 void onItemTriggered();
101 void onItemActiveFocusChanged();
102 void updateTextPadding();
103
104 QQuickMenu *currentSubMenu() const;
105 void setParentMenu(QQuickMenu *parent);
106 void resolveParentItem();
107
108 void propagateKeyEvent(QKeyEvent *event);
109
110 void startHoverTimer();
111 void stopHoverTimer();
112
113 void setCurrentIndex(int index, Qt::FocusReason reason);
114 bool activateNextItem();
115 bool activatePreviousItem();
116
117 QQuickMenuItem *firstEnabledMenuItem() const;
118
119 static void contentData_append(QQmlListProperty<QObject> *prop, QObject *obj);
120 static qsizetype contentData_count(QQmlListProperty<QObject> *prop);
121 static QObject *contentData_at(QQmlListProperty<QObject> *prop, qsizetype index);
122 static void contentData_clear(QQmlListProperty<QObject> *prop);
123
124 QPalette defaultPalette() const override;
125 virtual QQuickPopup::PopupType resolvedPopupType() const override;
126
127 bool cascade = false;
128 bool triedToCreateNativeMenu = false;
129 int hoverTimer = 0;
130 int currentIndex = -1;
131 qreal overlap = 0;
132 qreal textPadding = 0;
133 QPointer<QQuickMenu> parentMenu;
134 QPointer<QQuickMenuItem> currentItem;
135 QQuickItem *contentItem = nullptr; // TODO: cleanup
136 QList<QObject *> contentData;
137 QQmlObjectModel *contentModel;
138 QQmlComponent *delegate = nullptr;
139 QString title;
140 QQuickIcon icon;
141
142 // For native menu support.
143 std::unique_ptr<QPlatformMenu> handle = nullptr;
144 QList<QQuickNativeMenuItem *> nativeItems;
145 QPointer<QQuickMenuBar> menuBar;
146 qreal lastDevicePixelRatio = 0;
147};
148
149QT_END_NAMESPACE
150
151#endif // QQUICKMENU_P_P_H
152

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

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