summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qgesture.cpp
blob: a16187600d35d27144c2135bbf5e274002f4089e (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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $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$
**
****************************************************************************/

#include "qgesture.h"
#include "private/qgesture_p.h"

QT_BEGIN_NAMESPACE

 /*!
    \class QGesture
    \since 4.6
    \ingroup gestures

    \brief The QGesture class represents a gesture, containing properties that
    describe the corresponding user input.

    Gesture objects are not constructed directly by developers. They are created by
    the QGestureRecognizer object that is registered with the application; see
    QApplication::registerGestureRecognizer().

    \section1 Gesture Properties

    The class has a list of properties that can be queried by the user to get
    some gesture-specific arguments. For example, the pinch gesture has a scale
    factor that is exposed as a property.

    Developers of custom gesture recognizers can add additional properties in
    order to provide additional information about a gesture. This can be done
    by adding new dynamic properties to a QGesture object, or by subclassing
    the QGesture class (or one of its subclasses).

    \section1 Lifecycle of a Gesture Object

    A QGesture instance is created when the application calls QWidget::grabGesture()
    or QGraphicsObject::grabGesture() to configure a widget or graphics object (the
    target object) for gesture input. One gesture object is created for each target
    object.

    The registered gesture recognizer monitors the input events for the target
    object via its \l{QGestureRecognizer::}{filterEvent()} function, updating the
    properties of the gesture object as required.

    The gesture object may be delivered to the target object in a QGestureEvent if
    the corresponding gesture is active or has just been canceled. Each event that
    is delivered contains a list of gesture objects, since support for more than
    one gesture may be enabled for the target object. Due to the way events are
    handled in Qt, gesture events may be filtered by other objects.

    \sa QGestureEvent, QGestureRecognizer
*/

/*!
    Constructs a new gesture object with the given \a parent.

    QGesture objects are created by gesture recognizers in the
    QGestureRecognizer::createGesture() function.
*/
QGesture::QGesture(QObject *parent)
    : QObject(*new QGesturePrivate, parent)
{
    d_func()->gestureType = Qt::CustomGesture;
}

/*!
    \internal
*/
QGesture::QGesture(QGesturePrivate &dd, QObject *parent)
    : QObject(dd, parent)
{
}

/*!
    Destroys the gesture object.
*/
QGesture::~QGesture()
{
}

/*!
    \property QGesture::state
    \brief the current state of the gesture
*/

/*!
    \property QGesture::gestureType
    \brief the type of the gesture
*/

/*!
    \property QGesture::hotSpot

    \brief The point that is used to find the receiver for the gesture event.

    The hot-spot is a point in the global coordinate system, use
    QWidget::mapFromGlobal() or QGestureEvent::mapToScene() to get a
    local hot-spot.

    If the hot-spot is not set, the targetObject is used as the receiver of the
    gesture event.
*/

/*!
    \property QGesture::hasHotSpot
    \brief whether the gesture has a hot-spot
*/

Qt::GestureType QGesture::gestureType() const
{
    return d_func()->gestureType;
}

Qt::GestureState QGesture::state() const
{
    return d_func()->state;
}

QPointF QGesture::hotSpot() const
{
    return d_func()->hotSpot;
}

void QGesture::setHotSpot(const QPointF &value)
{
    Q_D(QGesture);
    d->hotSpot = value;
    d->isHotSpotSet = true;
}

bool QGesture::hasHotSpot() const
{
    return d_func()->isHotSpotSet;
}

void QGesture::unsetHotSpot()
{
    d_func()->isHotSpotSet = false;
}

/*!
    \class QPanGesture
    \since 4.6
    \brief The QPanGesture class describes a panning gesture made by the user.
    \ingroup gestures

    \image pangesture.png

    \sa {Gestures Programming}, QPinchGesture, QSwipeGesture
*/

/*!
    \property QPanGesture::totalOffset
    \brief the total offset from the first input position to the current input
    position

    The total offset measures the total change in position of the user's input
    covered by the gesture on the input device.
*/

/*!
    \property QPanGesture::lastOffset
    \brief the last offset recorded for this gesture

    The last offset contains the change in position of the user's input as
    reported in the \l offset property when a previous gesture event was
    delivered for this gesture.

    If no previous event was delivered with information about this gesture
    (i.e., this gesture object contains information about the first movement
    in the gesture) then this property contains a zero size.
*/

/*!
    \property QPanGesture::offset
    \brief the offset from the previous input position to the current input
    position

    The offset measures the change in position of the user's input on the
    input device.
*/

/*!
    \property QPanGesture::acceleration
*/

/*!
    \internal
*/
QPanGesture::QPanGesture(QObject *parent)
    : QGesture(*new QPanGesturePrivate, parent)
{
    d_func()->gestureType = Qt::PanGesture;
}

QPointF QPanGesture::totalOffset() const
{
    return d_func()->totalOffset;
}

QPointF QPanGesture::lastOffset() const
{
    return d_func()->lastOffset;
}

QPointF QPanGesture::offset() const
{
    return d_func()->offset;
}

qreal QPanGesture::acceleration() const
{
    return d_func()->acceleration;
}


void QPanGesture::setTotalOffset(const QPointF &value)
{
    d_func()->totalOffset = value;
}

void QPanGesture::setLastOffset(const QPointF &value)
{
    d_func()->lastOffset = value;
}

void QPanGesture::setOffset(const QPointF &value)
{
    d_func()->offset = value;
}

void QPanGesture::setAcceleration(qreal value)
{
    d_func()->acceleration = value;
}

/*!
    \class QPinchGesture
    \since 4.6
    \brief The QPinchGesture class describes a pinch gesture made my the user.
    \ingroup multitouch
    \ingroup gestures

    A pinch gesture is a form of multitouch user input in which the user typically
    touches two points on the input device with a thumb and finger, before moving
    them closer together or further apart to change the scale factor, zoom, or level
    of detail of the user interface.

    \image pinchgesture.png

    Instead of repeatedly applying the same pinching gesture, the user may
    continue to touch the input device in one place, and apply a second touch
    to a new point, continuing the gesture. When this occurs, gesture events
    will continue to be delivered to the target object, containing an instance
    of QPinchGesture in the Qt::GestureUpdated state.

    \sa {Gestures Programming}, QPanGesture, QSwipeGesture
*/

/*!
    \enum QPinchGesture::WhatChange
    
    This enum describes the changes that can occur to the properties of
    the gesture object.

    \value ScaleFactorChanged The scale factor held by scaleFactor changed.
    \value RotationAngleChanged The rotation angle held by rotationAngle changed.
    \value CenterPointChanged The center point held by centerPoint changed.

    \sa whatChanged
*/

/*!
    \property QPinchGesture::whatChanged
    \brief the property of the gesture that has changed

    This property indicates which of the other properties has changed since
    the previous gesture event included information about this gesture. You
    can use this information to determine which aspect of your user interface
    needs to be updated.

    \sa scaleFactor, rotationAngle, centerPoint
*/

/*!
    \property QPinchGesture::totalScaleFactor
    \brief the total scale factor

    The total scale factor measures the total change in scale factor from the
    original value to the current scale factor.

    \sa scaleFactor, lastScaleFactor
*/
/*!
    \property QPinchGesture::lastScaleFactor
    \brief the last scale factor recorded for this gesture

    The last scale factor contains the scale factor reported in the
    \l scaleFactor property when a previous gesture event included
    information about this gesture.

    If no previous event was delivered with information about this gesture
    (i.e., this gesture object contains information about the first movement
    in the gesture) then this property contains zero.

    \sa scaleFactor, totalScaleFactor
*/
/*!
    \property QPinchGesture::scaleFactor
    \brief the current scale factor

    The scale factor measures the scale factor associated with the distance
    between two of the user's inputs on a multitouch device.

    \sa totalScaleFactor, lastScaleFactor
*/

/*!
    \property QPinchGesture::totalRotationAngle
    \brief the total angle covered by the gesture

    This total angle measures the complete angle covered by the gesture. Usually, this
    is equal to the value held by the \l rotationAngle property, except in the case where
    the user performs multiple rotations by removing and repositioning one of the touch
    points, as described above. In this case, the total angle will be the sum of the
    rotation angles for the multiple stages of the gesture.

    \sa rotationAngle, lastRotationAngle
*/
/*!
    \property QPinchGesture::lastRotationAngle
    \brief the last reported angle covered by the gesture motion

    The last rotation angle is the angle as reported in the \l rotationAngle property
    when a previous gesture event was delivered for this gesture.

    \sa rotationAngle, totalRotationAngle
*/
/*!
    \property QPinchGesture::rotationAngle
    \brief the angle covered by the gesture motion

    \sa totalRotationAngle, lastRotationAngle
*/

/*!
    \property QPinchGesture::startCenterPoint
    \brief the starting position of the center point

    \sa centerPoint, lastCenterPoint
*/
/*!
    \property QPinchGesture::lastCenterPoint
    \brief the last position of the center point recorded for this gesture

    \sa centerPoint, startCenterPoint
*/
/*!
    \property QPinchGesture::centerPoint
    \brief the current center point

    The center point is the midpoint between the two input points in the gesture.

    \sa startCenterPoint, lastCenterPoint
*/

/*!
    \internal
*/
QPinchGesture::QPinchGesture(QObject *parent)
    : QGesture(*new QPinchGesturePrivate, parent)
{
    d_func()->gestureType = Qt::PinchGesture;
}

QPinchGesture::WhatChanged QPinchGesture::whatChanged() const
{
    return d_func()->whatChanged;
}

void QPinchGesture::setWhatChanged(QPinchGesture::WhatChanged value)
{
    d_func()->whatChanged = value;
}


QPointF QPinchGesture::startCenterPoint() const
{
    return d_func()->startCenterPoint;
}

QPointF QPinchGesture::lastCenterPoint() const
{
    return d_func()->lastCenterPoint;
}

QPointF QPinchGesture::centerPoint() const
{
    return d_func()->centerPoint;
}

void QPinchGesture::setStartCenterPoint(const QPointF &value)
{
    d_func()->startCenterPoint = value;
}

void QPinchGesture::setLastCenterPoint(const QPointF &value)
{
    d_func()->lastCenterPoint = value;
}

void QPinchGesture::setCenterPoint(const QPointF &value)
{
    d_func()->centerPoint = value;
}


qreal QPinchGesture::totalScaleFactor() const
{
    return d_func()->totalScaleFactor;
}

qreal QPinchGesture::lastScaleFactor() const
{
    return d_func()->lastScaleFactor;
}

qreal QPinchGesture::scaleFactor() const
{
    return d_func()->scaleFactor;
}

void QPinchGesture::setTotalScaleFactor(qreal value)
{
    d_func()->totalScaleFactor = value;
}

void QPinchGesture::setLastScaleFactor(qreal value)
{
    d_func()->lastScaleFactor = value;
}

void QPinchGesture::setScaleFactor(qreal value)
{
    d_func()->scaleFactor = value;
}


qreal QPinchGesture::totalRotationAngle() const
{
    return d_func()->totalRotationAngle;
}

qreal QPinchGesture::lastRotationAngle() const
{
    return d_func()->lastRotationAngle;
}

qreal QPinchGesture::rotationAngle() const
{
    return d_func()->rotationAngle;
}

void QPinchGesture::setTotalRotationAngle(qreal value)
{
    d_func()->totalRotationAngle = value;
}

void QPinchGesture::setLastRotationAngle(qreal value)
{
    d_func()->lastRotationAngle = value;
}

void QPinchGesture::setRotationAngle(qreal value)
{
    d_func()->rotationAngle = value;
}

/*!
    \class QSwipeGesture
    \since 4.6
    \brief The QSwipeGesture class describes a swipe gesture made by the user.
    \ingroup gestures

    \image swipegesture.png

    \sa {Gestures Programming}, QPanGesture, QPinchGesture
*/

/*!
    \enum QSwipeGesture::SwipeDirection

    This enum describes the possible directions for the gesture's motion
    along the horizontal and vertical axes.

    \value NoDirection The gesture had no motion associated with it on a particular axis.
    \value Left     The gesture involved a horizontal motion to the left.
    \value Right    The gesture involved a horizontal motion to the right.
    \value Up       The gesture involved an upward vertical motion.
    \value Down     The gesture involved a downward vertical motion.
*/

/*!
    \property QSwipeGesture::horizontalDirection
    \brief the horizontal direction of the gesture

    If the gesture has a horizontal component, the horizontal direction
    is either Left or Right; otherwise, it is NoDirection.

    \sa verticalDirection, swipeAngle
*/

/*!
    \property QSwipeGesture::verticalDirection
    \brief the vertical direction of the gesture

    If the gesture has a vertical component, the vertical direction
    is either Up or Down; otherwise, it is NoDirection.

    \sa horizontalDirection, swipeAngle
*/

/*!
    \property QSwipeGesture::swipeAngle
    \brief the angle of the motion associated with the gesture

    If the gesture has either a horizontal or vertical component, the
    swipe angle describes the angle between the direction of motion and the
    x-axis as defined using the standard widget
    \l{The Coordinate System}{coordinate system}.

    \sa horizontalDirection, verticalDirection
*/

/*!
    \internal
*/
QSwipeGesture::QSwipeGesture(QObject *parent)
    : QGesture(*new QSwipeGesturePrivate, parent)
{
    d_func()->gestureType = Qt::SwipeGesture;
}

QSwipeGesture::SwipeDirection QSwipeGesture::horizontalDirection() const
{
    Q_D(const QSwipeGesture);
    if (d->swipeAngle < 0 || d->swipeAngle == 90 || d->swipeAngle == 270)
        return QSwipeGesture::NoDirection;
    else if (d->swipeAngle < 90 || d->swipeAngle > 270)
        return QSwipeGesture::Right;
    else
        return QSwipeGesture::Left;
}

QSwipeGesture::SwipeDirection QSwipeGesture::verticalDirection() const
{
    Q_D(const QSwipeGesture);
    if (d->swipeAngle <= 0 || d->swipeAngle == 180)
        return QSwipeGesture::NoDirection;
    else if (d->swipeAngle < 180)
        return QSwipeGesture::Up;
    else
        return QSwipeGesture::Down;
}

qreal QSwipeGesture::swipeAngle() const
{
    return d_func()->swipeAngle;
}

void QSwipeGesture::setSwipeAngle(qreal value)
{
    d_func()->swipeAngle = value;
}

QT_END_NAMESPACE