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