|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "gestures.h" |
|
43 |
|
44 #include <QTouchEvent> |
|
45 |
|
46 Qt::GestureType ThreeFingerSlideGesture::Type = Qt::CustomGesture; |
|
47 |
|
48 QGesture *ThreeFingerSlideGestureRecognizer::createGesture(QObject *) |
|
49 { |
|
50 return new ThreeFingerSlideGesture; |
|
51 } |
|
52 |
|
53 QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) |
|
54 { |
|
55 ThreeFingerSlideGesture *d = static_cast<ThreeFingerSlideGesture *>(state); |
|
56 QGestureRecognizer::Result result; |
|
57 switch (event->type()) { |
|
58 case QEvent::TouchBegin: |
|
59 result = QGestureRecognizer::MaybeGesture; |
|
60 case QEvent::TouchEnd: |
|
61 if (d->gestureFired) |
|
62 result = QGestureRecognizer::GestureFinished; |
|
63 else |
|
64 result = QGestureRecognizer::NotGesture; |
|
65 case QEvent::TouchUpdate: |
|
66 if (d->state() != Qt::NoGesture) { |
|
67 QTouchEvent *ev = static_cast<QTouchEvent*>(event); |
|
68 if (ev->touchPoints().size() == 3) { |
|
69 d->gestureFired = true; |
|
70 result = QGestureRecognizer::GestureTriggered; |
|
71 } else { |
|
72 result = QGestureRecognizer::MaybeGesture; |
|
73 for (int i = 0; i < ev->touchPoints().size(); ++i) { |
|
74 const QTouchEvent::TouchPoint &pt = ev->touchPoints().at(i); |
|
75 const int distance = (pt.pos().toPoint() - pt.startPos().toPoint()).manhattanLength(); |
|
76 if (distance > 20) { |
|
77 result = QGestureRecognizer::NotGesture; |
|
78 } |
|
79 } |
|
80 } |
|
81 } else { |
|
82 result = QGestureRecognizer::NotGesture; |
|
83 } |
|
84 |
|
85 break; |
|
86 case QEvent::MouseButtonPress: |
|
87 case QEvent::MouseButtonRelease: |
|
88 case QEvent::MouseMove: |
|
89 if (d->state() != Qt::NoGesture) |
|
90 result = QGestureRecognizer::Ignore; |
|
91 else |
|
92 result = QGestureRecognizer::NotGesture; |
|
93 break; |
|
94 default: |
|
95 result = QGestureRecognizer::Ignore; |
|
96 break; |
|
97 } |
|
98 return result; |
|
99 } |
|
100 |
|
101 void ThreeFingerSlideGestureRecognizer::reset(QGesture *state) |
|
102 { |
|
103 static_cast<ThreeFingerSlideGesture *>(state)->gestureFired = false; |
|
104 QGestureRecognizer::reset(state); |
|
105 } |
|
106 |
|
107 |
|
108 QGesture *RotateGestureRecognizer::createGesture(QObject *) |
|
109 { |
|
110 return new QGesture; |
|
111 } |
|
112 |
|
113 QGestureRecognizer::Result RotateGestureRecognizer::filterEvent(QGesture *, QObject *, QEvent *event) |
|
114 { |
|
115 switch (event->type()) { |
|
116 case QEvent::TouchBegin: |
|
117 case QEvent::TouchEnd: |
|
118 case QEvent::TouchUpdate: |
|
119 break; |
|
120 default: |
|
121 break; |
|
122 } |
|
123 return QGestureRecognizer::Ignore; |
|
124 } |
|
125 |
|
126 void RotateGestureRecognizer::reset(QGesture *state) |
|
127 { |
|
128 QGestureRecognizer::reset(state); |
|
129 } |
|
130 |
|
131 #include "moc_gestures.cpp" |