summaryrefslogtreecommitdiff
path: root/src/imports/location/qdeclarativegeomappincharea_p.h
blob: b81c725d8c3a7e7790e283a9e8cec71fb950a2cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QDECLARATIVEGEOMAPPINCHAREA_H
#define QDECLARATIVEGEOMAPPINCHAREA_H

#include <QtDeclarative/qdeclarative.h>
#include <QTouchEvent>
#include <QObject>
#include <QDebug>

class QGraphicsSceneMouseEvent;
class QDeclarative3DGraphicsGeoMap;
class QTouchEvent;
class Map;

QT_BEGIN_NAMESPACE


class QDeclarativeGeoMapPinchEvent : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QPointF center READ center) // TODO this probably needs to reset every time
    Q_PROPERTY(QPointF startCenter READ startCenter)
    Q_PROPERTY(QPointF previousCenter READ previousCenter)
    Q_PROPERTY(qreal zoomLevel READ zoomLevel)
    Q_PROPERTY(qreal previousZoomLevel READ previousZoomLevel)
    Q_PROPERTY(qreal angle READ angle)
    Q_PROPERTY(qreal previousAngle READ previousAngle)
    Q_PROPERTY(qreal rotation READ rotation)
    Q_PROPERTY(QPointF point1 READ point1)
    Q_PROPERTY(QPointF startPoint1 READ startPoint1)
    Q_PROPERTY(QPointF point2 READ point2)
    Q_PROPERTY(QPointF startPoint2 READ startPoint2)
    Q_PROPERTY(int pointCount READ pointCount)
    Q_PROPERTY(bool accepted READ accepted WRITE setAccepted)

public:
    QDeclarativeGeoMapPinchEvent(QPointF c, qreal s, qreal a, qreal r)
        : QObject(), center_(c), zoomLevel_(s), angle_(a), rotation_(r)
        , pointCount_(0), accepted_(true) {}
    QPointF center() const { return center_; }
    QPointF startCenter() const { return startCenter_; }
    void setStartCenter(QPointF c) { startCenter_ = c; }
    QPointF previousCenter() const { return lastCenter_; }
    void setPreviousCenter(QPointF c) { lastCenter_ = c; }
    qreal zoomLevel() const { return zoomLevel_; }
    qreal previousZoomLevel() const { return lastZoomLevel_; }
    void setPreviousZoomLevel(qreal s) { lastZoomLevel_ = s; }
    qreal angle() const { return angle_; }
    qreal previousAngle() const { return lastAngle_; }
    void setPreviousAngle(qreal a) { lastAngle_ = a; }
    qreal rotation() const { return rotation_; }
    QPointF point1() const { return point1_; }
    void setPoint1(QPointF p) { point1_ = p; }
    QPointF startPoint1() const { return startPoint1_; }
    void setStartPoint1(QPointF p) { startPoint1_ = p; }
    QPointF point2() const { return point2_; }
    void setPoint2(QPointF p) { point2_ = p; }
    QPointF startPoint2() const { return startPoint2_; }
    void setStartPoint2(QPointF p) { startPoint2_ = p; }
    int pointCount() const { return pointCount_; }
    void setPointCount(int count) { pointCount_ = count; }
    bool accepted() const { return accepted_; }
    void setAccepted(bool a) { accepted_ = a; }

private:
    QPointF center_;
    QPointF startCenter_;
    QPointF lastCenter_;
    qreal zoomLevel_;
    qreal lastZoomLevel_;
    qreal angle_;
    qreal lastAngle_;
    qreal rotation_;
    QPointF point1_;
    QPointF point2_;
    QPointF startPoint1_;
    QPointF startPoint2_;
    int pointCount_;
    bool accepted_;
};

class QDeclarativeGeoMapPinchArea: public QObject
{
    Q_OBJECT
    Q_ENUMS(ActiveGesture)
    Q_FLAGS(ActiveGestures)

    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
    Q_PROPERTY(bool active READ active NOTIFY activeChanged)
    Q_PROPERTY(ActiveGestures activeGestures READ activeGestures WRITE setActiveGestures NOTIFY activeGesturesChanged)
    Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel WRITE setMinimumZoomLevel NOTIFY minimumZoomLevelChanged)
    Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel WRITE setMaximumZoomLevel NOTIFY maximumZoomLevelChanged)
    Q_PROPERTY(qreal maximumZoomLevelChange READ maximumZoomLevelChange WRITE setMaximumZoomLevelChange NOTIFY maximumZoomLevelChangeChanged)
    Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged)
    Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged)
    Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged)
    Q_PROPERTY(qreal maximumTilt READ maximumTilt WRITE setMaximumTilt NOTIFY maximumTiltChanged)
    Q_PROPERTY(qreal minimumTilt READ minimumTilt WRITE setMinimumTilt NOTIFY minimumTiltChanged)
    Q_PROPERTY(qreal maximumTiltChange READ maximumTiltChange WRITE setMaximumTiltChange NOTIFY maximumTiltChangeChanged)

