Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickmultipointtoucharea_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKMULTIPOINTTOUCHAREA_H
6#define QQUICKMULTIPOINTTOUCHAREA_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtquickglobal_p.h>
20
21#include <QtQuick/qquickitem.h>
22
23#include <QtGui/qevent.h>
24#include <QtGui/qguiapplication.h>
25#include <QtGui/qstylehints.h>
26
27#include <QtCore/qlist.h>
28#include <QtCore/qmap.h>
29#include <QtCore/qpointer.h>
30
31#include <QtQml/qqmllist.h>
32
34
35class QQuickMultiPointTouchArea;
36class Q_QUICK_EXPORT QQuickTouchPoint : public QObject
37{
38 Q_OBJECT
39 Q_PROPERTY(int pointId READ pointId NOTIFY pointIdChanged)
40 Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId NOTIFY uniqueIdChanged REVISION(2, 9))
41 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
42 Q_PROPERTY(qreal x READ x NOTIFY xChanged)
43 Q_PROPERTY(qreal y READ y NOTIFY yChanged)
44 Q_PROPERTY(QSizeF ellipseDiameters READ ellipseDiameters NOTIFY ellipseDiametersChanged REVISION(2, 9))
45 Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged)
46 Q_PROPERTY(qreal rotation READ rotation NOTIFY rotationChanged REVISION(2, 9))
47 Q_PROPERTY(QVector2D velocity READ velocity NOTIFY velocityChanged)
48 Q_PROPERTY(QRectF area READ area NOTIFY areaChanged)
49
50 Q_PROPERTY(qreal startX READ startX NOTIFY startXChanged)
51 Q_PROPERTY(qreal startY READ startY NOTIFY startYChanged)
52 Q_PROPERTY(qreal previousX READ previousX NOTIFY previousXChanged)
53 Q_PROPERTY(qreal previousY READ previousY NOTIFY previousYChanged)
54 Q_PROPERTY(qreal sceneX READ sceneX NOTIFY sceneXChanged)
55 Q_PROPERTY(qreal sceneY READ sceneY NOTIFY sceneYChanged)
56 QML_NAMED_ELEMENT(TouchPoint)
57 QML_ADDED_IN_VERSION(2, 0)
58
59public:
60 QQuickTouchPoint(bool qmlDefined = true)
61 : _qmlDefined(qmlDefined)
62 {}
63
64 int pointId() const { return _id; }
65 void setPointId(int id);
66
67 QPointingDeviceUniqueId uniqueId() const { return _uniqueId; }
68 void setUniqueId(const QPointingDeviceUniqueId &id);
69
70 qreal x() const { return _x; }
71 qreal y() const { return _y; }
72 void setPosition(QPointF pos);
73
74 QSizeF ellipseDiameters() const { return _ellipseDiameters; }
75 void setEllipseDiameters(const QSizeF &d);
76
77 qreal pressure() const { return _pressure; }
78 void setPressure(qreal pressure);
79
80 qreal rotation() const { return _rotation; }
81 void setRotation(qreal r);
82
83 QVector2D velocity() const { return _velocity; }
84 void setVelocity(const QVector2D &velocity);
85
86 QRectF area() const { return _area; }
87 void setArea(const QRectF &area);
88
89 bool isQmlDefined() const { return _qmlDefined; }
90
91 bool inUse() const { return _inUse; }
92 void setInUse(bool inUse) { _inUse = inUse; }
93
94 bool pressed() const { return _pressed; }
95 void setPressed(bool pressed);
96
97 qreal startX() const { return _startX; }
98 void setStartX(qreal startX);
99
100 qreal startY() const { return _startY; }
101 void setStartY(qreal startY);
102
103 qreal previousX() const { return _previousX; }
104 void setPreviousX(qreal previousX);
105
106 qreal previousY() const { return _previousY; }
107 void setPreviousY(qreal previousY);
108
109 qreal sceneX() const { return _sceneX; }
110 void setSceneX(qreal sceneX);
111
112 qreal sceneY() const { return _sceneY; }
113 void setSceneY(qreal sceneY);
114
115Q_SIGNALS:
116 void pressedChanged();
117 void pointIdChanged();
118 Q_REVISION(2, 9) void uniqueIdChanged();
119 void xChanged();
120 void yChanged();
121 Q_REVISION(2, 9) void ellipseDiametersChanged();
122 void pressureChanged();
123 Q_REVISION(2, 9) void rotationChanged();
124 void velocityChanged();
125 void areaChanged();
126 void startXChanged();
127 void startYChanged();
128 void previousXChanged();
129 void previousYChanged();
130 void sceneXChanged();
131 void sceneYChanged();
132
133private:
134 friend class QQuickMultiPointTouchArea;
135 int _id = 0;
136 qreal _x = 0.0;
137 qreal _y = 0.0;
138 qreal _pressure = 0.0;
139 qreal _rotation = 0;
140 QSizeF _ellipseDiameters;
141 QVector2D _velocity;
142 QRectF _area;
143 bool _qmlDefined;
144 bool _inUse = false; //whether the point is currently in use (only valid when _qmlDefined == true)
145 bool _pressed = false;
146 qreal _startX = 0.0;
147 qreal _startY = 0.0;
148 qreal _previousX = 0.0;
149 qreal _previousY = 0.0;
150 qreal _sceneX = 0.0;
151 qreal _sceneY = 0.0;
152 QPointingDeviceUniqueId _uniqueId;
153};
154
156{
157 Q_OBJECT
158 Q_PROPERTY(QQmlListProperty<QObject> touchPoints READ touchPoints CONSTANT FINAL)
162 QML_UNCREATABLE("GestureEvent is only available in the context of handling the gestureStarted signal from MultiPointTouchArea.")
163
164public:
166
167 Q_INVOKABLE void grab() { _grab = true; }
168 bool wantsGrab() const { return _grab; }
169
174
175private:
177 bool _grab = false;
178 qreal _dragThreshold;
179 QList<QObject*> _touchPoints;
180};
181
182class Q_QUICK_EXPORT QQuickMultiPointTouchArea : public QQuickItem
183{
184 Q_OBJECT
185 Q_DISABLE_COPY_MOVE(QQuickMultiPointTouchArea)
186
187 Q_PROPERTY(QQmlListProperty<QQuickTouchPoint> touchPoints READ touchPoints CONSTANT)
188 Q_PROPERTY(int minimumTouchPoints READ minimumTouchPoints WRITE setMinimumTouchPoints NOTIFY minimumTouchPointsChanged)
189 Q_PROPERTY(int maximumTouchPoints READ maximumTouchPoints WRITE setMaximumTouchPoints NOTIFY maximumTouchPointsChanged)
190 Q_PROPERTY(bool mouseEnabled READ mouseEnabled WRITE setMouseEnabled NOTIFY mouseEnabledChanged)
191 QML_NAMED_ELEMENT(MultiPointTouchArea)
192 QML_ADDED_IN_VERSION(2, 0)
193
194public:
195 QQuickMultiPointTouchArea(QQuickItem *parent=nullptr);
196 ~QQuickMultiPointTouchArea();
197
198 int minimumTouchPoints() const;
199 void setMinimumTouchPoints(int num);
200 int maximumTouchPoints() const;
201 void setMaximumTouchPoints(int num);
202 bool mouseEnabled() const { return _mouseEnabled; }
203 void setMouseEnabled(bool arg);
204
205 QQmlListProperty<QQuickTouchPoint> touchPoints() {
206 return QQmlListProperty<QQuickTouchPoint>(this, nullptr, QQuickMultiPointTouchArea::touchPoint_append, QQuickMultiPointTouchArea::touchPoint_count, QQuickMultiPointTouchArea::touchPoint_at, nullptr);
207 }
208
209 static void touchPoint_append(QQmlListProperty<QQuickTouchPoint> *list, QQuickTouchPoint* touch) {
210 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
211 q->addTouchPrototype(touch);
212 }
213
214 static qsizetype touchPoint_count(QQmlListProperty<QQuickTouchPoint> *list) {
215 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
216 return q->_touchPrototypes.size();
217 }
218
219 static QQuickTouchPoint* touchPoint_at(QQmlListProperty<QQuickTouchPoint> *list, qsizetype index) {
220 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
221 return q->_touchPrototypes.value(index);
222 }
223
224Q_SIGNALS:
225#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
226 void pressed(const QList<QObject*> &touchPoints);
227 void updated(const QList<QObject*> &touchPoints);
228 void released(const QList<QObject*> &touchPoints);
229 void canceled(const QList<QObject*> &touchPoints);
230#else
231 void pressed(const QList<QObject*> &points);
232 void updated(const QList<QObject*> &points);
233 void released(const QList<QObject*> &points);
234 void canceled(const QList<QObject*> &points);
235#endif
236 void gestureStarted(QQuickGrabGestureEvent *gesture);
237#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
238 void touchUpdated(const QList<QObject*> &touchPoints);
239#else
240 void touchUpdated(const QList<QObject*> &points);
241#endif
242 void minimumTouchPointsChanged();
243 void maximumTouchPointsChanged();
244 void mouseEnabledChanged();
245
246protected:
247 void touchEvent(QTouchEvent *) override;
248 bool childMouseEventFilter(QQuickItem *receiver, QEvent *event) override;
249 void mousePressEvent(QMouseEvent *event) override;
250 void mouseReleaseEvent(QMouseEvent *event) override;
251 void mouseMoveEvent(QMouseEvent *event) override;
252 void mouseUngrabEvent() override;
253 void touchUngrabEvent() override;
254
255 void addTouchPrototype(QQuickTouchPoint* prototype);
256 void addTouchPoint(const QEventPoint *p);
257 void addTouchPoint(const QMouseEvent *e);
258 void clearTouchLists();
259
260 void updateTouchPoint(QQuickTouchPoint*, const QEventPoint*);
261 void updateTouchPoint(QQuickTouchPoint *dtp, const QMouseEvent *e);
262 enum class RemapEventPoints { No, ToLocal };
263 void updateTouchData(QEvent*, RemapEventPoints remap = RemapEventPoints::No);
264
265 bool sendMouseEvent(QMouseEvent *event);
266 bool shouldFilter(QEvent *event);
267 void grabGesture(QPointingDevice *dev);
268 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
269#ifdef Q_OS_MACOS
270 void hoverEnterEvent(QHoverEvent *event) override;
271 void hoverLeaveEvent(QHoverEvent *event) override;
272 void setTouchEventsEnabled(bool enable);
273 void itemChange(ItemChange change, const ItemChangeData &data) override;
274#endif
275
276private:
277 void ungrab(bool normalRelease = false);
278 QMap<int,QQuickTouchPoint*> _touchPrototypes; //TouchPoints defined in QML
279 QMap<int,QObject*> _touchPoints; //All current touch points
280 QList<QObject*> _releasedTouchPoints;
281 QList<QObject*> _pressedTouchPoints;
282 QList<QObject*> _movedTouchPoints;
283 int _minimumTouchPoints;
284 int _maximumTouchPoints;
285 QVector<int> _lastFilterableTouchPointIds;
286 QPointer<QQuickTouchPoint> _mouseTouchPoint; // exists when mouse button is down and _mouseEnabled is true; null otherwise
287 QEventPoint _mouseQpaTouchPoint; // synthetic QPA touch point to hold state and position of the mouse
288 const QPointingDevice *_touchMouseDevice;
289 QPointF _mousePos;
290 bool _stealMouse;
291 bool _mouseEnabled;
292};
293
294QT_END_NAMESPACE
295
296#endif // QQUICKMULTIPOINTTOUCHAREA_H
For specifying a pen used for drawing rectangle borders on a QQuickView.
\qmltype TextDocument \nativetype QQuickTextDocument \inqmlmodule QtQuick
Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid)
static void qt_quickitems_defineModule()
#define QQuickTextInterface_iid