aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickevents_p_p.h
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-07-23 13:56:26 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-09-18 20:56:25 +0200
commita97759a336c597327cb82eebc9f45c793aec32c9 (patch)
tree632bbee8568d38af56974e02df5810afcf48aedc /src/quick/items/qquickevents_p_p.h
parent39f4d687fc37f48cbc181f42797c42be91b4a345 (diff)
Remove QQuickPointerEvent etc.; deliver QPointerEvents directly
QEventPoint does not have an accessor to get the QPointerEvent that it came from, because that's inconsistent with the idea that QPointerEvent instances are temporary, stack-allocated and movable (the pointer would often be wrong or null, therefore could not be relied upon). So most functions that worked directly with QQuickEventPoint before (which fortunately are still private API) now need to receive the QPointerEvent too, which we choose to pass by pointer. QEventPoint is always passed by reference (const where possible) to be consistent with functions in QPointerEvent that take QEventPoint by reference. QEventPoint::velocity() should be always in scene coordinates now, which saves us the trouble of transforming it to each item's coordinate system during delivery, but means that it will need to be done in handlers or applications sometimes. If we were going to transform it, it would be important to also store the sceneVelocity separately in QEventPoint so that the transformation could be done repeatedly for different items. Task-number: QTBUG-72173 Change-Id: I7ee164d2e6893c4e407fb7d579c75aa32843933a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/quick/items/qquickevents_p_p.h')
-rw-r--r--src/quick/items/qquickevents_p_p.h448
1 files changed, 3 insertions, 445 deletions
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index b491445323..9b89d8300e 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -68,14 +68,8 @@
QT_BEGIN_NAMESPACE
class QPointingDevice;
-class QQuickPointerEvent;
-class QQuickPointerMouseEvent;
-#if QT_CONFIG(gestures)
-class QQuickPointerNativeGestureEvent;
-#endif
-class QQuickPointerScrollEvent;
-class QQuickPointerTabletEvent;
-class QQuickPointerTouchEvent;
+class QPointerEvent;
+class QMouseEvent;
class QQuickPointerHandler;
class QQuickKeyEvent : public QObject
@@ -267,441 +261,6 @@ private:
bool _accepted = true;
};
-class Q_QUICK_PRIVATE_EXPORT QQuickEventPoint : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QQuickPointerEvent *event READ pointerEvent CONSTANT)
- Q_PROPERTY(QPointF position READ position CONSTANT)
- Q_PROPERTY(QPointF scenePosition READ scenePosition CONSTANT)
- Q_PROPERTY(QPointF scenePressPosition READ scenePressPosition CONSTANT)
- Q_PROPERTY(QPointF sceneGrabPosition READ sceneGrabPosition CONSTANT)
- Q_PROPERTY(State state READ state CONSTANT)
- Q_PROPERTY(int pointId READ pointId CONSTANT)
- Q_PROPERTY(qreal timeHeld READ timeHeld CONSTANT)
- Q_PROPERTY(QVector2D velocity READ velocity CONSTANT)
- Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
- Q_PROPERTY(QObject *exclusiveGrabber READ exclusiveGrabber WRITE setExclusiveGrabber)
-
- QML_NAMED_ELEMENT(EventPoint)
- QML_UNCREATABLE("EventPoint is only available as a member of PointerEvent.")
- QML_ADDED_IN_VERSION(2, 12)
-
-public:
- enum State {
- Pressed = QEventPoint::State::Pressed,
- Updated = QEventPoint::State::Updated,
- Stationary = QEventPoint::State::Stationary,
- Released = QEventPoint::State::Released
- };
- Q_DECLARE_FLAGS(States, State)
- Q_FLAG(States)
-
- enum GrabTransition {
- GrabPassive = 0x01,
- UngrabPassive = 0x02,
- CancelGrabPassive = 0x03,
- OverrideGrabPassive = 0x04,
- GrabExclusive = 0x10,
- UngrabExclusive = 0x20,
- CancelGrabExclusive = 0x30,
- };
- Q_ENUM(GrabTransition)
-
- QQuickEventPoint(QQuickPointerEvent *parent);
-
- void reset(QEventPoint::State state, const QPointF &scenePosition, int pointId, ulong timestamp, const QVector2D &velocity = QVector2D());
- void localizePosition(QQuickItem *target);
-
- QQuickPointerEvent *pointerEvent() const;
- QPointF position() const { return m_pos; }
- QPointF scenePosition() const { return m_scenePos; }
- QPointF scenePressPosition() const { return m_scenePressPos; }
- QPointF sceneGrabPosition() const { return m_sceneGrabPos; }
- QVector2D velocity() const { return m_velocity; }
- State state() const { return m_state; }
- int pointId() const { return m_pointId; }
- qreal timeHeld() const { return (m_timestamp - m_pressTimestamp) / 1000.0; }
- bool isAccepted() const { return m_accept; }
- void setAccepted(bool accepted = true);
- QObject *exclusiveGrabber() const;
- void setExclusiveGrabber(QObject *exclusiveGrabber);
-
- QQuickItem *grabberItem() const;
- void setGrabberItem(QQuickItem *exclusiveGrabber);
-
- QQuickPointerHandler *grabberPointerHandler() const;
- void setGrabberPointerHandler(QQuickPointerHandler *exclusiveGrabber, bool exclusive = false);
-
- void cancelExclusiveGrab();
- void cancelPassiveGrab(QQuickPointerHandler *handler);
- bool removePassiveGrabber(QQuickPointerHandler *handler);
- void cancelAllGrabs(QQuickPointerHandler *handler);
-
- QVector<QPointer <QQuickPointerHandler> > passiveGrabbers() const { return m_passiveGrabbers; }
- void setPassiveGrabbers(const QVector<QPointer <QQuickPointerHandler> > &grabbers) { m_passiveGrabbers = grabbers; }
- void clearPassiveGrabbers() { m_passiveGrabbers.clear(); }
-
-protected:
- void cancelExclusiveGrabImpl(QTouchEvent *cancelEvent = nullptr);
-
-private:
- QVector2D estimatedVelocity() const;
-
-protected:
- QPointF m_pos;
- QPointF m_scenePos;
- QPointF m_scenePressPos;
- QPointF m_sceneGrabPos;
- QVector2D m_velocity;
- int m_pointId;
- QPointer<QObject> m_exclusiveGrabber;
- QVector<QPointer <QQuickPointerHandler> > m_passiveGrabbers;
- ulong m_timestamp;
- ulong m_pressTimestamp;
- State m_state;
- bool m_accept : 1;
- bool m_grabberIsHandler : 1;
- int m_reserved : 29;
-
- friend class QQuickPointerTouchEvent;
- friend class QQuickWindowPrivate;
-
- Q_DISABLE_COPY(QQuickEventPoint)
-};
-
-class Q_QUICK_PRIVATE_EXPORT QQuickEventTouchPoint : public QQuickEventPoint
-{
- Q_OBJECT
- Q_PROPERTY(qreal rotation READ rotation)
- Q_PROPERTY(qreal pressure READ pressure)
- Q_PROPERTY(QSizeF ellipseDiameters READ ellipseDiameters)
- Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId)
-
- QML_NAMED_ELEMENT(EventTouchPoint)
- QML_UNCREATABLE("EventTouchPoint is only available as a member of PointerEvent.")
- QML_ADDED_IN_VERSION(2, 12)
-
-public:
- QQuickEventTouchPoint(QQuickPointerTouchEvent *parent);
-
- void reset(const QEventPoint &tp, ulong timestamp);
-
- qreal rotation() const { return m_rotation; }
- qreal pressure() const { return m_pressure; }
- QSizeF ellipseDiameters() const { return m_ellipseDiameters; }
- QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; }
-
-private:
- qreal m_rotation;
- qreal m_pressure;
- QSizeF m_ellipseDiameters;
- QPointingDeviceUniqueId m_uniqueId;
-
- friend class QQuickPointerTouchEvent;
-
- Q_DISABLE_COPY(QQuickEventTouchPoint)
-};
-
-class Q_QUICK_PRIVATE_EXPORT QQuickPointerEvent : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QPointingDevice *device READ device CONSTANT)
- Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers CONSTANT)
- Q_PROPERTY(Qt::MouseButtons button READ button CONSTANT)
- Q_PROPERTY(Qt::MouseButtons buttons READ buttons CONSTANT)
-
- QML_NAMED_ELEMENT(PointerEvent)
- QML_UNCREATABLE("PointerEvent is only available as a parameter of several signals in PointerHandler")
- QML_ADDED_IN_VERSION(2, 12)
-
-public:
- QQuickPointerEvent(QObject *parent = nullptr, const QPointingDevice *device = nullptr)
- : QObject(parent)
- , m_device(device)
- , m_pressedButtons(Qt::NoButton)
- {}
-
- ~QQuickPointerEvent() override;
-
-public: // property accessors
- // non-const only because of QML engine limitations (similar to QTBUG-61749)
- QPointingDevice *device() const { return const_cast<QPointingDevice *>(m_device); }
- Qt::KeyboardModifiers modifiers() const { return m_event ? m_event->modifiers() : Qt::NoModifier; }
- Qt::MouseButton button() const { return m_button; }
- Qt::MouseButtons buttons() const { return m_pressedButtons; }
-
-public: // helpers for C++ only (during event delivery)
- virtual QQuickPointerEvent *reset(QEvent *ev) = 0;
- virtual void localize(QQuickItem *target) = 0;
-
- virtual bool isPressEvent() const = 0;
- virtual bool isDoubleClickEvent() const { return false; }
- virtual bool isUpdateEvent() const = 0;
- virtual bool isReleaseEvent() const = 0;
- virtual QQuickPointerMouseEvent *asPointerMouseEvent() { return nullptr; }
- virtual QQuickPointerTouchEvent *asPointerTouchEvent() { return nullptr; }
- virtual QQuickPointerTabletEvent *asPointerTabletEvent() { return nullptr; }
-#if QT_CONFIG(gestures)
- virtual QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() { return nullptr; }
-#endif
- virtual QQuickPointerScrollEvent *asPointerScrollEvent() { return nullptr; }
- virtual const QQuickPointerMouseEvent *asPointerMouseEvent() const { return nullptr; }
- virtual const QQuickPointerTouchEvent *asPointerTouchEvent() const { return nullptr; }
- virtual const QQuickPointerTabletEvent *asPointerTabletEvent() const { return nullptr; }
-#if QT_CONFIG(gestures)
- virtual const QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() const { return nullptr; }
-#endif
- virtual const QQuickPointerScrollEvent *asPointerScrollEvent() const { return nullptr; }
- virtual bool allPointsAccepted() const = 0;
- virtual bool allUpdatedPointsAccepted() const = 0;
- virtual bool allPointsGrabbed() const = 0;
- bool isAccepted() { return m_event ? m_event->isAccepted() : false; }
- void setAccepted(bool accepted) { if (m_event) m_event->setAccepted(accepted); }
- QVector<QPointF> unacceptedPressedPointScenePositions() const;
-
- virtual int pointCount() const = 0;
- virtual QQuickEventPoint *point(int i) const = 0;
- virtual QQuickEventPoint *pointById(int pointId) const = 0;
- virtual QVector<QObject *> exclusiveGrabbers() const = 0;
- virtual void clearGrabbers() const = 0;
- virtual bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const = 0;
-
- ulong timestamp() const { return m_event ? m_event->timestamp() : 0; }
-
-protected:
- const QPointingDevice *m_device = nullptr;
- QPointerEvent *m_event = nullptr; // original event as received by QQuickWindow
- Qt::MouseButton m_button = Qt::NoButton;
- Qt::MouseButtons m_pressedButtons;
-
- friend class QQuickWindowPrivate;
-
- Q_DISABLE_COPY(QQuickPointerEvent)
-};
-
-class Q_QUICK_PRIVATE_EXPORT QQuickSinglePointEvent : public QQuickPointerEvent
-{
- Q_OBJECT
-public:
- QQuickSinglePointEvent(QObject *parent, const QPointingDevice *device)
- : QQuickPointerEvent(parent, device) { }
-
- void localize(QQuickItem *target) override;
- int pointCount() const override { return 1; }
- QQuickEventPoint *point(int i) const override;
- QQuickEventPoint *pointById(int pointId) const override;
- bool allPointsAccepted() const override;
- bool allUpdatedPointsAccepted() const override;
- bool allPointsGrabbed() const override;
- QVector<QObject *> exclusiveGrabbers() const override;
- void clearGrabbers() const override;
- bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const override;
-
-protected:
- QQuickEventPoint *m_point = nullptr;
-
- Q_DISABLE_COPY(QQuickSinglePointEvent)
-};
-
-class Q_QUICK_PRIVATE_EXPORT QQuickPointerMouseEvent : public QQuickSinglePointEvent
-{
- Q_OBJECT
-
- QML_NAMED_ELEMENT(PointerMouseEvent)
- QML_UNCREATABLE("PointerMouseEvent is only available as a parameter of several signals in PointerHandler")
- QML_ADDED_IN_VERSION(2, 12)
-
-public:
- QQuickPointerMouseEvent(QObject *parent, const QPointingDevice *device);
-
- QQuickPointerEvent *reset(QEvent *) override;
- bool isPressEvent() const override;
- bool isDoubleClickEvent() const override;
- bool isUpdateEvent() const override;
- bool isReleaseEvent() const override;
- QQuickPointerMouseEvent *asPointerMouseEvent() override { return this; }
- const QQuickPointerMouseEvent *asPointerMouseEvent() const override { return this; }
-
- QMouseEvent *asMouseEvent(const QPointF& localPos) const;
-
- Q_DISABLE_COPY(QQuickPointerMouseEvent)
-};
-
-class Q_QUICK_PRIVATE_EXPORT QQuickPointerTouchEvent : public QQuickPointerEvent
-{
- Q_OBJECT
-
- QML_NAMED_ELEMENT(PointerTouchEvent)
- QML_UNCREATABLE("PointerTouchEvent is only available as a parameter of several signals in PointerHandler")
- QML_ADDED_IN_VERSION(2, 12)
-
-public:
- QQuickPointerTouchEvent(QObject *parent = nullptr, const QPointingDevice *device = nullptr)
- : QQuickPointerEvent(parent, device)
- , m_synthMouseEvent(QEvent::MouseMove, QPointF(), Qt::NoButton, Qt::NoButton, Qt::NoModifier)
- {}
-
- QQuickPointerEvent *reset(QEvent *) override;
- void localize(QQuickItem *target) override;
- bool isPressEvent() const override;
- bool isUpdateEvent() const override;
- bool isReleaseEvent() const override;
- QQuickPointerTouchEvent *asPointerTouchEvent() override { return this; }
- const QQuickPointerTouchEvent *asPointerTouchEvent() const override { return this; }
- int pointCount() const override { return m_pointCount; }
- QQuickEventPoint *point(int i) const override;
- QQuickEventPoint *pointById(int pointId) const override;
- const QEventPoint *touchPointById(int pointId) const;
- bool allPointsAccepted() const override;
- bool allUpdatedPointsAccepted() const override;
- bool allPointsGrabbed() const override;
- QVector<QObject *> exclusiveGrabbers() const override;
- void clearGrabbers() const override;
- bool hasExclusiveGrabber(const QQuickPointerHandler *handler) const override;
-
- QMouseEvent *syntheticMouseEvent(int pointID, QQuickItem *relativeTo) const;
- QTouchEvent *touchEventForItem(QQuickItem *item, bool isFiltering = false) const;
-
- QTouchEvent *asTouchEvent() const;
-
-private:
- QEventPoint::States touchPointStates() const;
-
- int m_pointCount = 0;
- QVector<QQuickEventTouchPoint *> m_touchPoints;
- mutable QMouseEvent m_synthMouseEvent;
-
- Q_DISABLE_COPY(QQuickPointerTouchEvent)
-};
-
-#if QT_CONFIG(tabletevent)
-class Q_QUICK_PRIVATE_EXPORT QQuickEventTabletPoint : public QQuickEventPoint
-{
- Q_OBJECT
- Q_PROPERTY(qreal rotation READ rotation)
- Q_PROPERTY(qreal pressure READ pressure)
- Q_PROPERTY(qreal tangentialPressure READ tangentialPressure)
- Q_PROPERTY(QVector2D tilt READ tilt)
-
- QML_NAMED_ELEMENT(EventTabletPoint)
- QML_UNCREATABLE("EventTouchPoint is only available as a member of PointerEvent.")
- QML_ADDED_IN_VERSION(2, 15)
-
-public:
- QQuickEventTabletPoint(QQuickPointerTabletEvent *parent);
-
- void reset(const QTabletEvent *e);
-
- qreal rotation() const { return m_rotation; }
- qreal pressure() const { return m_pressure; }
- qreal tangentialPressure() const { return m_tangentialPressure; }
- QVector2D tilt() const { return m_tilt; }
-
-private:
- qreal m_rotation;
- qreal m_pressure;
- qreal m_tangentialPressure;
- QVector2D m_tilt;
-
- friend class QQuickPointerTouchEvent;
-
- Q_DISABLE_COPY(QQuickEventTabletPoint)
-};
-
-class Q_QUICK_PRIVATE_EXPORT QQuickPointerTabletEvent : public QQuickSinglePointEvent
-{
- Q_OBJECT
-public:
- QQuickPointerTabletEvent(QObject *parent, const QPointingDevice *device);
-
- QQuickPointerEvent *reset(QEvent *) override;
- bool isPressEvent() const override;
- bool isUpdateEvent() const override;
- bool isReleaseEvent() const override;
- QQuickPointerTabletEvent *asPointerTabletEvent() override { return this; }
- const QQuickPointerTabletEvent *asPointerTabletEvent() const override { return this; }
- const QQuickEventTabletPoint *tabletPoint() const { return static_cast<QQuickEventTabletPoint *>(m_point); }
-
- QTabletEvent *asTabletEvent() const;
-
- Q_DISABLE_COPY(QQuickPointerTabletEvent)
-};
-#endif // QT_CONFIG(tabletevent)
-
-#if QT_CONFIG(gestures)
-class Q_QUICK_PRIVATE_EXPORT QQuickPointerNativeGestureEvent : public QQuickSinglePointEvent
-{
- Q_OBJECT
- Q_PROPERTY(Qt::NativeGestureType type READ type CONSTANT)
- Q_PROPERTY(qreal value READ value CONSTANT)
-
-public:
- QQuickPointerNativeGestureEvent(QObject *parent, const QPointingDevice *device);
-
- QQuickPointerEvent *reset(QEvent *) override;
- bool isPressEvent() const override;
- bool isUpdateEvent() const override;
- bool isReleaseEvent() const override;
- QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() override { return this; }
- const QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() const override { return this; }
- Qt::NativeGestureType type() const;
- qreal value() const;
-
- Q_DISABLE_COPY(QQuickPointerNativeGestureEvent)
-};
-#endif // QT_CONFIG(gestures)
-
-class Q_QUICK_PRIVATE_EXPORT QQuickPointerScrollEvent : public QQuickSinglePointEvent
-{
- Q_OBJECT
- Q_PROPERTY(QVector2D angleDelta READ angleDelta CONSTANT)
- Q_PROPERTY(QVector2D pixelDelta READ pixelDelta CONSTANT)
- Q_PROPERTY(bool hasAngleDelta READ hasAngleDelta CONSTANT)
- Q_PROPERTY(bool hasPixelDelta READ hasPixelDelta CONSTANT)
- Q_PROPERTY(bool inverted READ isInverted CONSTANT)
-
- QML_NAMED_ELEMENT(PointerScrollEvent)
- QML_UNCREATABLE("PointerScrollEvent is only available via the WheelHandler::wheel signal.")
- QML_ADDED_IN_VERSION(2, 14)
-
-public:
- QQuickPointerScrollEvent(QObject *parent, const QPointingDevice *device);
-
- QQuickPointerEvent *reset(QEvent *) override;
- void localize(QQuickItem *target) override;
- bool isPressEvent() const override;
- bool isUpdateEvent() const override;
- bool isReleaseEvent() const override;
- QQuickPointerScrollEvent *asPointerScrollEvent() override { return this; }
- const QQuickPointerScrollEvent *asPointerScrollEvent() const override { return this; }
- QVector2D angleDelta() const { return m_angleDelta; }
- QVector2D pixelDelta() const { return m_pixelDelta; }
- bool hasAngleDelta() const { return !angleDelta().isNull(); }
- bool hasPixelDelta() const { return !pixelDelta().isNull(); }
- bool isInverted() const { return m_inverted; }
- Qt::ScrollPhase phase() const { return m_phase; }
-
-private:
- // TODO remove this if it's obsolete
- Qt::MouseEventSource synthSource() const { return m_synthSource; }
-
-private:
- QVector2D m_angleDelta;
- QVector2D m_pixelDelta;
- Qt::ScrollPhase m_phase = Qt::NoScrollPhase;
- Qt::MouseEventSource m_synthSource = Qt::MouseEventNotSynthesized;
- bool m_inverted = false;
-
- friend class QQuickWindowPrivate;
- friend class QQuickWheelHandler;
-
- Q_DISABLE_COPY(QQuickPointerScrollEvent)
-};
-
-Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickPointerEvent *);
-Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventPoint *);
-//Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventTouchPoint *); TODO maybe
-
QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickKeyEvent)
@@ -710,7 +269,6 @@ QML_DECLARE_TYPE(QQuickWheelEvent)
QML_DECLARE_TYPE(QQuickCloseEvent)
QML_DECLARE_TYPE(QPointingDevice)
QML_DECLARE_TYPE(QPointingDeviceUniqueId)
-QML_DECLARE_TYPE(QQuickPointerEvent)
-Q_DECLARE_METATYPE(QQuickEventPoint::GrabTransition)
+QML_DECLARE_TYPE(QPointerEvent)
#endif // QQUICKEVENTS_P_P_H