| 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 | |
| 4 | #ifndef QQUICKPINCHHANDLER_H |
| 5 | #define QQUICKPINCHHANDLER_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtGui/qevent.h> |
| 19 | #include <QtQuick/qquickitem.h> |
| 20 | |
| 21 | #include "qquickmultipointhandler_p.h" |
| 22 | #include <private/qquicktranslate_p.h> |
| 23 | #include "qquickdragaxis_p.h" |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | using namespace Qt::StringLiterals; |
| 28 | |
| 29 | class Q_QUICK_EXPORT QQuickPinchHandler : public QQuickMultiPointHandler |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | |
| 33 | Q_PROPERTY(QQuickDragAxis *scaleAxis READ scaleAxis CONSTANT) |
| 34 | #if QT_DEPRECATED_SINCE(6, 5) |
| 35 | Q_PROPERTY(qreal minimumScale READ minimumScale WRITE setMinimumScale NOTIFY minimumScaleChanged) |
| 36 | Q_PROPERTY(qreal maximumScale READ maximumScale WRITE setMaximumScale NOTIFY maximumScaleChanged) |
| 37 | Q_PROPERTY(qreal scale READ scale NOTIFY updated) |
| 38 | #endif |
| 39 | Q_PROPERTY(qreal activeScale READ activeScale NOTIFY scaleChanged) |
| 40 | Q_PROPERTY(qreal persistentScale READ persistentScale WRITE setPersistentScale NOTIFY scaleChanged) |
| 41 | |
| 42 | Q_PROPERTY(QQuickDragAxis *rotationAxis READ rotationAxis CONSTANT) |
| 43 | #if QT_DEPRECATED_SINCE(6, 5) |
| 44 | Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged) |
| 45 | Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged) |
| 46 | Q_PROPERTY(qreal rotation READ rotation NOTIFY updated) |
| 47 | #endif |
| 48 | Q_PROPERTY(qreal activeRotation READ activeRotation NOTIFY rotationChanged) |
| 49 | Q_PROPERTY(qreal persistentRotation READ persistentRotation WRITE setPersistentRotation NOTIFY rotationChanged) |
| 50 | |
| 51 | Q_PROPERTY(QQuickDragAxis * xAxis READ xAxis CONSTANT) |
| 52 | Q_PROPERTY(QQuickDragAxis * yAxis READ yAxis CONSTANT) |
| 53 | #if QT_DEPRECATED_SINCE(6, 5) |
| 54 | Q_PROPERTY(QVector2D translation READ translation NOTIFY updated) |
| 55 | #endif |
| 56 | Q_PROPERTY(QPointF activeTranslation READ activeTranslation NOTIFY translationChanged REVISION(6, 5)) |
| 57 | Q_PROPERTY(QPointF persistentTranslation READ persistentTranslation WRITE setPersistentTranslation NOTIFY translationChanged REVISION(6, 5)) |
| 58 | |
| 59 | QML_NAMED_ELEMENT(PinchHandler) |
| 60 | QML_ADDED_IN_VERSION(2, 12) |
| 61 | |
| 62 | public: |
| 63 | explicit QQuickPinchHandler(QQuickItem *parent = nullptr); |
| 64 | |
| 65 | QQuickDragAxis *xAxis() { return &m_xAxis; } |
| 66 | QQuickDragAxis *yAxis() { return &m_yAxis; } |
| 67 | #if QT_DEPRECATED_SINCE(6, 5) |
| 68 | QVector2D translation() const { return QVector2D(activeTranslation()); } |
| 69 | #endif |
| 70 | QPointF activeTranslation() const { return QPointF(m_xAxis.activeValue(), m_yAxis.activeValue()); } |
| 71 | QPointF persistentTranslation() const { return QPointF(m_xAxis.persistentValue(), m_yAxis.persistentValue()); } |
| 72 | void setPersistentTranslation(const QPointF &trans); |
| 73 | |
| 74 | QQuickDragAxis *scaleAxis() { return &m_scaleAxis; } |
| 75 | #if QT_DEPRECATED_SINCE(6, 5) |
| 76 | qreal minimumScale() const { return m_scaleAxis.minimum(); } |
| 77 | void setMinimumScale(qreal minimumScale); |
| 78 | qreal maximumScale() const { return m_scaleAxis.maximum(); } |
| 79 | void setMaximumScale(qreal maximumScale); |
| 80 | qreal scale() const { return persistentScale(); } |
| 81 | #endif |
| 82 | qreal activeScale() const { return m_scaleAxis.activeValue(); } |
| 83 | void setActiveScale(qreal scale); |
| 84 | qreal persistentScale() const { return m_scaleAxis.persistentValue(); } |
| 85 | void setPersistentScale(qreal scale); |
| 86 | |
| 87 | QQuickDragAxis *rotationAxis() { return &m_rotationAxis; } |
| 88 | #if QT_DEPRECATED_SINCE(6, 5) |
| 89 | qreal minimumRotation() const { return m_rotationAxis.minimum(); } |
| 90 | void setMinimumRotation(qreal minimumRotation); |
| 91 | qreal maximumRotation() const { return m_rotationAxis.maximum(); } |
| 92 | void setMaximumRotation(qreal maximumRotation); |
| 93 | qreal rotation() const { return activeRotation(); } |
| 94 | #endif |
| 95 | qreal activeRotation() const { return m_rotationAxis.activeValue(); } |
| 96 | void setActiveRotation(qreal rot); |
| 97 | qreal persistentRotation() const { return m_rotationAxis.persistentValue(); } |
| 98 | void setPersistentRotation(qreal rot); |
| 99 | |
| 100 | Q_SIGNALS: |
| 101 | void minimumScaleChanged(); |
| 102 | void maximumScaleChanged(); |
| 103 | void minimumRotationChanged(); |
| 104 | void maximumRotationChanged(); |
| 105 | void updated(); |
| 106 | void scaleChanged(qreal delta); |
| 107 | void rotationChanged(qreal delta); |
| 108 | void translationChanged(QVector2D delta); |
| 109 | |
| 110 | protected: |
| 111 | bool wantsPointerEvent(QPointerEvent *event) override; |
| 112 | void onActiveChanged() override; |
| 113 | void handlePointerEventImpl(QPointerEvent *event) override; |
| 114 | |
| 115 | private: |
| 116 | QQuickDragAxis m_xAxis = {this, u"x"_s }; |
| 117 | QQuickDragAxis m_yAxis = {this, u"y"_s }; |
| 118 | QQuickDragAxis m_scaleAxis = {this, u"scale"_s , 1}; |
| 119 | QQuickDragAxis m_rotationAxis = {this, u"rotation"_s }; |
| 120 | |
| 121 | // internal |
| 122 | qreal m_startDistance = 0; |
| 123 | qreal m_accumulatedStartCentroidDistance = 0; |
| 124 | QPointF m_startTargetPos; |
| 125 | QVector<PointData> m_startAngles; |
| 126 | QQuickMatrix4x4 m_transform; |
| 127 | }; |
| 128 | |
| 129 | QT_END_NAMESPACE |
| 130 | |
| 131 | #endif // QQUICKPINCHHANDLER_H |
| 132 | |