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 | |
60 | QT_BEGIN_NAMESPACE |
61 | |
62 | class 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 | QML_NAMED_ELEMENT(PinchHandler) |
82 | QML_ADDED_IN_MINOR_VERSION(12) |
83 | |
84 | public: |
85 | explicit QQuickPinchHandler(QQuickItem *parent = nullptr); |
86 | |
87 | qreal minimumScale() const { return m_minimumScale; } |
88 | void setMinimumScale(qreal minimumScale); |
89 | |
90 | qreal maximumScale() const { return m_maximumScale; } |
91 | void setMaximumScale(qreal maximumScale); |
92 | |
93 | qreal minimumRotation() const { return m_minimumRotation; } |
94 | void setMinimumRotation(qreal minimumRotation); |
95 | |
96 | qreal maximumRotation() const { return m_maximumRotation; } |
97 | void setMaximumRotation(qreal maximumRotation); |
98 | |
99 | QVector2D translation() const { return m_activeTranslation; } |
100 | qreal scale() const { return m_accumulatedScale; } |
101 | qreal activeScale() const { return m_activeScale; } |
102 | qreal rotation() const { return m_activeRotation; } |
103 | |
104 | #if QT_DEPRECATED_SINCE(5, 12) |
105 | void warnAboutMinMaxDeprecated() const; |
106 | qreal minimumX() const { warnAboutMinMaxDeprecated(); return m_minimumX; } |
107 | void setMinimumX(qreal minX); |
108 | qreal maximumX() const { warnAboutMinMaxDeprecated(); return m_maximumX; } |
109 | void setMaximumX(qreal maxX); |
110 | qreal minimumY() const { warnAboutMinMaxDeprecated(); return m_minimumY; } |
111 | void setMinimumY(qreal minY); |
112 | qreal maximumY() const { warnAboutMinMaxDeprecated(); return m_maximumY; } |
113 | void setMaximumY(qreal maxY); |
114 | #endif |
115 | |
116 | QQuickDragAxis *xAxis() { return &m_xAxis; } |
117 | QQuickDragAxis *yAxis() { return &m_yAxis; } |
118 | |
119 | signals: |
120 | void minimumScaleChanged(); |
121 | void maximumScaleChanged(); |
122 | void minimumRotationChanged(); |
123 | void maximumRotationChanged(); |
124 | void minimumXChanged(); |
125 | void maximumXChanged(); |
126 | void minimumYChanged(); |
127 | void maximumYChanged(); |
128 | void updated(); |
129 | |
130 | protected: |
131 | bool wantsPointerEvent(QQuickPointerEvent *event) override; |
132 | void onActiveChanged() override; |
133 | void handlePointerEventImpl(QQuickPointerEvent *event) override; |
134 | |
135 | private: |
136 | // properties |
137 | qreal m_activeScale = 1; |
138 | qreal m_accumulatedScale = 1; |
139 | qreal m_activeRotation = 0; |
140 | QVector2D m_activeTranslation = QVector2D(0, 0); |
141 | |
142 | qreal m_minimumScale = -qInf(); |
143 | qreal m_maximumScale = qInf(); |
144 | |
145 | qreal m_minimumRotation = -qInf(); |
146 | qreal m_maximumRotation = qInf(); |
147 | |
148 | qreal m_minimumX = -qInf(); |
149 | qreal m_maximumX = qInf(); |
150 | qreal m_minimumY = -qInf(); |
151 | qreal m_maximumY = qInf(); |
152 | QQuickDragAxis m_xAxis; |
153 | QQuickDragAxis m_yAxis; |
154 | |
155 | // internal |
156 | qreal m_startScale = 1; |
157 | qreal m_startRotation = 0; |
158 | qreal m_startDistance = 0; |
159 | QPointF m_startPos; |
160 | qreal m_accumulatedStartCentroidDistance = 0; |
161 | QVector<PointData> m_startAngles; |
162 | QQuickMatrix4x4 m_transform; |
163 | }; |
164 | |
165 | QT_END_NAMESPACE |
166 | |
167 | QML_DECLARE_TYPE(QQuickPinchHandler) |
168 | |
169 | #endif // QQUICKPINCHHANDLER_H |
170 | |