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
7#include <private/qquickdeliveryagent_p.h>
8
10
31
36
38{
41 return false;
42
43 if (d->pointInfo.id() != -1) {
44 // We already know which one we want, so check whether it's there.
45 // It's expected to be an update or a release.
46 // If we no longer want it, cancel the grab.
47 int candidatePointCount = 0;
48 bool missing = true;
49 QEventPoint *point = nullptr;
50 for (int i = 0; i < event->pointCount(); ++i) {
51 auto &p = event->point(i);
52 const bool found = (p.id() == d->pointInfo.id());
53 if (found)
54 missing = false;
55 if (wantsEventPoint(event, p)) {
56 ++candidatePointCount;
57 if (found)
58 point = &p;
59 }
60 }
61 if (missing) {
62 // Received a stray touch begin event => reset and start over.
63 if (event->type() == QEvent::TouchBegin && event->points().count() == 1) {
64 const QEventPoint &point = event->point(0);
65 qCDebug(lcTouchTarget) << this << "pointId" << Qt::hex << point.id()
66 << "was received as a stray TouchBegin event. Canceling existing gesture"
67 " and starting over.";
68 d->pointInfo.reset(event, point);
69 return true;
70 } else {
71 qCWarning(lcTouchTarget) << this << "pointId" << Qt::hex << d->pointInfo.id()
72 << "is missing from current event, but was neither canceled nor released."
73 " Ignoring:" << event->type();
74 }
75 }
76 if (point) {
77 if (candidatePointCount == 1 || (candidatePointCount > 1 && d->ignoreAdditionalPoints)) {
78 point->setAccepted();
79 return true;
80 } else {
82 }
83 } else {
84 return false;
85 }
86 } else {
87 // We have not yet chosen a point; choose the first one for which wantsEventPoint() returns true.
88 int candidatePointCount = 0;
89 QEventPoint *chosen = nullptr;
90 for (int i = 0; i < event->pointCount(); ++i) {
91 auto &p = event->point(i);
92 if (!event->exclusiveGrabber(p) && wantsEventPoint(event, p)) {
93 ++candidatePointCount;
94 if (!chosen) {
95 chosen = &p;
96 break;
97 }
98 }
99 }
100 if (chosen && candidatePointCount == 1) {
101 setPointId(chosen->id());
102 chosen->setAccepted();
103 }
104 }
105 return d->pointInfo.id() != -1;
106}
107
118
120{
121 if (point.state() == QEventPoint::Released) {
122 // If it's a mouse or tablet event, with buttons,
123 // do not deactivate unless all acceptable buttons are released.
124 if (event->isSinglePointEvent()) {
125 const Qt::MouseButtons releasedButtons = static_cast<QSinglePointEvent *>(event)->buttons();
126 if ((releasedButtons & acceptedButtons()) != Qt::NoButton)
127 return;
128 }
129
130 // Deactivate this handler on release
132 d_func()->reset();
133 }
134}
135
137{
139 if (grabber != this)
140 return;
141 switch (transition) {
143 d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition();
144 setActive(true);
145 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
146 break;
148 d->pointInfo.m_sceneGrabPosition = point.sceneGrabPosition();
149 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
150 break;
152 return; // don't emit
157 // the grab is lost or relinquished, so the point is no longer relevant
158 QQuickPointerHandler::onGrabChanged(grabber, transition, event, point);
159 d->reset();
160 break;
161 }
162}
163
165{
167 d->ignoreAdditionalPoints = v;
168}
169
171{
174 d->pointInfo.m_scenePosition = point.scenePosition();
175 d->pointInfo.m_position = target()->mapFromScene(d->pointInfo.m_scenePosition);
176}
177
179{
181 d->pointInfo.m_id = id;
182}
183
185{
186 Q_D(const QQuickSinglePointHandler);
187 return d->pointInfo;
188}
189
202
204{
206 q->setActive(false);
208}
209
211
212#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,...)
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