public:
    QDeclarativeGeoMapPinchArea(QDeclarative3DGraphicsGeoMap* map, QObject *parent = 0);
    ~QDeclarativeGeoMapPinchArea();

    enum ActiveGesture {
        NoGesture = 0x0000,
        ZoomGesture = 0x0001,
        RotationGesture = 0x0002,
        TiltGesture = 0x0004
    };
    Q_DECLARE_FLAGS(ActiveGestures, ActiveGesture);

    ActiveGestures activeGestures() const;
    void setActiveGestures(ActiveGestures activeGestures);

    bool active() const;
    void setActive(bool active);

    bool enabled() const;
    void setEnabled(bool enabled);

    qreal minimumZoomLevel() const;
    void setMinimumZoomLevel(qreal zoomLevel);

    qreal maximumZoomLevel() const;
    void setMaximumZoomLevel(qreal zoomLevel);

    qreal maximumZoomLevelChange() const;
    void setMaximumZoomLevelChange(qreal maxChange);

    qreal minimumRotation() const;
    void setMinimumRotation(qreal zoomLevel);

    qreal maximumRotation() const;
    void setMaximumRotation(qreal zoomLevel);

    qreal rotationSpeed() const;
    void setRotationSpeed(qreal speed);

    qreal maximumTilt() const;
    void setMaximumTilt(qreal tilt);

    qreal minimumTilt() const;
    void setMinimumTilt(qreal tilt);

    qreal maximumTiltChange() const;
    void setMaximumTiltChange(qreal tilt);

    // TODO likely we only need touchEvent, not mouseEvents.
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void touchEvent(QTouchEvent *event);

signals:
    void activeChanged();
    void enabledChanged();
    void minimumZoomLevelChanged();
    void maximumZoomLevelChanged();
    void maximumZoomLevelChangeChanged();
    void minimumRotationChanged();
    void maximumRotationChanged();
    void rotationSpeedChanged();
    void activeGesturesChanged();
    void minimumTiltChanged();
    void maximumTiltChanged();
    void maximumTiltChangeChanged();

    void pinchStarted(QDeclarativeGeoMapPinchEvent* pinch);
    void pinchUpdated(QDeclarativeGeoMapPinchEvent* pinch);
    void pinchFinished(QDeclarativeGeoMapPinchEvent* pinch);

private:
    void updatePinch();

private:
    // pinch target (fixed for now)
    QDeclarative3DGraphicsGeoMap* map_;

    // own
    bool enabled_;

    // qsgpinch
    bool active_;
    qreal minimumZoomLevel_;
    qreal maximumZoomLevel_;
    qreal minimumRotation_;
    qreal maximumRotation_;

    // qsgpincharea
    QList<QTouchEvent::TouchPoint> touchPoints_;
    bool inPinch_;
    bool pinchRejected_;
    bool pinchActivated_;
    //QSGPinch *pinch_;
    QPointF sceneStartPoint1_;
    QPointF sceneStartPoint2_;
    QPointF lastPoint1_;
    QPointF lastPoint2_;
    qreal pinchStartDist_;
    qreal pinchStartZoomLevel_;
    qreal pinchLastZoomLevel_;
    qreal pinchStartRotation_;
    qreal pinchStartAngle_;
    qreal pinchLastAngle_;
    qreal pinchRotation_;
    QPointF sceneStartCenter_;
    QPointF pinchStartCenter_;
    QPointF sceneLastCenter_;
    QPointF pinchStartPos_;
    int id1_;
    qreal maximumZoomLevelChange_;
    qreal rotationSpeed_;
    ActiveGestures activeGestures_;
    qreal minimumTilt_;
    qreal maximumTilt_;
    qreal maximumTiltChange_;

    qreal pinchLastTilt_;
    qreal pinchStartTilt_;
};

QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeGeoMapPinchArea);

#endif