f3687e0c15c6456148a660d50bbdb6353a692782
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickpincharea_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKPINCHAREA_H
43 #define QQUICKPINCHAREA_H
44
45 #include "qquickitem.h"
46
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51 class Q_AUTOTEST_EXPORT QQuickPinch : public QObject
52 {
53     Q_OBJECT
54
55     Q_ENUMS(Axis)
56     Q_PROPERTY(QQuickItem *target READ target WRITE setTarget RESET resetTarget)
57     Q_PROPERTY(qreal minimumScale READ minimumScale WRITE setMinimumScale NOTIFY minimumScaleChanged)
58     Q_PROPERTY(qreal maximumScale READ maximumScale WRITE setMaximumScale NOTIFY maximumScaleChanged)
59     Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged)
60     Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged)
61     Q_PROPERTY(Axis dragAxis READ axis WRITE setAxis NOTIFY dragAxisChanged)
62     Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
63     Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
64     Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
65     Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
66     Q_PROPERTY(bool active READ active NOTIFY activeChanged)
67
68 public:
69     QQuickPinch();
70
71     QQuickItem *target() const { return m_target; }
72     void setTarget(QQuickItem *target) {
73         if (target == m_target)
74             return;
75         m_target = target;
76         emit targetChanged();
77     }
78     void resetTarget() {
79         if (!m_target)
80             return;
81         m_target = 0;
82         emit targetChanged();
83     }
84
85     qreal minimumScale() const { return m_minScale; }
86     void setMinimumScale(qreal s) {
87         if (s == m_minScale)
88             return;
89         m_minScale = s;
90         emit minimumScaleChanged();
91     }
92     qreal maximumScale() const { return m_maxScale; }
93     void setMaximumScale(qreal s) {
94         if (s == m_maxScale)
95             return;
96         m_maxScale = s;
97         emit maximumScaleChanged();
98     }
99
100     qreal minimumRotation() const { return m_minRotation; }
101     void setMinimumRotation(qreal r) {
102         if (r == m_minRotation)
103             return;
104         m_minRotation = r;
105         emit minimumRotationChanged();
106     }
107     qreal maximumRotation() const { return m_maxRotation; }
108     void setMaximumRotation(qreal r) {
109         if (r == m_maxRotation)
110             return;
111         m_maxRotation = r;
112         emit maximumRotationChanged();
113     }
114
115     enum Axis { NoDrag=0x00, XAxis=0x01, YAxis=0x02, XAndYAxis=0x03, XandYAxis=XAndYAxis };
116     Axis axis() const { return m_axis; }
117     void setAxis(Axis a) {
118         if (a == m_axis)
119             return;
120         m_axis = a;
121         emit dragAxisChanged();
122     }
123
124     qreal xmin() const { return m_xmin; }
125     void setXmin(qreal x) {
126         if (x == m_xmin)
127             return;
128         m_xmin = x;
129         emit minimumXChanged();
130     }
131     qreal xmax() const { return m_xmax; }
132     void setXmax(qreal x) {
133         if (x == m_xmax)
134             return;
135         m_xmax = x;
136         emit maximumXChanged();
137     }
138     qreal ymin() const { return m_ymin; }
139     void setYmin(qreal y) {
140         if (y == m_ymin)
141             return;
142         m_ymin = y;
143         emit minimumYChanged();
144     }
145     qreal ymax() const { return m_ymax; }
146     void setYmax(qreal y) {
147         if (y == m_ymax)
148             return;
149         m_ymax = y;
150         emit maximumYChanged();
151     }
152
153     bool active() const { return m_active; }
154     void setActive(bool a) {
155         if (a == m_active)
156             return;
157         m_active = a;
158         emit activeChanged();
159     }
160
161 signals:
162     void targetChanged();
163     void minimumScaleChanged();
164     void maximumScaleChanged();
165     void minimumRotationChanged();
166     void maximumRotationChanged();
167     void dragAxisChanged();
168     void minimumXChanged();
169     void maximumXChanged();
170     void minimumYChanged();
171     void maximumYChanged();
172     void activeChanged();
173
174 private:
175     QQuickItem *m_target;
176     qreal m_minScale;
177     qreal m_maxScale;
178     qreal m_minRotation;
179     qreal m_maxRotation;
180     Axis m_axis;
181     qreal m_xmin;
182     qreal m_xmax;
183     qreal m_ymin;
184     qreal m_ymax;
185     bool m_active;
186 };
187
188 class Q_AUTOTEST_EXPORT QQuickPinchEvent : public QObject
189 {
190     Q_OBJECT
191
192     Q_PROPERTY(QPointF center READ center)
193     Q_PROPERTY(QPointF startCenter READ startCenter)
194     Q_PROPERTY(QPointF previousCenter READ previousCenter)
195     Q_PROPERTY(qreal scale READ scale)
196     Q_PROPERTY(qreal previousScale READ previousScale)
197     Q_PROPERTY(qreal angle READ angle)
198     Q_PROPERTY(qreal previousAngle READ previousAngle)
199     Q_PROPERTY(qreal rotation READ rotation)
200     Q_PROPERTY(QPointF point1 READ point1)
201     Q_PROPERTY(QPointF startPoint1 READ startPoint1)
202     Q_PROPERTY(QPointF point2 READ point2)
203     Q_PROPERTY(QPointF startPoint2 READ startPoint2)
204     Q_PROPERTY(int pointCount READ pointCount)
205     Q_PROPERTY(bool accepted READ accepted WRITE setAccepted)
206
207 public:
208     QQuickPinchEvent(QPointF c, qreal s, qreal a, qreal r)
209         : QObject(), m_center(c), m_scale(s), m_angle(a), m_rotation(r)
210         , m_pointCount(0), m_accepted(true) {}
211
212     QPointF center() const { return m_center; }
213     QPointF startCenter() const { return m_startCenter; }
214     void setStartCenter(QPointF c) { m_startCenter = c; }
215     QPointF previousCenter() const { return m_lastCenter; }
216     void setPreviousCenter(QPointF c) { m_lastCenter = c; }
217     qreal scale() const { return m_scale; }
218     qreal previousScale() const { return m_lastScale; }
219     void setPreviousScale(qreal s) { m_lastScale = s; }
220     qreal angle() const { return m_angle; }
221     qreal previousAngle() const { return m_lastAngle; }
222     void setPreviousAngle(qreal a) { m_lastAngle = a; }
223     qreal rotation() const { return m_rotation; }
224     QPointF point1() const { return m_point1; }
225     void setPoint1(QPointF p) { m_point1 = p; }
226     QPointF startPoint1() const { return m_startPoint1; }
227     void setStartPoint1(QPointF p) { m_startPoint1 = p; }
228     QPointF point2() const { return m_point2; }
229     void setPoint2(QPointF p) { m_point2 = p; }
230     QPointF startPoint2() const { return m_startPoint2; }
231     void setStartPoint2(QPointF p) { m_startPoint2 = p; }
232     int pointCount() const { return m_pointCount; }
233     void setPointCount(int count) { m_pointCount = count; }
234
235     bool accepted() const { return m_accepted; }
236     void setAccepted(bool a) { m_accepted = a; }
237
238 private:
239     QPointF m_center;
240     QPointF m_startCenter;
241     QPointF m_lastCenter;
242     qreal m_scale;
243     qreal m_lastScale;
244     qreal m_angle;
245     qreal m_lastAngle;
246     qreal m_rotation;
247     QPointF m_point1;
248     QPointF m_point2;
249     QPointF m_startPoint1;
250     QPointF m_startPoint2;
251     int m_pointCount;
252     bool m_accepted;
253 };
254
255
256 class QQuickMouseEvent;
257 class QQuickPinchAreaPrivate;
258 class Q_AUTOTEST_EXPORT QQuickPinchArea : public QQuickItem
259 {
260     Q_OBJECT
261
262     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
263     Q_PROPERTY(QQuickPinch *pinch READ pinch CONSTANT)
264
265 public:
266     QQuickPinchArea(QQuickItem *parent=0);
267     ~QQuickPinchArea();
268
269     bool isEnabled() const;
270     void setEnabled(bool);
271
272     QQuickPinch *pinch();
273
274 Q_SIGNALS:
275     void enabledChanged();
276     void pinchStarted(QQuickPinchEvent *pinch);
277     void pinchUpdated(QQuickPinchEvent *pinch);
278     void pinchFinished(QQuickPinchEvent *pinch);
279
280 protected:
281     virtual bool childMouseEventFilter(QQuickItem *i, QEvent *e);
282     virtual void touchEvent(QTouchEvent *event);
283
284     virtual void geometryChanged(const QRectF &newGeometry,
285                                  const QRectF &oldGeometry);
286     virtual void itemChange(ItemChange change, const ItemChangeData& value);
287
288 private:
289     void updatePinch();
290     void handlePress();
291     void handleRelease();
292
293 private:
294     Q_DISABLE_COPY(QQuickPinchArea)
295     Q_DECLARE_PRIVATE(QQuickPinchArea)
296 };
297
298 QT_END_NAMESPACE
299
300 QML_DECLARE_TYPE(QQuickPinch)
301 QML_DECLARE_TYPE(QQuickPinchEvent)
302 QML_DECLARE_TYPE(QQuickPinchArea)
303
304 QT_END_HEADER
305
306 #endif // QQUICKPINCHAREA_H
307