52 \brief The QGesture class represents a gesture, containing properties that |
52 \brief The QGesture class represents a gesture, containing properties that |
53 describe the corresponding user input. |
53 describe the corresponding user input. |
54 |
54 |
55 Gesture objects are not constructed directly by developers. They are created by |
55 Gesture objects are not constructed directly by developers. They are created by |
56 the QGestureRecognizer object that is registered with the application; see |
56 the QGestureRecognizer object that is registered with the application; see |
57 QApplication::registerGestureRecognizer(). |
57 QGestureRecognizer::registerRecognizer(). |
58 |
58 |
59 \section1 Gesture Properties |
59 \section1 Gesture Properties |
60 |
60 |
61 The class has a list of properties that can be queried by the user to get |
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 |
62 some gesture-specific arguments. For example, the pinch gesture has a scale |
67 by adding new dynamic properties to a QGesture object, or by subclassing |
67 by adding new dynamic properties to a QGesture object, or by subclassing |
68 the QGesture class (or one of its subclasses). |
68 the QGesture class (or one of its subclasses). |
69 |
69 |
70 \section1 Lifecycle of a Gesture Object |
70 \section1 Lifecycle of a Gesture Object |
71 |
71 |
72 A QGesture instance is created when the application calls QWidget::grabGesture() |
72 A QGesture instance is implicitly created when needed and is owned by Qt. |
73 or QGraphicsObject::grabGesture() to configure a widget or graphics object (the |
73 Developers should never destroy them or store them for later use as Qt may |
74 target object) for gesture input. One gesture object is created for each target |
74 destroy particular instances of them and create new ones to replace them. |
75 object. |
|
76 |
75 |
77 The registered gesture recognizer monitors the input events for the target |
76 The registered gesture recognizer monitors the input events for the target |
78 object via its \l{QGestureRecognizer::}{filterEvent()} function, updating the |
77 object via its \l{QGestureRecognizer::}{recognize()} function, updating the |
79 properties of the gesture object as required. |
78 properties of the gesture object as required. |
80 |
79 |
81 The gesture object may be delivered to the target object in a QGestureEvent if |
80 The gesture object may be delivered to the target object in a QGestureEvent if |
82 the corresponding gesture is active or has just been canceled. Each event that |
81 the corresponding gesture is active or has just been canceled. Each event that |
83 is delivered contains a list of gesture objects, since support for more than |
82 is delivered contains a list of gesture objects, since support for more than |
89 |
88 |
90 /*! |
89 /*! |
91 Constructs a new gesture object with the given \a parent. |
90 Constructs a new gesture object with the given \a parent. |
92 |
91 |
93 QGesture objects are created by gesture recognizers in the |
92 QGesture objects are created by gesture recognizers in the |
94 QGestureRecognizer::createGesture() function. |
93 QGestureRecognizer::create() function. |
95 */ |
94 */ |
96 QGesture::QGesture(QObject *parent) |
95 QGesture::QGesture(QObject *parent) |
97 : QObject(*new QGesturePrivate, parent) |
96 : QObject(*new QGesturePrivate, parent) |
98 { |
97 { |
99 d_func()->gestureType = Qt::CustomGesture; |
98 d_func()->gestureType = Qt::CustomGesture; |
128 \property QGesture::hotSpot |
127 \property QGesture::hotSpot |
129 |
128 |
130 \brief The point that is used to find the receiver for the gesture event. |
129 \brief The point that is used to find the receiver for the gesture event. |
131 |
130 |
132 The hot-spot is a point in the global coordinate system, use |
131 The hot-spot is a point in the global coordinate system, use |
133 QWidget::mapFromGlobal() or QGestureEvent::mapToScene() to get a |
132 QWidget::mapFromGlobal() or QGestureEvent::mapToGraphicsScene() to get a |
134 local hot-spot. |
133 local hot-spot. |
135 |
134 |
136 If the hot-spot is not set, the targetObject is used as the receiver of the |
135 The hot-spot should be set by the gesture recognizer to allow gesture event |
137 gesture event. |
136 delivery to a QGraphicsObject. |
138 */ |
137 */ |
139 |
138 |
140 /*! |
139 /*! |
141 \property QGesture::hasHotSpot |
140 \property QGesture::hasHotSpot |
142 \brief whether the gesture has a hot-spot |
141 \brief whether the gesture has a hot-spot |
143 */ |
|
144 |
|
145 /*! |
|
146 \property QGesture::targetObject |
|
147 \brief the target object which will receive the gesture event if the hotSpot is |
|
148 not set |
|
149 */ |
142 */ |
150 |
143 |
151 Qt::GestureType QGesture::gestureType() const |
144 Qt::GestureType QGesture::gestureType() const |
152 { |
145 { |
153 return d_func()->gestureType; |
146 return d_func()->gestureType; |
176 } |
169 } |
177 |
170 |
178 void QGesture::unsetHotSpot() |
171 void QGesture::unsetHotSpot() |
179 { |
172 { |
180 d_func()->isHotSpotSet = false; |
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 |
|
199 void QGesture::setGestureCancelPolicy(GestureCancelPolicy policy) |
|
200 { |
|
201 Q_D(QGesture); |
|
202 d->gestureCancelPolicy = static_cast<uint>(policy); |
|
203 } |
|
204 |
|
205 QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const |
|
206 { |
|
207 Q_D(const QGesture); |
|
208 return static_cast<GestureCancelPolicy>(d->gestureCancelPolicy); |
181 } |
209 } |
182 |
210 |
183 /*! |
211 /*! |
184 \class QPanGesture |
212 \class QPanGesture |
185 \since 4.6 |
213 \since 4.6 |
190 |
218 |
191 \sa {Gestures Programming}, QPinchGesture, QSwipeGesture |
219 \sa {Gestures Programming}, QPinchGesture, QSwipeGesture |
192 */ |
220 */ |
193 |
221 |
194 /*! |
222 /*! |
195 \property QPanGesture::totalOffset |
|
196 \brief the total offset from the first input position to the current input |
|
197 position |
|
198 |
|
199 The total offset measures the total change in position of the user's input |
|
200 covered by the gesture on the input device. |
|
201 */ |
|
202 |
|
203 /*! |
|
204 \property QPanGesture::lastOffset |
223 \property QPanGesture::lastOffset |
205 \brief the last offset recorded for this gesture |
224 \brief the last offset recorded for this gesture |
206 |
225 |
207 The last offset contains the change in position of the user's input as |
226 The last offset contains the change in position of the user's input as |
208 reported in the \l offset property when a previous gesture event was |
227 reported in the \l offset property when a previous gesture event was |
213 in the gesture) then this property contains a zero size. |
232 in the gesture) then this property contains a zero size. |
214 */ |
233 */ |
215 |
234 |
216 /*! |
235 /*! |
217 \property QPanGesture::offset |
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 |
218 \brief the offset from the previous input position to the current input |
246 \brief the offset from the previous input position to the current input |
219 position |
247 |
220 |
248 This is essentially the same as the difference between offset() and |
221 The offset measures the change in position of the user's input on the |
249 lastOffset(). |
222 input device. |
|
223 */ |
250 */ |
224 |
251 |
225 /*! |
252 /*! |
226 \property QPanGesture::acceleration |
253 \property QPanGesture::acceleration |
227 */ |
254 */ |
233 : QGesture(*new QPanGesturePrivate, parent) |
260 : QGesture(*new QPanGesturePrivate, parent) |
234 { |
261 { |
235 d_func()->gestureType = Qt::PanGesture; |
262 d_func()->gestureType = Qt::PanGesture; |
236 } |
263 } |
237 |
264 |
238 QPointF QPanGesture::totalOffset() const |
|
239 { |
|
240 return d_func()->totalOffset; |
|
241 } |
|
242 |
265 |
243 QPointF QPanGesture::lastOffset() const |
266 QPointF QPanGesture::lastOffset() const |
244 { |
267 { |
245 return d_func()->lastOffset; |
268 return d_func()->lastOffset; |
246 } |
269 } |
248 QPointF QPanGesture::offset() const |
271 QPointF QPanGesture::offset() const |
249 { |
272 { |
250 return d_func()->offset; |
273 return d_func()->offset; |
251 } |
274 } |
252 |
275 |
|
276 QPointF QPanGesture::delta() const |
|
277 { |
|
278 Q_D(const QPanGesture); |
|
279 return d->offset - d->lastOffset; |
|
280 } |
|
281 |
253 qreal QPanGesture::acceleration() const |
282 qreal QPanGesture::acceleration() const |
254 { |
283 { |
255 return d_func()->acceleration; |
284 return d_func()->acceleration; |
256 } |
|
257 |
|
258 |
|
259 void QPanGesture::setTotalOffset(const QPointF &value) |
|
260 { |
|
261 d_func()->totalOffset = value; |
|
262 } |
285 } |
263 |
286 |
264 void QPanGesture::setLastOffset(const QPointF &value) |
287 void QPanGesture::setLastOffset(const QPointF &value) |
265 { |
288 { |
266 d_func()->lastOffset = value; |
289 d_func()->lastOffset = value; |
298 |
321 |
299 \sa {Gestures Programming}, QPanGesture, QSwipeGesture |
322 \sa {Gestures Programming}, QPanGesture, QSwipeGesture |
300 */ |
323 */ |
301 |
324 |
302 /*! |
325 /*! |
303 \enum QPinchGesture::WhatChange |
326 \enum QPinchGesture::ChangeFlag |
304 |
327 |
305 This enum describes the changes that can occur to the properties of |
328 This enum describes the changes that can occur to the properties of |
306 the gesture object. |
329 the gesture object. |
307 |
330 |
308 \value ScaleFactorChanged The scale factor held by scaleFactor changed. |
331 \value ScaleFactorChanged The scale factor held by scaleFactor changed. |
309 \value RotationAngleChanged The rotation angle held by rotationAngle changed. |
332 \value RotationAngleChanged The rotation angle held by rotationAngle changed. |
310 \value CenterPointChanged The center point held by centerPoint changed. |
333 \value CenterPointChanged The center point held by centerPoint changed. |
311 |
334 |
312 \sa whatChanged |
335 \sa changeFlags, totalChangeFlags |
313 */ |
336 */ |
314 |
337 |
315 /*! |
338 /*! |
316 \property QPinchGesture::whatChanged |
339 \property QPinchGesture::totalChangeFlags |
317 \brief the property of the gesture that has changed |
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 |
318 |
352 |
319 This property indicates which of the other properties has changed since |
353 This property indicates which of the other properties has changed since |
320 the previous gesture event included information about this gesture. You |
354 the previous gesture event included information about this gesture. You |
321 can use this information to determine which aspect of your user interface |
355 can use this information to determine which aspect of your user interface |
322 needs to be updated. |
356 needs to be updated. |
323 |
357 |
324 \sa scaleFactor, rotationAngle, centerPoint |
358 \sa totalChangeFlags, scaleFactor, rotationAngle, centerPoint |
325 */ |
359 */ |
326 |
360 |
327 /*! |
361 /*! |
328 \property QPinchGesture::totalScaleFactor |
362 \property QPinchGesture::totalScaleFactor |
329 \brief the total scale factor |
363 \brief the total scale factor |
413 : QGesture(*new QPinchGesturePrivate, parent) |
447 : QGesture(*new QPinchGesturePrivate, parent) |
414 { |
448 { |
415 d_func()->gestureType = Qt::PinchGesture; |
449 d_func()->gestureType = Qt::PinchGesture; |
416 } |
450 } |
417 |
451 |
418 QPinchGesture::WhatChanged QPinchGesture::whatChanged() const |
452 QPinchGesture::ChangeFlags QPinchGesture::totalChangeFlags() const |
419 { |
453 { |
420 return d_func()->whatChanged; |
454 return d_func()->totalChangeFlags; |
421 } |
455 } |
422 |
456 |
423 void QPinchGesture::setWhatChanged(QPinchGesture::WhatChanged value) |
457 void QPinchGesture::setTotalChangeFlags(QPinchGesture::ChangeFlags value) |
424 { |
458 { |
425 d_func()->whatChanged = value; |
459 d_func()->totalChangeFlags = value; |
426 } |
460 } |
427 |
461 |
|
462 QPinchGesture::ChangeFlags QPinchGesture::changeFlags() const |
|
463 { |
|
464 return d_func()->changeFlags; |
|
465 } |
|
466 |
|
467 void QPinchGesture::setChangeFlags(QPinchGesture::ChangeFlags value) |
|
468 { |
|
469 d_func()->changeFlags = value; |
|
470 } |
428 |
471 |
429 QPointF QPinchGesture::startCenterPoint() const |
472 QPointF QPinchGesture::startCenterPoint() const |
430 { |
473 { |
431 return d_func()->startCenterPoint; |
474 return d_func()->startCenterPoint; |
432 } |
475 } |
613 void QSwipeGesture::setSwipeAngle(qreal value) |
656 void QSwipeGesture::setSwipeAngle(qreal value) |
614 { |
657 { |
615 d_func()->swipeAngle = value; |
658 d_func()->swipeAngle = value; |
616 } |
659 } |
617 |
660 |
|
661 /*! |
|
662 \class QTapGesture |
|
663 \since 4.6 |
|
664 \brief The QTapGesture class describes a tap gesture made by the user. |
|
665 \ingroup gestures |
|
666 |
|
667 \sa {Gestures Programming}, QPanGesture, QPinchGesture |
|
668 */ |
|
669 |
|
670 /*! |
|
671 \property QTapGesture::position |
|
672 \brief the position of the tap |
|
673 */ |
|
674 |
|
675 /*! |
|
676 \internal |
|
677 */ |
|
678 QTapGesture::QTapGesture(QObject *parent) |
|
679 : QGesture(*new QTapGesturePrivate, parent) |
|
680 { |
|
681 d_func()->gestureType = Qt::TapGesture; |
|
682 } |
|
683 |
|
684 QPointF QTapGesture::position() const |
|
685 { |
|
686 return d_func()->position; |
|
687 } |
|
688 |
|
689 void QTapGesture::setPosition(const QPointF &value) |
|
690 { |
|
691 d_func()->position = value; |
|
692 } |
|
693 /*! |
|
694 \class QTapAndHoldGesture |
|
695 \since 4.6 |
|
696 \brief The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) |
|
697 gesture made by the user. |
|
698 \ingroup gestures |
|
699 |
|
700 \sa {Gestures Programming}, QPanGesture, QPinchGesture |
|
701 */ |
|
702 |
|
703 /*! |
|
704 \property QTapAndHoldGesture::position |
|
705 \brief the position of the tap |
|
706 */ |
|
707 |
|
708 /*! |
|
709 \internal |
|
710 */ |
|
711 QTapAndHoldGesture::QTapAndHoldGesture(QObject *parent) |
|
712 : QGesture(*new QTapAndHoldGesturePrivate, parent) |
|
713 { |
|
714 d_func()->gestureType = Qt::TapAndHoldGesture; |
|
715 } |
|
716 |
|
717 QPointF QTapAndHoldGesture::position() const |
|
718 { |
|
719 return d_func()->position; |
|
720 } |
|
721 |
|
722 void QTapAndHoldGesture::setPosition(const QPointF &value) |
|
723 { |
|
724 d_func()->position = value; |
|
725 } |
|
726 |
618 QT_END_NAMESPACE |
727 QT_END_NAMESPACE |