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