Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
30
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
117
119{
120 if (point.state() == QEventPoint::Released) {
121 // If it's a mouse or tablet event, with buttons,
122 // do not deactivate unless all acceptable buttons are released.
123 if (event->isSinglePointEvent()) {
124 const Qt::MouseButtons releasedButtons = static_cast<QSinglePointEvent *>(event)->buttons();
125 if ((releasedButtons & acceptedButtons()) != Qt::NoButton)
126 return;
127 }
128
129 // Deactivate this handler on release
131 d_func()->reset();
132 }
133}
134
136{
138 if (grabber != this)
139 return;
140 switch (transition) {
142 d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition();
143 setActive(true);
144 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
145 break;
147 d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition();
148 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
149 break;
151 return; // don't emit
156 // the grab is lost or relinquished, so the point is no longer relevant
157 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
158 d->reset();
159 break;
160 }
161}
162
164{
166 d->ignoreAdditionalPoints = v;
167}
168
170{
173 d->pointInfo.m_scenePosition = point.scenePosition();
174 d->pointInfo.m_position = target()->mapFromScene(d->pointInfo.m_scenePosition);
175}
176
178{
180 d->pointInfo.m_id = id;
181}
182
184{
185 Q_D(const QQuickSinglePointHandler);
186 return d->pointInfo;
187}
188
201
203{
205 q->setActive(false);
207}
208
210
211#include "moc_qquicksinglepointhandler_p.cpp"
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
@ TouchBegin
Definition qcoreevent.h:241
\inmodule QtCore\reentrant
Definition qpoint.h:217
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:63
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:109
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:57
#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