author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 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 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
QGesture *ThreeFingerSlideGestureRecognizer::create(QObject *) |
0 | 49 |
{ |
50 |
return new ThreeFingerSlideGesture; |
|
51 |
} |
|
52 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) |
0 | 54 |
{ |
55 |
ThreeFingerSlideGesture *d = static_cast<ThreeFingerSlideGesture *>(state); |
|
56 |
QGestureRecognizer::Result result; |
|
57 |
switch (event->type()) { |
|
58 |
case QEvent::TouchBegin: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
result = QGestureRecognizer::MayBeGesture; |
0 | 60 |
case QEvent::TouchEnd: |
61 |
if (d->gestureFired) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
result = QGestureRecognizer::FinishGesture; |
0 | 63 |
else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
result = QGestureRecognizer::CancelGesture; |
0 | 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; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
result = QGestureRecognizer::TriggerGesture; |
0 | 71 |
} else { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
result = QGestureRecognizer::MayBeGesture; |
0 | 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) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
result = QGestureRecognizer::CancelGesture; |
0 | 78 |
} |
79 |
} |
|
80 |
} |
|
81 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
result = QGestureRecognizer::CancelGesture; |
0 | 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 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
result = QGestureRecognizer::CancelGesture; |
0 | 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 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
QGesture *RotateGestureRecognizer::create(QObject *) |
0 | 109 |
{ |
110 |
return new QGesture; |
|
111 |
} |
|
112 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
QGestureRecognizer::Result RotateGestureRecognizer::recognize(QGesture *, QObject *, QEvent *event) |
0 | 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" |