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
10
11
42
44{
45 m_pressPosition = item->mapFromScene(m_scenePressPosition);
46}
47
49{
50 m_id = -1;
52 m_uniqueId = QPointingDeviceUniqueId();
53 m_position = QPointF();
54 m_scenePosition = QPointF();
55 m_pressPosition = QPointF();
56 m_scenePressPosition = QPointF();
57 m_sceneGrabPosition = QPointF();
58 m_velocity = QVector2D();
59 m_rotation = 0;
60 m_pressure = 0;
61 m_ellipseDiameters = QSizeF();
62 m_pressedButtons = Qt::NoButton;
63 m_pressedModifiers = Qt::NoModifier;
64}
65
67{
69 m_id = point.id();
70 m_device = event->pointingDevice();
71 const auto state = (isTouch ? static_cast<const QTouchEvent *>(event)->touchPointStates() : point.state());
72 if (state.testFlag(QEventPoint::Pressed)) {
73 m_pressPosition = point.position();
74 m_scenePressPosition = point.scenePosition();
75 }
76 if (!isTouch)
77 m_pressedButtons = static_cast<const QSinglePointEvent *>(event)->buttons();
78 m_pressedModifiers = event->modifiers();
79 if (isTouch) {
80 m_uniqueId = point.uniqueId();
81 m_rotation = point.rotation();
82 m_pressure = point.pressure();
83 m_ellipseDiameters = point.ellipseDiameters();
84#if QT_CONFIG(tabletevent)
86 m_uniqueId = event->pointingDevice()->uniqueId();
87 m_rotation = point.rotation();
88 m_pressure = point.pressure();
89 m_ellipseDiameters = QSizeF();
90#endif
91 } else {
92 m_uniqueId = event->pointingDevice()->uniqueId();
93 m_rotation = 0;
94 m_pressure = m_pressedButtons ? 1 : 0;
95 m_ellipseDiameters = QSizeF();
96 }
97 m_position = point.position();
98 m_scenePosition = point.scenePosition();
99 if (point.state() == QEventPoint::Updated)
100 m_velocity = point.velocity();
101}
102
103void QQuickHandlerPoint::reset(const QVector<QQuickHandlerPoint> &points)
104{
105 if (points.isEmpty()) {
106 qWarning("reset: no points");
107 return;
108 }
109 if (points.size() == 1) {
110 *this = points.first(); // copy all values
111 return;
112 }
113 // all points are required to be from the same event
114 QPointF posSum;
115 QPointF scenePosSum;
116 QPointF pressPosSum;
117 QPointF scenePressPosSum;
118 QVector2D velocitySum;
119 qreal pressureSum = 0;
120 QSizeF ellipseDiameterSum;
121 for (const QQuickHandlerPoint &point : points) {
122 posSum += point.position();
123 scenePosSum += point.scenePosition();
124 pressPosSum += point.pressPosition();
125 scenePressPosSum += point.scenePressPosition();
126 velocitySum += point.velocity();
127 pressureSum += point.pressure();
128 ellipseDiameterSum += point.ellipseDiameters();
129 }
130 m_id = -1;
131 m_device = nullptr;
132 m_uniqueId = QPointingDeviceUniqueId();
133 // all points are required to be from the same event, so pressed buttons and modifiers should be the same
134 m_pressedButtons = points.first().pressedButtons();
135 m_pressedModifiers = points.first().modifiers();
136 m_position = posSum / points.size();
137 m_scenePosition = scenePosSum / points.size();
138 m_pressPosition = pressPosSum / points.size();
139 m_scenePressPosition = scenePressPosSum / points.size();
140 m_velocity = velocitySum / points.size();
141 m_rotation = 0; // averaging the rotations of all the points isn't very sensible
142 m_pressure = pressureSum / points.size();
143 m_ellipseDiameters = ellipseDiameterSum / points.size();
144}
145
321
322#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)
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:166
#define Q_DECLARE_LOGGING_CATEGORY(name)
struct _cl_event * event
GLfixed GLfixed GLint GLint GLfixed points
double qreal
Definition qtypes.h:187
QGraphicsItem * item