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