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

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