summaryrefslogtreecommitdiff
path: root/src/imports/location/qdeclarativegeomappincharea_p.h
blob: 60aee11af88524d39ccd17d42421d02947eee6c7 (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
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QDECLARATIVEGEOMAPPINCHAREA_H
#define QDECLARATIVEGEOMAPPINCHAREA_H

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

QT_BEGIN_NAMESPACE

class QGraphicsSceneMouseEvent;
class QDeclarativeGeoMap;
class QTouchEvent;
class QGeoMap;

class QDeclarativeGeoMapPinchEvent : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QPointF center READ center)
    Q_PROPERTY(qreal angle READ angle)
    Q_PROPERTY(QPointF point1 READ point1)
    Q_PROPERTY(QPointF point2 READ point2)
    Q_PROPERTY(int pointCount READ pointCount)
    Q_PROPERTY(bool accepted READ accepted WRITE setAccepted)

public:
    QDeclarativeGeoMapPinchEvent(QPointF center, qreal angle,
                                 QPointF point1, QPointF point2,
                                 int pointCount = 0, bool accepted = true)
        : QObject(), center_(center), angle_(angle),
          point1_(point1), point2_(point2),
        pointCount_(pointCount), accepted_(accepted) {}
    QDeclarativeGeoMapPinchEvent() {}

    QPointF center() const { return center_; }
    void setCenter(QPointF center) { center_ = center; }
    qreal angle() const { return angle_; }
    void setAngle(qreal angle) { angle_ = angle; }
    QPointF point1() const { return point1_; }
    void setPoint1(QPointF p) { point1_ = p; }
    QPointF point2() const { return point2_; }
    void setPoint2(QPointF p) { point2_ = 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_;
    qreal angle_;
    QPointF point1_;
    QPointF point2_;
    int pointCount_;
    bool accepted_;
};

// tbd: should we have a 'active' / 'moving' boolean attribute when pinch is active?

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 maximumZoomLevelChange READ maximumZoomLevelChange WRITE setMaximumZoomLevelChange NOTIFY maximumZoomLevelChangeChanged)
    Q_PROPERTY(qreal rotationFactor READ rotationFactor WRITE setRotationFactor NOTIFY rotationFactorChanged)
    // need for these is not clear, use-case(s) not yet identified:
    //Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged)
    //Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged)
    //Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel WRITE setMinimumZoomLevel NOTIFY minimumZoomLevelChanged)
    //Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel WRITE setMaximumZoomLevel NOTIFY maximumZoomLevelChanged)
    // when tilt is supported, these are needed:
    //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(QDeclarativeGeoMap* 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 rotationFactor() const;
    void setRotationFactor(qreal factor);

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

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

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

    void touchEvent(QTouchEvent *event);

    void zoomLevelLimits(qreal min, qreal max);

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

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

private:
    void updatePinch();

private:
    QDeclarativeGeoMap* map_;
    QDeclarativeGeoMapPinchEvent pinchEvent_;
    bool enabled_;
    bool active_;
    qreal minimumZoomLevel_;
    qreal maximumZoomLevel_;
    qreal minimumRotation_;
    qreal maximumRotation_;
    QList<QTouchEvent::TouchPoint> touchPoints_;
    bool inPinch_;
    bool pinchRejected_;
    bool pinchActivated_;
    QPointF sceneStartPoint1_;
    QPointF sceneStartPoint2_;
    QPointF lastPoint1_;
    QPointF lastPoint2_;
    qreal pinchStartDist_;
    qreal pinchStartZoomLevel_;
    qreal pinchLastZoomLevel_;
    qreal pinchStartRotation_;
    qreal pinchLastAngle_;
    qreal pinchRotation_;
    QPointF sceneLastCenter_;
    int id1_;
    qreal maximumZoomLevelChange_;
    qreal rotationFactor_;
    ActiveGestures activeGestures_;
    qreal minimumTilt_;
    qreal maximumTilt_;
    qreal maximumTiltChange_;

    qreal pinchLastTilt_;
    qreal pinchStartTilt_;
};

QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeGeoMapPinchArea);

#endif