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
qquickdeliveryagent_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QQUICKDELIVERYAGENT_P_P_H
6#define QQUICKDELIVERYAGENT_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 <QtQuick/private/qquickdeliveryagent_p.h>
20#include <QtGui/qevent.h>
21#include <QtCore/qstack.h>
22#include <QtCore/qxpfunctional.h>
23
24#include <private/qevent_p.h>
25#include <private/qpointingdevice_p.h>
26
27#include <QtCore/qpointer.h>
28#include <private/qobject_p.h>
29
30#include <memory>
31
32QT_BEGIN_NAMESPACE
33
34class QQuickDragGrabber;
35class QQuickItem;
36class QQuickPointerHandler;
37class QQuickWindow;
38
39/*! \internal
40 Extra device-specific data to be stored in QInputDevicePrivate::qqExtra
41*/
43 // used in QQuickPointerHandlerPrivate::deviceDeliveryTargets
45};
46
47class Q_QUICK_EXPORT QQuickDeliveryAgentPrivate : public QObjectPrivate
48{
49public:
50 Q_DECLARE_PUBLIC(QQuickDeliveryAgent)
51 QQuickDeliveryAgentPrivate(QQuickItem *root);
52 ~QQuickDeliveryAgentPrivate();
53
54 QQuickItem *rootItem = nullptr;
55
56 QQuickItem *activeFocusItem = nullptr;
57
58 void deliverKeyEvent(QKeyEvent *e);
59
60 enum FocusOption {
61 DontChangeFocusProperty = 0x01,
62 DontChangeSubFocusItem = 0x02
63 };
64 Q_DECLARE_FLAGS(FocusOptions, FocusOption)
65
66 void setFocusInScope(QQuickItem *scope, QQuickItem *item, Qt::FocusReason reason, FocusOptions = { });
67 void clearFocusInScope(QQuickItem *scope, QQuickItem *item, Qt::FocusReason reason, FocusOptions = { });
68 static void notifyFocusChangesRecur(QQuickItem **item, int remaining, Qt::FocusReason reason);
69 void clearFocusObject();
70 void updateFocusItemTransform();
71
72 QQuickItem *focusTargetItem() const;
73
74 // Keeps track of the item currently receiving mouse events
75#if QT_CONFIG(quick_draganddrop)
76 QQuickDragGrabber *dragGrabber = nullptr;
77#endif
78 QQuickItem *lastUngrabbed = nullptr;
79 QStack<QPointerEvent *> eventsInDelivery;
80 QFlatMap<QPointer<QQuickItem>, uint> hoverItems;
81 QVector<QQuickItem *> hasFiltered; // during event delivery to a single receiver, the filtering parents for which childMouseEventFilter was already called
82 QVector<QQuickItem *> skipDelivery; // during delivery of one event to all receivers, Items to which we know delivery is no longer necessary
83
84 std::unique_ptr<QMutableTouchEvent> delayedTouch;
85 QList<const QPointingDevice *> knownPointingDevices;
86
87 uint currentHoverId = 0;
88#if QT_CONFIG(wheelevent)
89 uint lastWheelEventAccepted = 0;
90#endif
91 uchar compressedTouchCount = 0;
92 bool allowChildEventFiltering = true;
93 bool frameSynchronousHoverEnabled = true;
94 bool hoveredLeafItemFound = false;
95
96 bool isSubsceneAgent = false;
97 static bool subsceneAgentsExist;
98 // QQuickDeliveryAgent::event() sets this to the one that's currently (trying to) handle the event
99 static QQuickDeliveryAgent *currentEventDeliveryAgent;
100 static QQuickDeliveryAgent *currentOrItemDeliveryAgent(const QQuickItem *item);
101
102 Qt::FocusReason lastFocusReason = Qt::OtherFocusReason;
103 int pointerEventRecursionGuard = 0;
104
105 int touchMouseId = -1; // only for obsolete stuff like QQuickItem::grabMouse()
106 // TODO get rid of these
107 const QPointingDevice *touchMouseDevice = nullptr;
108 ulong touchMousePressTimestamp = 0;
109 QPoint touchMousePressPos; // in screen coordinates
110
111 QQuickDeliveryAgent::Transform *sceneTransform = nullptr;
112
113 bool isDeliveringTouchAsMouse() const { return touchMouseId != -1 && touchMouseDevice; }
114 void cancelTouchMouseSynthesis();
115
116 bool checkIfDoubleTapped(ulong newPressEventTimestamp, const QPoint &newPressPos);
117 void resetIfDoubleTapPrevented(const QEventPoint &pressedPoint);
118 QPointingDevicePrivate::EventPointData *mousePointData();
119 QPointerEvent *eventInDelivery() const;
120
121 // Mouse positions are saved in widget coordinates
122 QPointF lastMousePosition;
123 bool deliverTouchAsMouse(QQuickItem *item, QTouchEvent *pointerEvent);
124 void translateTouchEvent(QTouchEvent *touchEvent);
125 void removeGrabber(QQuickItem *grabber, bool mouse = true, bool touch = true, bool cancel = false);
126 void clearGrabbers(QPointerEvent *pointerEvent);
127 void onGrabChanged(QObject *grabber, QPointingDevice::GrabTransition transition, const QPointerEvent *event, const QEventPoint &point);
128 static QPointerEvent *clonePointerEvent(QPointerEvent *event, std::optional<QPointF> transformedLocalPos = std::nullopt);
129 void deliverToPassiveGrabbers(const QVector<QPointer<QObject> > &passiveGrabbers, QPointerEvent *pointerEvent);
130 bool sendFilteredMouseEvent(QEvent *event, QQuickItem *receiver, QQuickItem *filteringParent);
131 bool sendFilteredPointerEvent(QPointerEvent *event, QQuickItem *receiver, QQuickItem *filteringParent = nullptr);
132 bool sendFilteredPointerEventImpl(QPointerEvent *event, QQuickItem *receiver, QQuickItem *filteringParent);
133 bool deliverSinglePointEventUntilAccepted(QPointerEvent *);
134
135 // entry point of events to the window
136 void handleTouchEvent(QTouchEvent *);
137 void handleMouseEvent(QMouseEvent *);
138 bool compressTouchEvent(QTouchEvent *);
139 void flushFrameSynchronousEvents(QQuickWindow *win);
140 void deliverDelayedTouchEvent();
141 void handleWindowDeactivate(QQuickWindow *win);
142 void handleWindowHidden(QQuickWindow *win);
143
144 // utility functions that used to be in QQuickPointerEvent et al.
145 bool allUpdatedPointsAccepted(const QPointerEvent *ev);
146 static void localizePointerEvent(QPointerEvent *ev, const QQuickItem *dest);
147 QList<QObject *> exclusiveGrabbers(QPointerEvent *ev);
148 static bool anyPointGrabbed(const QPointerEvent *ev);
149 static bool allPointsGrabbed(const QPointerEvent *ev);
150 static bool isMouseEvent(const QPointerEvent *ev);
151 static bool isMouseOrWheelEvent(const QPointerEvent *ev);
152 static bool isHoverEvent(const QPointerEvent *ev);
153 static bool isHoveringMoveEvent(const QPointerEvent *ev);
154 static bool isTouchEvent(const QPointerEvent *ev);
155 static bool isTabletEvent(const QPointerEvent *ev);
156 static bool isEventFromMouseOrTouchpad(const QPointerEvent *ev);
157 static bool isSynthMouse(const QPointerEvent *ev);
158 static bool isWithinDoubleClickInterval(ulong timeInterval);
159 static bool isWithinDoubleTapDistance(const QPoint &distanceBetweenPresses);
160 static bool isSinglePointDevice(const QInputDevice *dev);
161 static QQuickPointingDeviceExtra *deviceExtra(const QInputDevice *device);
162
163 // delivery of pointer events:
164 void touchToMouseEvent(QEvent::Type type, const QEventPoint &p, const QTouchEvent *touchEvent, QMutableSinglePointEvent *mouseEvent);
165 void ensureDeviceConnected(const QPointingDevice *dev);
166 void deliverPointerEvent(QPointerEvent *);
167 bool deliverTouchCancelEvent(QTouchEvent *);
168 bool deliverPressOrReleaseEvent(QPointerEvent *, bool handlersOnly = false);
169 void deliverUpdatedPoints(QPointerEvent *event);
170 void deliverMatchingPointsToItem(QQuickItem *item, bool isGrabber, QPointerEvent *pointerEvent, bool handlersOnly = false);
171
172 QVector<QQuickItem *> eventTargets(QQuickItem *, const QEvent *event, QPointF scenePos, qxp::function_ref<std::optional<bool> (QQuickItem *, const QEvent *)> predicate) const;
173 QVector<QQuickItem *> pointerTargets(QQuickItem *, const QPointerEvent *event, const QEventPoint &point,
174 bool checkMouseButtons, bool checkAcceptsTouch) const;
175 QVector<QQuickItem *> mergePointerTargets(const QVector<QQuickItem *> &list1, const QVector<QQuickItem *> &list2) const;
176
177 // hover delivery
178 enum class HoverChange : uint8_t {
179 Clear,
180 Set,
181 };
182 bool deliverHoverEvent(const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, ulong timestamp);
183 bool deliverHoverEventRecursive(QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, ulong timestamp);
184 bool deliverHoverEventToItem(QQuickItem *item, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, ulong timestamp,
185 HoverChange hoverChange);
186 bool sendHoverEvent(QEvent::Type, QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos,
187 Qt::KeyboardModifiers modifiers, ulong timestamp);
188 bool clearHover(ulong timestamp = 0);
189
190#if QT_CONFIG(quick_draganddrop)
191 void deliverDragEvent(QQuickDragGrabber *, QEvent *);
192 bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *,
193 QVarLengthArray<QQuickItem *, 64> *currentGrabItems = nullptr,
194 QObject *formerTarget = nullptr);
195#endif
196
197 static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event, int startDragThreshold = -1);
198
199 static bool dragOverThreshold(qreal d, Qt::Axis axis, const QEventPoint &tp, int startDragThreshold = -1);
200
201 static bool dragOverThreshold(QVector2D delta);
202
203 // context menu events
204 QVector<QQuickItem *> contextMenuTargets(QQuickItem *item, const QContextMenuEvent *event) const;
205 void deliverContextMenuEvent(QContextMenuEvent *event);
206};
207
208Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickDeliveryAgentPrivate::FocusOptions)
209
210QT_END_NAMESPACE
211
212#endif // QQUICKDELIVERYAGENT_P_P_H
QVector< QObject * > deliveryTargets