1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKEVENTS_P_P_H
41#define QQUICKEVENTS_P_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <private/qtquickglobal_p.h>
55#include <qqml.h>
56
57#include <QtCore/qobject.h>
58#include <QtCore/qpointer.h>
59#include <QtGui/qvector2d.h>
60#include <QtGui/qevent.h>
61#include <QtGui/qkeysequence.h>
62#include <QtQuick/qquickitem.h>
63
64QT_BEGIN_NAMESPACE
65
66class QQuickPointerDevice;
67class QQuickPointerEvent;
68class QQuickPointerMouseEvent;
69#if QT_CONFIG(gestures)
70class QQuickPointerNativeGestureEvent;
71#endif
72class QQuickPointerScrollEvent;
73class QQuickPointerTabletEvent;
74class QQuickPointerTouchEvent;
75class QQuickPointerHandler;
76
77class QQuickKeyEvent : public QObject
78{
79 Q_OBJECT
80 Q_PROPERTY(int key READ key CONSTANT)
81 Q_PROPERTY(QString text READ text CONSTANT)
82 Q_PROPERTY(int modifiers READ modifiers CONSTANT)
83 Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat CONSTANT)
84 Q_PROPERTY(int count READ count CONSTANT)
85 Q_PROPERTY(quint32 nativeScanCode READ nativeScanCode CONSTANT)
86 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
87
88public:
89 QQuickKeyEvent()
90 : event(QEvent::None, 0, nullptr)
91 {}
92
93 void reset(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
94 const QString &text = QString(), bool autorep = false, ushort count = 1)
95 {
96 event = QKeyEvent(type, key, modifiers, text, autorep, count);
97 event.setAccepted(false);
98 }
99
100 void reset(const QKeyEvent &ke)
101 {
102 event = ke;
103 event.setAccepted(false);
104 }
105
106 int key() const { return event.key(); }
107 QString text() const { return event.text(); }
108 int modifiers() const { return event.modifiers(); }
109 bool isAutoRepeat() const { return event.isAutoRepeat(); }
110 int count() const { return event.count(); }
111 quint32 nativeScanCode() const { return event.nativeScanCode(); }
112
113 bool isAccepted() { return event.isAccepted(); }
114 void setAccepted(bool accepted) { event.setAccepted(accepted); }
115
116#if QT_CONFIG(shortcut)
117 Q_REVISION(2) Q_INVOKABLE bool matches(QKeySequence::StandardKey key) const { return event.matches(key); }
118#endif
119
120private:
121 QKeyEvent event;
122};
123
124// used in Qt Location
125class Q_QUICK_PRIVATE_EXPORT QQuickMouseEvent : public QObject
126{
127 Q_OBJECT
128 Q_PROPERTY(qreal x READ x CONSTANT)
129 Q_PROPERTY(qreal y READ y CONSTANT)
130 Q_PROPERTY(int button READ button CONSTANT)
131 Q_PROPERTY(int buttons READ buttons CONSTANT)
132 Q_PROPERTY(int modifiers READ modifiers CONSTANT)
133 Q_PROPERTY(int source READ source CONSTANT REVISION 7)
134 Q_PROPERTY(bool wasHeld READ wasHeld CONSTANT)
135 Q_PROPERTY(bool isClick READ isClick CONSTANT)
136 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
137 Q_PROPERTY(int flags READ flags CONSTANT REVISION 11)
138
139public:
140 QQuickMouseEvent()
141 : _buttons(Qt::NoButton), _modifiers(Qt::NoModifier)
142 , _wasHeld(false), _isClick(false), _accepted(false)
143 , _flags(Qt::MouseEventFlags(nullptr))
144 {}
145
146 void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons,
147 Qt::KeyboardModifiers modifiers, bool isClick = false, bool wasHeld = false,
148 Qt::MouseEventFlags flags = nullptr)
149 {
150 _x = x;
151 _y = y;
152 _button = button;
153 _buttons = buttons;
154 _modifiers = modifiers;
155 _source = Qt::MouseEventNotSynthesized;
156 _wasHeld = wasHeld;
157 _isClick = isClick;
158 _accepted = true;
159 _flags = flags;
160 }
161
162 qreal x() const { return _x; }
163 qreal y() const { return _y; }
164 int button() const { return _button; }
165 int buttons() const { return _buttons; }
166 int modifiers() const { return _modifiers; }
167 int source() const { return _source; }
168 bool wasHeld() const { return _wasHeld; }
169 bool isClick() const { return _isClick; }
170
171 // only for internal usage
172 void setX(qreal x) { _x = x; }
173 void setY(qreal y) { _y = y; }
174 void setPosition(const QPointF &point) { _x = point.x(); _y = point.y(); }
175 void setSource(Qt::MouseEventSource s) { _source = s; }
176
177 bool isAccepted() { return _accepted; }
178 void setAccepted(bool accepted) { _accepted = accepted; }
179 int flags() const { return _flags; }
180private:
181 qreal _x = 0;
182 qreal _y = 0;
183 Qt::MouseButton _button = Qt::NoButton;
184 Qt::MouseButtons _buttons;
185 Qt::KeyboardModifiers _modifiers;
186 Qt::MouseEventSource _source = Qt::MouseEventNotSynthesized;
187 bool _wasHeld : 1;
188 bool _isClick : 1;
189 bool _accepted : 1;
190 Qt::MouseEventFlags _flags;
191};
192
193class QQuickWheelEvent : public QObject
194{
195 Q_OBJECT
196 Q_PROPERTY(qreal x READ x CONSTANT)
197 Q_PROPERTY(qreal y READ y CONSTANT)
198 Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT)
199 Q_PROPERTY(QPoint pixelDelta READ pixelDelta CONSTANT)
200 Q_PROPERTY(int buttons READ buttons CONSTANT)
201 Q_PROPERTY(int modifiers READ modifiers CONSTANT)
202 Q_PROPERTY(bool inverted READ inverted CONSTANT)
203 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
204
205public:
206 QQuickWheelEvent()
207 : _buttons(Qt::NoButton), _modifiers(Qt::NoModifier)
208 {}
209
210 void reset(qreal x, qreal y, const QPoint &angleDelta, const QPoint &pixelDelta,
211 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, bool inverted)
212 {
213 _x = x;
214 _y = y;
215 _angleDelta = angleDelta;
216 _pixelDelta = pixelDelta;
217 _buttons = buttons;
218 _modifiers = modifiers;
219 _accepted = true;
220 _inverted = inverted;
221 }
222
223 qreal x() const { return _x; }
224 qreal y() const { return _y; }
225 QPoint angleDelta() const { return _angleDelta; }
226 QPoint pixelDelta() const { return _pixelDelta; }
227 int buttons() const { return _buttons; }
228 int modifiers() const { return _modifiers; }
229 bool inverted() const { return _inverted; }
230 bool isAccepted() { return _accepted; }
231 void setAccepted(bool accepted) { _accepted = accepted; }
232
233private:
234 qreal _x = 0;
235 qreal _y = 0;
236 QPoint _angleDelta;
237 QPoint _pixelDelta;
238 Qt::MouseButtons _buttons;
239 Qt::KeyboardModifiers _modifiers;
240 bool _inverted = false;
241 bool _accepted = false;
242};
243
244class Q_QUICK_PRIVATE_EXPORT QQuickCloseEvent : public QObject
245{
246 Q_OBJECT
247 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
248
249public:
250 QQuickCloseEvent() {}
251
252 bool isAccepted() { return _accepted; }
253 void setAccepted(bool accepted) { _accepted = accepted; }
254
255private:
256 bool _accepted = true;
257};
258
259class Q_QUICK_PRIVATE_EXPORT QQuickEventPoint : public QObject
260{
261 Q_OBJECT
262 Q_PROPERTY(QQuickPointerEvent *event READ pointerEvent CONSTANT)
263 Q_PROPERTY(QPointF position READ position CONSTANT)
264 Q_PROPERTY(QPointF scenePosition READ scenePosition CONSTANT)
265 Q_PROPERTY(QPointF scenePressPosition READ scenePressPosition CONSTANT)
266 Q_PROPERTY(QPointF sceneGrabPosition READ sceneGrabPosition CONSTANT)
267 Q_PROPERTY(State state READ state CONSTANT)
268 Q_PROPERTY(int pointId READ pointId CONSTANT)
269 Q_PROPERTY(qreal timeHeld READ timeHeld CONSTANT)
270 Q_PROPERTY(QVector2D velocity READ velocity CONSTANT)
271 Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
272 Q_PROPERTY(QObject *exclusiveGrabber READ exclusiveGrabber WRITE setExclusiveGrabber)
273
274public:
275 enum State {
276 Pressed = Qt::TouchPointPressed,
277 Updated = Qt::TouchPointMoved,
278 Stationary = Qt::TouchPointStationary,
279 Released = Qt::TouchPointReleased
280 };
281 Q_DECLARE_FLAGS(States, State)
282 Q_FLAG(States)
283
284 enum GrabTransition {
285 GrabPassive = 0x01,
286 UngrabPassive = 0x02,
287 CancelGrabPassive = 0x03,
288 OverrideGrabPassive = 0x04,
289 GrabExclusive = 0x10,
290 UngrabExclusive = 0x20,
291 CancelGrabExclusive = 0x30,
292 };
293 Q_ENUM(GrabTransition)
294
295 QQuickEventPoint(QQuickPointerEvent *parent);
296
297 void reset(Qt::TouchPointState state, const QPointF &scenePosition, int pointId, ulong timestamp, const QVector2D &velocity = QVector2D());
298 void localizePosition(QQuickItem *target);
299
300 QQuickPointerEvent *pointerEvent() const;
301 QPointF position() const { return m_pos; }
302 QPointF scenePosition() const { return m_scenePos; }
303 QPointF scenePressPosition() const { return m_scenePressPos; }
304 QPointF sceneGrabPosition() const { return m_sceneGrabPos; }
305 QVector2D velocity() const { return m_velocity; }
306 State state() const { return m_state; }
307 int pointId() const { return m_pointId; }
308 qreal timeHeld() const { return (m_timestamp - m_pressTimestamp) / 1000.0; }
309 bool isAccepted() const { return m_accept; }
310 void setAccepted(bool accepted = true);
311 QObject *exclusiveGrabber() const;
312 void setExclusiveGrabber(QObject *exclusiveGrabber);
313
314 QQuickItem *grabberItem() const;
315 void setGrabberItem(QQuickItem *exclusiveGrabber);
316
317 QQuickPointerHandler *grabberPointerHandler() const;
318 void setGrabberPointerHandler(QQuickPointerHandler *exclusiveGrabber, bool exclusive = false);
319
320 void cancelExclusiveGrab();
321 void cancelPassiveGrab(QQuickPointerHandler *handler);
322 bool removePassiveGrabber(QQuickPointerHandler *handler);
323 void cancelAllGrabs(QQuickPointerHandler *handler);
324
325 QVector<QPointer <QQuickPointerHandler> > passiveGrabbers() const { return m_passiveGrabbers; }
326 void setPassiveGrabbers(const QVector<QPointer <QQuickPointerHandler> > &grabbers) { m_passiveGrabbers = grabbers; }
327 void clearPassiveGrabbers() { m_passiveGrabbers.clear(); }
328
329protected:
330 void cancelExclusiveGrabImpl(QTouchEvent *cancelEvent = nullptr);
331
332private:
333 QVector2D estimatedVelocity() const;
334
335protected:
336 QPointF m_pos;
337 QPointF m_scenePos;
338 QPointF m_scenePressPos;
339 QPointF m_sceneGrabPos;
340 QVector2D m_velocity;
341 int m_pointId;
342 QPointer<QObject> m_exclusiveGrabber;
343 QVector<QPointer <QQuickPointerHandler> > m_passiveGrabbers;
344 ulong m_timestamp;
345 ulong m_pressTimestamp;
346 State m_state;
347 bool m_accept : 1;
348 bool m_grabberIsHandler : 1;
349 int m_reserved : 29;
350
351 friend class QQuickPointerTouchEvent;
352 friend class QQuickWindowPrivate;
353
354 Q_DISABLE_COPY(QQuickEventPoint)
355};
356
357class Q_QUICK_PRIVATE_EXPORT QQuickEventTouchPoint : public QQuickEventPoint
358{
359 Q_OBJECT
360 Q_PROPERTY(qreal rotation READ rotation)
361 Q_PROPERTY(qreal pressure READ pressure)
362 Q_PROPERTY(QSizeF ellipseDiameters READ ellipseDiameters)
363 Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId)
364
365public:
366 QQuickEventTouchPoint(QQuickPointerTouchEvent *parent);
367
368 void reset(const QTouchEvent::TouchPoint &tp, ulong timestamp);
369
370 qreal rotation() const { return m_rotation; }
371 qreal pressure() const { return m_pressure; }
372 QSizeF ellipseDiameters() const { return m_ellipseDiameters; }
373 QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; }
374
375private:
376 qreal m_rotation;
377 qreal m_pressure;
378 QSizeF m_ellipseDiameters;
379 QPointingDeviceUniqueId m_uniqueId;
380
381 friend class QQuickPointerTouchEvent;
382
383 Q_DISABLE_COPY(QQuickEventTouchPoint)
384};
385
386class Q_QUICK_PRIVATE_EXPORT QQuickPointerEvent : public QObject
387{
388 Q_OBJECT
389 Q_PROPERTY(QQuickPointerDevice *device READ device CONSTANT)
390 Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers CONSTANT)
391 Q_PROPERTY(Qt::MouseButtons button READ button CONSTANT)
392 Q_PROPERTY(Qt::MouseButtons buttons READ buttons CONSTANT)
393
394public:
395 QQuickPointerEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
396 : QObject(parent)
397 , m_device(device)
398 , m_pressedButtons(Qt::NoButton)
399 {}
400
401 ~QQuickPointerEvent() override;
402
403public: // property accessors
404 QQuickPointerDevice *device() const { return m_device; }
405 Qt::KeyboardModifiers modifiers() const { return m_event ? m_event->modifiers() : Qt::NoModifier; }
406 Qt::MouseButton button() const { return m_button; }
407 Qt::MouseButtons buttons() const { return m_pressedButtons; }
408
409public: // helpers for C++ only (during event delivery)
410 virtual QQuickPointerEvent *reset(QEvent *ev) = 0;
411 virtual void localize(QQuickItem *target) = 0;
412
413 virtual bool isPressEvent() const = 0;
414 virtual bool isDoubleClickEvent() const { return false; }
415 virtual bool isUpdateEvent() const = 0;
416 virtual bool isReleaseEvent() const = 0;
417 virtual QQuickPointerMouseEvent *asPointerMouseEvent() { return nullptr; }
418 virtual QQuickPointerTouchEvent *asPointerTouchEvent() { return nullptr; }
419 virtual QQuickPointerTabletEvent *asPointerTabletEvent() { return nullptr; }
420#if QT_CONFIG(gestures)
421 virtual QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() { return nullptr; }
422#endif
423 virtual QQuickPointerScrollEvent *asPointerScrollEvent() { return nullptr; }
424 virtual const QQuickPointerMouseEvent *asPointerMouseEvent() const { return nullptr; }
425 virtual const QQuickPointerTouchEvent *asPointerTouchEvent() const { return nullptr; }
426 virtual const QQuickPointerTabletEvent *asPointerTabletEvent() const { return nullptr; }
427#if QT_CONFIG(gestures)
428 virtual const QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() const { return nullptr; }
429#endif
430 virtual const QQuickPointerScrollEvent *asPointerScrollEvent() const { return nullptr; }
431 virtual bool allPointsAccepted() const = 0;
432 virtual bool allUpdatedPointsAccepted() const = 0;
433 virtual bool allPointsGrabbed() const = 0;
434 bool isAccepted() { return m_event ? m_event->isAccepted() : false; }
435 void setAccepted(bool accepted) { if (m_event) m_event->setAccepted(accepted); }
436 QVector<QPointF> unacceptedPressedPointScenePositions() const;
437
438 virtual int pointCount() const = 0;
439 virtual QQuickEventPoint *point(int i) const = 0;
440 virtual QQuickEventPoint *pointById(int pointId) const = 0;
441 virtual QVector<QObject *> exclusiveGrabbers() const = 0;
442 virtual void clearGrabbers() const = 0;
443 virtual bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const = 0;
444
445 ulong timestamp() const { return m_event ? m_event->timestamp() : 0; }
446
447protected:
448 QQuickPointerDevice *m_device;
449 QInputEvent *m_event = nullptr; // original event as received by QQuickWindow
450 Qt::MouseButton m_button = Qt::NoButton;
451 Qt::MouseButtons m_pressedButtons;
452
453 friend class QQuickWindowPrivate;
454
455 Q_DISABLE_COPY(QQuickPointerEvent)
456};
457
458class Q_QUICK_PRIVATE_EXPORT QQuickSinglePointEvent : public QQuickPointerEvent
459{
460 Q_OBJECT
461public:
462 QQuickSinglePointEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
463 : QQuickPointerEvent(parent, device), m_point(new QQuickEventPoint(this)) { }
464
465 void localize(QQuickItem *target) override;
466 int pointCount() const override { return 1; }
467 QQuickEventPoint *point(int i) const override;
468 QQuickEventPoint *pointById(int pointId) const override;
469 bool allPointsAccepted() const override;
470 bool allUpdatedPointsAccepted() const override;
471 bool allPointsGrabbed() const override;
472 QVector<QObject *> exclusiveGrabbers() const override;
473 void clearGrabbers() const override;
474 bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const override;
475
476protected:
477 QQuickEventPoint *m_point;
478
479 Q_DISABLE_COPY(QQuickSinglePointEvent)
480};
481
482class Q_QUICK_PRIVATE_EXPORT QQuickPointerMouseEvent : public QQuickSinglePointEvent
483{
484 Q_OBJECT
485public:
486 QQuickPointerMouseEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
487 : QQuickSinglePointEvent(parent, device) { }
488
489 QQuickPointerEvent *reset(QEvent *) override;
490 bool isPressEvent() const override;
491 bool isDoubleClickEvent() const override;
492 bool isUpdateEvent() const override;
493 bool isReleaseEvent() const override;
494 QQuickPointerMouseEvent *asPointerMouseEvent() override { return this; }
495 const QQuickPointerMouseEvent *asPointerMouseEvent() const override { return this; }
496
497 QMouseEvent *asMouseEvent(const QPointF& localPos) const;
498
499 Q_DISABLE_COPY(QQuickPointerMouseEvent)
500};
501
502class Q_QUICK_PRIVATE_EXPORT QQuickPointerTouchEvent : public QQuickPointerEvent
503{
504 Q_OBJECT
505public:
506 QQuickPointerTouchEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
507 : QQuickPointerEvent(parent, device)
508 , m_synthMouseEvent(QEvent::MouseMove, QPointF(), Qt::NoButton, Qt::NoButton, Qt::NoModifier)
509 {}
510
511 QQuickPointerEvent *reset(QEvent *) override;
512 void localize(QQuickItem *target) override;
513 bool isPressEvent() const override;
514 bool isUpdateEvent() const override;
515 bool isReleaseEvent() const override;
516 QQuickPointerTouchEvent *asPointerTouchEvent() override { return this; }
517 const QQuickPointerTouchEvent *asPointerTouchEvent() const override { return this; }
518 int pointCount() const override { return m_pointCount; }
519 QQuickEventPoint *point(int i) const override;
520 QQuickEventPoint *pointById(int pointId) const override;
521 const QTouchEvent::TouchPoint *touchPointById(int pointId) const;
522 bool allPointsAccepted() const override;
523 bool allUpdatedPointsAccepted() const override;
524 bool allPointsGrabbed() const override;
525 QVector<QObject *> exclusiveGrabbers() const override;
526 void clearGrabbers() const override;
527 bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const override;
528
529 QMouseEvent *syntheticMouseEvent(int pointID, QQuickItem *relativeTo) const;
530 QTouchEvent *touchEventForItem(QQuickItem *item, bool isFiltering = false) const;
531
532 QTouchEvent *asTouchEvent() const;
533
534private:
535 Qt::TouchPointStates touchPointStates() const;
536
537 int m_pointCount = 0;
538 QVector<QQuickEventTouchPoint *> m_touchPoints;
539 mutable QMouseEvent m_synthMouseEvent;
540
541 Q_DISABLE_COPY(QQuickPointerTouchEvent)
542};
543
544#if QT_CONFIG(gestures)
545class Q_QUICK_PRIVATE_EXPORT QQuickPointerNativeGestureEvent : public QQuickSinglePointEvent
546{
547 Q_OBJECT
548 Q_PROPERTY(Qt::NativeGestureType type READ type CONSTANT)
549 Q_PROPERTY(qreal value READ value CONSTANT)
550
551public:
552 QQuickPointerNativeGestureEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
553 : QQuickSinglePointEvent(parent, device) { }
554
555 QQuickPointerEvent *reset(QEvent *) override;
556 bool isPressEvent() const override;
557 bool isUpdateEvent() const override;
558 bool isReleaseEvent() const override;
559 QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() override { return this; }
560 const QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() const override { return this; }
561 Qt::NativeGestureType type() const;
562 qreal value() const;
563
564 Q_DISABLE_COPY(QQuickPointerNativeGestureEvent)
565};
566#endif // QT_CONFIG(gestures)
567
568class Q_QUICK_PRIVATE_EXPORT QQuickPointerScrollEvent : public QQuickSinglePointEvent
569{
570 Q_OBJECT
571 Q_PROPERTY(QVector2D angleDelta READ angleDelta CONSTANT)
572 Q_PROPERTY(QVector2D pixelDelta READ pixelDelta CONSTANT)
573 Q_PROPERTY(bool hasAngleDelta READ hasAngleDelta CONSTANT)
574 Q_PROPERTY(bool hasPixelDelta READ hasPixelDelta CONSTANT)
575 Q_PROPERTY(bool inverted READ isInverted CONSTANT)
576
577public:
578 QQuickPointerScrollEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
579 : QQuickSinglePointEvent(parent, device) { }
580
581 QQuickPointerEvent *reset(QEvent *) override;
582 void localize(QQuickItem *target) override;
583 bool isPressEvent() const override;
584 bool isUpdateEvent() const override;
585 bool isReleaseEvent() const override;
586 QQuickPointerScrollEvent *asPointerScrollEvent() override { return this; }
587 const QQuickPointerScrollEvent *asPointerScrollEvent() const override { return this; }
588 QVector2D angleDelta() const { return m_angleDelta; }
589 QVector2D pixelDelta() const { return m_pixelDelta; }
590 bool hasAngleDelta() const { return !angleDelta().isNull(); }
591 bool hasPixelDelta() const { return !pixelDelta().isNull(); }
592 bool isInverted() const { return m_inverted; }
593 Qt::ScrollPhase phase() const { return m_phase; }
594
595private:
596 // TODO add QQuickPointerDevice source() whenever QInputEvent is extended to have a source device
597 // then maybe Qt::MouseEventSource synthSource() will be obsolete... that's why it's not public now
598 Qt::MouseEventSource synthSource() const { return m_synthSource; }
599
600private:
601 QVector2D m_angleDelta;
602 QVector2D m_pixelDelta;
603 Qt::ScrollPhase m_phase = Qt::NoScrollPhase;
604 Qt::MouseEventSource m_synthSource = Qt::MouseEventNotSynthesized;
605 bool m_inverted = false;
606
607 friend class QQuickWindowPrivate;
608 friend class QQuickWheelHandler;
609
610 Q_DISABLE_COPY(QQuickPointerScrollEvent)
611};
612
613
614// ### Qt 6: move this to qtbase, replace QTouchDevice and the enums in QTabletEvent
615class Q_QUICK_PRIVATE_EXPORT QQuickPointerDevice : public QObject
616{
617 Q_OBJECT
618 Q_PROPERTY(DeviceType type READ type CONSTANT)
619 Q_PROPERTY(PointerType pointerType READ pointerType CONSTANT)
620 Q_PROPERTY(Capabilities capabilities READ capabilities CONSTANT)
621 Q_PROPERTY(int maximumTouchPoints READ maximumTouchPoints CONSTANT)
622 Q_PROPERTY(int buttonCount READ buttonCount CONSTANT)
623 Q_PROPERTY(QString name READ name CONSTANT)
624 Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId CONSTANT)
625
626public:
627 enum DeviceType : qint16 {
628 UnknownDevice = 0x0000,
629 Mouse = 0x0001,
630 TouchScreen = 0x0002,
631 TouchPad = 0x0004,
632 Puck = 0x0008,
633 Stylus = 0x0010,
634 Airbrush = 0x0020,
635 AllDevices = 0x7FFF
636 };
637 Q_DECLARE_FLAGS(DeviceTypes, DeviceType)
638 Q_FLAG(DeviceTypes)
639
640 enum PointerType : qint16 {
641 GenericPointer = 0x0001,
642 Finger = 0x0002,
643 Pen = 0x0004,
644 Eraser = 0x0008,
645 Cursor = 0x0010,
646 AllPointerTypes = 0x7FFF
647 };
648 Q_DECLARE_FLAGS(PointerTypes, PointerType)
649 Q_FLAG(PointerTypes)
650
651 enum CapabilityFlag : qint16 {
652 Position = QTouchDevice::Position,
653 Area = QTouchDevice::Area,
654 Pressure = QTouchDevice::Pressure,
655 Velocity = QTouchDevice::Velocity,
656 MouseEmulation = QTouchDevice::MouseEmulation,
657 // some bits reserved in case we need more of QTouchDevice::Capabilities
658 Scroll = 0x0100, // mouse has a wheel, or there is OS-level scroll gesture recognition (dubious?)
659 Hover = 0x0200,
660 Rotation = 0x0400,
661 XTilt = 0x0800,
662 YTilt = 0x1000
663 };
664 Q_DECLARE_FLAGS(Capabilities, CapabilityFlag)
665 Q_FLAG(Capabilities)
666
667 DeviceType type() const { return m_deviceType; }
668 PointerType pointerType() const { return m_pointerType; }
669 Capabilities capabilities() const { return static_cast<Capabilities>(m_capabilities); }
670 bool hasCapability(CapabilityFlag cap) { return m_capabilities & cap; }
671 int maximumTouchPoints() const { return m_maximumTouchPoints; }
672 int buttonCount() const { return m_buttonCount; }
673 QString name() const { return m_name; }
674 QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; }
675 const QTouchDevice *qTouchDevice() const;
676
677 static QQuickPointerDevice *touchDevice(const QTouchDevice *d);
678 static QList<QQuickPointerDevice *> touchDevices();
679 static QQuickPointerDevice *genericMouseDevice();
680 static QQuickPointerDevice *tabletDevice(qint64);
681
682 QVector<QQuickPointerHandler *> &eventDeliveryTargets() { return m_eventDeliveryTargets; }
683
684private:
685 QQuickPointerDevice(DeviceType devType, PointerType pType, Capabilities caps, int maxPoints, int buttonCount, const QString &name, qint64 uniqueId = 0)
686 : m_deviceType(devType), m_pointerType(pType), m_capabilities(static_cast<qint16>(caps))
687 , m_maximumTouchPoints(static_cast<qint8>(maxPoints)), m_buttonCount(static_cast<qint8>(buttonCount)), m_name(name)
688 , m_uniqueId(QPointingDeviceUniqueId::fromNumericId(uniqueId))
689 {
690 }
691 ~QQuickPointerDevice() override { }
692
693private:
694 // begin 64-bit field
695 DeviceType m_deviceType;
696 PointerType m_pointerType;
697 qint16 m_capabilities;
698 qint8 m_maximumTouchPoints;
699 qint8 m_buttonCount;
700 // end 64-bit field
701 QString m_name;
702 QPointingDeviceUniqueId m_uniqueId;
703 QVector<QQuickPointerHandler *> m_eventDeliveryTargets; // during delivery, handlers which have already seen the event
704
705 Q_DISABLE_COPY(QQuickPointerDevice)
706 friend struct ConstructableQQuickPointerDevice;
707};
708
709Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::DeviceTypes)
710Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::PointerTypes)
711Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::Capabilities)
712
713Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickPointerDevice *);
714Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickPointerEvent *);
715Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventPoint *);
716//Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventTouchPoint *); TODO maybe
717
718QT_END_NAMESPACE
719
720QML_DECLARE_TYPE(QQuickKeyEvent)
721QML_DECLARE_TYPE(QQuickMouseEvent)
722QML_DECLARE_TYPE(QQuickWheelEvent)
723QML_DECLARE_TYPE(QQuickCloseEvent)
724QML_DECLARE_TYPE(QQuickPointerDevice)
725QML_DECLARE_TYPE(QPointingDeviceUniqueId)
726QML_DECLARE_TYPE(QQuickPointerEvent)
727Q_DECLARE_METATYPE(QQuickEventPoint::GrabTransition)
728
729#endif // QQUICKEVENTS_P_P_H
730