source: trunk/src/gui/kernel/qgesture.cpp@ 624

Last change on this file since 624 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 19.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qgesture.h"
43#include "private/qgesture_p.h"
44
45QT_BEGIN_NAMESPACE
46
47 /*!
48 \class QGesture
49 \since 4.6
50 \ingroup gestures
51
52 \brief The QGesture class represents a gesture, containing properties that
53 describe the corresponding user input.
54
55 Gesture objects are not constructed directly by developers. They are created by
56 the QGestureRecognizer object that is registered with the application; see
57 QGestureRecognizer::registerRecognizer().
58
59 \section1 Gesture Properties
60
61 The class has a list of properties that can be queried by the user to get
62 some gesture-specific arguments. For example, the pinch gesture has a scale
63 factor that is exposed as a property.
64
65 Developers of custom gesture recognizers can add additional properties in
66 order to provide additional information about a gesture. This can be done
67 by adding new dynamic properties to a QGesture object, or by subclassing
68 the QGesture class (or one of its subclasses).
69
70 \section1 Lifecycle of a Gesture Object
71
72 A QGesture instance is implicitly created when needed and is owned by Qt.
73 Developers should never destroy them or store them for later use as Qt may
74 destroy particular instances of them and create new ones to replace them.
75
76 The registered gesture recognizer monitors the input events for the target
77 object via its \l{QGestureRecognizer::}{recognize()} function, updating the
78 properties of the gesture object as required.
79
80 The gesture object may be delivered to the target object in a QGestureEvent if
81 the corresponding gesture is active or has just been canceled. Each event that
82 is delivered contains a list of gesture objects, since support for more than
83 one gesture may be enabled for the target object. Due to the way events are
84 handled in Qt, gesture events may be filtered by other objects.
85
86 \sa QGestureEvent, QGestureRecognizer
87*/
88
89/*!
90 Constructs a new gesture object with the given \a parent.
91
92 QGesture objects are created by gesture recognizers in the
93 QGestureRecognizer::create() function.
94*/
95QGesture::QGesture(QObject *parent)
96 : QObject(*new QGesturePrivate, parent)
97{
98 d_func()->gestureType = Qt::CustomGesture;
99}
100
101/*!
102 \internal
103*/
104QGesture::QGesture(QGesturePrivate &dd, QObject *parent)
105 : QObject(dd, parent)
106{
107}
108
109/*!
110 Destroys the gesture object.
111*/
112QGesture::~QGesture()
113{
114}
115
116/*!
117 \property QGesture::state
118 \brief the current state of the gesture
119*/
120
121/*!
122 \property QGesture::gestureType
123 \brief the type of the gesture
124*/
125
126/*!
127 \property QGesture::hotSpot
128
129 \brief The point that is used to find the receiver for the gesture event.
130
131 The hot-spot is a point in the global coordinate system, use
132 QWidget::mapFromGlobal() or QGestureEvent::mapToGraphicsScene() to get a
133 local hot-spot.
134
135 The hot-spot should be set by the gesture recognizer to allow gesture event
136 delivery to a QGraphicsObject.
137*/
138
139/*!
140 \property QGesture::hasHotSpot
141 \brief whether the gesture has a hot-spot
142*/
143
144Qt::GestureType QGesture::gestureType() const
145{
146 return d_func()->gestureType;
147}
148
149Qt::GestureState QGesture::state() const
150{
151 return d_func()->state;
152}
153
154QPointF QGesture::hotSpot() const
155{
156 return d_func()->hotSpot;
157}
158
159void QGesture::setHotSpot(const QPointF &value)
160{
161 Q_D(QGesture);
162 d->hotSpot = value;
163 d->isHotSpotSet = true;
164}
165
166bool QGesture::hasHotSpot() const
167{
168 return d_func()->isHotSpotSet;
169}
170
171void QGesture::unsetHotSpot()
172{
173 d_func()->isHotSpotSet = false;
174}
175
176/*!
177 \property QGesture::gestureCancelPolicy
178 \brief the policy for deciding what happens on accepting a gesture
179
180 On accepting one gesture Qt can automatically cancel other gestures
181 that belong to other targets. The policy is normally set to not cancel
182 any other gestures and can be set to cancel all active gestures in the
183 context. For example for all child widgets.
184*/
185
186/*!
187 \enum QGesture::GestureCancelPolicy
188
189 This enum describes how accepting a gesture can cancel other gestures
190 automatically.
191
192 \value CancelNone On accepting this gesture no other gestures will be affected.
193
194 \value CancelAllInContext On accepting this gesture all gestures that are
195 active in the context (respecting the Qt::GestureFlag that were specified
196 when subscribed to the gesture) will be cancelled.
197*/
198
199void QGesture::setGestureCancelPolicy(GestureCancelPolicy policy)
200{
201 Q_D(QGesture);
202 d->gestureCancelPolicy = static_cast<uint>(policy);
203}
204
205QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const
206{
207 Q_D(const QGesture);
208 return static_cast<GestureCancelPolicy>(d->gestureCancelPolicy);
209}
210
211/*!
212 \class QPanGesture
213 \since 4.6
214 \brief The QPanGesture class describes a panning gesture made by the user.
215 \ingroup gestures
216
217 \image pangesture.png
218
219 \sa {Gestures Programming}, QPinchGesture, QSwipeGesture
220*/
221
222/*!
223 \property QPanGesture::lastOffset
224 \brief the last offset recorded for this gesture
225
226 The last offset contains the change in position of the user's input as
227 reported in the \l offset property when a previous gesture event was
228 delivered for this gesture.
229
230 If no previous event was delivered with information about this gesture
231 (i.e., this gesture object contains information about the first movement
232 in the gesture) then this property contains a zero size.
233*/
234
235/*!
236 \property QPanGesture::offset
237 \brief the total offset from the first input position to the current input
238 position
239
240 The offset measures the total change in position of the user's input
241 covered by the gesture on the input device.
242*/
243
244/*!
245 \property QPanGesture::delta
246 \brief the offset from the previous input position to the current input
247
248 This is essentially the same as the difference between offset() and
249 lastOffset().
250*/
251
252/*!
253 \property QPanGesture::acceleration
254*/
255
256/*!
257 \internal
258*/
259QPanGesture::QPanGesture(QObject *parent)
260 : QGesture(*new QPanGesturePrivate, parent)
261{
262 d_func()->gestureType = Qt::PanGesture;
263}
264
265
266QPointF QPanGesture::lastOffset() const
267{
268 return d_func()->lastOffset;
269}
270
271QPointF QPanGesture::offset() const
272{
273 return d_func()->offset;
274}
275
276QPointF QPanGesture::delta() const
277{
278 Q_D(const QPanGesture);
279 return d->offset - d->lastOffset;
280}
281
282qreal QPanGesture::acceleration() const
283{
284 return d_func()->acceleration;
285}
286
287void QPanGesture::setLastOffset(const QPointF &value)
288{
289 d_func()->lastOffset = value;
290}
291
292void QPanGesture::setOffset(const QPointF &value)
293{
294 d_func()->offset = value;
295}
296
297void QPanGesture::setAcceleration(qreal value)
298{
299 d_func()->acceleration = value;
300}
301
302/*!
303 \class QPinchGesture
304 \since 4.6
305 \brief The QPinchGesture class describes a pinch gesture made my the user.
306 \ingroup multitouch
307 \ingroup gestures
308
309 A pinch gesture is a form of multitouch user input in which the user typically
310 touches two points on the input device with a thumb and finger, before moving
311 them closer together or further apart to change the scale factor, zoom, or level
312 of detail of the user interface.
313
314 \image pinchgesture.png
315
316 Instead of repeatedly applying the same pinching gesture, the user may
317 continue to touch the input device in one place, and apply a second touch
318 to a new point, continuing the gesture. When this occurs, gesture events
319 will continue to be delivered to the target object, containing an instance
320 of QPinchGesture in the Qt::GestureUpdated state.
321
322 \sa {Gestures Programming}, QPanGesture, QSwipeGesture
323*/
324
325/*!
326 \enum QPinchGesture::ChangeFlag
327
328 This enum describes the changes that can occur to the properties of
329 the gesture object.
330
331 \value ScaleFactorChanged The scale factor held by scaleFactor changed.
332 \value RotationAngleChanged The rotation angle held by rotationAngle changed.
333 \value CenterPointChanged The center point held by centerPoint changed.
334
335 \sa changeFlags, totalChangeFlags
336*/
337
338/*!
339 \property QPinchGesture::totalChangeFlags
340 \brief the property of the gesture that has change
341
342 This property indicates which of the other properties has changed since the
343 gesture has started. You can use this information to determine which aspect
344 of your user interface needs to be updated.
345
346 \sa changeFlags, scaleFactor, rotationAngle, centerPoint
347*/
348
349/*!
350 \property QPinchGesture::changeFlags
351 \brief the property of the gesture that has changed in the current step
352
353 This property indicates which of the other properties has changed since
354 the previous gesture event included information about this gesture. You
355 can use this information to determine which aspect of your user interface
356 needs to be updated.
357
358 \sa totalChangeFlags, scaleFactor, rotationAngle, centerPoint
359*/
360
361/*!
362 \property QPinchGesture::totalScaleFactor
363 \brief the total scale factor
364
365 The total scale factor measures the total change in scale factor from the
366 original value to the current scale factor.
367
368 \sa scaleFactor, lastScaleFactor
369*/
370/*!
371 \property QPinchGesture::lastScaleFactor
372 \brief the last scale factor recorded for this gesture
373
374 The last scale factor contains the scale factor reported in the
375 \l scaleFactor property when a previous gesture event included
376 information about this gesture.
377
378 If no previous event was delivered with information about this gesture
379 (i.e., this gesture object contains information about the first movement
380 in the gesture) then this property contains zero.
381
382 \sa scaleFactor, totalScaleFactor
383*/
384/*!
385 \property QPinchGesture::scaleFactor
386 \brief the current scale factor
387
388 The scale factor measures the scale factor associated with the distance
389 between two of the user's inputs on a multitouch device.