Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquicksinglepointhandler.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 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
6
9
10
28{
29}
30
33{
34}
35
37{
40 return false;
41
42 if (d->pointInfo.id() != -1) {
43 // We already know which one we want, so check whether it's there.
44 // It's expected to be an update or a release.
45 // If we no longer want it, cancel the grab.
46 int candidatePointCount = 0;
47 bool missing = true;
48 QEventPoint *point = nullptr;
49 for (int i = 0; i < event->pointCount(); ++i) {
50 auto &p = event->point(i);
51 const bool found = (p.id() == d->pointInfo.id());
52 if (found)
53 missing = false;
54 if (wantsEventPoint(event, p)) {
55 ++candidatePointCount;
56 if (found)
57 point = &p;
58 }
59 }
60 if (missing) {
61 // Received a stray touch begin event => reset and start over.
62 if (event->type() == QEvent::TouchBegin && event->points().count() == 1) {
63 const QEventPoint &point = event->point(0);
64 qCDebug(lcTouchTarget) << this << "pointId" << Qt::hex << point.id()
65 << "was received as a stray TouchBegin event. Canceling existing gesture"
66 " and starting over.";
67 d->pointInfo.reset(event, point);
68 return true;
69 } else {
70 qCWarning(lcTouchTarget) << this << "pointId" << Qt::hex << d->pointInfo.id()
71 << "is missing from current event, but was neither canceled nor released."
72 " Ignoring:" << event->type();
73 }
74 }
75 if (point) {
76 if (candidatePointCount == 1 || (candidatePointCount > 1 && d->ignoreAdditionalPoints)) {
77 point->setAccepted();
78 return true;
79 } else {
81 }
82 } else {
83 return false;
84 }
85 } else {
86 // We have not yet chosen a point; choose the first one for which wantsEventPoint() returns true.
87 int candidatePointCount = 0;
88 QEventPoint *chosen = nullptr;
89 for (int i = 0; i < event->pointCount(); ++i) {
90 auto &p = event->point(i);
91 if (!event->exclusiveGrabber(p) && wantsEventPoint(event, p)) {
92 ++candidatePointCount;
93 if (!chosen) {
94 chosen = &p;
95 break;
96 }
97 }
98 }
99 if (chosen && candidatePointCount == 1) {
100 setPointId(chosen->id());
101 chosen->setAccepted();
102 }
103 }
104 return d->pointInfo.id() != -1;
105}
106
108{
111 QEventPoint *currentPoint = const_cast<QEventPoint *>(event->pointById(d->pointInfo.id()));
113 d->pointInfo.reset(event, *currentPoint);
116}
117
119{
120 if (point.state() != QEventPoint::Released)
121 return;
122
123 const Qt::MouseButtons releasedButtons = static_cast<QSinglePointEvent *>(event)->buttons();
124 if ((releasedButtons & acceptedButtons()) == Qt::NoButton) {
126 d_func()->reset();
127 }
128}
129
131{
133 if (grabber != this)
134 return;
135 switch (transition) {
137 d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition();
138 setActive(true);
139 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
140 break;
142 d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition();
143 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
144 break;
146 return; // don't emit
151 // the grab is lost or relinquished, so the point is no longer relevant
152 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
153 d->reset();
154 break;
155 }
156}
157
159{
161 d->ignoreAdditionalPoints = v;
162}
163
165{
168 d->pointInfo.m_scenePosition = point.scenePosition();
169 d->pointInfo.m_position = target()->mapFromScene(d->pointInfo.m_scenePosition);
170}
171
173{
175 d->pointInfo.m_id = id;
176}
177
179{
180 Q_D(const QQuickSinglePointHandler);
181 return d->pointInfo;
182}
183
194{
195}
196
198{
200 q->setActive(false);
202}
203
205
206#include "moc_qquicksinglepointhandler_p.cpp"
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
int id
the ID number of this event point.
Definition qeventpoint.h:25
void setAccepted(bool accepted=true)
@ TouchBegin
Definition qcoreevent.h:241
\inmodule QtCore\reentrant
Definition qpoint.h:214
A base class for pointer events.
Definition qevent.h:73
GrabTransition
This enum represents a transition of exclusive or passive grab from one object (possibly nullptr) to ...
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
QPointF mapFromScene(const QPointF &point) const
Maps the given point in the scene's coordinate system to the equivalent point within this item's coor...
void setPosition(const QPointF &)
bool wantsPointerEvent(QPointerEvent *event) override
It is the responsibility of this function to decide whether the event could be relevant at all to thi...
void cancelAllGrabs(QPointerEvent *event, QEventPoint &point)
Cancel any existing grab of the given point.
virtual bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point)
Returns true if the given point (as part of event) could be relevant at all to this handler,...
virtual void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point)
Notification that the grab has changed in some way which is relevant to this handler.
virtual void handlePointerEventImpl(QPointerEvent *event)
This function can be overridden to implement whatever behavior a specific subclass is intended to hav...
bool setExclusiveGrab(QPointerEvent *ev, const QEventPoint &point, bool grab=true)
Acquire or give up the exclusive grab of the given point, according to the grab state,...
QQuickSinglePointHandlerPrivate()
\readonly \qmlproperty handlerPoint QtQuick::SinglePointHandler::point
virtual void handleEventPoint(QPointerEvent *event, QEventPoint &point)
QQuickSinglePointHandler(QQuickItem *parent=nullptr)
\qmltype SinglePointHandler \qmlabstract \preliminary \instantiates QQuickSinglePointHandler \inherit...
QEventPoint & currentPoint(QPointerEvent *ev)
void handlePointerEventImpl(QPointerEvent *event) override
This function can be overridden to implement whatever behavior a specific subclass is intended to hav...
bool wantsPointerEvent(QPointerEvent *event) override
It is the responsibility of this function to decide whether the event could be relevant at all to thi...
void moveTarget(QPointF pos, QEventPoint &point)
void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override
Notification that the grab has changed in some way which is relevant to this handler.
A base class for pointer events containing a single point, such as mouse events.
Definition qevent.h:108
Combined button and popup list for selecting options.
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
@ NoButton
Definition qnamespace.h:56
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLsizei const GLfloat * v
[13]
GLenum GLuint id
[7]
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent