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