1// Copyright (C) 2020 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 QQUICKPINCHAREA_H
5#define QQUICKPINCHAREA_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 <private/qtquickglobal_p.h>
19
20#include "qquickitem.h"
21
22QT_BEGIN_NAMESPACE
23
24class Q_QUICK_PRIVATE_EXPORT QQuickPinch : public QObject
25{
26 Q_OBJECT
27
28 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget RESET resetTarget NOTIFY targetChanged FINAL)
29 Q_PROPERTY(qreal minimumScale READ minimumScale WRITE setMinimumScale NOTIFY minimumScaleChanged FINAL)
30 Q_PROPERTY(qreal maximumScale READ maximumScale WRITE setMaximumScale NOTIFY maximumScaleChanged FINAL)
31 Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged FINAL)
32 Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged FINAL)
33 Q_PROPERTY(Axis dragAxis READ axis WRITE setAxis NOTIFY dragAxisChanged FINAL)
34 Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged FINAL)
35 Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged FINAL)
36 Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged FINAL)
37 Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged FINAL)
38 Q_PROPERTY(bool active READ active NOTIFY activeChanged FINAL)
39 QML_NAMED_ELEMENT(Pinch)
40 QML_ADDED_IN_VERSION(2, 0)
41
42public:
43 QQuickPinch();
44
45 QQuickItem *target() const { return m_target; }
46 void setTarget(QQuickItem *target) {
47 if (target == m_target)
48 return;
49 m_target = target;
50 Q_EMIT targetChanged();
51 }
52 void resetTarget() {
53 if (!m_target)
54 return;
55 m_target = nullptr;
56 Q_EMIT targetChanged();
57 }
58
59 qreal minimumScale() const { return m_minScale; }
60 void setMinimumScale(qreal s) {
61 if (s == m_minScale)
62 return;
63 m_minScale = s;
64 Q_EMIT minimumScaleChanged();
65 }
66 qreal maximumScale() const { return m_maxScale; }
67 void setMaximumScale(qreal s) {
68 if (s == m_maxScale)
69 return;
70 m_maxScale = s;
71 Q_EMIT maximumScaleChanged();
72 }
73
74 qreal minimumRotation() const { return m_minRotation; }
75 void setMinimumRotation(qreal r) {
76 if (r == m_minRotation)
77 return;
78 m_minRotation = r;
79 Q_EMIT minimumRotationChanged();
80 }
81 qreal maximumRotation() const { return m_maxRotation; }
82 void setMaximumRotation(qreal r) {
83 if (r == m_maxRotation)
84 return;
85 m_maxRotation = r;
86 Q_EMIT maximumRotationChanged();
87 }
88
89 enum Axis { NoDrag=0x00, XAxis=0x01, YAxis=0x02, XAndYAxis=0x03, XandYAxis=XAndYAxis };
90 Q_ENUM(Axis)
91 Axis axis() const { return m_axis; }
92 void setAxis(Axis a) {
93 if (a == m_axis)
94 return;
95 m_axis = a;
96 Q_EMIT dragAxisChanged();
97 }
98
99 qreal xmin() const { return m_xmin; }
100 void setXmin(qreal x) {
101 if (x == m_xmin)
102 return;
103 m_xmin = x;
104 Q_EMIT minimumXChanged();
105 }
106 qreal xmax() const { return m_xmax; }
107 void setXmax(qreal x) {
108 if (x == m_xmax)
109 return;
110 m_xmax = x;
111 Q_EMIT maximumXChanged();
112 }
113 qreal ymin() const { return m_ymin; }
114 void setYmin(qreal y) {
115 if (y == m_ymin)
116 return;
117 m_ymin = y;
118 Q_EMIT minimumYChanged();
119 }
120 qreal ymax() const { return m_ymax; }
121 void setYmax(qreal y) {
122 if (y == m_ymax)
123 return;
124 m_ymax = y;
125 Q_EMIT maximumYChanged();
126 }
127
128 bool active() const { return m_active; }
129 void setActive(bool a) {
130 if (a == m_active)
131 return;
132 m_active = a;
133 Q_EMIT activeChanged();
134 }
135
136Q_SIGNALS:
137 void targetChanged();
138 void minimumScaleChanged();
139 void maximumScaleChanged();
140 void minimumRotationChanged();
141 void maximumRotationChanged();
142 void dragAxisChanged();
143 void minimumXChanged();
144 void maximumXChanged();
145 void minimumYChanged();
146 void maximumYChanged();
147 void activeChanged();
148
149private:
150 QQuickItem *m_target;
151 qreal m_minScale;
152 qreal m_maxScale;
153 qreal m_minRotation;
154 qreal m_maxRotation;
155 Axis m_axis;
156 qreal m_xmin;
157 qreal m_xmax;
158 qreal m_ymin;
159 qreal m_ymax;
160 bool m_active;
161};
162
163class Q_QUICK_PRIVATE_EXPORT QQuickPinchEvent : public QObject
164{
165 Q_OBJECT
166
167 Q_PROPERTY(QPointF center READ center FINAL)
168 Q_PROPERTY(QPointF startCenter READ startCenter FINAL)
169 Q_PROPERTY(QPointF previousCenter READ previousCenter FINAL)
170 Q_PROPERTY(qreal scale READ scale FINAL)
171 Q_PROPERTY(qreal previousScale READ previousScale FINAL)
172 Q_PROPERTY(qreal angle READ angle FINAL)
173 Q_PROPERTY(qreal previousAngle READ previousAngle FINAL)
174 Q_PROPERTY(qreal rotation READ rotation FINAL)
175 Q_PROPERTY(QPointF point1 READ point1 FINAL)
176 Q_PROPERTY(QPointF startPoint1 READ startPoint1 FINAL)
177 Q_PROPERTY(QPointF point2 READ point2 FINAL)
178 Q_PROPERTY(QPointF startPoint2 READ startPoint2 FINAL)
179 Q_PROPERTY(int pointCount READ pointCount FINAL)
180 Q_PROPERTY(bool accepted READ accepted WRITE setAccepted FINAL)
181 QML_ANONYMOUS
182 QML_ADDED_IN_VERSION(2, 0)
183
184public:
185 QQuickPinchEvent(QPointF c, qreal s, qreal a, qreal r)
186 : QObject(), m_center(c), m_scale(s), m_angle(a), m_rotation(r)
187 , m_pointCount(0), m_accepted(true) {}
188
189 QPointF center() const { return m_center; }
190 QPointF startCenter() const { return m_startCenter; }
191 void setStartCenter(QPointF c) { m_startCenter = c; }
192 QPointF previousCenter() const { return m_lastCenter; }
193 void setPreviousCenter(QPointF c) { m_lastCenter = c; }
194 qreal scale() const { return m_scale; }
195 qreal previousScale() const { return m_lastScale; }
196 void setPreviousScale(qreal s) { m_lastScale = s; }
197 qreal angle() const { return m_angle; }
198 qreal previousAngle() const { return m_lastAngle; }
199 void setPreviousAngle(qreal a) { m_lastAngle = a; }
200 qreal rotation() const { return m_rotation; }
201 QPointF point1() const { return m_point1; }
202 void setPoint1(QPointF p) { m_point1 = p; }
203 QPointF startPoint1() const { return m_startPoint1; }
204 void setStartPoint1(QPointF p) { m_startPoint1 = p; }
205 QPointF point2() const { return m_point2; }
206 void setPoint2(QPointF p) { m_point2 = p; }
207 QPointF startPoint2() const { return m_startPoint2; }
208 void setStartPoint2(QPointF p) { m_startPoint2 = p; }
209 int pointCount() const { return m_pointCount; }
210 void setPointCount(int count) { m_pointCount = count; }
211
212 bool accepted() const { return m_accepted; }
213 void setAccepted(bool a) { m_accepted = a; }
214
215private:
216 QPointF m_center;
217 QPointF m_startCenter;
218 QPointF m_lastCenter;
219 qreal m_scale;
220 qreal m_lastScale;
221 qreal m_angle;
222 qreal m_lastAngle;
223 qreal m_rotation;
224 QPointF m_point1;
225 QPointF m_point2;
226 QPointF m_startPoint1;
227 QPointF m_startPoint2;
228 int m_pointCount;
229 bool m_accepted;
230};
231
232
233class QQuickPinchAreaPrivate;
234class Q_QUICK_PRIVATE_EXPORT QQuickPinchArea : public QQuickItem
235{
236 Q_OBJECT
237
238 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
239 Q_PROPERTY(QQuickPinch *pinch READ pinch CONSTANT FINAL)
240 QML_NAMED_ELEMENT(PinchArea)
241 QML_ADDED_IN_VERSION(2, 0)
242
243public:
244 QQuickPinchArea(QQuickItem *parent=nullptr);
245 ~QQuickPinchArea();
246
247 bool isEnabled() const;
248 void setEnabled(bool);
249
250 QQuickPinch *pinch();
251
252Q_SIGNALS:
253 void enabledChanged();
254 void pinchStarted(QQuickPinchEvent *pinch);
255 void pinchUpdated(QQuickPinchEvent *pinch);
256 void pinchFinished(QQuickPinchEvent *pinch);
257 Q_REVISION(2, 5) void smartZoom(QQuickPinchEvent *pinch);
258
259protected:
260 bool childMouseEventFilter(QQuickItem *i, QEvent *e) override;
261 void touchEvent(QTouchEvent *event) override;
262
263 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
264 void itemChange(ItemChange change, const ItemChangeData& value) override;
265 bool event(QEvent *) override;
266
267private:
268 void clearPinch(QTouchEvent *event);
269 void cancelPinch(QTouchEvent *event);
270 void updatePinch(QTouchEvent *event, bool filtering);
271 void updatePinchTarget();
272
273private:
274 Q_DISABLE_COPY(QQuickPinchArea)
275 Q_DECLARE_PRIVATE(QQuickPinchArea)
276};
277
278QT_END_NAMESPACE
279
280QML_DECLARE_TYPE(QQuickPinch)
281QML_DECLARE_TYPE(QQuickPinchEvent)
282QML_DECLARE_TYPE(QQuickPinchArea)
283
284#endif // QQUICKPINCHAREA_H
285
286

source code of qtdeclarative/src/quick/items/qquickpincharea_p.h