author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include "../../shared/util.h" |
|
45 |
||
46 |
#include <qevent.h> |
|
47 |
#include <qwidget.h> |
|
48 |
#include <qlayout.h> |
|
49 |
#include <qgesture.h> |
|
50 |
#include <qgesturerecognizer.h> |
|
51 |
#include <qgraphicsitem.h> |
|
52 |
#include <qgraphicsview.h> |
|
53 |
||
54 |
#include <qdebug.h> |
|
55 |
||
56 |
//TESTED_CLASS= |
|
57 |
//TESTED_FILES= |
|
58 |
||
59 |
static QPointF mapToGlobal(const QPointF &pt, QGraphicsItem *item, QGraphicsView *view) |
|
60 |
{ |
|
61 |
return view->mapToGlobal(view->mapFromScene(item->mapToScene(pt))); |
|
62 |
} |
|
63 |
||
64 |
class CustomGesture : public QGesture |
|
65 |
{ |
|
66 |
Q_OBJECT |
|
67 |
public: |
|
68 |
static Qt::GestureType GestureType; |
|
69 |
||
70 |
CustomGesture(QObject *parent = 0) |
|
71 |
: QGesture(parent), serial(0) |
|
72 |
{ |
|
73 |
} |
|
74 |
||
75 |
int serial; |
|
76 |
||
77 |
static const int SerialMaybeThreshold; |
|
78 |
static const int SerialStartedThreshold; |
|
79 |
static const int SerialFinishedThreshold; |
|
80 |
}; |
|
81 |
Qt::GestureType CustomGesture::GestureType = Qt::CustomGesture; |
|
82 |
const int CustomGesture::SerialMaybeThreshold = 1; |
|
83 |
const int CustomGesture::SerialStartedThreshold = 3; |
|
84 |
const int CustomGesture::SerialFinishedThreshold = 6; |
|
85 |
||
86 |
class CustomEvent : public QEvent |
|
87 |
{ |
|
88 |
public: |
|
89 |
static int EventType; |
|
90 |
||
91 |
CustomEvent(int serial_ = 0) |
|
92 |
: QEvent(QEvent::Type(CustomEvent::EventType)), |
|
93 |
serial(serial_), hasHotSpot(false) |
|
94 |
{ |
|
95 |
} |
|
96 |
||
97 |
int serial; |
|
98 |
QPointF hotSpot; |
|
99 |
bool hasHotSpot; |
|
100 |
}; |
|
101 |
int CustomEvent::EventType = 0; |
|
102 |
||
103 |
class CustomGestureRecognizer : public QGestureRecognizer |
|
104 |
{ |
|
105 |
public: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
static bool ConsumeEvents; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
|
0 | 108 |
CustomGestureRecognizer() |
109 |
{ |
|
110 |
if (!CustomEvent::EventType) |
|
111 |
CustomEvent::EventType = QEvent::registerEventType(); |
|
112 |
} |
|
113 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
QGesture* create(QObject *) |
0 | 115 |
{ |
116 |
return new CustomGesture; |
|
117 |
} |
|
118 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) |
0 | 120 |
{ |
121 |
if (event->type() == CustomEvent::EventType) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
QGestureRecognizer::Result result = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
if (CustomGestureRecognizer::ConsumeEvents) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
result |= QGestureRecognizer::ConsumeEventHint; |
0 | 125 |
CustomGesture *g = static_cast<CustomGesture*>(state); |
126 |
CustomEvent *e = static_cast<CustomEvent*>(event); |
|
127 |
g->serial = e->serial; |
|
128 |
if (e->hasHotSpot) |
|
129 |
g->setHotSpot(e->hotSpot); |
|
130 |
if (g->serial >= CustomGesture::SerialFinishedThreshold) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
result |= QGestureRecognizer::FinishGesture; |
0 | 132 |
else if (g->serial >= CustomGesture::SerialStartedThreshold) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
result |= QGestureRecognizer::TriggerGesture; |
0 | 134 |
else if (g->serial >= CustomGesture::SerialMaybeThreshold) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
result |= QGestureRecognizer::MayBeGesture; |
0 | 136 |
else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
result = QGestureRecognizer::CancelGesture; |
0 | 138 |
return result; |
139 |
} |
|
140 |
return QGestureRecognizer::Ignore; |
|
141 |
} |
|
142 |
||
143 |
void reset(QGesture *state) |
|
144 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
CustomGesture *g = static_cast<CustomGesture *>(state); |
0 | 146 |
g->serial = 0; |
147 |
QGestureRecognizer::reset(state); |
|
148 |
} |
|
149 |
}; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
bool CustomGestureRecognizer::ConsumeEvents = false; |
0 | 151 |
|
152 |
// same as CustomGestureRecognizer but triggers early without the maybe state |
|
153 |
class CustomContinuousGestureRecognizer : public QGestureRecognizer |
|
154 |
{ |
|
155 |
public: |
|
156 |
CustomContinuousGestureRecognizer() |
|
157 |
{ |
|
158 |
if (!CustomEvent::EventType) |
|
159 |
CustomEvent::EventType = QEvent::registerEventType(); |
|
160 |
} |
|
161 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
QGesture* create(QObject *) |
0 | 163 |
{ |
164 |
return new CustomGesture; |
|
165 |
} |
|
166 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) |
0 | 168 |
{ |
169 |
if (event->type() == CustomEvent::EventType) { |
|
170 |
QGestureRecognizer::Result result = QGestureRecognizer::ConsumeEventHint; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
CustomGesture *g = static_cast<CustomGesture *>(state); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
CustomEvent *e = static_cast<CustomEvent *>(event); |
0 | 173 |
g->serial = e->serial; |
174 |
if (e->hasHotSpot) |
|
175 |
g->setHotSpot(e->hotSpot); |
|
176 |
if (g->serial >= CustomGesture::SerialFinishedThreshold) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
result |= QGestureRecognizer::FinishGesture; |
0 | 178 |
else if (g->serial >= CustomGesture::SerialMaybeThreshold) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
result |= QGestureRecognizer::TriggerGesture; |
0 | 180 |
else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
result = QGestureRecognizer::CancelGesture; |
0 | 182 |
return result; |
183 |
} |
|
184 |
return QGestureRecognizer::Ignore; |
|
185 |
} |
|
186 |
||
187 |
void reset(QGesture *state) |
|
188 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
CustomGesture *g = static_cast<CustomGesture *>(state); |
0 | 190 |
g->serial = 0; |
191 |
QGestureRecognizer::reset(state); |
|
192 |
} |
|
193 |
}; |
|
194 |
||
195 |
class GestureWidget : public QWidget |
|
196 |
{ |
|
197 |
Q_OBJECT |
|
198 |
public: |
|
199 |
GestureWidget(const char *name = 0, QWidget *parent = 0) |
|
200 |
: QWidget(parent) |
|
201 |
{ |
|
202 |
if (name) |
|
203 |
setObjectName(QLatin1String(name)); |
|
204 |
reset(); |
|
205 |
acceptGestureOverride = false; |
|
206 |
} |
|
207 |
void reset() |
|
208 |
{ |
|
209 |
customEventsReceived = 0; |
|
210 |
gestureEventsReceived = 0; |
|
211 |
gestureOverrideEventsReceived = 0; |
|
212 |
events.clear(); |
|
213 |
overrideEvents.clear(); |
|
214 |
ignoredGestures.clear(); |
|
215 |
} |
|
216 |
||
217 |
int customEventsReceived; |
|
218 |
int gestureEventsReceived; |
|
219 |
int gestureOverrideEventsReceived; |
|
220 |
struct Events |
|
221 |
{ |
|
222 |
QList<Qt::GestureType> all; |
|
223 |
QList<Qt::GestureType> started; |
|
224 |
QList<Qt::GestureType> updated; |
|
225 |
QList<Qt::GestureType> finished; |
|
226 |
QList<Qt::GestureType> canceled; |
|
227 |
||
228 |
void clear() |
|
229 |
{ |
|
230 |
all.clear(); |
|
231 |
started.clear(); |
|
232 |
updated.clear(); |
|
233 |
finished.clear(); |
|
234 |
canceled.clear(); |
|
235 |
} |
|
236 |
} events, overrideEvents; |
|
237 |
||
238 |
bool acceptGestureOverride; |
|
239 |
QSet<Qt::GestureType> ignoredGestures; |
|
240 |
||
241 |
protected: |
|
242 |
bool event(QEvent *event) |
|
243 |
{ |
|
244 |
Events *eventsPtr = 0; |
|
245 |
if (event->type() == QEvent::Gesture) { |
|
246 |
QGestureEvent *e = static_cast<QGestureEvent*>(event); |
|
247 |
++gestureEventsReceived; |
|
248 |
eventsPtr = &events; |
|
249 |
foreach(Qt::GestureType type, ignoredGestures) |
|
250 |
e->ignore(e->gesture(type)); |
|
251 |
} else if (event->type() == QEvent::GestureOverride) { |
|
252 |
++gestureOverrideEventsReceived; |
|
253 |
eventsPtr = &overrideEvents; |
|
254 |
if (acceptGestureOverride) |
|
255 |
event->accept(); |
|
256 |
} |
|
257 |
if (eventsPtr) { |
|
258 |
QGestureEvent *e = static_cast<QGestureEvent*>(event); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
QList<QGesture*> gestures = e->gestures(); |
0 | 260 |
foreach(QGesture *g, gestures) { |
261 |
eventsPtr->all << g->gestureType(); |
|
262 |
switch(g->state()) { |
|
263 |
case Qt::GestureStarted: |
|
264 |
eventsPtr->started << g->gestureType(); |
|
265 |
break; |
|
266 |
case Qt::GestureUpdated: |
|
267 |
eventsPtr->updated << g->gestureType(); |
|
268 |
break; |
|
269 |
case Qt::GestureFinished: |
|
270 |
eventsPtr->finished << g->gestureType(); |
|
271 |
break; |
|
272 |
case Qt::GestureCanceled: |
|
273 |
eventsPtr->canceled << g->gestureType(); |
|
274 |
break; |
|
275 |
default: |
|
276 |
Q_ASSERT(false); |
|
277 |
} |
|
278 |
} |
|
279 |
} else if (event->type() == CustomEvent::EventType) { |
|
280 |
++customEventsReceived; |
|
281 |
} else { |
|
282 |
return QWidget::event(event); |
|
283 |
} |
|
284 |
return true; |
|
285 |
} |
|
286 |
}; |
|
287 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
// TODO rename to sendGestureSequence |
0 | 289 |
static void sendCustomGesture(CustomEvent *event, QObject *object, QGraphicsScene *scene = 0) |
290 |
{ |
|
291 |
for (int i = CustomGesture::SerialMaybeThreshold; |
|
292 |
i <= CustomGesture::SerialFinishedThreshold; ++i) { |
|
293 |
event->serial = i; |
|
294 |
if (scene) |
|
295 |
scene->sendEvent(qobject_cast<QGraphicsObject *>(object), event); |
|
296 |
else |
|
297 |
QApplication::sendEvent(object, event); |
|
298 |
} |
|
299 |
} |
|
300 |
||
301 |
class tst_Gestures : public QObject |
|
302 |
{ |
|
303 |
Q_OBJECT |
|
304 |
||
305 |
public: |
|
306 |
tst_Gestures(); |
|
307 |
virtual ~tst_Gestures(); |
|
308 |
||
309 |
public slots: |
|
310 |
void initTestCase(); |
|
311 |
void cleanupTestCase(); |
|
312 |
void init(); |
|
313 |
void cleanup(); |
|
314 |
||
315 |
private slots: |
|
316 |
void customGesture(); |
|
317 |
void autoCancelingGestures(); |
|
318 |
void gestureOverChild(); |
|
319 |
void multipleWidgetOnlyGestureInTree(); |
|
320 |
void conflictingGestures(); |
|
321 |
void finishedWithoutStarted(); |
|
322 |
void unknownGesture(); |
|
323 |
void graphicsItemGesture(); |
|
324 |
void graphicsItemTreeGesture(); |
|
325 |
void explicitGraphicsObjectTarget(); |
|
326 |
void gestureOverChildGraphicsItem(); |
|
327 |
void twoGesturesOnDifferentLevel(); |
|
328 |
void multipleGesturesInTree(); |
|
329 |
void multipleGesturesInComplexTree(); |
|
330 |
void testMapToScene(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
void ungrabGesture(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
void consumeEventHint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
void unregisterRecognizer(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
334 |
void autoCancelGestures(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
335 |
void autoCancelGestures2(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
336 |
void panelPropagation(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
337 |
void panelStacksBehindParent(); |
0 | 338 |
}; |
339 |
||
340 |
tst_Gestures::tst_Gestures() |
|
341 |
{ |
|
342 |
} |
|
343 |
||
344 |
tst_Gestures::~tst_Gestures() |
|
345 |
{ |
|
346 |
} |
|
347 |
||
348 |
void tst_Gestures::initTestCase() |
|
349 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
CustomGesture::GestureType = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
0 | 351 |
QVERIFY(CustomGesture::GestureType != Qt::GestureType(0)); |
352 |
QVERIFY(CustomGesture::GestureType != Qt::CustomGesture); |
|
353 |
} |
|
354 |
||
355 |
void tst_Gestures::cleanupTestCase() |
|
356 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
QGestureRecognizer::unregisterRecognizer(CustomGesture::GestureType); |
0 | 358 |
} |
359 |
||
360 |
void tst_Gestures::init() |
|
361 |
{ |
|
362 |
} |
|
363 |
||
364 |
void tst_Gestures::cleanup() |
|
365 |
{ |
|
366 |
} |
|
367 |
||
368 |
void tst_Gestures::customGesture() |
|
369 |
{ |
|
370 |
GestureWidget widget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 372 |
CustomEvent event; |
373 |
sendCustomGesture(&event, &widget); |
|
374 |
||
375 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
376 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
|
377 |
QCOMPARE(widget.customEventsReceived, TotalCustomEventsCount); |
|
378 |
QCOMPARE(widget.gestureEventsReceived, TotalGestureEventsCount); |
|
379 |
QCOMPARE(widget.gestureOverrideEventsReceived, 0); |
|
380 |
QCOMPARE(widget.events.all.size(), TotalGestureEventsCount); |
|
381 |
for(int i = 0; i < widget.events.all.size(); ++i) |
|
382 |
QCOMPARE(widget.events.all.at(i), CustomGesture::GestureType); |
|
383 |
QCOMPARE(widget.events.started.size(), 1); |
|
384 |
QCOMPARE(widget.events.updated.size(), TotalGestureEventsCount - 2); |
|
385 |
QCOMPARE(widget.events.finished.size(), 1); |
|
386 |
QCOMPARE(widget.events.canceled.size(), 0); |
|
387 |
} |
|
388 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
void tst_Gestures::consumeEventHint() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
GestureWidget widget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
CustomGestureRecognizer::ConsumeEvents = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
CustomEvent event; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
sendCustomGesture(&event, &widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
CustomGestureRecognizer::ConsumeEvents = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
QCOMPARE(widget.customEventsReceived, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
|
0 | 402 |
void tst_Gestures::autoCancelingGestures() |
403 |
{ |
|
404 |
GestureWidget widget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 406 |
// send partial gesture. The gesture will be in the "maybe" state, but will |
407 |
// never get enough events to fire, so Qt will have to kill it. |
|
408 |
CustomEvent ev; |
|
409 |
for (int i = CustomGesture::SerialMaybeThreshold; |
|
410 |
i < CustomGesture::SerialStartedThreshold; ++i) { |
|
411 |
ev.serial = i; |
|
412 |
QApplication::sendEvent(&widget, &ev); |
|
413 |
} |
|
414 |
// wait long enough so the gesture manager will cancel the gesture |
|
415 |
QTest::qWait(5000); |
|
416 |
QCOMPARE(widget.customEventsReceived, CustomGesture::SerialStartedThreshold - CustomGesture::SerialMaybeThreshold); |
|
417 |
QCOMPARE(widget.gestureEventsReceived, 0); |
|
418 |
QCOMPARE(widget.gestureOverrideEventsReceived, 0); |
|
419 |
QCOMPARE(widget.events.all.size(), 0); |
|
420 |
} |
|
421 |
||
422 |
void tst_Gestures::gestureOverChild() |
|
423 |
{ |
|
424 |
GestureWidget widget("widget"); |
|
425 |
QVBoxLayout *l = new QVBoxLayout(&widget); |
|
426 |
GestureWidget *child = new GestureWidget("child"); |
|
427 |
l->addWidget(child); |
|
428 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 430 |
|
431 |
CustomEvent event; |
|
432 |
sendCustomGesture(&event, child); |
|
433 |
||
434 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
435 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
|
436 |
||
437 |
QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); |
|
438 |
QCOMPARE(widget.customEventsReceived, 0); |
|
439 |
QCOMPARE(child->gestureEventsReceived, 0); |
|
440 |
QCOMPARE(child->gestureOverrideEventsReceived, 0); |
|
441 |
QCOMPARE(widget.gestureEventsReceived, 0); |
|
442 |
QCOMPARE(widget.gestureOverrideEventsReceived, 0); |
|
443 |
||
444 |
// enable gestures over the children |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
widget.grabGesture(CustomGesture::GestureType); |
0 | 446 |
|
447 |
widget.reset(); |
|
448 |
child->reset(); |
|
449 |
||
450 |
sendCustomGesture(&event, child); |
|
451 |
||
452 |
QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); |
|
453 |
QCOMPARE(widget.customEventsReceived, 0); |
|
454 |
||
455 |
QCOMPARE(child->gestureEventsReceived, 0); |
|
456 |
QCOMPARE(child->gestureOverrideEventsReceived, 0); |
|
457 |
QCOMPARE(widget.gestureEventsReceived, TotalGestureEventsCount); |
|
458 |
QCOMPARE(widget.gestureOverrideEventsReceived, 0); |
|
459 |
for(int i = 0; i < widget.events.all.size(); ++i) |
|
460 |
QCOMPARE(widget.events.all.at(i), CustomGesture::GestureType); |
|
461 |
QCOMPARE(widget.events.started.size(), 1); |
|
462 |
QCOMPARE(widget.events.updated.size(), TotalGestureEventsCount - 2); |
|
463 |
QCOMPARE(widget.events.finished.size(), 1); |
|
464 |
QCOMPARE(widget.events.canceled.size(), 0); |
|
465 |
} |
|
466 |
||
467 |
void tst_Gestures::multipleWidgetOnlyGestureInTree() |
|
468 |
{ |
|
469 |
GestureWidget parent("parent"); |
|
470 |
QVBoxLayout *l = new QVBoxLayout(&parent); |
|
471 |
GestureWidget *child = new GestureWidget("child"); |
|
472 |
l->addWidget(child); |
|
473 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
parent.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
child->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 476 |
|
477 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
478 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
|
479 |
||
480 |
// sending events to the child and making sure there is no conflict |
|
481 |
CustomEvent event; |
|
482 |
sendCustomGesture(&event, child); |
|
483 |
||
484 |
QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); |
|
485 |
QCOMPARE(parent.customEventsReceived, 0); |
|
486 |
QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); |
|
487 |
QCOMPARE(child->gestureOverrideEventsReceived, 0); |
|
488 |
QCOMPARE(parent.gestureEventsReceived, 0); |
|
489 |
QCOMPARE(parent.gestureOverrideEventsReceived, 0); |
|
490 |
||
491 |
parent.reset(); |
|
492 |
child->reset(); |
|
493 |
||
494 |
// same for the parent widget |
|
495 |
sendCustomGesture(&event, &parent); |
|
496 |
||
497 |
QCOMPARE(child->customEventsReceived, 0); |
|
498 |
QCOMPARE(parent.customEventsReceived, TotalCustomEventsCount); |
|
499 |
QCOMPARE(child->gestureEventsReceived, 0); |
|
500 |
QCOMPARE(child->gestureOverrideEventsReceived, 0); |
|
501 |
QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); |
|
502 |
QCOMPARE(parent.gestureOverrideEventsReceived, 0); |
|
503 |
} |
|
504 |
||
505 |
void tst_Gestures::conflictingGestures() |
|
506 |
{ |
|
507 |
GestureWidget parent("parent"); |
|
508 |
QVBoxLayout *l = new QVBoxLayout(&parent); |
|
509 |
GestureWidget *child = new GestureWidget("child"); |
|
510 |
l->addWidget(child); |
|
511 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
512 |
parent.grabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
513 |
child->grabGesture(CustomGesture::GestureType); |
0 | 514 |
|
515 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
516 |
||
517 |
// child accepts the override, parent will not receive anything |
|
518 |
parent.acceptGestureOverride = false; |
|
519 |
child->acceptGestureOverride = true; |
|
520 |
||
521 |
// sending events to the child and making sure there is no conflict |
|
522 |
CustomEvent event; |
|
523 |
sendCustomGesture(&event, child); |
|
524 |
||
525 |
QCOMPARE(child->gestureOverrideEventsReceived, 1); |
|
526 |
QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); |
|
527 |
QCOMPARE(parent.gestureOverrideEventsReceived, 0); |
|
528 |
QCOMPARE(parent.gestureEventsReceived, 0); |
|
529 |
||
530 |
parent.reset(); |
|
531 |
child->reset(); |
|
532 |
||
533 |
// parent accepts the override |
|
534 |
parent.acceptGestureOverride = true; |
|
535 |
child->acceptGestureOverride = false; |
|
536 |
||
537 |
// sending events to the child and making sure there is no conflict |
|
538 |
sendCustomGesture(&event, child); |
|
539 |
||
540 |
QCOMPARE(child->gestureOverrideEventsReceived, 1); |
|
541 |
QCOMPARE(child->gestureEventsReceived, 0); |
|
542 |
QCOMPARE(parent.gestureOverrideEventsReceived, 1); |
|
543 |
QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); |
|
544 |
||
545 |
parent.reset(); |
|
546 |
child->reset(); |
|
547 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
548 |
// nobody accepts the override, we will send normal events to the closest |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
// context (i.e. to the child widget) and it will be propagated and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
// accepted by the parent widget |
0 | 551 |
parent.acceptGestureOverride = false; |
552 |
child->acceptGestureOverride = false; |
|
553 |
child->ignoredGestures << CustomGesture::GestureType; |
|
554 |
||
555 |
// sending events to the child and making sure there is no conflict |
|
556 |
sendCustomGesture(&event, child); |
|
557 |
||
558 |
QCOMPARE(child->gestureOverrideEventsReceived, 1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
QCOMPARE(child->gestureEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
QCOMPARE(parent.gestureOverrideEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
parent.reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
child->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
// nobody accepts the override, and nobody accepts the gesture event |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
567 |
parent.acceptGestureOverride = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
568 |
child->acceptGestureOverride = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
569 |
parent.ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
570 |
child->ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
571 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
572 |
// sending events to the child and making sure there is no conflict |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
573 |
sendCustomGesture(&event, child); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
574 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
QCOMPARE(child->gestureOverrideEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
576 |
QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
577 |
QCOMPARE(parent.gestureOverrideEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
578 |
QCOMPARE(parent.gestureEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
579 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
580 |
parent.reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
581 |
child->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
582 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
583 |
// we set an attribute to make sure all gesture events are propagated |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
584 |
parent.grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
585 |
parent.acceptGestureOverride = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
child->acceptGestureOverride = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
parent.ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
child->ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
589 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
590 |
// sending events to the child and making sure there is no conflict |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
591 |
sendCustomGesture(&event, child); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
592 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
593 |
QCOMPARE(child->gestureOverrideEventsReceived, 1); |
0 | 594 |
QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); |
595 |
QCOMPARE(parent.gestureOverrideEventsReceived, 1); |
|
596 |
QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); |
|
597 |
||
598 |
parent.reset(); |
|
599 |
child->reset(); |
|
600 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
601 |
Qt::GestureType ContinuousGesture = QGestureRecognizer::registerRecognizer(new CustomContinuousGestureRecognizer); |
0 | 602 |
static const int ContinuousGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
603 |
child->grabGesture(ContinuousGesture); |
|
604 |
// child accepts override. And it also receives another custom gesture. |
|
605 |
parent.acceptGestureOverride = false; |
|
606 |
child->acceptGestureOverride = true; |
|
607 |
sendCustomGesture(&event, child); |
|
608 |
||
609 |
QCOMPARE(child->gestureOverrideEventsReceived, 1); |
|
610 |
QVERIFY(child->gestureEventsReceived > TotalGestureEventsCount); |
|
611 |
QCOMPARE(child->events.all.count(), TotalGestureEventsCount + ContinuousGestureEventsCount); |
|
612 |
QCOMPARE(parent.gestureOverrideEventsReceived, 0); |
|
613 |
QCOMPARE(parent.gestureEventsReceived, 0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
614 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
615 |
QGestureRecognizer::unregisterRecognizer(ContinuousGesture); |
0 | 616 |
} |
617 |
||
618 |
void tst_Gestures::finishedWithoutStarted() |
|
619 |
{ |
|
620 |
GestureWidget widget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
621 |
widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 622 |
|
623 |
// the gesture will claim it finished, but it was never started. |
|
624 |
CustomEvent ev; |
|
625 |
ev.serial = CustomGesture::SerialFinishedThreshold; |
|
626 |
QApplication::sendEvent(&widget, &ev); |
|
627 |
||
628 |
QCOMPARE(widget.customEventsReceived, 1); |
|
629 |
QCOMPARE(widget.gestureEventsReceived, 2); |
|
630 |
QCOMPARE(widget.gestureOverrideEventsReceived, 0); |
|
631 |
QCOMPARE(widget.events.all.size(), 2); |
|
632 |
QCOMPARE(widget.events.started.size(), 1); |
|
633 |
QCOMPARE(widget.events.updated.size(), 0); |
|
634 |
QCOMPARE(widget.events.finished.size(), 1); |
|
635 |
QCOMPARE(widget.events.canceled.size(), 0); |
|
636 |
} |
|
637 |
||
638 |
void tst_Gestures::unknownGesture() |
|
639 |
{ |
|
640 |
GestureWidget widget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
641 |
widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
widget.grabGesture(Qt::CustomGesture, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
643 |
widget.grabGesture(Qt::GestureType(Qt::PanGesture+512), Qt::DontStartGestureOnChildren); |
0 | 644 |
|
645 |
CustomEvent event; |
|
646 |
sendCustomGesture(&event, &widget); |
|
647 |
||
648 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
649 |
||
650 |
QCOMPARE(widget.gestureEventsReceived, TotalGestureEventsCount); |
|
651 |
} |
|
652 |
||
653 |
static const QColor InstanceColors[] = { |
|
654 |
Qt::blue, Qt::red, Qt::green, Qt::gray, Qt::yellow |
|
655 |
}; |
|
656 |
||
657 |
class GestureItem : public QGraphicsObject |
|
658 |
{ |
|
659 |
static int InstanceCount; |
|
660 |
||
661 |
public: |
|
662 |
GestureItem(const char *name = 0) |
|
663 |
{ |
|
664 |
instanceNumber = InstanceCount++; |
|
665 |
if (name) |
|
666 |
setObjectName(QLatin1String(name)); |
|
667 |
size = QRectF(0, 0, 100, 100); |
|
668 |
customEventsReceived = 0; |
|
669 |
gestureEventsReceived = 0; |
|
670 |
gestureOverrideEventsReceived = 0; |
|
671 |
events.clear(); |
|
672 |
overrideEvents.clear(); |
|
673 |
acceptGestureOverride = false; |
|
674 |
} |
|
675 |
~GestureItem() |
|
676 |
{ |
|
677 |
--InstanceCount; |
|
678 |
} |
|
679 |
||
680 |
int customEventsReceived; |
|
681 |
int gestureEventsReceived; |
|
682 |
int gestureOverrideEventsReceived; |
|
683 |
struct Events |
|
684 |
{ |
|
685 |
QList<Qt::GestureType> all; |
|
686 |
QList<Qt::GestureType> started; |
|
687 |
QList<Qt::GestureType> updated; |
|
688 |
QList<Qt::GestureType> finished; |
|
689 |
QList<Qt::GestureType> canceled; |
|
690 |
||
691 |
void clear() |
|
692 |
{ |
|
693 |
all.clear(); |
|
694 |
started.clear(); |
|
695 |
updated.clear(); |
|
696 |
finished.clear(); |
|
697 |
canceled.clear(); |
|
698 |
} |
|
699 |
} events, overrideEvents; |
|
700 |
||
701 |
bool acceptGestureOverride; |
|
702 |
QSet<Qt::GestureType> ignoredGestures; |
|
703 |
||
704 |
QRectF size; |
|
705 |
int instanceNumber; |
|
706 |
||
707 |
void reset() |
|
708 |
{ |
|
709 |
customEventsReceived = 0; |
|
710 |
gestureEventsReceived = 0; |
|
711 |
gestureOverrideEventsReceived = 0; |
|
712 |
events.clear(); |
|
713 |
overrideEvents.clear(); |
|
714 |
ignoredGestures.clear(); |
|
715 |
} |
|
716 |
||
717 |
protected: |
|
718 |
QRectF boundingRect() const |
|
719 |
{ |
|
720 |
return size; |
|
721 |
} |
|
722 |
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) |
|
723 |
{ |
|
724 |
QColor color = InstanceColors[instanceNumber % (sizeof(InstanceColors)/sizeof(InstanceColors[0]))]; |
|
725 |
p->fillRect(boundingRect(), color); |
|
726 |
} |
|
727 |
||
728 |
bool event(QEvent *event) |
|
729 |
{ |
|
730 |
Events *eventsPtr = 0; |
|
731 |
if (event->type() == QEvent::Gesture) { |
|
732 |
++gestureEventsReceived; |
|
733 |
eventsPtr = &events; |
|
734 |
QGestureEvent *e = static_cast<QGestureEvent *>(event); |
|
735 |
foreach(Qt::GestureType type, ignoredGestures) |
|
736 |
e->ignore(e->gesture(type)); |
|
737 |
} else if (event->type() == QEvent::GestureOverride) { |
|
738 |
++gestureOverrideEventsReceived; |
|
739 |
eventsPtr = &overrideEvents; |
|
740 |
if (acceptGestureOverride) |
|
741 |
event->accept(); |
|
742 |
} |
|
743 |
if (eventsPtr) { |
|
744 |
QGestureEvent *e = static_cast<QGestureEvent*>(event); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
745 |
QList<QGesture*> gestures = e->gestures(); |
0 | 746 |
foreach(QGesture *g, gestures) { |
747 |
eventsPtr->all << g->gestureType(); |
|
748 |
switch(g->state()) { |
|
749 |
case Qt::GestureStarted: |
|
750 |
eventsPtr->started << g->gestureType(); |
|
751 |
break; |
|
752 |
case Qt::GestureUpdated: |
|
753 |
eventsPtr->updated << g->gestureType(); |
|
754 |
break; |
|
755 |
case Qt::GestureFinished: |
|
756 |
eventsPtr->finished << g->gestureType(); |
|
757 |
break; |
|
758 |
case Qt::GestureCanceled: |
|
759 |
eventsPtr->canceled << g->gestureType(); |
|
760 |
break; |
|
761 |
default: |
|
762 |
Q_ASSERT(false); |
|
763 |
} |
|
764 |
} |
|
765 |
} else if (event->type() == CustomEvent::EventType) { |
|
766 |
++customEventsReceived; |
|
767 |
} else { |
|
768 |
return QGraphicsObject::event(event); |
|
769 |
} |
|
770 |
return true; |
|
771 |
} |
|
772 |
}; |
|
773 |
int GestureItem::InstanceCount = 0; |
|
774 |
||
775 |
void tst_Gestures::graphicsItemGesture() |
|
776 |
{ |
|
777 |
QGraphicsScene scene; |
|
778 |
QGraphicsView view(&scene); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
0 | 780 |
|
781 |
GestureItem *item = new GestureItem("item"); |
|
782 |
scene.addItem(item); |
|
783 |
item->setPos(100, 100); |
|
784 |
||
785 |
view.show(); |
|
786 |
QTest::qWaitForWindowShown(&view); |
|
787 |
view.ensureVisible(scene.sceneRect()); |
|
788 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
789 |
view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 790 |
item->grabGesture(CustomGesture::GestureType); |
791 |
||
792 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
793 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
|
794 |
||
795 |
CustomEvent event; |
|
796 |
// gesture without hotspot should not be delivered to items in the view |
|
797 |
QTest::ignoreMessage(QtWarningMsg, "QGestureManager::deliverEvent: could not find the target for gesture"); |
|
798 |
QTest::ignoreMessage(QtWarningMsg, "QGestureManager::deliverEvent: could not find the target for gesture"); |
|
799 |
QTest::ignoreMessage(QtWarningMsg, "QGestureManager::deliverEvent: could not find the target for gesture"); |
|
800 |
QTest::ignoreMessage(QtWarningMsg, "QGestureManager::deliverEvent: could not find the target for gesture"); |
|
801 |
sendCustomGesture(&event, item, &scene); |
|
802 |
||
803 |
QCOMPARE(item->customEventsReceived, TotalCustomEventsCount); |
|
804 |
QCOMPARE(item->gestureEventsReceived, 0); |
|
805 |
QCOMPARE(item->gestureOverrideEventsReceived, 0); |
|
806 |
||
807 |
item->reset(); |
|
808 |
||
809 |
// make sure the event is properly delivered if only the hotspot is set. |
|
810 |
event.hotSpot = mapToGlobal(QPointF(10, 10), item, &view); |
|
811 |
event.hasHotSpot = true; |
|
812 |
sendCustomGesture(&event, item, &scene); |
|
813 |
||
814 |
QCOMPARE(item->customEventsReceived, TotalCustomEventsCount); |
|
815 |
QCOMPARE(item->gestureEventsReceived, TotalGestureEventsCount); |
|
816 |
QCOMPARE(item->gestureOverrideEventsReceived, 0); |
|
817 |
QCOMPARE(item->events.all.size(), TotalGestureEventsCount); |
|
818 |
for(int i = 0; i < item->events.all.size(); ++i) |
|
819 |
QCOMPARE(item->events.all.at(i), CustomGesture::GestureType); |
|
820 |
QCOMPARE(item->events.started.size(), 1); |
|
821 |
QCOMPARE(item->events.updated.size(), TotalGestureEventsCount - 2); |
|
822 |
QCOMPARE(item->events.finished.size(), 1); |
|
823 |
QCOMPARE(item->events.canceled.size(), 0); |
|
824 |
||
825 |
item->reset(); |
|
826 |
||
827 |
// send gesture to the item which ignores it. |
|
828 |
item->ignoredGestures << CustomGesture::GestureType; |
|
829 |
||
830 |
event.hotSpot = mapToGlobal(QPointF(10, 10), item, &view); |
|
831 |
event.hasHotSpot = true; |
|
832 |
sendCustomGesture(&event, item, &scene); |
|
833 |
QCOMPARE(item->customEventsReceived, TotalCustomEventsCount); |
|
834 |
QCOMPARE(item->gestureEventsReceived, TotalGestureEventsCount); |
|
835 |
QCOMPARE(item->gestureOverrideEventsReceived, 0); |
|
836 |
} |
|
837 |
||
838 |
void tst_Gestures::graphicsItemTreeGesture() |
|
839 |
{ |
|
840 |
QGraphicsScene scene; |
|
841 |
QGraphicsView view(&scene); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
842 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
0 | 843 |
|
844 |
GestureItem *item1 = new GestureItem("item1"); |
|
845 |
item1->setPos(100, 100); |
|
846 |
item1->size = QRectF(0, 0, 350, 200); |
|
847 |
scene.addItem(item1); |
|
848 |
||
849 |
GestureItem *item1_child1 = new GestureItem("item1_child1"); |
|
850 |
item1_child1->setPos(50, 50); |
|
851 |
item1_child1->size = QRectF(0, 0, 100, 100); |
|
852 |
item1_child1->setParentItem(item1); |
|
853 |
||
854 |
GestureItem *item1_child2 = new GestureItem("item1_child2"); |
|
855 |
item1_child2->size = QRectF(0, 0, 100, 100); |
|
856 |
item1_child2->setPos(200, 50); |
|
857 |
item1_child2->setParentItem(item1); |
|
858 |
||
859 |
view.show(); |
|
860 |
QTest::qWaitForWindowShown(&view); |
|
861 |
view.ensureVisible(scene.sceneRect()); |
|
862 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
863 |
view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 864 |
item1->grabGesture(CustomGesture::GestureType); |
865 |
||
866 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
867 |
||
868 |
CustomEvent event; |
|
869 |
event.hotSpot = mapToGlobal(QPointF(10, 10), item1_child1, &view); |
|
870 |
event.hasHotSpot = true; |
|
871 |
||
872 |
item1->ignoredGestures << CustomGesture::GestureType; |
|
873 |
sendCustomGesture(&event, item1_child1, &scene); |
|
874 |
QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); |
|
875 |
QCOMPARE(item1_child1->gestureEventsReceived, 0); |
|
876 |
QCOMPARE(item1_child2->gestureEventsReceived, 0); |
|
877 |
QCOMPARE(item1_child2->gestureOverrideEventsReceived, 0); |
|
878 |
QCOMPARE(item1->gestureOverrideEventsReceived, 0); |
|
879 |
QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); |
|
880 |
||
881 |
item1->reset(); item1_child1->reset(); item1_child2->reset(); |
|
882 |
||
883 |
item1_child1->grabGesture(CustomGesture::GestureType); |
|
884 |
||
885 |
item1->ignoredGestures << CustomGesture::GestureType; |
|
886 |
item1_child1->ignoredGestures << CustomGesture::GestureType; |
|
887 |
sendCustomGesture(&event, item1_child1, &scene); |
|
888 |
QCOMPARE(item1_child1->gestureOverrideEventsReceived, 1); |
|
889 |
QCOMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount); |
|
890 |
QCOMPARE(item1_child2->gestureEventsReceived, 0); |
|
891 |
QCOMPARE(item1_child2->gestureOverrideEventsReceived, 0); |
|
892 |
QCOMPARE(item1->gestureOverrideEventsReceived, 1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
893 |
QCOMPARE(item1->gestureEventsReceived, 1); |
0 | 894 |
} |
895 |
||
896 |
void tst_Gestures::explicitGraphicsObjectTarget() |
|
897 |
{ |
|
898 |
QGraphicsScene scene; |
|
899 |
QGraphicsView view(&scene); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
900 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
0 | 901 |
|
902 |
GestureItem *item1 = new GestureItem("item1"); |
|
903 |
scene.addItem(item1); |
|
904 |
item1->setPos(100, 100); |
|
905 |
item1->setZValue(1); |
|
906 |
||
907 |
GestureItem *item2 = new GestureItem("item2"); |
|
908 |
scene.addItem(item2); |
|
909 |
item2->setPos(100, 100); |
|
910 |
item2->setZValue(5); |
|
911 |
||
912 |
GestureItem *item2_child1 = new GestureItem("item2_child1"); |
|
913 |
scene.addItem(item2_child1); |
|
914 |
item2_child1->setParentItem(item2); |
|
915 |
item2_child1->setPos(10, 10); |
|
916 |
||
917 |
view.show(); |
|
918 |
QTest::qWaitForWindowShown(&view); |
|
919 |
view.ensureVisible(scene.sceneRect()); |
|
920 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
921 |
view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
922 |
item1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
923 |
item2->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
924 |
item2_child1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 925 |
|
926 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
927 |
||
928 |
// sending events to item1, but the hotSpot is set to item2 |
|
929 |
CustomEvent event; |
|
930 |
event.hotSpot = mapToGlobal(QPointF(15, 15), item2, &view); |
|
931 |
event.hasHotSpot = true; |
|
932 |
||
933 |
sendCustomGesture(&event, item1, &scene); |
|
934 |
||
935 |
QCOMPARE(item1->gestureEventsReceived, 0); |
|
936 |
QCOMPARE(item1->gestureOverrideEventsReceived, 1); |
|
937 |
QCOMPARE(item2_child1->gestureEventsReceived, TotalGestureEventsCount); |
|
938 |
QCOMPARE(item2_child1->gestureOverrideEventsReceived, 1); |
|
939 |
QCOMPARE(item2_child1->events.all.size(), TotalGestureEventsCount); |
|
940 |
for(int i = 0; i < item2_child1->events.all.size(); ++i) |
|
941 |
QCOMPARE(item2_child1->events.all.at(i), CustomGesture::GestureType); |
|
942 |
QCOMPARE(item2_child1->events.started.size(), 1); |
|
943 |
QCOMPARE(item2_child1->events.updated.size(), TotalGestureEventsCount - 2); |
|
944 |
QCOMPARE(item2_child1->events.finished.size(), 1); |
|
945 |
QCOMPARE(item2_child1->events.canceled.size(), 0); |
|
946 |
QCOMPARE(item2->gestureEventsReceived, 0); |
|
947 |
QCOMPARE(item2->gestureOverrideEventsReceived, 1); |
|
948 |
} |
|
949 |
||
950 |
void tst_Gestures::gestureOverChildGraphicsItem() |
|
951 |
{ |
|
952 |
QGraphicsScene scene; |
|
953 |
QGraphicsView view(&scene); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
954 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
0 | 955 |
|
956 |
GestureItem *item0 = new GestureItem("item0"); |
|
957 |
scene.addItem(item0); |
|
958 |
item0->setPos(0, 0); |
|
959 |
item0->grabGesture(CustomGesture::GestureType); |
|
960 |
item0->setZValue(1); |
|
961 |
||
962 |
GestureItem *item1 = new GestureItem("item1"); |
|
963 |
scene.addItem(item1); |
|
964 |
item1->setPos(100, 100); |
|
965 |
item1->setZValue(5); |
|
966 |
||
967 |
GestureItem *item2 = new GestureItem("item2"); |
|
968 |
scene.addItem(item2); |
|
969 |
item2->setPos(100, 100); |
|
970 |
item2->setZValue(10); |
|
971 |
||
972 |
GestureItem *item2_child1 = new GestureItem("item2_child1"); |
|
973 |
scene.addItem(item2_child1); |
|
974 |
item2_child1->setParentItem(item2); |
|
975 |
item2_child1->setPos(0, 0); |
|
976 |
||
977 |
view.show(); |
|
978 |
QTest::qWaitForWindowShown(&view); |
|
979 |
view.ensureVisible(scene.sceneRect()); |
|
980 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
981 |
view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
0 | 982 |
item1->grabGesture(CustomGesture::GestureType); |
983 |
||
984 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
985 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
|
986 |
||
987 |
CustomEvent event; |
|
988 |
event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); |
|
989 |
event.hasHotSpot = true; |
|
990 |
sendCustomGesture(&event, item0, &scene); |
|
991 |
||
992 |
QCOMPARE(item0->customEventsReceived, TotalCustomEventsCount); |
|
993 |
QCOMPARE(item2_child1->gestureEventsReceived, 0); |
|
994 |
QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); |
|
995 |
QCOMPARE(item2->gestureEventsReceived, 0); |
|
996 |
QCOMPARE(item2->gestureOverrideEventsReceived, 0); |
|
997 |
QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); |
|
998 |
QCOMPARE(item1->gestureOverrideEventsReceived, 0); |
|
999 |
||
1000 |
item0->reset(); item1->reset(); item2->reset(); item2_child1->reset(); |
|
1001 |
item2->grabGesture(CustomGesture::GestureType); |
|
1002 |
item2->ignoredGestures << CustomGesture::GestureType; |
|
1003 |
||
1004 |
event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); |
|
1005 |
event.hasHotSpot = true; |
|
1006 |
sendCustomGesture(&event, item0, &scene); |
|
1007 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1008 |
QCOMPARE(item2_child1->gestureEventsReceived, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1009 |
QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1010 |
QCOMPARE(item2->gestureEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1011 |
QCOMPARE(item2->gestureOverrideEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1012 |
QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1013 |
QCOMPARE(item1->gestureOverrideEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1014 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1015 |
item0->reset(); item1->reset(); item2->reset(); item2_child1->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1016 |
item2->grabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1017 |
item2->ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1018 |
item1->ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1019 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1020 |
event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1021 |
event.hasHotSpot = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1022 |
sendCustomGesture(&event, item0, &scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1023 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1024 |
QCOMPARE(item2_child1->gestureEventsReceived, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1025 |
QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1026 |
QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1027 |
QCOMPARE(item2->gestureOverrideEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1028 |
QCOMPARE(item1->gestureEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1029 |
QCOMPARE(item1->gestureOverrideEventsReceived, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1030 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1031 |
item0->reset(); item1->reset(); item2->reset(); item2_child1->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1032 |
item2->grabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1033 |
item2->ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1034 |
item1->ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1035 |
item1->grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1036 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1037 |
event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1038 |
event.hasHotSpot = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1039 |
sendCustomGesture(&event, item0, &scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1040 |
|
0 | 1041 |
QCOMPARE(item2_child1->gestureEventsReceived, 0); |
1042 |
QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); |
|
1043 |
QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); |
|
1044 |
QCOMPARE(item2->gestureOverrideEventsReceived, 1); |
|
1045 |
QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); |
|
1046 |
QCOMPARE(item1->gestureOverrideEventsReceived, 1); |
|
1047 |
} |
|
1048 |
||
1049 |
void tst_Gestures::twoGesturesOnDifferentLevel() |
|
1050 |
{ |
|
1051 |
GestureWidget parent("parent"); |
|
1052 |
QVBoxLayout *l = new QVBoxLayout(&parent); |
|
1053 |
GestureWidget *child = new GestureWidget("child"); |
|
1054 |
l->addWidget(child); |
|
1055 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1056 |
Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
0 | 1057 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1058 |
parent.grabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1059 |
child->grabGesture(SecondGesture); |
0 | 1060 |
|
1061 |
CustomEvent event; |
|
1062 |
// sending events that form a gesture to one widget, but they will be |
|
1063 |
// filtered by two different gesture recognizers and will generate two |
|
1064 |
// QGesture objects. Check that those gesture objects are delivered to |
|
1065 |
// different widgets properly. |
|
1066 |
sendCustomGesture(&event, child); |
|
1067 |
||
1068 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
1069 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
|
1070 |
||
1071 |
QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); |
|
1072 |
QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); |
|
1073 |
QCOMPARE(child->gestureOverrideEventsReceived, 0); |
|
1074 |
QCOMPARE(child->events.all.size(), TotalGestureEventsCount); |
|
1075 |
for(int i = 0; i < child->events.all.size(); ++i) |
|
1076 |
QCOMPARE(child->events.all.at(i), SecondGesture); |
|
1077 |
||
1078 |
QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); |
|
1079 |
QCOMPARE(parent.gestureOverrideEventsReceived, 0); |
|
1080 |
QCOMPARE(parent.events.all.size(), TotalGestureEventsCount); |
|
1081 |
for(int i = 0; i < child->events.all.size(); ++i) |
|
1082 |
QCOMPARE(parent.events.all.at(i), CustomGesture::GestureType); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1083 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1084 |
QGestureRecognizer::unregisterRecognizer(SecondGesture); |
0 | 1085 |
} |
1086 |
||
1087 |
void tst_Gestures::multipleGesturesInTree() |
|
1088 |
{ |
|
1089 |
GestureWidget a("A"); |
|
1090 |
GestureWidget *A = &a; |
|
1091 |
GestureWidget *B = new GestureWidget("B", A); |
|
1092 |
GestureWidget *C = new GestureWidget("C", B); |
|
1093 |
GestureWidget *D = new GestureWidget("D", C); |
|
1094 |
||
1095 |
Qt::GestureType FirstGesture = CustomGesture::GestureType; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1096 |
Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1097 |
Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
0 | 1098 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1099 |
Qt::GestureFlags flags = Qt::ReceivePartialGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1100 |
A->grabGesture(FirstGesture, flags); // A [1 3] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1101 |
A->grabGesture(ThirdGesture, flags); // | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1102 |
B->grabGesture(SecondGesture, flags); // B [ 2 3] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1103 |
B->grabGesture(ThirdGesture, flags); // | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1104 |
C->grabGesture(FirstGesture, flags); // C [1 2 3] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1105 |
C->grabGesture(SecondGesture, flags); // | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1106 |
C->grabGesture(ThirdGesture, flags); // D [1 3] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1107 |
D->grabGesture(FirstGesture, flags); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1108 |
D->grabGesture(ThirdGesture, flags); |
0 | 1109 |
|
1110 |
// make sure all widgets ignore events, so they get propagated. |
|
1111 |
A->ignoredGestures << FirstGesture << ThirdGesture; |
|
1112 |
B->ignoredGestures << SecondGesture << ThirdGesture; |
|
1113 |
C->ignoredGestures << FirstGesture << SecondGesture << ThirdGesture; |
|
1114 |
D->ignoredGestures << FirstGesture << ThirdGesture; |
|
1115 |
||
1116 |
CustomEvent event; |
|
1117 |
sendCustomGesture(&event, D); |
|
1118 |
||
1119 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
1120 |
||
1121 |
// gesture override events |
|
1122 |
QCOMPARE(D->overrideEvents.all.count(FirstGesture), 1); |
|
1123 |
QCOMPARE(D->overrideEvents.all.count(SecondGesture), 0); |
|
1124 |
QCOMPARE(D->overrideEvents.all.count(ThirdGesture), 1); |
|
1125 |
||
1126 |
QCOMPARE(C->overrideEvents.all.count(FirstGesture), 1); |
|
1127 |
QCOMPARE(C->overrideEvents.all.count(SecondGesture), 1); |
|
1128 |
QCOMPARE(C->overrideEvents.all.count(ThirdGesture), 1); |
|
1129 |
||
1130 |
QCOMPARE(B->overrideEvents.all.count(FirstGesture), 0); |
|
1131 |
QCOMPARE(B->overrideEvents.all.count(SecondGesture), 1); |
|
1132 |
QCOMPARE(B->overrideEvents.all.count(ThirdGesture), 1); |
|
1133 |
||
1134 |
QCOMPARE(A->overrideEvents.all.count(FirstGesture), 1); |
|
1135 |
QCOMPARE(A->overrideEvents.all.count(SecondGesture), 0); |
|
1136 |
QCOMPARE(A->overrideEvents.all.count(ThirdGesture), 1); |
|
1137 |
||
1138 |
// normal gesture events |
|
1139 |
QCOMPARE(D->events.all.count(FirstGesture), TotalGestureEventsCount); |
|
1140 |
QCOMPARE(D->events.all.count(SecondGesture), 0); |
|
1141 |
QCOMPARE(D->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
1142 |
||
1143 |
QCOMPARE(C->events.all.count(FirstGesture), TotalGestureEventsCount); |
|
1144 |
QCOMPARE(C->events.all.count(SecondGesture), TotalGestureEventsCount); |
|
1145 |
QCOMPARE(C->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
1146 |
||
1147 |
QCOMPARE(B->events.all.count(FirstGesture), 0); |
|
1148 |
QCOMPARE(B->events.all.count(SecondGesture), TotalGestureEventsCount); |
|
1149 |
QCOMPARE(B->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
1150 |
||
1151 |
QCOMPARE(A->events.all.count(FirstGesture), TotalGestureEventsCount); |
|
1152 |
QCOMPARE(A->events.all.count(SecondGesture), 0); |
|
1153 |
QCOMPARE(A->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1154 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1155 |
QGestureRecognizer::unregisterRecognizer(SecondGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1156 |
QGestureRecognizer::unregisterRecognizer(ThirdGesture); |
0 | 1157 |
} |
1158 |
||
1159 |
void tst_Gestures::multipleGesturesInComplexTree() |
|
1160 |
{ |
|
1161 |
GestureWidget a("A"); |
|
1162 |
GestureWidget *A = &a; |
|
1163 |
GestureWidget *B = new GestureWidget("B", A); |
|
1164 |
GestureWidget *C = new GestureWidget("C", B); |
|
1165 |
GestureWidget *D = new GestureWidget("D", C); |
|
1166 |
||
1167 |
Qt::GestureType FirstGesture = CustomGesture::GestureType; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1168 |
Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1169 |
Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1170 |
Qt::GestureType FourthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1171 |
Qt::GestureType FifthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1172 |
Qt::GestureType SixthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1173 |
Qt::GestureType SeventhGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
0 | 1174 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1175 |
Qt::GestureFlags flags = Qt::ReceivePartialGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1176 |
A->grabGesture(FirstGesture, flags); // A [1,3,4] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1177 |
A->grabGesture(ThirdGesture, flags); // | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1178 |
A->grabGesture(FourthGesture, flags); // B [2,3,5] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1179 |
B->grabGesture(SecondGesture, flags); // | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1180 |
B->grabGesture(ThirdGesture, flags); // C [1,2,3,6] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1181 |
B->grabGesture(FifthGesture, flags); // | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1182 |
C->grabGesture(FirstGesture, flags); // D [1,3,7] |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1183 |
C->grabGesture(SecondGesture, flags); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
C->grabGesture(ThirdGesture, flags); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
C->grabGesture(SixthGesture, flags); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
D->grabGesture(FirstGesture, flags); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1187 |
D->grabGesture(ThirdGesture, flags); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1188 |
D->grabGesture(SeventhGesture, flags); |
0 | 1189 |
|
1190 |
// make sure all widgets ignore events, so they get propagated. |
|
1191 |
QSet<Qt::GestureType> allGestureTypes; |
|
1192 |
allGestureTypes << FirstGesture << SecondGesture << ThirdGesture |
|
1193 |
<< FourthGesture << FifthGesture << SixthGesture << SeventhGesture; |
|
1194 |
A->ignoredGestures = B->ignoredGestures = allGestureTypes; |
|
1195 |
C->ignoredGestures = D->ignoredGestures = allGestureTypes; |
|
1196 |
||
1197 |
CustomEvent event; |
|
1198 |
sendCustomGesture(&event, D); |
|
1199 |
||
1200 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
|
1201 |
||
1202 |
// gesture override events |
|
1203 |
QCOMPARE(D->overrideEvents.all.count(FirstGesture), 1); |
|
1204 |
QCOMPARE(D->overrideEvents.all.count(SecondGesture), 0); |
|
1205 |
QCOMPARE(D->overrideEvents.all.count(ThirdGesture), 1); |
|
1206 |
||
1207 |
QCOMPARE(C->overrideEvents.all.count(FirstGesture), 1); |
|
1208 |
QCOMPARE(C->overrideEvents.all.count(SecondGesture), 1); |
|
1209 |
QCOMPARE(C->overrideEvents.all.count(ThirdGesture), 1); |
|
1210 |
||
1211 |
QCOMPARE(B->overrideEvents.all.count(FirstGesture), 0); |
|
1212 |
QCOMPARE(B->overrideEvents.all.count(SecondGesture), 1); |
|
1213 |
QCOMPARE(B->overrideEvents.all.count(ThirdGesture), 1); |
|
1214 |
||
1215 |
QCOMPARE(A->overrideEvents.all.count(FirstGesture), 1); |
|
1216 |
QCOMPARE(A->overrideEvents.all.count(SecondGesture), 0); |
|
1217 |
QCOMPARE(A->overrideEvents.all.count(ThirdGesture), 1); |
|
1218 |
||
1219 |
// normal gesture events |
|
1220 |
QCOMPARE(D->events.all.count(FirstGesture), TotalGestureEventsCount); |
|
1221 |
QCOMPARE(D->events.all.count(SecondGesture), 0); |
|
1222 |
QCOMPARE(D->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
1223 |
QCOMPARE(D->events.all.count(FourthGesture), 0); |
|
1224 |
QCOMPARE(D->events.all.count(FifthGesture), 0); |
|
1225 |
QCOMPARE(D->events.all.count(SixthGesture), 0); |
|
1226 |
QCOMPARE(D->events.all.count(SeventhGesture), TotalGestureEventsCount); |
|
1227 |
||
1228 |
QCOMPARE(C->events.all.count(FirstGesture), TotalGestureEventsCount); |
|
1229 |
QCOMPARE(C->events.all.count(SecondGesture), TotalGestureEventsCount); |
|
1230 |
QCOMPARE(C->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
1231 |
QCOMPARE(C->events.all.count(FourthGesture), 0); |
|
1232 |
QCOMPARE(C->events.all.count(FifthGesture), 0); |
|
1233 |
QCOMPARE(C->events.all.count(SixthGesture), TotalGestureEventsCount); |
|
1234 |
QCOMPARE(C->events.all.count(SeventhGesture), 0); |
|
1235 |
||
1236 |
QCOMPARE(B->events.all.count(FirstGesture), 0); |
|
1237 |
QCOMPARE(B->events.all.count(SecondGesture), TotalGestureEventsCount); |
|
1238 |
QCOMPARE(B->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
1239 |
QCOMPARE(B->events.all.count(FourthGesture), 0); |
|
1240 |
QCOMPARE(B->events.all.count(FifthGesture), TotalGestureEventsCount); |
|
1241 |
QCOMPARE(B->events.all.count(SixthGesture), 0); |
|
1242 |
QCOMPARE(B->events.all.count(SeventhGesture), 0); |
|
1243 |
||
1244 |
QCOMPARE(A->events.all.count(FirstGesture), TotalGestureEventsCount); |
|
1245 |
QCOMPARE(A->events.all.count(SecondGesture), 0); |
|
1246 |
QCOMPARE(A->events.all.count(ThirdGesture), TotalGestureEventsCount); |
|
1247 |
QCOMPARE(A->events.all.count(FourthGesture), TotalGestureEventsCount); |
|
1248 |
QCOMPARE(A->events.all.count(FifthGesture), 0); |
|
1249 |
QCOMPARE(A->events.all.count(SixthGesture), 0); |
|
1250 |
QCOMPARE(A->events.all.count(SeventhGesture), 0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1251 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1252 |
QGestureRecognizer::unregisterRecognizer(SecondGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1253 |
QGestureRecognizer::unregisterRecognizer(ThirdGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1254 |
QGestureRecognizer::unregisterRecognizer(FourthGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1255 |
QGestureRecognizer::unregisterRecognizer(FifthGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1256 |
QGestureRecognizer::unregisterRecognizer(SixthGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1257 |
QGestureRecognizer::unregisterRecognizer(SeventhGesture); |
0 | 1258 |
} |
1259 |
||
1260 |
void tst_Gestures::testMapToScene() |
|
1261 |
{ |
|
1262 |
QGesture gesture; |
|
1263 |
QList<QGesture*> list; |
|
1264 |
list << &gesture; |
|
1265 |
QGestureEvent event(list); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1266 |
QCOMPARE(event.mapToGraphicsScene(gesture.hotSpot()), QPointF()); // not set, can't do much |
0 | 1267 |
|
1268 |
QGraphicsScene scene; |
|
1269 |
QGraphicsView view(&scene); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1270 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
0 | 1271 |
|
1272 |
GestureItem *item0 = new GestureItem; |
|
1273 |
scene.addItem(item0); |
|
1274 |
item0->setPos(14, 16); |
|
1275 |
||
1276 |
view.show(); // need to show to give it a global coordinate |
|
1277 |
QTest::qWaitForWindowShown(&view); |
|
1278 |
view.ensureVisible(scene.sceneRect()); |
|
1279 |
||
1280 |
QPoint origin = view.mapToGlobal(QPoint()); |
|
1281 |
event.setWidget(view.viewport()); |
|
1282 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1283 |
QCOMPARE(event.mapToGraphicsScene(origin + QPoint(100, 200)), view.mapToScene(QPoint(100, 200))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1284 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1285 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1286 |
void tst_Gestures::ungrabGesture() // a method on QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1287 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1288 |
class MockGestureWidget : public GestureWidget { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1289 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1290 |
MockGestureWidget(const char *name = 0, QWidget *parent = 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1291 |
: GestureWidget(name, parent) { } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1292 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1293 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1294 |
QSet<QGesture*> gestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1295 |
protected: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1296 |
bool event(QEvent *event) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1297 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1298 |
if (event->type() == QEvent::Gesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1299 |
QGestureEvent *gestureEvent = static_cast<QGestureEvent*>(event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1300 |
if (gestureEvent) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1301 |
foreach (QGesture *g, gestureEvent->gestures()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1302 |
gestures.insert(g); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1303 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1304 |
return GestureWidget::event(event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1305 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1306 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1307 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
MockGestureWidget parent("A"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1309 |
MockGestureWidget *a = &parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1310 |
MockGestureWidget *b = new MockGestureWidget("B", a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1311 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1312 |
a->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1313 |
b->grabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1314 |
b->ignoredGestures << CustomGesture::GestureType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1315 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1316 |
CustomEvent event; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1317 |
// sending an event will cause the QGesture objects to be instantiated for the widgets |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1318 |
sendCustomGesture(&event, b); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1319 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1320 |
QCOMPARE(a->gestures.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1321 |
QPointer<QGesture> customGestureA; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1322 |
customGestureA = *(a->gestures.begin()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
QVERIFY(!customGestureA.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1324 |
QCOMPARE(customGestureA->gestureType(), CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1325 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1326 |
QCOMPARE(b->gestures.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1327 |
QPointer<QGesture> customGestureB; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1328 |
customGestureB = *(b->gestures.begin()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1329 |
QVERIFY(!customGestureB.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1330 |
QVERIFY(customGestureA.data() == customGestureB.data()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1331 |
QCOMPARE(customGestureB->gestureType(), CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1332 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1333 |
a->gestures.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1334 |
// sending an event will cause the QGesture objects to be instantiated for the widget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1335 |
sendCustomGesture(&event, a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1336 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1337 |
QCOMPARE(a->gestures.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
customGestureA = *(a->gestures.begin()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1339 |
QVERIFY(!customGestureA.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1340 |
QCOMPARE(customGestureA->gestureType(), CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1341 |
QVERIFY(customGestureA.data() != customGestureB.data()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1342 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1343 |
a->ungrabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1344 |
QVERIFY(customGestureA.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1345 |
QVERIFY(!customGestureB.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1346 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1347 |
a->gestures.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1348 |
a->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1349 |
// send again to 'b' and make sure a never gets it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1350 |
sendCustomGesture(&event, b); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1351 |
QCOMPARE(a->gestureEventsReceived, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1352 |
QCOMPARE(a->gestureOverrideEventsReceived, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1353 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1354 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1355 |
void tst_Gestures::unregisterRecognizer() // a method on QApplication |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1356 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1357 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1358 |
The hardest usecase to get right is when we remove a recognizer while several |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1359 |
of the gestures it created are in active state and we immediately add a new recognizer |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1360 |
for the same type (thus replacing the old one). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1361 |
The expected result is that all old gestures continue till they are finished/cancelled |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1362 |
and the new recognizer starts creating gestures immediately at registration. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1363 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1364 |
This implies that deleting of the recognizer happens only when there are no more gestures |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1365 |
that it created. (since gestures might have a pointer to the recognizer) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1366 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1367 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1368 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1369 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1370 |
void tst_Gestures::autoCancelGestures() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1371 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1372 |
class MockWidget : public GestureWidget { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1373 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1374 |
MockWidget(const char *name) : GestureWidget(name) { } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1375 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1376 |
bool event(QEvent *event) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1377 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1378 |
if (event->type() == QEvent::Gesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1379 |
QGestureEvent *ge = static_cast<QGestureEvent*>(event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1380 |
Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1381 |
ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1382 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1383 |
return GestureWidget::event(event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1384 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1385 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1386 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1387 |
const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1388 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1389 |
MockWidget parent("parent"); // this one sets the cancel policy to CancelAllInContext |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1390 |
parent.resize(300, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1391 |
parent.setWindowFlags(Qt::X11BypassWindowManagerHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1392 |
GestureWidget *child = new GestureWidget("child", &parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1393 |
child->setGeometry(10, 10, 100, 80); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1394 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1395 |
parent.grabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1396 |
child->grabGesture(secondGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1397 |
parent.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1398 |
QTest::qWaitForWindowShown(&parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1399 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1401 |
An event is send to both the child and the parent, when the child gets it a gesture is triggered |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1402 |
and send to the child. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1403 |
When the parent gets the event a new gesture is triggered and delivered to the parent. When the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1404 |
parent gets it he accepts it and that causes the cancel policy to activate. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1405 |
The cause of that is the gesture for the child is cancelled and send to the child as such. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1406 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1407 |
CustomEvent event; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1408 |
event.serial = CustomGesture::SerialStartedThreshold; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1409 |
QApplication::sendEvent(child, &event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1410 |
QCOMPARE(child->events.all.count(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1411 |
QCOMPARE(child->events.started.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1412 |
QCOMPARE(child->events.canceled.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1413 |
QCOMPARE(parent.events.all.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1414 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1415 |
// clean up, make the parent gesture finish |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1416 |
event.serial = CustomGesture::SerialFinishedThreshold; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1417 |
QApplication::sendEvent(child, &event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1418 |
QCOMPARE(parent.events.all.count(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1419 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1420 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1421 |
void tst_Gestures::autoCancelGestures2() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1422 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1423 |
class MockItem : public GestureItem { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1424 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1425 |
MockItem(const char *name) : GestureItem(name) { } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1426 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1427 |
bool event(QEvent *event) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1428 |
if (event->type() == QEvent::Gesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1429 |
QGestureEvent *ge = static_cast<QGestureEvent*>(event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1430 |
Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1431 |
ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1432 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1433 |
return GestureItem::event(event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1434 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1435 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1436 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1437 |
const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1438 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1439 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1440 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1441 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1442 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1443 |
MockItem *parent = new MockItem("parent"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1444 |
GestureItem *child = new GestureItem("child"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1445 |
child->setParentItem(parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1446 |
parent->setPos(0, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1447 |
child->setPos(10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1448 |
scene.addItem(parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1449 |
view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1450 |
view.viewport()->grabGesture(secondGesture, Qt::DontStartGestureOnChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1451 |
parent->grabGesture(CustomGesture::GestureType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1452 |
child->grabGesture(secondGesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1453 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1454 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1455 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1456 |
view.ensureVisible(scene.sceneRect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1457 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1458 |
CustomEvent event; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1459 |
event.serial = CustomGesture::SerialStartedThreshold; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1460 |
event.hasHotSpot = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1461 |
event.hotSpot = mapToGlobal(QPointF(5, 5), child, &view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1462 |
scene.sendEvent(child, &event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1463 |
QCOMPARE(parent->events.all.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1464 |
QCOMPARE(child->events.started.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1465 |
QCOMPARE(child->events.canceled.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1466 |
QCOMPARE(child->events.all.count(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1467 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1468 |
// clean up, make the parent gesture finish |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1469 |
event.serial = CustomGesture::SerialFinishedThreshold; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1470 |
scene.sendEvent(child, &event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1471 |
QCOMPARE(parent->events.all.count(), 2); |
0 | 1472 |
} |
1473 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1474 |
void tst_Gestures::panelPropagation() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1475 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1476 |
QGraphicsScene scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1477 |
QGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1478 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1479 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1480 |
GestureItem *item0 = new GestureItem("item0"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1481 |
scene.addItem(item0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1482 |
item0->setPos(0, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1483 |
item0->size = QRectF(0, 0, 200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1484 |
item0->grabGesture(CustomGesture::GestureType); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1485 |
item0->setZValue(1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1486 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1487 |
GestureItem *item1 = new GestureItem("item1"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1488 |
item1->grabGesture(CustomGesture::GestureType); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1489 |
scene.addItem(item1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1490 |
item1->setPos(10, 10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1491 |
item1->size = QRectF(0, 0, 180, 180); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1492 |
item1->setZValue(2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1493 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1494 |
GestureItem *item1_child1 = new GestureItem("item1_child1[panel]"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1495 |
item1_child1->setFlags(QGraphicsItem::ItemIsPanel); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1496 |
item1_child1->setParentItem(item1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1497 |
item1_child1->grabGesture(CustomGesture::GestureType); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1498 |
item1_child1->setPos(10, 10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1499 |
item1_child1->size = QRectF(0, 0, 160, 160); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1500 |
item1_child1->setZValue(5); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1501 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1502 |
GestureItem *item1_child1_child1 = new GestureItem("item1_child1_child1"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1503 |
item1_child1_child1->setParentItem(item1_child1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1504 |
item1_child1_child1->grabGesture(CustomGesture::GestureType); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1505 |
item1_child1_child1->setPos(10, 10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1506 |
item1_child1_child1->size = QRectF(0, 0, 140, 140); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1507 |
item1_child1_child1->setZValue(10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1508 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1509 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1510 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1511 |
view.ensureVisible(scene.sceneRect()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1512 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1513 |
view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1514 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1515 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1516 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1517 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1518 |
CustomEvent event; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1519 |
event.hotSpot = mapToGlobal(QPointF(5, 5), item1_child1_child1, &view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1520 |
event.hasHotSpot = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1521 |
sendCustomGesture(&event, item0, &scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1522 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1523 |
QCOMPARE(item0->customEventsReceived, TotalCustomEventsCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1524 |
QCOMPARE(item1_child1_child1->gestureEventsReceived, TotalGestureEventsCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1525 |
QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1526 |
QCOMPARE(item1_child1->gestureOverrideEventsReceived, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1527 |
QCOMPARE(item1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1528 |
QCOMPARE(item1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1529 |
QCOMPARE(item0->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1530 |
QCOMPARE(item0->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1531 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1532 |
item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1533 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1534 |
event.hotSpot = mapToGlobal(QPointF(5, 5), item1, &view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1535 |
event.hasHotSpot = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1536 |
sendCustomGesture(&event, item1, &scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1537 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1538 |
QCOMPARE(item1_child1_child1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1539 |
QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1540 |
QCOMPARE(item1_child1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1541 |
QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1542 |
QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1543 |
QCOMPARE(item1->gestureOverrideEventsReceived, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1544 |
QCOMPARE(item0->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1545 |
QCOMPARE(item0->gestureOverrideEventsReceived, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1546 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1547 |
item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1548 |
// try with a modal panel |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1549 |
item1_child1->setPanelModality(QGraphicsItem::PanelModal); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1550 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1551 |
event.hotSpot = mapToGlobal(QPointF(5, 5), item1, &view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1552 |
event.hasHotSpot = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1553 |
sendCustomGesture(&event, item1, &scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1554 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1555 |
QCOMPARE(item1_child1_child1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1556 |
QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1557 |
QCOMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1558 |
QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1559 |
QCOMPARE(item1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1560 |
QCOMPARE(item1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1561 |
QCOMPARE(item0->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1562 |
QCOMPARE(item0->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1563 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1564 |
item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1565 |
// try with a modal panel, however set the hotspot to be outside of the |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1566 |
// panel and its parent |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1567 |
item1_child1->setPanelModality(QGraphicsItem::PanelModal); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1568 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1569 |
event.hotSpot = mapToGlobal(QPointF(5, 5), item0, &view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1570 |
event.hasHotSpot = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1571 |
sendCustomGesture(&event, item1, &scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1572 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1573 |
QCOMPARE(item1_child1_child1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1574 |
QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1575 |
QCOMPARE(item1_child1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1576 |
QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1577 |
QCOMPARE(item1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1578 |
QCOMPARE(item1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1579 |
QCOMPARE(item0->gestureEventsReceived, TotalGestureEventsCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1580 |
QCOMPARE(item0->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1581 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1582 |
item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1583 |
// try with a scene modal panel |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1584 |
item1_child1->setPanelModality(QGraphicsItem::SceneModal); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1585 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1586 |
event.hotSpot = mapToGlobal(QPointF(5, 5), item0, &view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1587 |
event.hasHotSpot = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1588 |
sendCustomGesture(&event, item0, &scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1589 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1590 |
QCOMPARE(item1_child1_child1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1591 |
QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1592 |
QCOMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1593 |
QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1594 |
QCOMPARE(item1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1595 |
QCOMPARE(item1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1596 |
QCOMPARE(item0->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1597 |
QCOMPARE(item0->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1598 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1599 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1600 |
void tst_Gestures::panelStacksBehindParent() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1601 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1602 |
QGraphicsScene scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1603 |
QGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1604 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1605 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1606 |
GestureItem *item1 = new GestureItem("item1"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1607 |
item1->grabGesture(CustomGesture::GestureType); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1608 |
scene.addItem(item1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1609 |
item1->setPos(10, 10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1610 |
item1->size = QRectF(0, 0, 180, 180); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1611 |
item1->setZValue(2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1612 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1613 |
GestureItem *panel = new GestureItem("panel"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1614 |
panel->setFlags(QGraphicsItem::ItemIsPanel | QGraphicsItem::ItemStacksBehindParent); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1615 |
panel->setPanelModality(QGraphicsItem::PanelModal); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1616 |
panel->setParentItem(item1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1617 |
panel->grabGesture(CustomGesture::GestureType); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1618 |
panel->setPos(-10, -10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1619 |
panel->size = QRectF(0, 0, 200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1620 |
panel->setZValue(5); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1621 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1622 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1623 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1624 |
view.ensureVisible(scene.sceneRect()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1625 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1626 |
view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1627 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1628 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1629 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1630 |
CustomEvent event; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1631 |
event.hotSpot = mapToGlobal(QPointF(5, 5), item1, &view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1632 |
event.hasHotSpot = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1633 |
sendCustomGesture(&event, item1, &scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1634 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1635 |
QCOMPARE(item1->gestureEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1636 |
QCOMPARE(item1->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1637 |
QCOMPARE(panel->gestureEventsReceived, TotalGestureEventsCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1638 |
QCOMPARE(panel->gestureOverrideEventsReceived, 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1639 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1640 |
|
0 | 1641 |
QTEST_MAIN(tst_Gestures) |
1642 |
#include "tst_gestures.moc" |