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
qquickdraghandler_p.h
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKDRAGHANDLER_H
6#define QQUICKDRAGHANDLER_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
21
23
24using namespace Qt::StringLiterals;
25
26class Q_QUICK_EXPORT QQuickDragHandler : public QQuickMultiPointHandler
27{
28 Q_OBJECT
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)
33#endif
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)
39
40public:
41 enum SnapMode {
42 NoSnap = 0,
43 SnapAuto,
44 SnapIfPressedOutsideTarget,
45 SnapAlways
46 };
47 Q_ENUM(SnapMode)
48
49 explicit QQuickDragHandler(QQuickItem *parent = nullptr);
50
51 void handlePointerEventImpl(QPointerEvent *event) override;
52
53 QQuickDragAxis *xAxis() { return &m_xAxis; }
54 QQuickDragAxis *yAxis() { return &m_yAxis; }
55
56#if QT_DEPRECATED_SINCE(6, 2)
57 QVector2D translation() const { return activeTranslation(); }
58#endif
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);
65
66Q_SIGNALS:
67 void translationChanged(QVector2D delta);
68 Q_REVISION(2, 14) void snapModeChanged();
69
70protected:
71 bool wantsPointerEvent(QPointerEvent *event) override;
72 void onActiveChanged() override;
73 void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override;
74
75private:
76 void ungrab();
77 void enforceAxisConstraints(QPointF *localPos);
78 QPointF targetCentroidPosition();
79
80private:
81 QPointF m_pressTargetPos; // We must also store the local targetPos, because we cannot deduce
82 // the press target pos from the scene pos in case there was e.g a
83 // flick in one of the ancestors during the drag.
84
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;
90
91 friend class QQuickDragAxis;
92};
93
94QT_END_NAMESPACE
95
96#endif // QQUICKDRAGHANDLER_H
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
static QT_BEGIN_NAMESPACE const qreal DragAngleToleranceDegrees