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