29 Q_PROPERTY(QQuickDragAxis * xAxis READ xAxis CONSTANT)
30 Q_PROPERTY(QQuickDragAxis * yAxis READ yAxis CONSTANT)
31#if QT_DEPRECATED_SINCE(6
, 2
)
32 Q_PROPERTY(QVector2D translation READ translation NOTIFY translationChanged)
34 Q_PROPERTY(QVector2D activeTranslation READ activeTranslation NOTIFY translationChanged REVISION(6, 2))
35 Q_PROPERTY(QVector2D persistentTranslation READ persistentTranslation WRITE setPersistentTranslation NOTIFY translationChanged REVISION(6, 2))
36 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged REVISION(2, 14))
37 QML_NAMED_ELEMENT(DragHandler)
38 QML_ADDED_IN_VERSION(2, 12)
44 SnapIfPressedOutsideTarget,
49 explicit QQuickDragHandler(QQuickItem *parent =
nullptr);
51 void handlePointerEventImpl(QPointerEvent *event) override;
53 QQuickDragAxis *xAxis() {
return &m_xAxis; }
54 QQuickDragAxis *yAxis() {
return &m_yAxis; }
56#if QT_DEPRECATED_SINCE(6
, 2
)
57 QVector2D translation()
const {
return activeTranslation(); }
59 QVector2D activeTranslation()
const {
return QVector2D(QPointF(m_xAxis.activeValue(), m_yAxis.activeValue())); }
60 void setActiveTranslation(
const QVector2D &trans);
61 QVector2D persistentTranslation()
const {
return QVector2D(QPointF(m_xAxis.persistentValue(), m_yAxis.persistentValue())); }
62 void setPersistentTranslation(
const QVector2D &trans);
63 QQuickDragHandler::SnapMode snapMode()
const;
64 void setSnapMode(QQuickDragHandler::SnapMode mode);
67 void translationChanged(QVector2D delta);
68 Q_REVISION(2, 14)
void snapModeChanged();
71 bool wantsPointerEvent(QPointerEvent *event) override;
72 void onActiveChanged() override;
73 void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override;
77 void enforceAxisConstraints(QPointF *localPos);
78 QPointF targetCentroidPosition();
81 QPointF m_pressTargetPos;
85 QQuickDragAxis m_xAxis = {
this, u"x"_s};
86 QQuickDragAxis m_yAxis = {
this, u"y"_s};
87 QQuickDragHandler::SnapMode m_snapMode = SnapAuto;
88 bool m_pressedInsideParent =
false;
89 bool m_pressedInsideTarget =
false;
91 friend class QQuickDragAxis;