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
qquickhandlerpoint.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
5#include "private/qquickevents_p_p.h"
6#include "private/qquickdeliveryagent_p_p.h"
7
9
41
43{
44 m_pressPosition = item->mapFromScene(m_scenePressPosition);
45}
46
48{
49 m_id = -1;
51 m_uniqueId = QPointingDeviceUniqueId();
52 m_position = QPointF();
53 m_scenePosition = QPointF();
54 m_pressPosition = QPointF();
55 m_scenePressPosition = QPointF();
56 m_sceneGrabPosition = QPointF();
57 m_velocity = QVector2D();
58 m_rotation = 0;
59 m_pressure = 0;
60 m_ellipseDiameters = QSizeF();
61 m_pressedButtons = Qt::NoButton;
62 m_pressedModifiers = Qt::NoModifier;
63}
64
66{
68 m_id = point.id();
69 m_device = event->pointingDevice();
70 const auto state = (isTouch ? static_cast<const QTouchEvent *>(event)->touchPointStates() : point.state());
71 if (state.testFlag(QEventPoint::Pressed)) {
72 m_pressPosition = point.position();
73 m_scenePressPosition = point.scenePosition();
74 }
75 if (!isTouch)
76 m_pressedButtons = static_cast<const QSinglePointEvent *>(event)->buttons();
77 m_pressedModifiers = event->modifiers();
78 if (isTouch) {
79 m_uniqueId = point.uniqueId();
80 m_rotation = point.rotation();
81 m_pressure = point.pressure();
82 m_ellipseDiameters = point.ellipseDiameters();
83#if QT_CONFIG(tabletevent)
85 m_uniqueId = event->pointingDevice()->uniqueId();
86 m_rotation = point.rotation();
87 m_pressure = point.pressure();
88 m_ellipseDiameters = QSizeF();
89#endif
90 } else {
91 m_uniqueId = event->pointingDevice()->uniqueId();
92 m_rotation = 0;
93 m_pressure = m_pressedButtons ? 1 : 0;
94 m_ellipseDiameters = QSizeF();
95 }
96 m_position = point.position();
97 m_scenePosition = point.scenePosition();
98 if (point.state() == QEventPoint::Updated)
99 m_velocity = point.velocity();
100}
101
102void QQuickHandlerPoint::reset(const QVector<QQuickHandlerPoint> &points)
103{
104 if (points.isEmpty()) {
105 qWarning("reset: no points");
106 return;
107 }
108 if (points.size() == 1) {
109 *this = points.first(); // copy all values
110 return;
111 }
112 // all points are required to be from the same event
113 QPointF posSum;
114 QPointF scenePosSum;
115 QPointF pressPosSum;
116 QPointF scenePressPosSum;
117 QVector2D velocitySum;
118 qreal pressureSum = 0;
119 QSizeF ellipseDiameterSum;
120 for (const QQuickHandlerPoint &point : points) {
121 posSum += point.position();
122 scenePosSum += point.scenePosition();
123 pressPosSum += point.pressPosition();
124 scenePressPosSum += point.scenePressPosition();
125 velocitySum += point.velocity();
126 pressureSum += point.pressure();
127 ellipseDiameterSum += point.ellipseDiameters();
128 }
129 m_id = -1;
130 m_device = nullptr;
131 m_uniqueId = QPointingDeviceUniqueId();
132 // all points are required to be from the same event, so pressed buttons and modifiers should be the same
133 m_pressedButtons = points.first().pressedButtons();
134 m_pressedModifiers = points.first().modifiers();
135 m_position = posSum / points.size();
136 m_scenePosition = scenePosSum / points.size();
137 m_pressPosition = pressPosSum / points.size();
138 m_scenePressPosition = scenePressPosSum / points.size();
139 m_velocity = velocitySum / points.size();
140 m_rotation = 0; // averaging the rotations of all the points isn't very sensible
141 m_pressure = pressureSum / points.size();
142 m_ellipseDiameters = ellipseDiameterSum / points.size();
143}
144
320
321#include "moc_qquickhandlerpoint_p.cpp"
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
qreal pressure
the pressure of this point.
Definition qeventpoint.h:31
int id
the ID number of this event point.
Definition qeventpoint.h:24
QPointF scenePosition
the scene position of this point.
Definition qeventpoint.h:39
State state
the current state of the event point.
Definition qeventpoint.h:26
qreal rotation
the angular orientation of this point.
Definition qeventpoint.h:32
QSizeF ellipseDiameters
the width and height of the bounding ellipse of the touch point.
Definition qeventpoint.h:33
QPointingDeviceUniqueId uniqueId
the unique ID of this point or token, if any.
Definition qeventpoint.h:25
QPointF position
the position of this point.
Definition qeventpoint.h:35
QVector2D velocity
a velocity vector, in units of pixels per second, in the coordinate.
Definition qeventpoint.h:34
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item's scene's coordinate system, to this item's coordinate sy...
\inmodule QtCore\reentrant
Definition qpoint.h:217
A base class for pointer events.
Definition qevent.h:73
QPointingDeviceUniqueId identifies a unique object, such as a tagged token or stylus,...
static const QPointingDevice * primaryPointingDevice(const QString &seatName=QString())
Returns the primary pointing device (the core pointer, traditionally assumed to be a mouse) on the gi...
static bool isTabletEvent(const QPointerEvent *ev)
static bool isTouchEvent(const QPointerEvent *ev)
QQuickHandlerPoint()
\qmltype handlerPoint \instantiates QQuickHandlerPoint \inqmlmodule QtQuick
void localize(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
A base class for pointer events containing a single point, such as mouse events.
Definition qevent.h:109
\inmodule QtCore
Definition qsize.h:208
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
else opt state
[0]
Combined button and popup list for selecting options.
@ NoButton
Definition qnamespace.h:57
@ NoModifier
#define qWarning
Definition qlogging.h:167
struct _cl_event * event
GLfixed GLfixed GLint GLint GLfixed points
double qreal
Definition qtypes.h:187
QGraphicsItem * item