summaryrefslogtreecommitdiff
path: root/src/imports/location/qdeclarativegeomappincharea.cpp
blob: 7152ee7bba9b71f0f7e3b2ad4824ac1b8cea0cf8 (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** 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$
**
****************************************************************************/

#include <QtGui/QGuiApplication>
#include "qdeclarativegeomappincharea_p.h"
#include "qdeclarativegeomap_p.h"
#include "qdeclarativecoordinate_p.h"
#include <QtGui/qevent.h>
#include <QtGui/QStyleHints>
#include <QtQml/qqmlinfo.h>
#include <QPropertyAnimation>
#include <QDebug>
#include "math.h"
#include "qgeomap_p.h"

#define QML_MAP_FLICK_DEFAULTMAXVELOCITY 2500
#define QML_MAP_FLICK_MINIMUMDECELERATION 500
#define QML_MAP_FLICK_DEFAULTDECELERATION 2500
#define QML_MAP_FLICK_MAXIMUMDECELERATION 10000
// The number of samples to use in calculating the velocity of a flick
#define QML_MAP_FLICK_SAMPLEBUFFER 3
// The number of samples to discard when calculating the flick velocity.
// Touch panels often produce inaccurate results as the finger is lifted.
#define QML_MAP_FLICK_DISCARDSAMPLES 1

// FlickThreshold determines how far the "mouse" must have moved
// before we perform a flick.
static const int FlickThreshold = 20;
// RetainGrabVelocity is the maxmimum instantaneous velocity that
// will ensure the Flickable retains the grab on consecutive flicks.
static const int RetainGrabVelocity = 15;
// Really slow flicks can be annoying.
const qreal MinimumFlickVelocity = 75.0;

QT_BEGIN_NAMESPACE


/*!
    \qmlclass MapPinchEvent
    \inqmlmodule QtLocation 5

    \brief MapPinchEvent element provides basic information about pinch event.

    MapPinchEvent element provides basic information about pinch event. They are
    present in handlers of MapPinch (for example pinchStarted/pinchUpdated). Events are only
    guaranteed to be valid for the duration of the handler.

    Except for the \l accepted property, all properties are read-only.

    \section2 Example Usage

    The following example enables the pinch gesture on a map and reacts to the
    finished event.

    \code
    Map {
        id: map
        pinch.enabled: true
        pinch.onPinchFinished:{
            var coordinate1 = map.toCoordinate(pinch.point1)
            var coordinate2 = map.toCoordinate(pinch.point2)
            console.log("Pinch startet at:")
            console.log("        Points (" + pinch.point1.x + ", " + pinch.point1.y + ") - (" + pinch.point2.x + ", " + pinch.point2.y + ")")
            console.log("   Coordinates (" + coordinate1.latitude + ", " + coordinate1.longitude + ") - (" + coordinate2.latitude + ", " + coordinate2.longitude + ")")
        }
    }
    \endcode

    \ingroup qml-QtLocation5-maps
    \since Qt Location 5.0
*/

/*!
    \qmlproperty QPoint QtLocation5::MapPinchEvent::center

    This read-only property holds the current center point.
*/

/*!
    \qmlproperty real QtLocation5::MapPinchEvent::angle

    This read-only property holds the current angle between the two points in
    the range -180 to 180. Positive values for the angles mean counter-clockwise
    while negative values mean the clockwise direction. Zero degrees is at the
    3 o'clock position.
*/

/*!
    \qmlproperty QPoint QtLocation5::MapPinchEvent::point1
    \qmlproperty QPoint QtLocation5::MapPinchEvent::point2

    These read-only properties hold the actual touch points generating the pinch.
    The points are not in any particular order.
*/

/*!
    \qmlproperty int QtLocation5::MapPinchEvent::pointCount

    This read-only property holds the number of points currently touched.
    The MapPinch will not react until two touch points have initiated a gesture,
    but will remain active until all touch points have been released.
*/

/*!
    \qmlproperty bool QtLocation5::MapPinchEvent::accepted

    Setting this property to false in the \c MapPinch::onPinchStarted handler
    will result in no further pinch events being generated, and the gesture
    ignored.
*/

/*!
    \qmlclass MapPinchArea QDeclarativeGeoMapPinchArea

    \inqmlmodule QtLocation 5

    \brief The MapPinchArea element provides basic Map pinch interaction.

    MapPinchArea elements are used as part of a Map, to provide for the
    pinch-to-zoom gesture used on touch displays. This is comparable to the
    activity of the \l{PinchArea} element.

    A MapPinchArea is automatically created with a new Map and available with
    the \l{QtLocation5::Map::pinch}{pinch} property. This is the only way
    to create a MapPinchArea, and once created this way cannot be destroyed
    without its parent Map.

    The two most commonly used properties of the MapPinchArea are the \l enabled
    and \l activeGestures properties. Both of these must be set before a
    MapPinchArea will have any effect upon interaction with the Map.

    \section2 Performance

    The MapPinchArea, when enabled, must process all incoming touch events in
    order to track the shape and size of the "pinch". The overhead added on
    touch events can be considered constant time.

    \section2 Example Usage

    The following example enables the pinch gesture on a map.

    \code
    Map {
        pinch.enabled: true
        pinch.activeGestures: MapPinchArea.ZoomGesture
    }
    \endcode

    \ingroup qml-QtLocation5-maps
    \since Qt Location 5.0
*/

/*!
    \qmlproperty bool QtLocation5::MapPinchArea::enabled

    This property holds whether the pinch gestures are enabled.
    Note: disabling pinch during active pinch does not have effect on
    the potentially active current pinch.
*/

/*!
    \qmlproperty bool QtLocation5::MapPinchArea::active

    This read-only property holds whether a pinch gesture is active.
*/

/*!
    \qmlproperty enumeration QtLocation5::MapPinchArea::activeGestures

    This property holds the gestures that the pinch should control. By default
    the ZoomGesture is enabled.

    \list
    \li PinchArea.NoGesture - Don't support any additional gestures (value: 0x0000).
    \li PinchArea.ZoomGesture - Support the map zoom gesture (value: 0x0001).
    \li PinchArea.RotationGesture - Support the map rotation gesture (value: 0x0002).
    \li PinchArea.TiltGesture - Support the map tilt gesture (value: 0x0004).
    \li PinchArea.PanGesture  - Support the map pan gesture while pinching (value: 0x0008).
    \endlist

    For the extremist, one may OR flag the RotationGesture or TiltGesture
    but these come with absolutely no warranty or guarantees at the moment
    (may be removed, changed, moved around)

    \note For the time being, only \l PinchArea.ZoomGesture is supported.
*/

/*!
    \qmlproperty real QtLocation5::MapPinchArea::maximumZoomLevelChange

    This property holds the maximum zoom level change per pinch, essentially
    meant to be used for setting the zoom sensitivity.

    It is an indicative measure calculated from the dimensions of the
    map area, roughly corresponding how much zoom level could change with
    maximum pinch zoom. Default value is 2.0, maximum value is 10.0
*/

/*!
    \qmlproperty real MapPinchArea::rotationFactor

    This property holds the rotation factor for zoom, essentially meant to be used for setting
    the rotation sensitivity.

    It is an indicative measure; the default value 1.0 means the map roughly follows the fingers,
    whereas 2.0 means rotating twice as fast. Maximum value is 5.0.
*/

/*!
    \qmlsignal void QtLocation5::MapPinchArea::pinchStarted(PinchEvent event)

    Raised when a pinch gesture is started.

    \sa pinchUpdated, pinchFinished
*/

/*!
    \qmlsignal void QtLocation5::MapPinchArea::pinchUpdated(PinchEvent event)

    Once a pinch has begun this event gets raised as the user moves her fingers
    across the map.

    \sa pinchStarted, pinchFinished
*/

/*!
    \qmlsignal void QtLocation5::MapPinchArea::pinchUpdated(PinchEvent event)

    The end of a pinch gesture is signaled by this event.

    \sa pinchUpdated, pinchFinished
*/

/*!
    \qmlproperty bool QtLocation5::MapPinchArea::enabled

    This property holds whether the pinch gestures are enabled.
    Note: disabling pinch during active pinch does not have effect on
    the potentially active current pinch.
*/


QDeclarativeGeoMapPinchArea::QDeclarativeGeoMapPinchArea(QObject *parent,
                                                         QDeclarativeGeoMapGestureArea *gestureArea)
    : QObject(parent),
      gestureArea_(gestureArea)
{
    gestureArea_->registerPinchDeprecated(this);
}

QDeclarativeGeoMapPinchArea::~QDeclarativeGeoMapPinchArea()
{
}

#include "moc_qdeclarativegeomappincharea_p.cpp"

QT_END_NAMESPACE