1/****************************************************************************
2**
3** Copyright (C) 2016 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 QQUICKPINCHHANDLER_H
41#define QQUICKPINCHHANDLER_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 "qquickitem.h"
55#include "qevent.h"
56#include "qquickmultipointhandler_p.h"
57#include <private/qquicktranslate_p.h>
58#include "qquickdragaxis_p.h"
59
60QT_BEGIN_NAMESPACE
61
62class Q_QUICK_PRIVATE_EXPORT QQuickPinchHandler : public QQuickMultiPointHandler
63{
64 Q_OBJECT
65 Q_PROPERTY(qreal minimumScale READ minimumScale WRITE setMinimumScale NOTIFY minimumScaleChanged)
66 Q_PROPERTY(qreal maximumScale READ maximumScale WRITE setMaximumScale NOTIFY maximumScaleChanged)
67 Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged)
68 Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged)
69 Q_PROPERTY(qreal scale READ scale NOTIFY updated)
70 Q_PROPERTY(qreal activeScale READ activeScale NOTIFY updated)
71 Q_PROPERTY(qreal rotation READ rotation NOTIFY updated)
72 Q_PROPERTY(QVector2D translation READ translation NOTIFY updated)
73#if QT_DEPRECATED_SINCE(5, 12)
74 Q_PROPERTY(qreal minimumX READ minimumX WRITE setMinimumX NOTIFY minimumXChanged) // ### Qt 6: remove
75 Q_PROPERTY(qreal maximumX READ maximumX WRITE setMaximumX NOTIFY maximumXChanged) // ### Qt 6: remove
76 Q_PROPERTY(qreal minimumY READ minimumY WRITE setMinimumY NOTIFY minimumYChanged) // ### Qt 6: remove
77 Q_PROPERTY(qreal maximumY READ maximumY WRITE setMaximumY NOTIFY maximumYChanged) // ### Qt 6: remove
78#endif
79 Q_PROPERTY(QQuickDragAxis * xAxis READ xAxis CONSTANT)
80 Q_PROPERTY(QQuickDragAxis * yAxis READ yAxis CONSTANT)
81
82public:
83 explicit QQuickPinchHandler(QQuickItem *parent = nullptr);
84
85 qreal minimumScale() const { return m_minimumScale; }
86 void setMinimumScale(qreal minimumScale);
87
88 qreal maximumScale() const { return m_maximumScale; }
89 void setMaximumScale(qreal maximumScale);
90
91 qreal minimumRotation() const { return m_minimumRotation; }
92 void setMinimumRotation(qreal minimumRotation);
93
94 qreal maximumRotation() const { return m_maximumRotation; }
95 void setMaximumRotation(qreal maximumRotation);
96
97 QVector2D translation() const { return m_activeTranslation; }
98 qreal scale() const { return m_accumulatedScale; }
99 qreal activeScale() const { return m_activeScale; }
100 qreal rotation() const { return m_activeRotation; }
101
102#if QT_DEPRECATED_SINCE(5, 12)
103 void warnAboutMinMaxDeprecated() const;
104 qreal minimumX() const { warnAboutMinMaxDeprecated(); return m_minimumX; }
105 void setMinimumX(qreal minX);
106 qreal maximumX() const { warnAboutMinMaxDeprecated(); return m_maximumX; }
107 void setMaximumX(qreal maxX);
108 qreal minimumY() const { warnAboutMinMaxDeprecated(); return m_minimumY; }
109 void setMinimumY(qreal minY);
110 qreal maximumY() const { warnAboutMinMaxDeprecated(); return m_maximumY; }
111 void setMaximumY(qreal maxY);
112#endif
113
114 QQuickDragAxis *xAxis() { return &m_xAxis; }
115 QQuickDragAxis *yAxis() { return &m_yAxis; }
116
117signals:
118 void minimumScaleChanged();
119 void maximumScaleChanged();
120 void minimumRotationChanged();
121 void maximumRotationChanged();
122 void minimumXChanged();
123 void maximumXChanged();
124 void minimumYChanged();
125 void maximumYChanged();
126 void updated();
127
128protected:
129 bool wantsPointerEvent(QQuickPointerEvent *event) override;
130 void onActiveChanged() override;
131 void handlePointerEventImpl(QQuickPointerEvent *event) override;
132
133private:
134 // properties
135 qreal m_activeScale = 1;
136 qreal m_accumulatedScale = 1;
137 qreal m_activeRotation = 0;
138 QVector2D m_activeTranslation = QVector2D(0, 0);
139
140 qreal m_minimumScale = -qInf();
141 qreal m_maximumScale = qInf();
142
143 qreal m_minimumRotation = -qInf();
144 qreal m_maximumRotation = qInf();
145
146 qreal m_minimumX = -qInf();
147 qreal m_maximumX = qInf();
148 qreal m_minimumY = -qInf();
149 qreal m_maximumY = qInf();
150 QQuickDragAxis m_xAxis;
151 QQuickDragAxis m_yAxis;
152
153 // internal
154 qreal m_startScale = 1;
155 qreal m_startRotation = 0;
156 qreal m_startDistance = 0;
157 QPointF m_startPos;
158 qreal m_accumulatedStartCentroidDistance = 0;
159 QVector<PointData> m_startAngles;
160 QQuickMatrix4x4 m_transform;
161};
162
163QT_END_NAMESPACE
164
165QML_DECLARE_TYPE(QQuickPinchHandler)
166
167#endif // QQUICKPINCHHANDLER_H
168