author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
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 $MODULE$ of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtGui> |
|
43 |
#include <QtTest> |
|
44 |
||
45 |
class tst_QTouchEventWidget : public QWidget |
|
46 |
{ |
|
47 |
public: |
|
48 |
QList<QTouchEvent::TouchPoint> touchBeginPoints, touchUpdatePoints, touchEndPoints; |
|
49 |
bool seenTouchBegin, seenTouchUpdate, seenTouchEnd; |
|
50 |
bool acceptTouchBegin, acceptTouchUpdate, acceptTouchEnd; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd; |
0 | 52 |
|
53 |
tst_QTouchEventWidget() |
|
54 |
: QWidget() |
|
55 |
{ |
|
56 |
reset(); |
|
57 |
} |
|
58 |
||
59 |
void reset() |
|
60 |
{ |
|
61 |
touchBeginPoints.clear(); |
|
62 |
touchUpdatePoints.clear(); |
|
63 |
touchEndPoints.clear(); |
|
64 |
seenTouchBegin = seenTouchUpdate = seenTouchEnd = false; |
|
65 |
acceptTouchBegin = acceptTouchUpdate = acceptTouchEnd = true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false; |
0 | 67 |
} |
68 |
||
69 |
bool event(QEvent *event) |
|
70 |
{ |
|
71 |
switch (event->type()) { |
|
72 |
case QEvent::TouchBegin: |
|
73 |
if (seenTouchBegin) qWarning("TouchBegin: already seen a TouchBegin"); |
|
74 |
if (seenTouchUpdate) qWarning("TouchBegin: TouchUpdate cannot happen before TouchBegin"); |
|
75 |
if (seenTouchEnd) qWarning("TouchBegin: TouchEnd cannot happen before TouchBegin"); |
|
76 |
seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd; |
|
77 |
touchBeginPoints = static_cast<QTouchEvent *>(event)->touchPoints(); |
|
78 |
event->setAccepted(acceptTouchBegin); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
if (deleteInTouchBegin) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
delete this; |
0 | 81 |
break; |
82 |
case QEvent::TouchUpdate: |
|
83 |
if (!seenTouchBegin) qWarning("TouchUpdate: have not seen TouchBegin"); |
|
84 |
if (seenTouchEnd) qWarning("TouchUpdate: TouchEnd cannot happen before TouchUpdate"); |
|
85 |
seenTouchUpdate = seenTouchBegin && !seenTouchEnd; |
|
86 |
touchUpdatePoints = static_cast<QTouchEvent *>(event)->touchPoints(); |
|
87 |
event->setAccepted(acceptTouchUpdate); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
if (deleteInTouchUpdate) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
delete this; |
0 | 90 |
break; |
91 |
case QEvent::TouchEnd: |
|
92 |
if (!seenTouchBegin) qWarning("TouchEnd: have not seen TouchBegin"); |
|
93 |
if (seenTouchEnd) qWarning("TouchEnd: already seen a TouchEnd"); |
|
94 |
seenTouchEnd = seenTouchBegin && !seenTouchEnd; |
|
95 |
touchEndPoints = static_cast<QTouchEvent *>(event)->touchPoints(); |
|
96 |
event->setAccepted(acceptTouchEnd); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
if (deleteInTouchEnd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
delete this; |
0 | 99 |
break; |
100 |
default: |
|
101 |
return QWidget::event(event); |
|
102 |
} |
|
103 |
return true; |
|
104 |
} |
|
105 |
}; |
|
106 |
||
107 |
class tst_QTouchEventGraphicsItem : public QGraphicsItem |
|
108 |
{ |
|
109 |
public: |
|
110 |
QList<QTouchEvent::TouchPoint> touchBeginPoints, touchUpdatePoints, touchEndPoints; |
|
111 |
bool seenTouchBegin, seenTouchUpdate, seenTouchEnd; |
|
112 |
bool acceptTouchBegin, acceptTouchUpdate, acceptTouchEnd; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
tst_QTouchEventGraphicsItem **weakpointer; |
0 | 115 |
|
116 |
tst_QTouchEventGraphicsItem() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
: QGraphicsItem(), weakpointer(0) |
0 | 118 |
{ |
119 |
reset(); |
|
120 |
} |
|
121 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
~tst_QTouchEventGraphicsItem() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
if (weakpointer) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
*weakpointer = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
|
0 | 128 |
void reset() |
129 |
{ |
|
130 |
touchBeginPoints.clear(); |
|
131 |
touchUpdatePoints.clear(); |
|
132 |
touchEndPoints.clear(); |
|
133 |
seenTouchBegin = seenTouchUpdate = seenTouchEnd = false; |
|
134 |
acceptTouchBegin = acceptTouchUpdate = acceptTouchEnd = true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false; |
0 | 136 |
} |
137 |
||
138 |
QRectF boundingRect() const { return QRectF(0, 0, 10, 10); } |
|
139 |
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) { } |
|
140 |
||
141 |
bool sceneEvent(QEvent *event) |
|
142 |
{ |
|
143 |
switch (event->type()) { |
|
144 |
case QEvent::TouchBegin: |
|
145 |
if (seenTouchBegin) qWarning("TouchBegin: already seen a TouchBegin"); |
|
146 |
if (seenTouchUpdate) qWarning("TouchBegin: TouchUpdate cannot happen before TouchBegin"); |
|
147 |
if (seenTouchEnd) qWarning("TouchBegin: TouchEnd cannot happen before TouchBegin"); |
|
148 |
seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd; |
|
149 |
touchBeginPoints = static_cast<QTouchEvent *>(event)->touchPoints(); |
|
150 |
event->setAccepted(acceptTouchBegin); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
if (deleteInTouchBegin) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
delete this; |
0 | 153 |
break; |
154 |
case QEvent::TouchUpdate: |
|
155 |
if (!seenTouchBegin) qWarning("TouchUpdate: have not seen TouchBegin"); |
|
156 |
if (seenTouchEnd) qWarning("TouchUpdate: TouchEnd cannot happen before TouchUpdate"); |
|
157 |
seenTouchUpdate = seenTouchBegin && !seenTouchEnd; |
|
158 |
touchUpdatePoints = static_cast<QTouchEvent *>(event)->touchPoints(); |
|
159 |
event->setAccepted(acceptTouchUpdate); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
if (deleteInTouchUpdate) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
delete this; |
0 | 162 |
break; |
163 |
case QEvent::TouchEnd: |
|
164 |
if (!seenTouchBegin) qWarning("TouchEnd: have not seen TouchBegin"); |
|
165 |
if (seenTouchEnd) qWarning("TouchEnd: already seen a TouchEnd"); |
|
166 |
seenTouchEnd = seenTouchBegin && !seenTouchEnd; |
|
167 |
touchEndPoints = static_cast<QTouchEvent *>(event)->touchPoints(); |
|
168 |
event->setAccepted(acceptTouchEnd); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
if (deleteInTouchEnd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
delete this; |
0 | 171 |
break; |
172 |
default: |
|
173 |
return QGraphicsItem::sceneEvent(event); |
|
174 |
} |
|
175 |
return true; |
|
176 |
} |
|
177 |
}; |
|
178 |
||
179 |
class tst_QTouchEvent : public QObject |
|
180 |
{ |
|
181 |
Q_OBJECT |
|
182 |
public: |
|
183 |
tst_QTouchEvent() { } |
|
184 |
~tst_QTouchEvent() { } |
|
185 |
||
186 |
private slots: |
|
187 |
void touchDisabledByDefault(); |
|
188 |
void touchEventAcceptedByDefault(); |
|
189 |
void touchBeginPropagatesWhenIgnored(); |
|
190 |
void touchUpdateAndEndNeverPropagate(); |
|
191 |
void basicRawEventTranslation(); |
|
192 |
void multiPointRawEventTranslationOnTouchScreen(); |
|
193 |
void multiPointRawEventTranslationOnTouchPad(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
void deleteInEventHandler(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
void deleteInRawEventTranslation(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
196 |
void crashInQGraphicsSceneAfterNotHandlingTouchBegin(); |
0 | 197 |
}; |
198 |
||
199 |
void tst_QTouchEvent::touchDisabledByDefault() |
|
200 |
{ |
|
201 |
// QWidget |
|
202 |
{ |
|
203 |
// the widget attribute is not enabled by default |
|
204 |
QWidget widget; |
|
205 |
QVERIFY(!widget.testAttribute(Qt::WA_AcceptTouchEvents)); |
|
206 |
||
207 |
// events should not be accepted since they are not enabled |
|
208 |
QList<QTouchEvent::TouchPoint> touchPoints; |
|
209 |
touchPoints.append(QTouchEvent::TouchPoint(0)); |
|
210 |
QTouchEvent touchEvent(QEvent::TouchBegin, |
|
211 |
QTouchEvent::TouchScreen, |
|
212 |
Qt::NoModifier, |
|
213 |
Qt::TouchPointPressed, |
|
214 |
touchPoints); |
|
215 |
bool res = QApplication::sendEvent(&widget, &touchEvent); |
|
216 |
QVERIFY(!res); |
|
217 |
QVERIFY(!touchEvent.isAccepted()); |
|
218 |
} |
|
219 |
||
220 |
// QGraphicsView |
|
221 |
{ |
|
222 |
QGraphicsScene scene; |
|
223 |
tst_QTouchEventGraphicsItem item; |
|
224 |
QGraphicsView view(&scene); |
|
225 |
scene.addItem(&item); |
|
226 |
item.setPos(100, 100); |
|
227 |
view.resize(200, 200); |
|
228 |
view.fitInView(scene.sceneRect()); |
|
229 |
||
230 |
// touch events are not accepted by default |
|
231 |
QVERIFY(!item.acceptTouchEvents()); |
|
232 |
||
233 |
// compose an event to the scene that is over the item |
|
234 |
QTouchEvent::TouchPoint touchPoint(0); |
|
235 |
touchPoint.setState(Qt::TouchPointPressed); |
|
236 |
touchPoint.setPos(view.mapFromScene(item.mapToScene(item.boundingRect().center()))); |
|
237 |
touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); |
|
238 |
touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); |
|
239 |
QTouchEvent touchEvent(QEvent::TouchBegin, |
|
240 |
QTouchEvent::TouchScreen, |
|
241 |
Qt::NoModifier, |
|
242 |
Qt::TouchPointPressed, |
|
243 |
(QList<QTouchEvent::TouchPoint>() << touchPoint)); |
|
244 |
bool res = QApplication::sendEvent(view.viewport(), &touchEvent); |
|
245 |
QVERIFY(!res); |
|
246 |
QVERIFY(!touchEvent.isAccepted()); |
|
247 |
QVERIFY(!item.seenTouchBegin); |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
void tst_QTouchEvent::touchEventAcceptedByDefault() |
|
252 |
{ |
|
253 |
// QWidget |
|
254 |
{ |
|
255 |
// enabling touch events should automatically accept touch events |
|
256 |
QWidget widget; |
|
257 |
widget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
258 |
||
259 |
// QWidget handles touch event by converting them into a mouse event, so the event is both |
|
260 |
// accepted and handled (res == true) |
|
261 |
QList<QTouchEvent::TouchPoint> touchPoints; |
|
262 |
touchPoints.append(QTouchEvent::TouchPoint(0)); |
|
263 |
QTouchEvent touchEvent(QEvent::TouchBegin, |
|
264 |
QTouchEvent::TouchScreen, |
|
265 |
Qt::NoModifier, |
|
266 |
Qt::TouchPointPressed, |
|
267 |
touchPoints); |
|
268 |
bool res = QApplication::sendEvent(&widget, &touchEvent); |
|
269 |
QVERIFY(res); |
|
270 |
QVERIFY(touchEvent.isAccepted()); |
|
271 |
||
272 |
// tst_QTouchEventWidget does handle, sending succeeds |
|
273 |
tst_QTouchEventWidget touchWidget; |
|
274 |
touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
275 |
touchEvent.ignore(); |
|
276 |
res = QApplication::sendEvent(&touchWidget, &touchEvent); |
|
277 |
QVERIFY(res); |
|
278 |
QVERIFY(touchEvent.isAccepted()); |
|
279 |
} |
|
280 |
||
281 |
// QGraphicsView |
|
282 |
{ |
|
283 |
QGraphicsScene scene; |
|
284 |
tst_QTouchEventGraphicsItem item; |
|
285 |
QGraphicsView view(&scene); |
|
286 |
scene.addItem(&item); |
|
287 |
item.setPos(100, 100); |
|
288 |
view.resize(200, 200); |
|
289 |
view.fitInView(scene.sceneRect()); |
|
290 |
||
291 |
// enabling touch events on the item also enables events on the viewport |
|
292 |
item.setAcceptTouchEvents(true); |
|
293 |
QVERIFY(view.viewport()->testAttribute(Qt::WA_AcceptTouchEvents)); |
|
294 |
||
295 |
// compose an event to the scene that is over the item |
|
296 |
QTouchEvent::TouchPoint touchPoint(0); |
|
297 |
touchPoint.setState(Qt::TouchPointPressed); |
|
298 |
touchPoint.setPos(view.mapFromScene(item.mapToScene(item.boundingRect().center()))); |
|
299 |
touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); |
|
300 |
touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); |
|
301 |
QTouchEvent touchEvent(QEvent::TouchBegin, |
|
302 |
QTouchEvent::TouchScreen, |
|
303 |
Qt::NoModifier, |
|
304 |
Qt::TouchPointPressed, |
|
305 |
(QList<QTouchEvent::TouchPoint>() << touchPoint)); |
|
306 |
bool res = QApplication::sendEvent(view.viewport(), &touchEvent); |
|
307 |
QVERIFY(res); |
|
308 |
QVERIFY(touchEvent.isAccepted()); |
|
309 |
QVERIFY(item.seenTouchBegin); |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
void tst_QTouchEvent::touchBeginPropagatesWhenIgnored() |
|
314 |
{ |
|
315 |
// QWidget |
|
316 |
{ |
|
317 |
tst_QTouchEventWidget window, child, grandchild; |
|
318 |
child.setParent(&window); |
|
319 |
grandchild.setParent(&child); |
|
320 |
||
321 |
// all widgets accept touch events, grandchild ignores, so child sees the event, but not window |
|
322 |
window.setAttribute(Qt::WA_AcceptTouchEvents); |
|
323 |
child.setAttribute(Qt::WA_AcceptTouchEvents); |
|
324 |
grandchild.setAttribute(Qt::WA_AcceptTouchEvents); |
|
325 |
grandchild.acceptTouchBegin = false; |
|
326 |
||
327 |
QList<QTouchEvent::TouchPoint> touchPoints; |
|
328 |
touchPoints.append(QTouchEvent::TouchPoint(0)); |
|
329 |
QTouchEvent touchEvent(QEvent::TouchBegin, |
|
330 |
QTouchEvent::TouchScreen, |
|
331 |
Qt::NoModifier, |
|
332 |
Qt::TouchPointPressed, |
|
333 |
touchPoints); |
|
334 |
bool res = QApplication::sendEvent(&grandchild, &touchEvent); |
|
335 |
QVERIFY(res); |
|
336 |
QVERIFY(touchEvent.isAccepted()); |
|
337 |
QVERIFY(grandchild.seenTouchBegin); |
|
338 |
QVERIFY(child.seenTouchBegin); |
|
339 |
QVERIFY(!window.seenTouchBegin); |
|
340 |
||
341 |
// disable touch on grandchild. even though it doesn't accept it, child should still get the |
|
342 |
// TouchBegin |
|
343 |
grandchild.reset(); |
|
344 |
child.reset(); |
|
345 |
window.reset(); |
|
346 |
grandchild.setAttribute(Qt::WA_AcceptTouchEvents, false); |
|
347 |
||
348 |
touchEvent.ignore(); |
|
349 |
res = QApplication::sendEvent(&grandchild, &touchEvent); |
|
350 |
QVERIFY(res); |
|
351 |
QVERIFY(touchEvent.isAccepted()); |
|
352 |
QVERIFY(!grandchild.seenTouchBegin); |
|
353 |
QVERIFY(child.seenTouchBegin); |
|
354 |
QVERIFY(!window.seenTouchBegin); |
|
355 |
} |
|
356 |
||
357 |
// QGraphicsView |
|
358 |
{ |
|
359 |
QGraphicsScene scene; |
|
360 |
tst_QTouchEventGraphicsItem root, child, grandchild; |
|
361 |
QGraphicsView view(&scene); |
|
362 |
scene.addItem(&root); |
|
363 |
root.setPos(100, 100); |
|
364 |
child.setParentItem(&root); |
|
365 |
grandchild.setParentItem(&child); |
|
366 |
view.resize(200, 200); |
|
367 |
view.fitInView(scene.sceneRect()); |
|
368 |
||
369 |
// all items accept touch events, grandchild ignores, so child sees the event, but not root |
|
370 |
root.setAcceptTouchEvents(true); |
|
371 |
child.setAcceptTouchEvents(true); |
|
372 |
grandchild.setAcceptTouchEvents(true); |
|
373 |
grandchild.acceptTouchBegin = false; |
|
374 |
||
375 |
// compose an event to the scene that is over the grandchild |
|
376 |
QTouchEvent::TouchPoint touchPoint(0); |
|
377 |
touchPoint.setState(Qt::TouchPointPressed); |
|
378 |
touchPoint.setPos(view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center()))); |
|
379 |
touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); |
|
380 |
touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); |
|
381 |
QTouchEvent touchEvent(QEvent::TouchBegin, |
|
382 |
QTouchEvent::TouchScreen, |
|
383 |
Qt::NoModifier, |
|
384 |
Qt::TouchPointPressed, |
|
385 |
(QList<QTouchEvent::TouchPoint>() << touchPoint)); |
|
386 |
bool res = QApplication::sendEvent(view.viewport(), &touchEvent); |
|
387 |
QVERIFY(res); |
|
388 |
QVERIFY(touchEvent.isAccepted()); |
|
389 |
QVERIFY(grandchild.seenTouchBegin); |
|
390 |
QVERIFY(child.seenTouchBegin); |
|
391 |
QVERIFY(!root.seenTouchBegin); |
|
392 |
} |
|
393 |
||
394 |
// QGraphicsView |
|
395 |
{ |
|
396 |
QGraphicsScene scene; |
|
397 |
tst_QTouchEventGraphicsItem root, child, grandchild; |
|
398 |
QGraphicsView view(&scene); |
|
399 |
scene.addItem(&root); |
|
400 |
root.setPos(100, 100); |
|
401 |
child.setParentItem(&root); |
|
402 |
grandchild.setParentItem(&child); |
|
403 |
view.resize(200, 200); |
|
404 |
view.fitInView(scene.sceneRect()); |
|
405 |
||
406 |
// leave touch disabled on grandchild. even though it doesn't accept it, child should |
|
407 |
// still get the TouchBegin |
|
408 |
root.setAcceptTouchEvents(true); |
|
409 |
child.setAcceptTouchEvents(true); |
|
410 |
||
411 |
// compose an event to the scene that is over the grandchild |
|
412 |
QTouchEvent::TouchPoint touchPoint(0); |
|
413 |
touchPoint.setState(Qt::TouchPointPressed); |
|
414 |
touchPoint.setPos(view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center()))); |
|
415 |
touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); |
|
416 |
touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); |
|
417 |
QTouchEvent touchEvent(QEvent::TouchBegin, |
|
418 |
QTouchEvent::TouchScreen, |
|
419 |
Qt::NoModifier, |
|
420 |
Qt::TouchPointPressed, |
|
421 |
(QList<QTouchEvent::TouchPoint>() << touchPoint)); |
|
422 |
bool res = QApplication::sendEvent(view.viewport(), &touchEvent); |
|
423 |
QVERIFY(res); |
|
424 |
QVERIFY(touchEvent.isAccepted()); |
|
425 |
QVERIFY(!grandchild.seenTouchBegin); |
|
426 |
QVERIFY(child.seenTouchBegin); |
|
427 |
QVERIFY(!root.seenTouchBegin); |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
void tst_QTouchEvent::touchUpdateAndEndNeverPropagate() |
|
432 |
{ |
|
433 |
// QWidget |
|
434 |
{ |
|
435 |
tst_QTouchEventWidget window, child; |
|
436 |
child.setParent(&window); |
|
437 |
||
438 |
window.setAttribute(Qt::WA_AcceptTouchEvents); |
|
439 |
child.setAttribute(Qt::WA_AcceptTouchEvents); |
|
440 |
child.acceptTouchUpdate = false; |
|
441 |
child.acceptTouchEnd = false; |
|
442 |
||
443 |
QList<QTouchEvent::TouchPoint> touchPoints; |
|
444 |
touchPoints.append(QTouchEvent::TouchPoint(0)); |
|
445 |
QTouchEvent touchBeginEvent(QEvent::TouchBegin, |
|
446 |
QTouchEvent::TouchScreen, |
|
447 |
Qt::NoModifier, |
|
448 |
Qt::TouchPointPressed, |
|
449 |
touchPoints); |
|
450 |
bool res = QApplication::sendEvent(&child, &touchBeginEvent); |
|
451 |
QVERIFY(res); |
|
452 |
QVERIFY(touchBeginEvent.isAccepted()); |
|
453 |
QVERIFY(child.seenTouchBegin); |
|
454 |
QVERIFY(!window.seenTouchBegin); |
|
455 |
||
456 |
// send the touch update to the child, but ignore it, it doesn't propagate |
|
457 |
QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, |
|
458 |
QTouchEvent::TouchScreen, |
|
459 |
Qt::NoModifier, |
|
460 |
Qt::TouchPointMoved, |
|
461 |
touchPoints); |
|
462 |
res = QApplication::sendEvent(&child, &touchUpdateEvent); |
|
463 |
QVERIFY(res); |
|
464 |
QVERIFY(!touchUpdateEvent.isAccepted()); |
|
465 |
QVERIFY(child.seenTouchUpdate); |
|
466 |
QVERIFY(!window.seenTouchUpdate); |
|
467 |
||
468 |
// send the touch end, same thing should happen as with touch update |
|
469 |
QTouchEvent touchEndEvent(QEvent::TouchEnd, |
|
470 |
QTouchEvent::TouchScreen, |
|
471 |
Qt::NoModifier, |
|
472 |
Qt::TouchPointReleased, |
|
473 |
touchPoints); |
|
474 |
res = QApplication::sendEvent(&child, &touchEndEvent); |
|
475 |
QVERIFY(res); |
|
476 |
QVERIFY(!touchEndEvent.isAccepted()); |
|
477 |
QVERIFY(child.seenTouchEnd); |
|
478 |
QVERIFY(!window.seenTouchEnd); |
|
479 |
} |
|
480 |
||
481 |
// QGraphicsView |
|
482 |
{ |
|
483 |
QGraphicsScene scene; |
|
484 |
tst_QTouchEventGraphicsItem root, child, grandchild; |
|
485 |
QGraphicsView view(&scene); |
|
486 |
scene.addItem(&root); |
|
487 |
root.setPos(100, 100); |
|
488 |
child.setParentItem(&root); |
|
489 |
grandchild.setParentItem(&child); |
|
490 |
view.resize(200, 200); |
|
491 |
view.fitInView(scene.sceneRect()); |
|
492 |
||
493 |
root.setAcceptTouchEvents(true); |
|
494 |
child.setAcceptTouchEvents(true); |
|
495 |
child.acceptTouchUpdate = false; |
|
496 |
child.acceptTouchEnd = false; |
|
497 |
||
498 |
// compose an event to the scene that is over the child |
|
499 |
QTouchEvent::TouchPoint touchPoint(0); |
|
500 |
touchPoint.setState(Qt::TouchPointPressed); |
|
501 |
touchPoint.setPos(view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center()))); |
|
502 |
touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); |
|
503 |
touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); |
|
504 |
QTouchEvent touchBeginEvent(QEvent::TouchBegin, |
|
505 |
QTouchEvent::TouchScreen, |
|
506 |
Qt::NoModifier, |
|
507 |
Qt::TouchPointPressed, |
|
508 |
(QList<QTouchEvent::TouchPoint>() << touchPoint)); |
|
509 |
bool res = QApplication::sendEvent(view.viewport(), &touchBeginEvent); |
|
510 |
QVERIFY(res); |
|
511 |
QVERIFY(touchBeginEvent.isAccepted()); |
|
512 |
QVERIFY(child.seenTouchBegin); |
|
513 |
QVERIFY(!root.seenTouchBegin); |
|
514 |
||
515 |
// send the touch update to the child, but ignore it, it doesn't propagate |
|
516 |
touchPoint.setState(Qt::TouchPointMoved); |
|
517 |
QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, |
|
518 |
QTouchEvent::TouchScreen, |
|
519 |
Qt::NoModifier, |
|
520 |
Qt::TouchPointMoved, |
|
521 |
(QList<QTouchEvent::TouchPoint>() << touchPoint)); |
|
522 |
res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent); |
|
523 |
QVERIFY(res); |
|
524 |
// the scene accepts the event, since it found an item to send the event to |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
525 |
QVERIFY(!touchUpdateEvent.isAccepted()); |
0 | 526 |
QVERIFY(child.seenTouchUpdate); |
527 |
QVERIFY(!root.seenTouchUpdate); |
|
528 |
||
529 |
// send the touch end, same thing should happen as with touch update |
|
530 |
touchPoint.setState(Qt::TouchPointReleased); |
|
531 |
QTouchEvent touchEndEvent(QEvent::TouchEnd, |
|
532 |
QTouchEvent::TouchScreen, |
|
533 |
Qt::NoModifier, |
|
534 |
Qt::TouchPointReleased, |
|
535 |
(QList<QTouchEvent::TouchPoint>() << touchPoint)); |
|
536 |
res = QApplication::sendEvent(view.viewport(), &touchEndEvent); |
|
537 |
QVERIFY(res); |
|
538 |
// the scene accepts the event, since it found an item to send the event to |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
QVERIFY(!touchEndEvent.isAccepted()); |
0 | 540 |
QVERIFY(child.seenTouchEnd); |
541 |
QVERIFY(!root.seenTouchEnd); |
|
542 |
} |
|
543 |
} |
|
544 |
||
545 |
QPointF normalized(const QPointF &pos, const QRectF &rect) |
|
546 |
{ |
|
547 |
return QPointF(pos.x() / rect.width(), pos.y() / rect.height()); |
|
548 |
} |
|
549 |
||
550 |
void tst_QTouchEvent::basicRawEventTranslation() |
|
551 |
{ |
|
552 |
tst_QTouchEventWidget touchWidget; |
|
553 |
touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
554 |
touchWidget.setGeometry(100, 100, 400, 300); |
|
555 |
||
556 |
QPointF pos = touchWidget.rect().center(); |
|
557 |
QPointF screenPos = touchWidget.mapToGlobal(pos.toPoint()); |
|
558 |
QPointF delta(10, 10); |
|
559 |
QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget); |
|
560 |
||
561 |
QTouchEvent::TouchPoint rawTouchPoint; |
|
562 |
rawTouchPoint.setId(0); |
|
563 |
||
564 |
// this should be translated to a TouchBegin |
|
565 |
rawTouchPoint.setState(Qt::TouchPointPressed); |
|
566 |
rawTouchPoint.setScreenPos(screenPos); |
|
567 |
rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); |
|
568 |
qt_translateRawTouchEvent(&touchWidget, |
|
569 |
QTouchEvent::TouchScreen, |
|
570 |
QList<QTouchEvent::TouchPoint>() << rawTouchPoint); |
|
571 |
QVERIFY(touchWidget.seenTouchBegin); |
|
572 |
QVERIFY(!touchWidget.seenTouchUpdate); |
|
573 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
574 |
QCOMPARE(touchWidget.touchBeginPoints.count(), 1); |
|
575 |
QTouchEvent::TouchPoint touchBeginPoint = touchWidget.touchBeginPoints.first(); |
|
576 |
QCOMPARE(touchBeginPoint.id(), rawTouchPoint.id()); |
|
577 |
QCOMPARE(touchBeginPoint.state(), rawTouchPoint.state()); |
|
578 |
QCOMPARE(touchBeginPoint.pos(), pos); |
|
579 |
QCOMPARE(touchBeginPoint.startPos(), pos); |
|
580 |
QCOMPARE(touchBeginPoint.lastPos(), pos); |
|
581 |
QCOMPARE(touchBeginPoint.scenePos(), rawTouchPoint.screenPos()); |
|
582 |
QCOMPARE(touchBeginPoint.startScenePos(), rawTouchPoint.screenPos()); |
|
583 |
QCOMPARE(touchBeginPoint.lastScenePos(), rawTouchPoint.screenPos()); |
|
584 |
QCOMPARE(touchBeginPoint.screenPos(), rawTouchPoint.screenPos()); |
|
585 |
QCOMPARE(touchBeginPoint.startScreenPos(), rawTouchPoint.screenPos()); |
|
586 |
QCOMPARE(touchBeginPoint.lastScreenPos(), rawTouchPoint.screenPos()); |
|
587 |
QCOMPARE(touchBeginPoint.normalizedPos(), rawTouchPoint.normalizedPos()); |
|
588 |
QCOMPARE(touchBeginPoint.startNormalizedPos(), touchBeginPoint.normalizedPos()); |
|
589 |
QCOMPARE(touchBeginPoint.lastNormalizedPos(), touchBeginPoint.normalizedPos()); |
|
590 |
QCOMPARE(touchBeginPoint.rect(), QRectF(pos, QSizeF(0, 0))); |
|
591 |
QCOMPARE(touchBeginPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0))); |
|
592 |
QCOMPARE(touchBeginPoint.sceneRect(), touchBeginPoint.screenRect()); |
|
593 |
QCOMPARE(touchBeginPoint.pressure(), qreal(1.)); |
|
594 |
||
595 |
// moving the point should translate to TouchUpdate |
|
596 |
rawTouchPoint.setState(Qt::TouchPointMoved); |
|
597 |
rawTouchPoint.setScreenPos(screenPos + delta); |
|
598 |
rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); |
|
599 |
qt_translateRawTouchEvent(&touchWidget, |
|
600 |
QTouchEvent::TouchScreen, |
|
601 |
QList<QTouchEvent::TouchPoint>() << rawTouchPoint); |
|
602 |
QVERIFY(touchWidget.seenTouchBegin); |
|
603 |
QVERIFY(touchWidget.seenTouchUpdate); |
|
604 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
605 |
QCOMPARE(touchWidget.touchUpdatePoints.count(), 1); |
|
606 |
QTouchEvent::TouchPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first(); |
|
607 |
QCOMPARE(touchUpdatePoint.id(), rawTouchPoint.id()); |
|
608 |
QCOMPARE(touchUpdatePoint.state(), rawTouchPoint.state()); |
|
609 |
QCOMPARE(touchUpdatePoint.pos(), pos + delta); |
|
610 |
QCOMPARE(touchUpdatePoint.startPos(), pos); |
|
611 |
QCOMPARE(touchUpdatePoint.lastPos(), pos); |
|
612 |
QCOMPARE(touchUpdatePoint.scenePos(), rawTouchPoint.screenPos()); |
|
613 |
QCOMPARE(touchUpdatePoint.startScenePos(), screenPos); |
|
614 |
QCOMPARE(touchUpdatePoint.lastScenePos(), screenPos); |
|
615 |
QCOMPARE(touchUpdatePoint.screenPos(), rawTouchPoint.screenPos()); |
|
616 |
QCOMPARE(touchUpdatePoint.startScreenPos(), screenPos); |
|
617 |
QCOMPARE(touchUpdatePoint.lastScreenPos(), screenPos); |
|
618 |
QCOMPARE(touchUpdatePoint.normalizedPos(), rawTouchPoint.normalizedPos()); |
|
619 |
QCOMPARE(touchUpdatePoint.startNormalizedPos(), touchBeginPoint.normalizedPos()); |
|
620 |
QCOMPARE(touchUpdatePoint.lastNormalizedPos(), touchBeginPoint.normalizedPos()); |
|
621 |
QCOMPARE(touchUpdatePoint.rect(), QRectF(pos + delta, QSizeF(0, 0))); |
|
622 |
QCOMPARE(touchUpdatePoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0))); |
|
623 |
QCOMPARE(touchUpdatePoint.sceneRect(), touchUpdatePoint.screenRect()); |
|
624 |
QCOMPARE(touchUpdatePoint.pressure(), qreal(1.)); |
|
625 |
||
626 |
// releasing the point translates to TouchEnd |
|
627 |
rawTouchPoint.setState(Qt::TouchPointReleased); |
|
628 |
rawTouchPoint.setScreenPos(screenPos + delta + delta); |
|
629 |
rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); |
|
630 |
qt_translateRawTouchEvent(&touchWidget, |
|
631 |
QTouchEvent::TouchScreen, |
|
632 |
QList<QTouchEvent::TouchPoint>() << rawTouchPoint); |
|
633 |
QVERIFY(touchWidget.seenTouchBegin); |
|
634 |
QVERIFY(touchWidget.seenTouchUpdate); |
|
635 |
QVERIFY(touchWidget.seenTouchEnd); |
|
636 |
QCOMPARE(touchWidget.touchEndPoints.count(), 1); |
|
637 |
QTouchEvent::TouchPoint touchEndPoint = touchWidget.touchEndPoints.first(); |
|
638 |
QCOMPARE(touchEndPoint.id(), rawTouchPoint.id()); |
|
639 |
QCOMPARE(touchEndPoint.state(), rawTouchPoint.state()); |
|
640 |
QCOMPARE(touchEndPoint.pos(), pos + delta + delta); |
|
641 |
QCOMPARE(touchEndPoint.startPos(), pos); |
|
642 |
QCOMPARE(touchEndPoint.lastPos(), pos + delta); |
|
643 |
QCOMPARE(touchEndPoint.scenePos(), rawTouchPoint.screenPos()); |
|
644 |
QCOMPARE(touchEndPoint.startScenePos(), screenPos); |
|
645 |
QCOMPARE(touchEndPoint.lastScenePos(), screenPos + delta); |
|
646 |
QCOMPARE(touchEndPoint.screenPos(), rawTouchPoint.screenPos()); |
|
647 |
QCOMPARE(touchEndPoint.startScreenPos(), screenPos); |
|
648 |
QCOMPARE(touchEndPoint.lastScreenPos(), screenPos + delta); |
|
649 |
QCOMPARE(touchEndPoint.normalizedPos(), rawTouchPoint.normalizedPos()); |
|
650 |
QCOMPARE(touchEndPoint.startNormalizedPos(), touchBeginPoint.normalizedPos()); |
|
651 |
QCOMPARE(touchEndPoint.lastNormalizedPos(), touchUpdatePoint.normalizedPos()); |
|
652 |
QCOMPARE(touchEndPoint.rect(), QRectF(pos + delta + delta, QSizeF(0, 0))); |
|
653 |
QCOMPARE(touchEndPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0))); |
|
654 |
QCOMPARE(touchEndPoint.sceneRect(), touchEndPoint.screenRect()); |
|
655 |
QCOMPARE(touchEndPoint.pressure(), qreal(0.)); |
|
656 |
} |
|
657 |
||
658 |
void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() |
|
659 |
{ |
|
660 |
tst_QTouchEventWidget touchWidget; |
|
661 |
touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
662 |
touchWidget.setGeometry(100, 100, 400, 300); |
|
663 |
||
664 |
tst_QTouchEventWidget leftWidget; |
|
665 |
leftWidget.setParent(&touchWidget); |
|
666 |
leftWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
667 |
leftWidget.setGeometry(0, 100, 100, 100); |
|
668 |
leftWidget.show(); |
|
669 |
||
670 |
tst_QTouchEventWidget rightWidget; |
|
671 |
rightWidget.setParent(&touchWidget); |
|
672 |
rightWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
673 |
rightWidget.setGeometry(300, 100, 100, 100); |
|
674 |
rightWidget.show(); |
|
675 |
||
676 |
QPointF leftPos = leftWidget.rect().center(); |
|
677 |
QPointF rightPos = rightWidget.rect().center(); |
|
678 |
QPointF centerPos = touchWidget.rect().center(); |
|
679 |
QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint()); |
|
680 |
QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint()); |
|
681 |
QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint()); |
|
682 |
QPointF delta(10, 10); |
|
683 |
QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget); |
|
684 |
||
685 |
QList<QTouchEvent::TouchPoint> rawTouchPoints; |
|
686 |
rawTouchPoints.append(QTouchEvent::TouchPoint(0)); |
|
687 |
rawTouchPoints.append(QTouchEvent::TouchPoint(1)); |
|
688 |
||
689 |
// generate TouchBegins on both leftWidget and rightWidget |
|
690 |
rawTouchPoints[0].setState(Qt::TouchPointPressed); |
|
691 |
rawTouchPoints[0].setScreenPos(leftScreenPos); |
|
692 |
rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry)); |
|
693 |
rawTouchPoints[1].setState(Qt::TouchPointPressed); |
|
694 |
rawTouchPoints[1].setScreenPos(rightScreenPos); |
|
695 |
rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); |
|
696 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); |
|
697 |
QVERIFY(!touchWidget.seenTouchBegin); |
|
698 |
QVERIFY(!touchWidget.seenTouchUpdate); |
|
699 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
700 |
QVERIFY(leftWidget.seenTouchBegin); |
|
701 |
QVERIFY(!leftWidget.seenTouchUpdate); |
|
702 |
QVERIFY(!leftWidget.seenTouchEnd); |
|
703 |
QVERIFY(rightWidget.seenTouchBegin); |
|
704 |
QVERIFY(!rightWidget.seenTouchUpdate); |
|
705 |
QVERIFY(!rightWidget.seenTouchEnd); |
|
706 |
QCOMPARE(leftWidget.touchBeginPoints.count(), 1); |
|
707 |
QCOMPARE(rightWidget.touchBeginPoints.count(), 1); |
|
708 |
{ |
|
709 |
QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchBeginPoints.first(); |
|
710 |
QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id()); |
|
711 |
QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); |
|
712 |
QCOMPARE(leftTouchPoint.pos(), leftPos); |
|
713 |
QCOMPARE(leftTouchPoint.startPos(), leftPos); |
|
714 |
QCOMPARE(leftTouchPoint.lastPos(), leftPos); |
|
715 |
QCOMPARE(leftTouchPoint.scenePos(), leftScreenPos); |
|
716 |
QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos); |
|
717 |
QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos); |
|
718 |
QCOMPARE(leftTouchPoint.screenPos(), leftScreenPos); |
|
719 |
QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos); |
|
720 |
QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos); |
|
721 |
QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
722 |
QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
723 |
QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
724 |
QCOMPARE(leftTouchPoint.rect(), QRectF(leftPos, QSizeF(0, 0))); |
|
725 |
QCOMPARE(leftTouchPoint.sceneRect(), QRectF(leftScreenPos, QSizeF(0, 0))); |
|
726 |
QCOMPARE(leftTouchPoint.screenRect(), QRectF(leftScreenPos, QSizeF(0, 0))); |
|
727 |
QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); |
|
728 |
||
729 |
QTouchEvent::TouchPoint rightTouchPoint = rightWidget.touchBeginPoints.first(); |
|
730 |
QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id()); |
|
731 |
QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); |
|
732 |
QCOMPARE(rightTouchPoint.pos(), rightPos); |
|
733 |
QCOMPARE(rightTouchPoint.startPos(), rightPos); |
|
734 |
QCOMPARE(rightTouchPoint.lastPos(), rightPos); |
|
735 |
QCOMPARE(rightTouchPoint.scenePos(), rightScreenPos); |
|
736 |
QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos); |
|
737 |
QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos); |
|
738 |
QCOMPARE(rightTouchPoint.screenPos(), rightScreenPos); |
|
739 |
QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos); |
|
740 |
QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos); |
|
741 |
QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
742 |
QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
743 |
QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
744 |
QCOMPARE(rightTouchPoint.rect(), QRectF(rightPos, QSizeF(0, 0))); |
|
745 |
QCOMPARE(rightTouchPoint.sceneRect(), QRectF(rightScreenPos, QSizeF(0, 0))); |
|
746 |
QCOMPARE(rightTouchPoint.screenRect(), QRectF(rightScreenPos, QSizeF(0, 0))); |
|
747 |
QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); |
|
748 |
} |
|
749 |
||
750 |
// generate TouchUpdates on both leftWidget and rightWidget |
|
751 |
rawTouchPoints[0].setState(Qt::TouchPointMoved); |
|
752 |
rawTouchPoints[0].setScreenPos(centerScreenPos); |
|
753 |
rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry)); |
|
754 |
rawTouchPoints[1].setState(Qt::TouchPointMoved); |
|
755 |
rawTouchPoints[1].setScreenPos(centerScreenPos); |
|
756 |
rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); |
|
757 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); |
|
758 |
QVERIFY(!touchWidget.seenTouchBegin); |
|
759 |
QVERIFY(!touchWidget.seenTouchUpdate); |
|
760 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
761 |
QVERIFY(leftWidget.seenTouchBegin); |
|
762 |
QVERIFY(leftWidget.seenTouchUpdate); |
|
763 |
QVERIFY(!leftWidget.seenTouchEnd); |
|
764 |
QVERIFY(rightWidget.seenTouchBegin); |
|
765 |
QVERIFY(rightWidget.seenTouchUpdate); |
|
766 |
QVERIFY(!rightWidget.seenTouchEnd); |
|
767 |
QCOMPARE(leftWidget.touchUpdatePoints.count(), 1); |
|
768 |
QCOMPARE(rightWidget.touchUpdatePoints.count(), 1); |
|
769 |
{ |
|
770 |
QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchUpdatePoints.first(); |
|
771 |
QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id()); |
|
772 |
QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); |
|
773 |
QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); |
|
774 |
QCOMPARE(leftTouchPoint.startPos(), leftPos); |
|
775 |
QCOMPARE(leftTouchPoint.lastPos(), leftPos); |
|
776 |
QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos); |
|
777 |
QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos); |
|
778 |
QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos); |
|
779 |
QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos); |
|
780 |
QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos); |
|
781 |
QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos); |
|
782 |
QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
783 |
QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
784 |
QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
785 |
QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
786 |
QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
787 |
QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
788 |
QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); |
|
789 |
||
790 |
QTouchEvent::TouchPoint rightTouchPoint = rightWidget.touchUpdatePoints.first(); |
|
791 |
QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id()); |
|
792 |
QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); |
|
793 |
QCOMPARE(rightTouchPoint.pos(), QPointF(rightWidget.mapFromParent(centerPos.toPoint()))); |
|
794 |
QCOMPARE(rightTouchPoint.startPos(), rightPos); |
|
795 |
QCOMPARE(rightTouchPoint.lastPos(), rightPos); |
|
796 |
QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos); |
|
797 |
QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos); |
|
798 |
QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos); |
|
799 |
QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos); |
|
800 |
QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos); |
|
801 |
QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos); |
|
802 |
QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
803 |
QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
804 |
QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
805 |
QCOMPARE(rightTouchPoint.rect(), QRectF(rightWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
806 |
QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
807 |
QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
808 |
QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); |
|
809 |
} |
|
810 |
||
811 |
// generate TouchEnds on both leftWidget and rightWidget |
|
812 |
rawTouchPoints[0].setState(Qt::TouchPointReleased); |
|
813 |
rawTouchPoints[0].setScreenPos(centerScreenPos); |
|
814 |
rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry)); |
|
815 |
rawTouchPoints[1].setState(Qt::TouchPointReleased); |
|
816 |
rawTouchPoints[1].setScreenPos(centerScreenPos); |
|
817 |
rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); |
|
818 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); |
|
819 |
QVERIFY(!touchWidget.seenTouchBegin); |
|
820 |
QVERIFY(!touchWidget.seenTouchUpdate); |
|
821 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
822 |
QVERIFY(leftWidget.seenTouchBegin); |
|
823 |
QVERIFY(leftWidget.seenTouchUpdate); |
|
824 |
QVERIFY(leftWidget.seenTouchEnd); |
|
825 |
QVERIFY(rightWidget.seenTouchBegin); |
|
826 |
QVERIFY(rightWidget.seenTouchUpdate); |
|
827 |
QVERIFY(rightWidget.seenTouchEnd); |
|
828 |
QCOMPARE(leftWidget.touchEndPoints.count(), 1); |
|
829 |
QCOMPARE(rightWidget.touchEndPoints.count(), 1); |
|
830 |
{ |
|
831 |
QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchEndPoints.first(); |
|
832 |
QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id()); |
|
833 |
QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); |
|
834 |
QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); |
|
835 |
QCOMPARE(leftTouchPoint.startPos(), leftPos); |
|
836 |
QCOMPARE(leftTouchPoint.lastPos(), leftTouchPoint.pos()); |
|
837 |
QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos); |
|
838 |
QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos); |
|
839 |
QCOMPARE(leftTouchPoint.lastScenePos(), leftTouchPoint.scenePos()); |
|
840 |
QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos); |
|
841 |
QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos); |
|
842 |
QCOMPARE(leftTouchPoint.lastScreenPos(), leftTouchPoint.screenPos()); |
|
843 |
QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
844 |
QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
845 |
QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
846 |
QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
847 |
QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
848 |
QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
849 |
QCOMPARE(leftTouchPoint.pressure(), qreal(0.)); |
|
850 |
||
851 |
QTouchEvent::TouchPoint rightTouchPoint = rightWidget.touchEndPoints.first(); |
|
852 |
QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id()); |
|
853 |
QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); |
|
854 |
QCOMPARE(rightTouchPoint.pos(), QPointF(rightWidget.mapFromParent(centerPos.toPoint()))); |
|
855 |
QCOMPARE(rightTouchPoint.startPos(), rightPos); |
|
856 |
QCOMPARE(rightTouchPoint.lastPos(), rightTouchPoint.pos()); |
|
857 |
QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos); |
|
858 |
QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos); |
|
859 |
QCOMPARE(rightTouchPoint.lastScenePos(), rightTouchPoint.scenePos()); |
|
860 |
QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos); |
|
861 |
QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos); |
|
862 |
QCOMPARE(rightTouchPoint.lastScreenPos(), rightTouchPoint.screenPos()); |
|
863 |
QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
864 |
QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
865 |
QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
866 |
QCOMPARE(rightTouchPoint.rect(), QRectF(rightWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
867 |
QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
868 |
QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
869 |
QCOMPARE(rightTouchPoint.pressure(), qreal(0.)); |
|
870 |
} |
|
871 |
} |
|
872 |
||
873 |
void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() |
|
874 |
{ |
|
875 |
tst_QTouchEventWidget touchWidget; |
|
876 |
touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
877 |
touchWidget.setGeometry(100, 100, 400, 300); |
|
878 |
||
879 |
tst_QTouchEventWidget leftWidget; |
|
880 |
leftWidget.setParent(&touchWidget); |
|
881 |
leftWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
882 |
leftWidget.setGeometry(0, 100, 100, 100); |
|
883 |
leftWidget.show(); |
|
884 |
||
885 |
tst_QTouchEventWidget rightWidget; |
|
886 |
rightWidget.setParent(&touchWidget); |
|
887 |
rightWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
888 |
rightWidget.setGeometry(300, 100, 100, 100); |
|
889 |
rightWidget.show(); |
|
890 |
||
891 |
QPointF leftPos = leftWidget.rect().center(); |
|
892 |
QPointF rightPos = rightWidget.rect().center(); |
|
893 |
QPointF centerPos = touchWidget.rect().center(); |
|
894 |
QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint()); |
|
895 |
QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint()); |
|
896 |
QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint()); |
|
897 |
QPointF delta(10, 10); |
|
898 |
QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget); |
|
899 |
||
900 |
QList<QTouchEvent::TouchPoint> rawTouchPoints; |
|
901 |
rawTouchPoints.append(QTouchEvent::TouchPoint(0)); |
|
902 |
rawTouchPoints.append(QTouchEvent::TouchPoint(1)); |
|
903 |
||
904 |
// generate TouchBegin on leftWidget only |
|
905 |
rawTouchPoints[0].setState(Qt::TouchPointPressed); |
|
906 |
rawTouchPoints[0].setScreenPos(leftScreenPos); |
|
907 |
rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry)); |
|
908 |
rawTouchPoints[1].setState(Qt::TouchPointPressed); |
|
909 |
rawTouchPoints[1].setScreenPos(rightScreenPos); |
|
910 |
rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); |
|
911 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints); |
|
912 |
QVERIFY(!touchWidget.seenTouchBegin); |
|
913 |
QVERIFY(!touchWidget.seenTouchUpdate); |
|
914 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
915 |
QVERIFY(leftWidget.seenTouchBegin); |
|
916 |
QVERIFY(!leftWidget.seenTouchUpdate); |
|
917 |
QVERIFY(!leftWidget.seenTouchEnd); |
|
918 |
QVERIFY(!rightWidget.seenTouchBegin); |
|
919 |
QVERIFY(!rightWidget.seenTouchUpdate); |
|
920 |
QVERIFY(!rightWidget.seenTouchEnd); |
|
921 |
QCOMPARE(leftWidget.touchBeginPoints.count(), 2); |
|
922 |
QCOMPARE(rightWidget.touchBeginPoints.count(), 0); |
|
923 |
{ |
|
924 |
QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchBeginPoints.at(0); |
|
925 |
QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id()); |
|
926 |
QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); |
|
927 |
QCOMPARE(leftTouchPoint.pos(), leftPos); |
|
928 |
QCOMPARE(leftTouchPoint.startPos(), leftPos); |
|
929 |
QCOMPARE(leftTouchPoint.lastPos(), leftPos); |
|
930 |
QCOMPARE(leftTouchPoint.scenePos(), leftScreenPos); |
|
931 |
QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos); |
|
932 |
QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos); |
|
933 |
QCOMPARE(leftTouchPoint.screenPos(), leftScreenPos); |
|
934 |
QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos); |
|
935 |
QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos); |
|
936 |
QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
937 |
QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
938 |
QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
939 |
QCOMPARE(leftTouchPoint.rect(), QRectF(leftPos, QSizeF(0, 0))); |
|
940 |
QCOMPARE(leftTouchPoint.sceneRect(), QRectF(leftScreenPos, QSizeF(0, 0))); |
|
941 |
QCOMPARE(leftTouchPoint.screenRect(), QRectF(leftScreenPos, QSizeF(0, 0))); |
|
942 |
QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); |
|
943 |
||
944 |
QTouchEvent::TouchPoint rightTouchPoint = leftWidget.touchBeginPoints.at(1); |
|
945 |
QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id()); |
|
946 |
QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); |
|
947 |
QCOMPARE(rightTouchPoint.pos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()))); |
|
948 |
QCOMPARE(rightTouchPoint.startPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()))); |
|
949 |
QCOMPARE(rightTouchPoint.lastPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()))); |
|
950 |
QCOMPARE(rightTouchPoint.scenePos(), rightScreenPos); |
|
951 |
QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos); |
|
952 |
QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos); |
|
953 |
QCOMPARE(rightTouchPoint.screenPos(), rightScreenPos); |
|
954 |
QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos); |
|
955 |
QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos); |
|
956 |
QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
957 |
QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
958 |
QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
959 |
QCOMPARE(rightTouchPoint.rect(), QRectF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()), QSizeF(0, 0))); |
|
960 |
QCOMPARE(rightTouchPoint.sceneRect(), QRectF(rightScreenPos, QSizeF(0, 0))); |
|
961 |
QCOMPARE(rightTouchPoint.screenRect(), QRectF(rightScreenPos, QSizeF(0, 0))); |
|
962 |
QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); |
|
963 |
} |
|
964 |
||
965 |
// generate TouchUpdate on leftWidget |
|
966 |
rawTouchPoints[0].setState(Qt::TouchPointMoved); |
|
967 |
rawTouchPoints[0].setScreenPos(centerScreenPos); |
|
968 |
rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry)); |
|
969 |
rawTouchPoints[1].setState(Qt::TouchPointMoved); |
|
970 |
rawTouchPoints[1].setScreenPos(centerScreenPos); |
|
971 |
rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); |
|
972 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints); |
|
973 |
QVERIFY(!touchWidget.seenTouchBegin); |
|
974 |
QVERIFY(!touchWidget.seenTouchUpdate); |
|
975 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
976 |
QVERIFY(leftWidget.seenTouchBegin); |
|
977 |
QVERIFY(leftWidget.seenTouchUpdate); |
|
978 |
QVERIFY(!leftWidget.seenTouchEnd); |
|
979 |
QVERIFY(!rightWidget.seenTouchBegin); |
|
980 |
QVERIFY(!rightWidget.seenTouchUpdate); |
|
981 |
QVERIFY(!rightWidget.seenTouchEnd); |
|
982 |
QCOMPARE(leftWidget.touchUpdatePoints.count(), 2); |
|
983 |
QCOMPARE(rightWidget.touchUpdatePoints.count(), 0); |
|
984 |
{ |
|
985 |
QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchUpdatePoints.at(0); |
|
986 |
QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id()); |
|
987 |
QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); |
|
988 |
QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); |
|
989 |
QCOMPARE(leftTouchPoint.startPos(), leftPos); |
|
990 |
QCOMPARE(leftTouchPoint.lastPos(), leftPos); |
|
991 |
QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos); |
|
992 |
QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos); |
|
993 |
QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos); |
|
994 |
QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos); |
|
995 |
QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos); |
|
996 |
QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos); |
|
997 |
QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
998 |
QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
999 |
QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
1000 |
QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
1001 |
QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1002 |
QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1003 |
QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); |
|
1004 |
||
1005 |
QTouchEvent::TouchPoint rightTouchPoint = leftWidget.touchUpdatePoints.at(1); |
|
1006 |
QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id()); |
|
1007 |
QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); |
|
1008 |
QCOMPARE(rightTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); |
|
1009 |
QCOMPARE(rightTouchPoint.startPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()))); |
|
1010 |
QCOMPARE(rightTouchPoint.lastPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()))); |
|
1011 |
QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos); |
|
1012 |
QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos); |
|
1013 |
QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos); |
|
1014 |
QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos); |
|
1015 |
QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos); |
|
1016 |
QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos); |
|
1017 |
QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
1018 |
QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
1019 |
QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
1020 |
QCOMPARE(rightTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
1021 |
QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1022 |
QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1023 |
QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); |
|
1024 |
} |
|
1025 |
||
1026 |
// generate TouchEnd on leftWidget |
|
1027 |
rawTouchPoints[0].setState(Qt::TouchPointReleased); |
|
1028 |
rawTouchPoints[0].setScreenPos(centerScreenPos); |
|
1029 |
rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry)); |
|
1030 |
rawTouchPoints[1].setState(Qt::TouchPointReleased); |
|
1031 |
rawTouchPoints[1].setScreenPos(centerScreenPos); |
|
1032 |
rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); |
|
1033 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints); |
|
1034 |
QVERIFY(!touchWidget.seenTouchBegin); |
|
1035 |
QVERIFY(!touchWidget.seenTouchUpdate); |
|
1036 |
QVERIFY(!touchWidget.seenTouchEnd); |
|
1037 |
QVERIFY(leftWidget.seenTouchBegin); |
|
1038 |
QVERIFY(leftWidget.seenTouchUpdate); |
|
1039 |
QVERIFY(leftWidget.seenTouchEnd); |
|
1040 |
QVERIFY(!rightWidget.seenTouchBegin); |
|
1041 |
QVERIFY(!rightWidget.seenTouchUpdate); |
|
1042 |
QVERIFY(!rightWidget.seenTouchEnd); |
|
1043 |
QCOMPARE(leftWidget.touchEndPoints.count(), 2); |
|
1044 |
QCOMPARE(rightWidget.touchEndPoints.count(), 0); |
|
1045 |
{ |
|
1046 |
QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchEndPoints.at(0); |
|
1047 |
QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id()); |
|
1048 |
QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); |
|
1049 |
QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); |
|
1050 |
QCOMPARE(leftTouchPoint.startPos(), leftPos); |
|
1051 |
QCOMPARE(leftTouchPoint.lastPos(), leftTouchPoint.pos()); |
|
1052 |
QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos); |
|
1053 |
QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos); |
|
1054 |
QCOMPARE(leftTouchPoint.lastScenePos(), leftTouchPoint.scenePos()); |
|
1055 |
QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos); |
|
1056 |
QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos); |
|
1057 |
QCOMPARE(leftTouchPoint.lastScreenPos(), leftTouchPoint.screenPos()); |
|
1058 |
QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
1059 |
QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
1060 |
QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos()); |
|
1061 |
QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
1062 |
QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1063 |
QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1064 |
QCOMPARE(leftTouchPoint.pressure(), qreal(0.)); |
|
1065 |
||
1066 |
QTouchEvent::TouchPoint rightTouchPoint = leftWidget.touchEndPoints.at(1); |
|
1067 |
QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id()); |
|
1068 |
QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); |
|
1069 |
QCOMPARE(rightTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); |
|
1070 |
QCOMPARE(rightTouchPoint.startPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()))); |
|
1071 |
QCOMPARE(rightTouchPoint.lastPos(), rightTouchPoint.pos()); |
|
1072 |
QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos); |
|
1073 |
QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos); |
|
1074 |
QCOMPARE(rightTouchPoint.lastScenePos(), rightTouchPoint.scenePos()); |
|
1075 |
QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos); |
|
1076 |
QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos); |
|
1077 |
QCOMPARE(rightTouchPoint.lastScreenPos(), rightTouchPoint.screenPos()); |
|
1078 |
QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
1079 |
QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
1080 |
QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos()); |
|
1081 |
QCOMPARE(rightTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0))); |
|
1082 |
QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1083 |
QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0))); |
|
1084 |
QCOMPARE(rightTouchPoint.pressure(), qreal(0.)); |
|
1085 |
} |
|
1086 |
} |
|
1087 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1088 |
void tst_QTouchEvent::deleteInEventHandler() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1089 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1090 |
// QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1091 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1092 |
QWidget window; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1093 |
tst_QTouchEventWidget *child1, *child2, *child3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1094 |
child1 = new tst_QTouchEventWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1095 |
child2 = new tst_QTouchEventWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1096 |
child3 = new tst_QTouchEventWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1097 |
child1->setParent(&window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1098 |
child2->setParent(&window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1099 |
child3->setParent(&window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1100 |
child1->setAttribute(Qt::WA_AcceptTouchEvents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1101 |
child2->setAttribute(Qt::WA_AcceptTouchEvents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1102 |
child3->setAttribute(Qt::WA_AcceptTouchEvents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1103 |
child1->deleteInTouchBegin = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1104 |
child2->deleteInTouchUpdate = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1105 |
child3->deleteInTouchEnd = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1106 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1107 |
QList<QTouchEvent::TouchPoint> touchPoints; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1108 |
touchPoints.append(QTouchEvent::TouchPoint(0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1109 |
QTouchEvent touchBeginEvent(QEvent::TouchBegin, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1110 |
QTouchEvent::TouchScreen, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1111 |
Qt::NoModifier, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1112 |
Qt::TouchPointPressed, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1113 |
touchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1114 |
QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1115 |
QTouchEvent::TouchScreen, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1116 |
Qt::NoModifier, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
Qt::TouchPointStationary, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1118 |
touchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1119 |
QTouchEvent touchEndEvent(QEvent::TouchEnd, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1120 |
QTouchEvent::TouchScreen, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1121 |
Qt::NoModifier, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1122 |
Qt::TouchPointReleased, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1123 |
touchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1124 |
QWeakPointer<QWidget> p; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1125 |
bool res; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1126 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1127 |
touchBeginEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1128 |
p = child1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1129 |
res = QApplication::sendEvent(child1, &touchBeginEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1130 |
// event is handled, but widget should be deleted |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1131 |
QVERIFY(res && touchBeginEvent.isAccepted() && p.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1132 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1133 |
touchBeginEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1134 |
p = child2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1135 |
res = QApplication::sendEvent(child2, &touchBeginEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1136 |
QVERIFY(res && touchBeginEvent.isAccepted() && !p.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1137 |
touchUpdateEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1138 |
res = QApplication::sendEvent(child2, &touchUpdateEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1139 |
QVERIFY(res && touchUpdateEvent.isAccepted() && p.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1140 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1141 |
touchBeginEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1142 |
p = child3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1143 |
res = QApplication::sendEvent(child3, &touchBeginEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1144 |
QVERIFY(res && touchBeginEvent.isAccepted() && !p.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1145 |
touchUpdateEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1146 |
res = QApplication::sendEvent(child3, &touchUpdateEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1147 |
QVERIFY(res && touchUpdateEvent.isAccepted() && !p.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1148 |
touchEndEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1149 |
res = QApplication::sendEvent(child3, &touchEndEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1150 |
QVERIFY(res && touchEndEvent.isAccepted() && p.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1151 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1152 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1153 |
// QGraphicsView |
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 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1156 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1157 |
tst_QTouchEventGraphicsItem *root, *child1, *child2, *child3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1158 |
root = new tst_QTouchEventGraphicsItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1159 |
child1 = new tst_QTouchEventGraphicsItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1160 |
child2 = new tst_QTouchEventGraphicsItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1161 |
child3 = new tst_QTouchEventGraphicsItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1162 |
child1->setParentItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1163 |
child2->setParentItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1164 |
child3->setParentItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1165 |
child1->setZValue(1.); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1166 |
child2->setZValue(0.); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1167 |
child3->setZValue(-1.); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1168 |
child1->setAcceptTouchEvents(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1169 |
child2->setAcceptTouchEvents(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1170 |
child3->setAcceptTouchEvents(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1171 |
child1->deleteInTouchBegin = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1172 |
child2->deleteInTouchUpdate = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1173 |
child3->deleteInTouchEnd = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1174 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1175 |
scene.addItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1176 |
view.resize(200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1177 |
view.fitInView(scene.sceneRect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1178 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1179 |
QTouchEvent::TouchPoint touchPoint(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1180 |
touchPoint.setState(Qt::TouchPointPressed); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1181 |
touchPoint.setPos(view.mapFromScene(child1->mapToScene(child1->boundingRect().center()))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1182 |
touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1183 |
touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
QList<QTouchEvent::TouchPoint> touchPoints; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
touchPoints.append(touchPoint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
QTouchEvent touchBeginEvent(QEvent::TouchBegin, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1187 |
QTouchEvent::TouchScreen, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1188 |
Qt::NoModifier, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1189 |
Qt::TouchPointPressed, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1190 |
touchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1191 |
touchPoints[0].setState(Qt::TouchPointMoved); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1192 |
QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1193 |
QTouchEvent::TouchScreen, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1194 |
Qt::NoModifier, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1195 |
Qt::TouchPointMoved, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1196 |
touchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1197 |
touchPoints[0].setState(Qt::TouchPointReleased); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1198 |
QTouchEvent touchEndEvent(QEvent::TouchEnd, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1199 |
QTouchEvent::TouchScreen, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1200 |
Qt::NoModifier, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1201 |
Qt::TouchPointReleased, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1202 |
touchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1203 |
bool res; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1204 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1205 |
child1->weakpointer = &child1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1206 |
touchBeginEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1207 |
res = QApplication::sendEvent(view.viewport(), &touchBeginEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1208 |
QVERIFY(res && touchBeginEvent.isAccepted() && !child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1209 |
touchUpdateEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1210 |
res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1211 |
QVERIFY(res && touchUpdateEvent.isAccepted() && !child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1212 |
touchEndEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1213 |
res = QApplication::sendEvent(view.viewport(), &touchEndEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1214 |
QVERIFY(res && touchUpdateEvent.isAccepted() && !child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1215 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1216 |
child2->weakpointer = &child2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1217 |
touchBeginEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1218 |
res = QApplication::sendEvent(view.viewport(), &touchBeginEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1219 |
QVERIFY(res && touchBeginEvent.isAccepted() && child2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1220 |
touchUpdateEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1221 |
res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1222 |
QVERIFY(res && !touchUpdateEvent.isAccepted() && !child2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1223 |
touchEndEvent.ignore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1224 |
res = QApplication::sendEvent(view.viewport(), &touchEndEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1225 |
QVERIFY(res && !touchUpdateEvent.isAccepted() && !child2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1226 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1227 |
child3->weakpointer = &child3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1228 |
res = QApplication::sendEvent(view.viewport(), &touchBeginEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1229 |
QVERIFY(res && touchBeginEvent.isAccepted() && child3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1230 |
res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1231 |
QVERIFY(res && !touchUpdateEvent.isAccepted() && child3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1232 |
res = QApplication::sendEvent(view.viewport(), &touchEndEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1233 |
QVERIFY(res && !touchEndEvent.isAccepted() && !child3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1234 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1235 |
delete root; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1236 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1237 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1238 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1239 |
void tst_QTouchEvent::deleteInRawEventTranslation() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1240 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1241 |
tst_QTouchEventWidget touchWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1242 |
touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1243 |
touchWidget.setGeometry(100, 100, 300, 300); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1244 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1245 |
tst_QTouchEventWidget *leftWidget = new tst_QTouchEventWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1246 |
leftWidget->setParent(&touchWidget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1247 |
leftWidget->setAttribute(Qt::WA_AcceptTouchEvents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1248 |
leftWidget->setGeometry(0, 100, 100, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1249 |
leftWidget->deleteInTouchBegin = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1250 |
leftWidget->show(); |
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 |
tst_QTouchEventWidget *centerWidget = new tst_QTouchEventWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1253 |
centerWidget->setParent(&touchWidget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1254 |
centerWidget->setAttribute(Qt::WA_AcceptTouchEvents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1255 |
centerWidget->setGeometry(100, 100, 100, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1256 |
centerWidget->deleteInTouchUpdate = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1257 |
centerWidget->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1258 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1259 |
tst_QTouchEventWidget *rightWidget = new tst_QTouchEventWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1260 |
rightWidget->setParent(&touchWidget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1261 |
rightWidget->setAttribute(Qt::WA_AcceptTouchEvents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1262 |
rightWidget->setGeometry(200, 100, 100, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1263 |
rightWidget->deleteInTouchEnd = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1264 |
rightWidget->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1265 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1266 |
QPointF leftPos = leftWidget->rect().center(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1267 |
QPointF centerPos = centerWidget->rect().center(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
QPointF rightPos = rightWidget->rect().center(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1269 |
QPointF leftScreenPos = leftWidget->mapToGlobal(leftPos.toPoint()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1270 |
QPointF centerScreenPos = centerWidget->mapToGlobal(centerPos.toPoint()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
QPointF rightScreenPos = rightWidget->mapToGlobal(rightPos.toPoint()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1272 |
QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1274 |
QWeakPointer<QWidget> pl = leftWidget, pc = centerWidget, pr = rightWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1275 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1276 |
QList<QTouchEvent::TouchPoint> rawTouchPoints; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1277 |
rawTouchPoints.append(QTouchEvent::TouchPoint(0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1278 |
rawTouchPoints.append(QTouchEvent::TouchPoint(1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1279 |
rawTouchPoints.append(QTouchEvent::TouchPoint(2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1280 |
rawTouchPoints[0].setState(Qt::TouchPointPressed); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1281 |
rawTouchPoints[0].setScreenPos(leftScreenPos); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1282 |
rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1283 |
rawTouchPoints[1].setState(Qt::TouchPointPressed); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1284 |
rawTouchPoints[1].setScreenPos(centerScreenPos); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1285 |
rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1286 |
rawTouchPoints[2].setState(Qt::TouchPointPressed); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1287 |
rawTouchPoints[2].setScreenPos(rightScreenPos); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1288 |
rawTouchPoints[2].setNormalizedPos(normalized(rawTouchPoints[2].pos(), screenGeometry)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1289 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1290 |
// generate begin events on all widgets, the left widget should die |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1291 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1292 |
QVERIFY(pl.isNull() && !pc.isNull() && !pr.isNull()); |
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 |
// generate update events on all widget, the center widget should die |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1295 |
rawTouchPoints[0].setState(Qt::TouchPointMoved); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1296 |
rawTouchPoints[1].setState(Qt::TouchPointMoved); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1297 |
rawTouchPoints[2].setState(Qt::TouchPointMoved); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1298 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1299 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1300 |
// generate end events on all widget, the right widget should die |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1301 |
rawTouchPoints[0].setState(Qt::TouchPointReleased); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1302 |
rawTouchPoints[1].setState(Qt::TouchPointReleased); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1303 |
rawTouchPoints[2].setState(Qt::TouchPointReleased); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1304 |
qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); |
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 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1307 |
void tst_QTouchEvent::crashInQGraphicsSceneAfterNotHandlingTouchBegin() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1308 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1309 |
QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 100, 100); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1310 |
rect->setAcceptTouchEvents(true); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1311 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1312 |
QGraphicsRectItem *mainRect = new QGraphicsRectItem(0, 0, 100, 100, rect); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1313 |
mainRect->setBrush(Qt::lightGray); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1314 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1315 |
QGraphicsRectItem *button = new QGraphicsRectItem(-20, -20, 40, 40, mainRect); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1316 |
button->setPos(50, 50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1317 |
button->setBrush(Qt::darkGreen); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1318 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1319 |
QGraphicsView view; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1320 |
QGraphicsScene scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1321 |
scene.addItem(rect); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1322 |
scene.setSceneRect(0,0,100,100); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1323 |
view.setScene(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1324 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1325 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1326 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1327 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1328 |
QPoint centerPos = view.mapFromScene(rect->boundingRect().center()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1329 |
// Touch the button |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1330 |
QTest::touchEvent(view.viewport()).press(0, centerPos); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1331 |
QTest::touchEvent(view.viewport()).release(0, centerPos); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1332 |
// Touch outside of the button |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1333 |
QTest::touchEvent(view.viewport()).press(0, view.mapFromScene(QPoint(10, 10))); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1334 |
QTest::touchEvent(view.viewport()).release(0, view.mapFromScene(QPoint(10, 10))); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1335 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1336 |
|
0 | 1337 |
QTEST_MAIN(tst_QTouchEvent) |
1338 |
||
1339 |
#include "tst_qtouchevent.moc" |