author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
child 8 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#if defined(Q_OS_WINCE) |
|
45 |
#include <ceconfig.h> |
|
46 |
#endif |
|
47 |
||
48 |
#include <QtGui> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
#include <private/qgraphicsscene_p.h> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
#include <private/qgraphicssceneindex_p.h> |
0 | 51 |
#include <math.h> |
52 |
#include "../../shared/util.h" |
|
53 |
||
54 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
55 |
#include <windows.h> |
|
56 |
#define Q_CHECK_PAINTEVENTS \ |
|
57 |
if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \ |
|
58 |
QSKIP("The Graphics View doesn't get the paint events", SkipSingle); |
|
59 |
#else |
|
60 |
#define Q_CHECK_PAINTEVENTS |
|
61 |
#endif |
|
62 |
||
63 |
#ifdef Q_OS_SYMBIAN |
|
64 |
// In Symbian OS test data is located in applications private dir |
|
65 |
// Current path (C:\private\<UID>) contains only ascii chars |
|
66 |
#define SRCDIR QDir::currentPath().append("\\").toAscii() |
|
67 |
#endif |
|
68 |
||
69 |
//TESTED_CLASS= |
|
70 |
//TESTED_FILES= |
|
71 |
||
72 |
Q_DECLARE_METATYPE(QList<int>) |
|
73 |
Q_DECLARE_METATYPE(QList<QRectF>) |
|
74 |
Q_DECLARE_METATYPE(QMatrix) |
|
75 |
Q_DECLARE_METATYPE(QPainterPath) |
|
76 |
Q_DECLARE_METATYPE(QPointF) |
|
77 |
Q_DECLARE_METATYPE(QRectF) |
|
78 |
Q_DECLARE_METATYPE(Qt::AspectRatioMode) |
|
79 |
Q_DECLARE_METATYPE(Qt::ItemSelectionMode) |
|
80 |
||
81 |
static const int randomX[] = {276, 40, 250, 864, -56, 426, 855, 825, 184, 955, -798, -804, 773, |
|
82 |
282, 489, 686, 780, -220, 50, 749, -856, -205, 81, 492, -819, 518, |
|
83 |
895, 57, -559, 788, -965, 68, -442, -247, -339, -648, 292, 891, |
|
84 |
-865, 462, 864, 673, 640, 523, 194, 500, -727, 307, -243, 320, |
|
85 |
-545, 415, 448, 341, -619, 652, 892, -16, -14, -659, -101, -934, |
|
86 |
532, 356, 824, 132, 160, 130, 104, 886, -179, -174, 543, -644, 60, |
|
87 |
-470, -354, -728, 689, 682, -587, -694, -221, -741, 37, 372, -289, |
|
88 |
741, -300, 858, -320, 729, -602, -956, -544, -403, 203, 398, 284, |
|
89 |
-972, -572, -946, 81, 51, -403, -580, 867, 546, 565, -580, -484, |
|
90 |
659, 982, -518, -976, 423, -800, 659, -297, 712, 938, -19, -16, |
|
91 |
824, -252, 197, 321, -837, 824, 136, 226, -980, -909, -826, -479, |
|
92 |
-835, -503, -828, -901, -810, -641, -548, -179, 194, 749, -296, 539, |
|
93 |
-37, -599, -235, 121, 35, -230, -915, 789, 764, -622, -382, -90, -701, |
|
94 |
676, -407, 998, 267, 913, 817, -748, -370, -162, -797, 19, -556, 933, |
|
95 |
-670, -101, -765, -941, -17, 360, 31, 960, 509, 933, -35, 974, -924, |
|
96 |
-734, 589, 963, 724, 794, 843, 16, -272, -811, 721, 99, -122, 216, |
|
97 |
-404, 158, 787, -443, -437, -337, 383, -342, 538, -641, 791, 637, |
|
98 |
-848, 397, 820, 109, 11, 45, 809, 591, 933, 961, 625, -140, -592, |
|
99 |
-694, -969, 317, 293, 777, -18, -282, 835, -455, -708, -407, -204, |
|
100 |
748, 347, -501, -545, 292, -362, 176, 546, -573, -38, -854, -395, |
|
101 |
560, -624, -940, -971, 66, -910, 782, 985}; |
|
102 |
||
103 |
static const int randomY[] = {603, 70, -318, 843, 450, -637, 199, -527, 407, 964, -54, 620, -207, |
|
104 |
-736, -700, -476, -706, -142, 837, 621, 522, -98, 232, 292, -267, 900, |
|
105 |
615, -356, -415, 783, 290, 462, -857, -314, 677, 36, 772, 424, -72, |
|
106 |
-121, 547, -533, 537, -656, 289, 508, 914, 601, 434, 588, -779, -714, |
|
107 |
-368, 628, -276, 432, -1, -929, 638, -36, 253, -922, -943, 979, -34, |
|
108 |
-268, -193, 601, 686, -330, 165, 98, 75, -691, -605, 617, 773, 617, |
|
109 |
619, 238, -42, -405, 17, 384, -472, -846, 520, 110, 591, -217, 936, |
|
110 |
-373, 731, 734, 810, 961, 881, 939, 379, -905, -137, 437, 298, 688, |
|
111 |
-71, -204, 573, -120, -821, 489, -722, -926, 529, -113, -243, 543, |
|
112 |
868, -301, -781, -549, -842, -489, -80, -910, -928, 51, -91, 324, |
|
113 |
204, -92, 867, 723, 248, 709, -357, 591, -365, -379, 266, -649, -95, |
|
114 |
205, 551, 355, -631, 79, -186, 795, -7, -225, 46, -410, 665, -874, |
|
115 |
-618, 845, -548, 443, 471, -644, 606, -607, 59, -619, 288, -244, 529, |
|
116 |
690, 349, -738, -611, -879, -642, 801, -178, 823, -748, -552, -247, |
|
117 |
-223, -408, 651, -62, 949, -795, 171, -107, -210, -207, -842, -86, |
|
118 |
436, 528, 366, -178, 245, -695, 665, 613, -948, 667, -620, -979, -949, |
|
119 |
905, 181, -412, -467, -437, -774, 750, -10, 54, 205, -674, -290, -924, |
|
120 |
-361, -463, 912, -702, 622, -542, 220, 115, 832, 451, -38, -952, -230, |
|
121 |
-588, 864, 234, 225, -303, 493, 246, 153, 338, -378, 377, -819, 140, 136, |
|
122 |
467, -849, -326, -533, 166, 252, -994, -699, 904, -566, 621, -752}; |
|
123 |
||
124 |
class HoverItem : public QGraphicsRectItem |
|
125 |
{ |
|
126 |
public: |
|
127 |
HoverItem() |
|
128 |
: QGraphicsRectItem(QRectF(-10, -10, 20, 20)), isHovered(false) |
|
129 |
{ setAcceptsHoverEvents(true); } |
|
130 |
||
131 |
bool isHovered; |
|
132 |
||
133 |
protected: |
|
134 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) |
|
135 |
{ |
|
136 |
isHovered = (option->state & QStyle::State_MouseOver); |
|
137 |
||
138 |
painter->setOpacity(0.75); |
|
139 |
painter->setPen(Qt::NoPen); |
|
140 |
painter->setBrush(Qt::darkGray); |
|
141 |
painter->drawRoundRect(boundingRect().adjusted(3, 3, -3, -3), Qt::darkGray); |
|
142 |
painter->setPen(Qt::black); |
|
143 |
if (isHovered) { |
|
144 |
painter->setBrush(QColor(Qt::blue).light(120)); |
|
145 |
} else { |
|
146 |
painter->setBrush(Qt::gray); |
|
147 |
} |
|
148 |
painter->drawRoundRect(boundingRect().adjusted(0, 0, -5, -5)); |
|
149 |
} |
|
150 |
}; |
|
151 |
||
152 |
class EventSpy : public QGraphicsWidget |
|
153 |
{ |
|
154 |
Q_OBJECT |
|
155 |
public: |
|
156 |
EventSpy(QObject *watched, QEvent::Type type) |
|
157 |
: _count(0), spied(type) |
|
158 |
{ |
|
159 |
watched->installEventFilter(this); |
|
160 |
} |
|
161 |
||
162 |
EventSpy(QGraphicsScene *scene, QGraphicsItem *watched, QEvent::Type type) |
|
163 |
: _count(0), spied(type) |
|
164 |
{ |
|
165 |
scene->addItem(this); |
|
166 |
watched->installSceneEventFilter(this); |
|
167 |
} |
|
168 |
||
169 |
int count() const { return _count; } |
|
170 |
||
171 |
protected: |
|
172 |
bool eventFilter(QObject *watched, QEvent *event) |
|
173 |
{ |
|
174 |
Q_UNUSED(watched); |
|
175 |
if (event->type() == spied) |
|
176 |
++_count; |
|
177 |
return false; |
|
178 |
} |
|
179 |
||
180 |
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
181 |
{ |
|
182 |
Q_UNUSED(watched); |
|
183 |
if (event->type() == spied) |
|
184 |
++_count; |
|
185 |
return false; |
|
186 |
} |
|
187 |
||
188 |
int _count; |
|
189 |
QEvent::Type spied; |
|
190 |
}; |
|
191 |
||
192 |
class tst_QGraphicsScene : public QObject |
|
193 |
{ |
|
194 |
Q_OBJECT |
|
195 |
public slots: |
|
196 |
void initTestCase(); |
|
197 |
||
198 |
private slots: |
|
199 |
void construction(); |
|
200 |
void sceneRect(); |
|
201 |
void itemIndexMethod(); |
|
202 |
void bspTreeDepth(); |
|
203 |
void itemsBoundingRect_data(); |
|
204 |
void itemsBoundingRect(); |
|
205 |
void items(); |
|
206 |
void items_QPointF_data(); |
|
207 |
void items_QPointF(); |
|
208 |
void items_QRectF(); |
|
209 |
void items_QRectF_2_data(); |
|
210 |
void items_QRectF_2(); |
|
211 |
void items_QPolygonF(); |
|
212 |
void items_QPolygonF_2(); |
|
213 |
void items_QPainterPath(); |
|
214 |
void items_QPainterPath_2(); |
|
215 |
void selection(); |
|
216 |
void selectionChanged(); |
|
217 |
void selectionChanged2(); |
|
218 |
void addItem(); |
|
219 |
void addEllipse(); |
|
220 |
void addLine(); |
|
221 |
void addPath(); |
|
222 |
void addPixmap(); |
|
223 |
void addRect(); |
|
224 |
void addText(); |
|
225 |
void removeItem(); |
|
226 |
void clear(); |
|
227 |
void focusItem(); |
|
228 |
void focusItemLostFocus(); |
|
229 |
void setFocusItem(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
230 |
void setFocusItem_inactive(); |
0 | 231 |
void mouseGrabberItem(); |
232 |
void hoverEvents_siblings(); |
|
233 |
void hoverEvents_parentChild(); |
|
234 |
void createItemGroup(); |
|
235 |
void mouseEventPropagation(); |
|
236 |
void mouseEventPropagation_ignore(); |
|
237 |
void mouseEventPropagation_focus(); |
|
238 |
void mouseEventPropagation_doubleclick(); |
|
239 |
void mouseEventPropagation_mouseMove(); |
|
240 |
#ifndef QT_NO_DRAGANDDROP |
|
241 |
void dragAndDrop_simple(); |
|
242 |
void dragAndDrop_disabledOrInvisible(); |
|
243 |
void dragAndDrop_propagate(); |
|
244 |
#endif |
|
245 |
void render_data(); |
|
246 |
void render(); |
|
247 |
void contextMenuEvent(); |
|
248 |
void contextMenuEvent_ItemIgnoresTransformations(); |
|
249 |
void update(); |
|
250 |
void update2(); |
|
251 |
void views(); |
|
252 |
void event(); |
|
253 |
void eventsToDisabledItems(); |
|
254 |
void exposedRect(); |
|
255 |
void tabFocus_emptyScene(); |
|
256 |
void tabFocus_sceneWithFocusableItems(); |
|
257 |
void tabFocus_sceneWithFocusWidgets(); |
|
258 |
void tabFocus_sceneWithNestedFocusWidgets(); |
|
259 |
void style(); |
|
260 |
void sorting_data(); |
|
261 |
void sorting(); |
|
262 |
void changedSignal_data(); |
|
263 |
void changedSignal(); |
|
264 |
void stickyFocus_data(); |
|
265 |
void stickyFocus(); |
|
266 |
void sendEvent(); |
|
267 |
void inputMethod_data(); |
|
268 |
void inputMethod(); |
|
269 |
void dispatchHoverOnPress(); |
|
270 |
void initialFocus_data(); |
|
271 |
void initialFocus(); |
|
272 |
void polishItems(); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
273 |
void polishItems2(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
void isActive(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
void siblingIndexAlwaysValid(); |
0 | 276 |
|
277 |
// task specific tests below me |
|
278 |
void task139710_bspTreeCrash(); |
|
279 |
void task139782_containsItemBoundingRect(); |
|
280 |
void task176178_itemIndexMethodBreaksSceneRect(); |
|
281 |
void task160653_selectionChanged(); |
|
282 |
void task250680_childClip(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
void taskQTBUG_5904_crashWithDeviceCoordinateCache(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
void taskQT657_paintIntoCacheWithTransparentParts(); |
0 | 285 |
}; |
286 |
||
287 |
void tst_QGraphicsScene::initTestCase() |
|
288 |
{ |
|
289 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
290 |
qApp->setAutoMaximizeThreshold(-1); |
|
291 |
#endif |
|
292 |
} |
|
293 |
||
294 |
void tst_QGraphicsScene::construction() |
|
295 |
{ |
|
296 |
QGraphicsScene scene; |
|
297 |
QCOMPARE(scene.itemsBoundingRect(), QRectF()); |
|
298 |
QVERIFY(scene.items().isEmpty()); |
|
299 |
QVERIFY(scene.items(QPointF()).isEmpty()); |
|
300 |
QVERIFY(scene.items(QRectF()).isEmpty()); |
|
301 |
QVERIFY(scene.items(QPolygonF()).isEmpty()); |
|
302 |
QVERIFY(scene.items(QPainterPath()).isEmpty()); |
|
303 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsScene::collidingItems: cannot find collisions for null item"); |
|
304 |
QVERIFY(scene.collidingItems(0).isEmpty()); |
|
305 |
QVERIFY(!scene.itemAt(QPointF())); |
|
306 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
307 |
QVERIFY(!scene.focusItem()); |
|
308 |
} |
|
309 |
||
310 |
void tst_QGraphicsScene::sceneRect() |
|
311 |
{ |
|
312 |
QGraphicsScene scene; |
|
313 |
QSignalSpy sceneRectChanged(&scene, SIGNAL(sceneRectChanged(QRectF))); |
|
314 |
QCOMPARE(scene.sceneRect(), QRectF()); |
|
315 |
QCOMPARE(sceneRectChanged.count(), 0); |
|
316 |
||
317 |
QGraphicsItem *item = scene.addRect(QRectF(0, 0, 10, 10)); |
|
318 |
item->setPos(-5, -5); |
|
319 |
QCOMPARE(sceneRectChanged.count(), 0); |
|
320 |
||
321 |
QCOMPARE(scene.itemAt(0, 0), item); |
|
322 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)0); |
|
323 |
QCOMPARE(sceneRectChanged.count(), 0); |
|
324 |
QCOMPARE(scene.sceneRect(), QRectF(-5, -5, 10, 10)); |
|
325 |
QCOMPARE(sceneRectChanged.count(), 1); |
|
326 |
QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); |
|
327 |
||
328 |
item->setPos(0, 0); |
|
329 |
QCOMPARE(scene.sceneRect(), QRectF(-5, -5, 15, 15)); |
|
330 |
QCOMPARE(sceneRectChanged.count(), 2); |
|
331 |
QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); |
|
332 |
||
333 |
scene.setSceneRect(-100, -100, 10, 10); |
|
334 |
QCOMPARE(sceneRectChanged.count(), 3); |
|
335 |
QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); |
|
336 |
||
337 |
QCOMPARE(scene.itemAt(0, 0), item); |
|
338 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)0); |
|
339 |
QCOMPARE(scene.sceneRect(), QRectF(-100, -100, 10, 10)); |
|
340 |
item->setPos(10, 10); |
|
341 |
QCOMPARE(scene.sceneRect(), QRectF(-100, -100, 10, 10)); |
|
342 |
QCOMPARE(sceneRectChanged.count(), 3); |
|
343 |
QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); |
|
344 |
||
345 |
scene.setSceneRect(QRectF()); |
|
346 |
||
347 |
QCOMPARE(scene.itemAt(10, 10), item); |
|
348 |
QCOMPARE(scene.itemAt(20, 20), (QGraphicsItem *)0); |
|
349 |
QCOMPARE(sceneRectChanged.count(), 4); |
|
350 |
QCOMPARE(scene.sceneRect(), QRectF(-5, -5, 25, 25)); |
|
351 |
QCOMPARE(sceneRectChanged.count(), 5); |
|
352 |
QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); |
|
353 |
} |
|
354 |
||
355 |
void tst_QGraphicsScene::itemIndexMethod() |
|
356 |
{ |
|
357 |
QGraphicsScene scene; |
|
358 |
QCOMPARE(scene.itemIndexMethod(), QGraphicsScene::BspTreeIndex); |
|
359 |
||
360 |
#ifdef QT_ARCH_ARM |
|
361 |
const int minY = -500; |
|
362 |
const int maxY = 500; |
|
363 |
const int minX = -500; |
|
364 |
const int maxX = 500; |
|
365 |
#else |
|
366 |
const int minY = -1000; |
|
367 |
const int maxY = 2000; |
|
368 |
const int minX = -1000; |
|
369 |
const int maxX = 2000; |
|
370 |
#endif |
|
371 |
||
372 |
QList<QGraphicsItem *> items; |
|
373 |
for (int y = minY; y < maxY; y += 100) { |
|
374 |
for (int x = minX; x < maxX; x += 100) { |
|
375 |
QGraphicsItem *item = scene.addRect(QRectF(0, 0, 10, 10)); |
|
376 |
item->setPos(x, y); |
|
377 |
QCOMPARE(scene.itemAt(x, y), item); |
|
378 |
items << item; |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
int n = 0; |
|
383 |
for (int y = minY; y < maxY; y += 100) { |
|
384 |
for (int x = minX; x < maxX; x += 100) |
|
385 |
QCOMPARE(scene.itemAt(x, y), items.at(n++)); |
|
386 |
} |
|
387 |
||
388 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); |
|
389 |
QCOMPARE(scene.itemIndexMethod(), QGraphicsScene::NoIndex); |
|
390 |
||
391 |
n = 0; |
|
392 |
for (int y = minY; y < maxY; y += 100) { |
|
393 |
for (int x = minX; x < maxX; x += 100) |
|
394 |
QCOMPARE(scene.itemAt(x, y), items.at(n++)); |
|
395 |
} |
|
396 |
||
397 |
scene.setItemIndexMethod(QGraphicsScene::BspTreeIndex); |
|
398 |
QCOMPARE(scene.itemIndexMethod(), QGraphicsScene::BspTreeIndex); |
|
399 |
||
400 |
n = 0; |
|
401 |
for (int y = minY; y < maxY; y += 100) { |
|
402 |
for (int x = minX; x < maxX; x += 100) |
|
403 |
QCOMPARE(scene.itemAt(x, y), items.at(n++)); |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
void tst_QGraphicsScene::bspTreeDepth() |
|
408 |
{ |
|
409 |
QGraphicsScene scene; |
|
410 |
QCOMPARE(scene.itemIndexMethod(), QGraphicsScene::BspTreeIndex); |
|
411 |
QCOMPARE(scene.bspTreeDepth(), 0); |
|
412 |
scene.setBspTreeDepth(1); |
|
413 |
QCOMPARE(scene.bspTreeDepth(), 1); |
|
414 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsScene::setBspTreeDepth: invalid depth -1 ignored; must be >= 0"); |
|
415 |
scene.setBspTreeDepth(-1); |
|
416 |
QCOMPARE(scene.bspTreeDepth(), 1); |
|
417 |
} |
|
418 |
||
419 |
void tst_QGraphicsScene::items() |
|
420 |
{ |
|
421 |
#ifdef QT_ARCH_ARM |
|
422 |
const int minY = -500; |
|
423 |
const int maxY = 500; |
|
424 |
const int minX = -500; |
|
425 |
const int maxX = 500; |
|
426 |
#else |
|
427 |
const int minY = -1000; |
|
428 |
const int maxY = 2000; |
|
429 |
const int minX = -1000; |
|
430 |
const int maxX = 2000; |
|
431 |
#endif |
|
432 |
||
433 |
{ |
|
434 |
QGraphicsScene scene; |
|
435 |
||
436 |
QList<QGraphicsItem *> items; |
|
437 |
for (int y = minY; y < maxY; y += 100) { |
|
438 |
for (int x = minX; x < maxX; x += 100) |
|
439 |
items << scene.addRect(QRectF(0, 0, 10, 10)); |
|
440 |
} |
|
441 |
QCOMPARE(scene.items().size(), items.size()); |
|
442 |
scene.itemAt(0, 0); // trigger indexing |
|
443 |
||
444 |
scene.removeItem(items.at(5)); |
|
445 |
delete items.at(5); |
|
446 |
QVERIFY(!scene.items().contains(0)); |
|
447 |
delete items.at(7); |
|
448 |
QVERIFY(!scene.items().contains(0)); |
|
449 |
} |
|
450 |
{ |
|
451 |
QGraphicsScene scene; |
|
452 |
QGraphicsLineItem *l1 = scene.addLine(-5, 0, 5, 0); |
|
453 |
QGraphicsLineItem *l2 = scene.addLine(0, -5, 0, 5); |
|
454 |
QVERIFY(!l1->sceneBoundingRect().intersects(l2->sceneBoundingRect())); |
|
455 |
QVERIFY(!l2->sceneBoundingRect().intersects(l1->sceneBoundingRect())); |
|
456 |
QList<QGraphicsItem *> items; |
|
457 |
items<<l1<<l2; |
|
458 |
QCOMPARE(scene.items().size(), items.size()); |
|
459 |
QVERIFY(scene.items(-1, -1, 2, 2).contains(l1)); |
|
460 |
QVERIFY(scene.items(-1, -1, 2, 2).contains(l2)); |
|
461 |
} |
|
462 |
} |
|
463 |
||
464 |
void tst_QGraphicsScene::itemsBoundingRect_data() |
|
465 |
{ |
|
466 |
QTest::addColumn<QList<QRectF> >("rects"); |
|
467 |
QTest::addColumn<QMatrix>("matrix"); |
|
468 |
QTest::addColumn<QRectF>("boundingRect"); |
|
469 |
||
470 |
QMatrix transformationMatrix; |
|
471 |
transformationMatrix.translate(50, -50); |
|
472 |
transformationMatrix.scale(2, 2); |
|
473 |
transformationMatrix.rotate(90); |
|
474 |
||
475 |
QTest::newRow("none") |
|
476 |
<< QList<QRectF>() |
|
477 |
<< QMatrix() |
|
478 |
<< QRectF(); |
|
479 |
QTest::newRow("{{0, 0, 10, 10}}") |
|
480 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10)) |
|
481 |
<< QMatrix() |
|
482 |
<< QRectF(0, 0, 10, 10); |
|
483 |
QTest::newRow("{{-10, -10, 10, 10}}") |
|
484 |
<< (QList<QRectF>() << QRectF(-10, -10, 10, 10)) |
|
485 |
<< QMatrix() |
|
486 |
<< QRectF(-10, -10, 10, 10); |
|
487 |
QTest::newRow("{{-1000, -1000, 1, 1}, {-10, -10, 10, 10}}") |
|
488 |
<< (QList<QRectF>() << QRectF(-1000, -1000, 1, 1) << QRectF(-10, -10, 10, 10)) |
|
489 |
<< QMatrix() |
|
490 |
<< QRectF(-1000, -1000, 1000, 1000); |
|
491 |
QTest::newRow("transformed {{0, 0, 10, 10}}") |
|
492 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10)) |
|
493 |
<< transformationMatrix |
|
494 |
<< QRectF(30, -50, 20, 20); |
|
495 |
QTest::newRow("transformed {{-10, -10, 10, 10}}") |
|
496 |
<< (QList<QRectF>() << QRectF(-10, -10, 10, 10)) |
|
497 |
<< transformationMatrix |
|
498 |
<< QRectF(50, -70, 20, 20); |
|
499 |
QTest::newRow("transformed {{-1000, -1000, 1, 1}, {-10, -10, 10, 10}}") |
|
500 |
<< (QList<QRectF>() << QRectF(-1000, -1000, 1, 1) << QRectF(-10, -10, 10, 10)) |
|
501 |
<< transformationMatrix |
|
502 |
<< QRectF(50, -2050, 2000, 2000); |
|
503 |
||
504 |
QList<QRectF> all; |
|
505 |
for (int i = 0; i < 256; ++i) |
|
506 |
all << QRectF(randomX[i], randomY[i], 10, 10); |
|
507 |
QTest::newRow("all") |
|
508 |
<< all |
|
509 |
<< QMatrix() |
|
510 |
<< QRectF(-980, -994, 1988, 1983); |
|
511 |
QTest::newRow("transformed all") |
|
512 |
<< all |
|
513 |
<< transformationMatrix |
|
514 |
<< QRectF(-1928, -2010, 3966, 3976); |
|
515 |
} |
|
516 |
||
517 |
void tst_QGraphicsScene::itemsBoundingRect() |
|
518 |
{ |
|
519 |
QFETCH(QList<QRectF>, rects); |
|
520 |
QFETCH(QMatrix, matrix); |
|
521 |
QFETCH(QRectF, boundingRect); |
|
522 |
||
523 |
QGraphicsScene scene; |
|
524 |
||
525 |
foreach (QRectF rect, rects) { |
|
526 |
QPainterPath path; |
|
527 |
path.addRect(rect); |
|
528 |
scene.addPath(path)->setMatrix(matrix); |
|
529 |
} |
|
530 |
||
531 |
QCOMPARE(scene.itemsBoundingRect(), boundingRect); |
|
532 |
} |
|
533 |
||
534 |
void tst_QGraphicsScene::items_QPointF_data() |
|
535 |
{ |
|
536 |
QTest::addColumn<QList<QRectF> >("items"); |
|
537 |
QTest::addColumn<QPointF>("point"); |
|
538 |
QTest::addColumn<QList<int> >("itemsAtPoint"); |
|
539 |
||
540 |
QTest::newRow("empty") |
|
541 |
<< QList<QRectF>() |
|
542 |
<< QPointF() |
|
543 |
<< QList<int>(); |
|
544 |
QTest::newRow("1") |
|
545 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10)) |
|
546 |
<< QPointF(0, 0) |
|
547 |
<< (QList<int>() << 0); |
|
548 |
QTest::newRow("2") |
|
549 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10)) |
|
550 |
<< QPointF(5, 5) |
|
551 |
<< (QList<int>() << 0); |
|
552 |
QTest::newRow("3") |
|
553 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10)) |
|
554 |
<< QPointF(9.9, 9.9) |
|
555 |
<< (QList<int>() << 0); |
|
556 |
QTest::newRow("3.5") |
|
557 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10)) |
|
558 |
<< QPointF(10, 10) |
|
559 |
<< QList<int>(); |
|
560 |
QTest::newRow("4") |
|
561 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10) << QRectF(9.9, 9.9, 10, 10)) |
|
562 |
<< QPointF(9.9, 9.9) |
|
563 |
<< (QList<int>() << 1 << 0); |
|
564 |
QTest::newRow("4.5") |
|
565 |
<< (QList<QRectF>() << QRectF(0, 0, 10, 10) << QRectF(10, 10, 10, 10)) |
|
566 |
<< QPointF(10, 10) |
|
567 |
<< (QList<int>() << 1); |
|
568 |
QTest::newRow("5") |
|
569 |
<< (QList<QRectF>() << QRectF(5, 5, 10, 10) << QRectF(10, 10, 10, 10)) |
|
570 |
<< QPointF(10, 10) |
|
571 |
<< (QList<int>() << 1 << 0); |
|
572 |
QTest::newRow("6") |
|
573 |
<< (QList<QRectF>() << QRectF(5, 5, 10, 10) << QRectF(10, 10, 10, 10) << QRectF(0, 0, 20, 30)) |
|
574 |
<< QPointF(10, 10) |
|
575 |
<< (QList<int>() << 2 << 1 << 0); |
|
576 |
} |
|
577 |
||
578 |
void tst_QGraphicsScene::items_QPointF() |
|
579 |
{ |
|
580 |
QFETCH(QList<QRectF>, items); |
|
581 |
QFETCH(QPointF, point); |
|
582 |
QFETCH(QList<int>, itemsAtPoint); |
|
583 |
||
584 |
QGraphicsScene scene; |
|
585 |
||
586 |
int n = 0; |
|
587 |
QList<QGraphicsItem *> addedItems; |
|
588 |
foreach(QRectF rect, items) { |
|
589 |
QPainterPath path; |
|
590 |
path.addRect(0, 0, rect.width(), rect.height()); |
|
591 |
||
592 |
QGraphicsItem *item = scene.addPath(path); |
|
593 |
item->setZValue(n++); |
|
594 |
item->setPos(rect.topLeft()); |
|
595 |
addedItems << item; |
|
596 |
} |
|
597 |
||
598 |
QList<int> itemIndexes; |
|
599 |
foreach (QGraphicsItem *item, scene.items(point)) |
|
600 |
itemIndexes << addedItems.indexOf(item); |
|
601 |
||
602 |
QCOMPARE(itemIndexes, itemsAtPoint); |
|
603 |
} |
|
604 |
||
605 |
void tst_QGraphicsScene::items_QRectF() |
|
606 |
{ |
|
607 |
QGraphicsScene scene; |
|
608 |
QGraphicsItem *item1 = scene.addRect(QRectF(-10, -10, 10, 10)); |
|
609 |
QGraphicsItem *item2 = scene.addRect(QRectF(10, -10, 10, 10)); |
|
610 |
QGraphicsItem *item3 = scene.addRect(QRectF(10, 10, 10, 10)); |
|
611 |
QGraphicsItem *item4 = scene.addRect(QRectF(-10, 10, 10, 10)); |
|
612 |
||
613 |
item1->setZValue(0); |
|
614 |
item2->setZValue(1); |
|
615 |
item3->setZValue(2); |
|
616 |
item4->setZValue(3); |
|
617 |
||
618 |
QCOMPARE(scene.items(QRectF(-10, -10, 10, 10)), QList<QGraphicsItem *>() << item1); |
|
619 |
QCOMPARE(scene.items(QRectF(10, -10, 10, 10)), QList<QGraphicsItem *>() << item2); |
|
620 |
QCOMPARE(scene.items(QRectF(10, 10, 10, 10)), QList<QGraphicsItem *>() << item3); |
|
621 |
QCOMPARE(scene.items(QRectF(-10, 10, 10, 10)), QList<QGraphicsItem *>() << item4); |
|
622 |
QCOMPARE(scene.items(QRectF(-10, -10, 1, 1)), QList<QGraphicsItem *>() << item1); |
|
623 |
QCOMPARE(scene.items(QRectF(10, -10, 1, 1)), QList<QGraphicsItem *>() << item2); |
|
624 |
QCOMPARE(scene.items(QRectF(10, 10, 1, 1)), QList<QGraphicsItem *>() << item3); |
|
625 |
QCOMPARE(scene.items(QRectF(-10, 10, 1, 1)), QList<QGraphicsItem *>() << item4); |
|
626 |
||
627 |
QCOMPARE(scene.items(QRectF(-10, -10, 40, 10)), QList<QGraphicsItem *>() << item2 << item1); |
|
628 |
QCOMPARE(scene.items(QRectF(-10, 10, 40, 10)), QList<QGraphicsItem *>() << item4 << item3); |
|
629 |
||
630 |
item1->setZValue(3); |
|
631 |
item2->setZValue(2); |
|
632 |
item3->setZValue(1); |
|
633 |
item4->setZValue(0); |
|
634 |
||
635 |
QCOMPARE(scene.items(QRectF(-10, -10, 40, 10)), QList<QGraphicsItem *>() << item1 << item2); |
|
636 |
QCOMPARE(scene.items(QRectF(-10, 10, 40, 10)), QList<QGraphicsItem *>() << item3 << item4); |
|
637 |
} |
|
638 |
||
639 |
void tst_QGraphicsScene::items_QRectF_2_data() |
|
640 |
{ |
|
641 |
QTest::addColumn<QRectF>("ellipseRect"); |
|
642 |
QTest::addColumn<QRectF>("sceneRect"); |
|
643 |
QTest::addColumn<Qt::ItemSelectionMode>("selectionMode"); |
|
644 |
QTest::addColumn<bool>("contained"); |
|
645 |
QTest::addColumn<bool>("containedRotated"); |
|
646 |
||
647 |
// None of the rects contain the ellipse's shape nor bounding rect |
|
648 |
QTest::newRow("1") << QRectF(0, 0, 100, 100) << QRectF(1, 1, 10, 10) << Qt::ContainsItemShape << false << false; |
|
649 |
QTest::newRow("2") << QRectF(0, 0, 100, 100) << QRectF(1, 89, 10, 10) << Qt::ContainsItemShape << false << false; |
|
650 |
QTest::newRow("3") << QRectF(0, 0, 100, 100) << QRectF(89, 1, 10, 10) << Qt::ContainsItemShape << false << false; |
|
651 |
QTest::newRow("4") << QRectF(0, 0, 100, 100) << QRectF(89, 89, 10, 10) << Qt::ContainsItemShape << false << false; |
|
652 |
QTest::newRow("5") << QRectF(0, 0, 100, 100) << QRectF(1, 1, 10, 10) << Qt::ContainsItemBoundingRect << false << false; |
|
653 |
QTest::newRow("6") << QRectF(0, 0, 100, 100) << QRectF(1, 89, 10, 10) << Qt::ContainsItemBoundingRect << false << false; |
|
654 |
QTest::newRow("7") << QRectF(0, 0, 100, 100) << QRectF(89, 1, 10, 10) << Qt::ContainsItemBoundingRect << false << false; |
|
655 |
QTest::newRow("8") << QRectF(0, 0, 100, 100) << QRectF(89, 89, 10, 10) << Qt::ContainsItemBoundingRect << false << false; |
|
656 |
QTest::newRow("9") << QRectF(0, 0, 100, 100) << QRectF(0, 0, 50, 50) << Qt::ContainsItemShape << false << false; |
|
657 |
QTest::newRow("10") << QRectF(0, 0, 100, 100) << QRectF(0, 50, 50, 50) << Qt::ContainsItemShape << false << false; |
|
658 |
QTest::newRow("11") << QRectF(0, 0, 100, 100) << QRectF(50, 0, 50, 50) << Qt::ContainsItemShape << false << false; |
|
659 |
QTest::newRow("12") << QRectF(0, 0, 100, 100) << QRectF(50, 50, 50, 50) << Qt::ContainsItemShape << false << false; |
|
660 |
QTest::newRow("13") << QRectF(0, 0, 100, 100) << QRectF(0, 0, 50, 50) << Qt::ContainsItemBoundingRect << false << false; |
|
661 |
QTest::newRow("14") << QRectF(0, 0, 100, 100) << QRectF(0, 50, 50, 50) << Qt::ContainsItemBoundingRect << false << false; |
|
662 |
QTest::newRow("15") << QRectF(0, 0, 100, 100) << QRectF(50, 0, 50, 50) << Qt::ContainsItemBoundingRect << false << false; |
|
663 |
QTest::newRow("16") << QRectF(0, 0, 100, 100) << QRectF(50, 50, 50, 50) << Qt::ContainsItemBoundingRect << false << false; |
|
664 |
QTest::newRow("17") << QRectF(0, 0, 100, 100) << QRectF(-50, -50, 100, 100) << Qt::ContainsItemShape << false << false; |
|
665 |
QTest::newRow("18") << QRectF(0, 0, 100, 100) << QRectF(0, -50, 100, 100) << Qt::ContainsItemShape << false << false; |
|
666 |
QTest::newRow("19") << QRectF(0, 0, 100, 100) << QRectF(-50, 0, 100, 100) << Qt::ContainsItemShape << false << false; |
|
667 |
QTest::newRow("20") << QRectF(0, 0, 100, 100) << QRectF(0, 0, 100, 100) << Qt::ContainsItemShape << false << false; |
|
668 |
QTest::newRow("21") << QRectF(0, 0, 100, 100) << QRectF(-50, -50, 100, 100) << Qt::ContainsItemBoundingRect << false << false; |
|
669 |
QTest::newRow("22") << QRectF(0, 0, 100, 100) << QRectF(0, -50, 100, 100) << Qt::ContainsItemBoundingRect << false << false; |
|
670 |
QTest::newRow("23") << QRectF(0, 0, 100, 100) << QRectF(-50, 0, 100, 100) << Qt::ContainsItemBoundingRect << false << false; |
|
671 |
||
672 |
// The rect is the same as the ellipse's bounding rect |
|
673 |
QTest::newRow("24") << QRectF(0, 0, 100, 100) << QRectF(0, 0, 100, 100) << Qt::ContainsItemBoundingRect << false << false; |
|
674 |
||
675 |
// None intersects with the item's shape, but they all intersects with the |
|
676 |
// item's bounding rect. |
|
677 |
QTest::newRow("25") << QRectF(0, 0, 100, 100) << QRectF(1, 1, 10, 10) << Qt::IntersectsItemShape << false << false; |
|
678 |
QTest::newRow("26") << QRectF(0, 0, 100, 100) << QRectF(1, 89, 10, 10) << Qt::IntersectsItemShape << false << true; |
|
679 |
QTest::newRow("27") << QRectF(0, 0, 100, 100) << QRectF(89, 1, 10, 10) << Qt::IntersectsItemShape << false << false; |
|
680 |
QTest::newRow("28") << QRectF(0, 0, 100, 100) << QRectF(89, 89, 10, 10) << Qt::IntersectsItemShape << false << false; |
|
681 |
QTest::newRow("29") << QRectF(0, 0, 100, 100) << QRectF(1, 1, 10, 10) << Qt::IntersectsItemBoundingRect << true << true; |
|
682 |
QTest::newRow("30") << QRectF(0, 0, 100, 100) << QRectF(1, 89, 10, 10) << Qt::IntersectsItemBoundingRect << true << true; |
|
683 |
QTest::newRow("31") << QRectF(0, 0, 100, 100) << QRectF(89, 1, 10, 10) << Qt::IntersectsItemBoundingRect << true << false; |
|
684 |
QTest::newRow("32") << QRectF(0, 0, 100, 100) << QRectF(89, 89, 10, 10) << Qt::IntersectsItemBoundingRect << true << false; |
|
685 |
||
686 |
// This rect does not contain the shape nor the bounding rect |
|
687 |
QTest::newRow("33") << QRectF(0, 0, 100, 100) << QRectF(5, 5, 90, 90) << Qt::ContainsItemShape << false << false; |
|
688 |
QTest::newRow("34") << QRectF(0, 0, 100, 100) << QRectF(5, 5, 90, 90) << Qt::ContainsItemBoundingRect << false << false; |
|
689 |
||
690 |
// It will, however, intersect with both |
|
691 |
QTest::newRow("35") << QRectF(0, 0, 100, 100) << QRectF(5, 5, 90, 90) << Qt::IntersectsItemShape << true << true; |
|
692 |
QTest::newRow("36") << QRectF(0, 0, 100, 100) << QRectF(5, 5, 90, 90) << Qt::IntersectsItemBoundingRect << true << true; |
|
693 |
||
694 |
// A rect that contains the whole ellipse will both contain and intersect |
|
695 |
// with both the ellipse's shape and bounding rect. |
|
696 |
QTest::newRow("37") << QRectF(0, 0, 100, 100) << QRectF(-5, -5, 110, 110) << Qt::IntersectsItemBoundingRect << true << true; |
|
697 |
QTest::newRow("38") << QRectF(0, 0, 100, 100) << QRectF(-5, -5, 110, 110) << Qt::IntersectsItemShape << true << true; |
|
698 |
QTest::newRow("39") << QRectF(0, 0, 100, 100) << QRectF(-5, -5, 110, 110) << Qt::ContainsItemBoundingRect << true << false; |
|
699 |
QTest::newRow("40") << QRectF(0, 0, 100, 100) << QRectF(-5, -5, 110, 110) << Qt::ContainsItemShape << true << false; |
|
700 |
||
701 |
// A rect that is fully contained within the ellipse will intersect only |
|
702 |
QTest::newRow("41") << QRectF(0, 0, 100, 100) << QRectF(40, 40, 20, 20) << Qt::ContainsItemShape << false << false; |
|
703 |
QTest::newRow("42") << QRectF(0, 0, 100, 100) << QRectF(40, 40, 20, 20) << Qt::ContainsItemBoundingRect << false << false; |
|
704 |
QTest::newRow("43") << QRectF(0, 0, 100, 100) << QRectF(40, 40, 20, 20) << Qt::IntersectsItemShape << true << true; |
|
705 |
QTest::newRow("44") << QRectF(0, 0, 100, 100) << QRectF(40, 40, 20, 20) << Qt::IntersectsItemBoundingRect << true << true; |
|
706 |
} |
|
707 |
||
708 |
void tst_QGraphicsScene::items_QRectF_2() |
|
709 |
{ |
|
710 |
QFETCH(QRectF, ellipseRect); |
|
711 |
QFETCH(QRectF, sceneRect); |
|
712 |
QFETCH(Qt::ItemSelectionMode, selectionMode); |
|
713 |
QFETCH(bool, contained); |
|
714 |
QFETCH(bool, containedRotated); |
|
715 |
||
716 |
QGraphicsScene scene; |
|
717 |
QGraphicsItem *item = scene.addEllipse(ellipseRect); |
|
718 |
||
719 |
QCOMPARE(!scene.items(sceneRect, selectionMode).isEmpty(), contained); |
|
720 |
item->rotate(45); |
|
721 |
QCOMPARE(!scene.items(sceneRect, selectionMode).isEmpty(), containedRotated); |
|
722 |
} |
|
723 |
||
724 |
void tst_QGraphicsScene::items_QPolygonF() |
|
725 |
{ |
|
726 |
QGraphicsScene scene; |
|
727 |
QGraphicsItem *item1 = scene.addRect(QRectF(-10, -10, 10, 10)); |
|
728 |
QGraphicsItem *item2 = scene.addRect(QRectF(10, -10, 10, 10)); |
|
729 |
QGraphicsItem *item3 = scene.addRect(QRectF(10, 10, 10, 10)); |
|
730 |
QGraphicsItem *item4 = scene.addRect(QRectF(-10, 10, 10, 10)); |
|
731 |
||
732 |
item1->setZValue(0); |
|
733 |
item2->setZValue(1); |
|
734 |
item3->setZValue(2); |
|
735 |
item4->setZValue(3); |
|
736 |
||
737 |
QPolygonF poly1(item1->boundingRect()); |
|
738 |
QPolygonF poly2(item2->boundingRect()); |
|
739 |
QPolygonF poly3(item3->boundingRect()); |
|
740 |
QPolygonF poly4(item4->boundingRect()); |
|
741 |
||
742 |
QCOMPARE(scene.items(poly1), QList<QGraphicsItem *>() << item1); |
|
743 |
QCOMPARE(scene.items(poly2), QList<QGraphicsItem *>() << item2); |
|
744 |
QCOMPARE(scene.items(poly3), QList<QGraphicsItem *>() << item3); |
|
745 |
QCOMPARE(scene.items(poly4), QList<QGraphicsItem *>() << item4); |
|
746 |
||
747 |
poly1 = QPolygonF(QRectF(-10, -10, 1, 1)); |
|
748 |
poly2 = QPolygonF(QRectF(10, -10, 1, 1)); |
|
749 |
poly3 = QPolygonF(QRectF(10, 10, 1, 1)); |
|
750 |
poly4 = QPolygonF(QRectF(-10, 10, 1, 1)); |
|
751 |
||
752 |
QCOMPARE(scene.items(poly1), QList<QGraphicsItem *>() << item1); |
|
753 |
QCOMPARE(scene.items(poly2), QList<QGraphicsItem *>() << item2); |
|
754 |
QCOMPARE(scene.items(poly3), QList<QGraphicsItem *>() << item3); |
|
755 |
QCOMPARE(scene.items(poly4), QList<QGraphicsItem *>() << item4); |
|
756 |
||
757 |
poly1 = QPolygonF(QRectF(-10, -10, 40, 10)); |
|
758 |
poly2 = QPolygonF(QRectF(-10, 10, 40, 10)); |
|
759 |
||
760 |
QCOMPARE(scene.items(poly1), QList<QGraphicsItem *>() << item2 << item1); |
|
761 |
QCOMPARE(scene.items(poly2), QList<QGraphicsItem *>() << item4 << item3); |
|
762 |
||
763 |
item1->setZValue(3); |
|
764 |
item2->setZValue(2); |
|
765 |
item3->setZValue(1); |
|
766 |
item4->setZValue(0); |
|
767 |
||
768 |
QCOMPARE(scene.items(poly1), QList<QGraphicsItem *>() << item1 << item2); |
|
769 |
QCOMPARE(scene.items(poly2), QList<QGraphicsItem *>() << item3 << item4); |
|
770 |
} |
|
771 |
||
772 |
void tst_QGraphicsScene::items_QPolygonF_2() |
|
773 |
{ |
|
774 |
QGraphicsScene scene; |
|
775 |
QGraphicsItem *ellipse = scene.addEllipse(QRectF(0, 0, 100, 100)); |
|
776 |
||
777 |
// None of the rects contain the ellipse's shape nor bounding rect |
|
778 |
QVERIFY(scene.items(QPolygonF(QRectF(1, 1, 10, 10)), Qt::ContainsItemShape).isEmpty()); |
|
779 |
QVERIFY(scene.items(QPolygonF(QRectF(1, 89, 10, 10)), Qt::ContainsItemShape).isEmpty()); |
|
780 |
QVERIFY(scene.items(QPolygonF(QRectF(89, 1, 10, 10)), Qt::ContainsItemShape).isEmpty()); |
|
781 |
QVERIFY(scene.items(QPolygonF(QRectF(89, 89, 10, 10)), Qt::ContainsItemShape).isEmpty()); |
|
782 |
QVERIFY(scene.items(QPolygonF(QRectF(1, 1, 10, 10)), Qt::ContainsItemBoundingRect).isEmpty()); |
|
783 |
QVERIFY(scene.items(QPolygonF(QRectF(1, 89, 10, 10)), Qt::ContainsItemBoundingRect).isEmpty()); |
|
784 |
QVERIFY(scene.items(QPolygonF(QRectF(89, 1, 10, 10)), Qt::ContainsItemBoundingRect).isEmpty()); |
|
785 |
QVERIFY(scene.items(QPolygonF(QRectF(89, 89, 10, 10)), Qt::ContainsItemBoundingRect).isEmpty()); |
|
786 |
||
787 |
// None intersects with the item's shape, but they all intersects with the |
|
788 |
// item's bounding rect. |
|
789 |
QVERIFY(scene.items(QPolygonF(QRectF(1, 1, 10, 10)), Qt::IntersectsItemShape).isEmpty()); |
|
790 |
QVERIFY(scene.items(QPolygonF(QRectF(1, 89, 10, 10)), Qt::IntersectsItemShape).isEmpty()); |
|
791 |
QVERIFY(scene.items(QPolygonF(QRectF(89, 1, 10, 10)), Qt::IntersectsItemShape).isEmpty()); |
|
792 |
QVERIFY(scene.items(QPolygonF(QRectF(89, 89, 10, 10)), Qt::IntersectsItemShape).isEmpty()); |
|
793 |
QCOMPARE(scene.items(QPolygonF(QRectF(1, 1, 10, 10)), Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
794 |
QCOMPARE(scene.items(QPolygonF(QRectF(1, 89, 10, 10)), Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
795 |
QCOMPARE(scene.items(QPolygonF(QRectF(89, 1, 10, 10)), Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
796 |
QCOMPARE(scene.items(QPolygonF(QRectF(89, 89, 10, 10)), Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
797 |
||
798 |
// This rect does not contain the shape nor the bounding rect |
|
799 |
QVERIFY(scene.items(QPolygonF(QRectF(5, 5, 90, 90)), Qt::ContainsItemShape).isEmpty()); |
|
800 |
QVERIFY(scene.items(QPolygonF(QRectF(5, 5, 90, 90)), Qt::ContainsItemBoundingRect).isEmpty()); |
|
801 |
||
802 |
// It will, however, intersect with both |
|
803 |
QCOMPARE(scene.items(QPolygonF(QRectF(5, 5, 90, 90)), Qt::IntersectsItemShape).first(), ellipse); |
|
804 |
QCOMPARE(scene.items(QPolygonF(QRectF(5, 5, 90, 90)), Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
805 |
||
806 |
// A rect that contains the whole ellipse will both contain and intersect |
|
807 |
// with both the ellipse's shape and bounding rect. |
|
808 |
QCOMPARE(scene.items(QPolygonF(QRectF(-5, -5, 110, 110)), Qt::IntersectsItemShape).first(), ellipse); |
|
809 |
QCOMPARE(scene.items(QPolygonF(QRectF(-5, -5, 110, 110)), Qt::ContainsItemShape).first(), ellipse); |
|
810 |
QCOMPARE(scene.items(QPolygonF(QRectF(-5, -5, 110, 110)), Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
811 |
QCOMPARE(scene.items(QPolygonF(QRectF(-5, -5, 110, 110)), Qt::ContainsItemBoundingRect).first(), ellipse); |
|
812 |
} |
|
813 |
||
814 |
void tst_QGraphicsScene::items_QPainterPath() |
|
815 |
{ |
|
816 |
QGraphicsScene scene; |
|
817 |
QGraphicsItem *item1 = scene.addRect(QRectF(-10, -10, 10, 10)); |
|
818 |
QGraphicsItem *item2 = scene.addRect(QRectF(10, -10, 10, 10)); |
|
819 |
QGraphicsItem *item3 = scene.addRect(QRectF(10, 10, 10, 10)); |
|
820 |
QGraphicsItem *item4 = scene.addRect(QRectF(-10, 10, 10, 10)); |
|
821 |
||
822 |
item1->setZValue(0); |
|
823 |
item2->setZValue(1); |
|
824 |
item3->setZValue(2); |
|
825 |
item4->setZValue(3); |
|
826 |
||
827 |
QPainterPath path1; path1.addEllipse(item1->boundingRect()); |
|
828 |
QPainterPath path2; path2.addEllipse(item2->boundingRect()); |
|
829 |
QPainterPath path3; path3.addEllipse(item3->boundingRect()); |
|
830 |
QPainterPath path4; path4.addEllipse(item4->boundingRect()); |
|
831 |
||
832 |
QCOMPARE(scene.items(path1), QList<QGraphicsItem *>() << item1); |
|
833 |
QCOMPARE(scene.items(path2), QList<QGraphicsItem *>() << item2); |
|
834 |
QCOMPARE(scene.items(path3), QList<QGraphicsItem *>() << item3); |
|
835 |
QCOMPARE(scene.items(path4), QList<QGraphicsItem *>() << item4); |
|
836 |
||
837 |
path1 = QPainterPath(); path1.addEllipse(QRectF(-10, -10, 1, 1)); |
|
838 |
path2 = QPainterPath(); path2.addEllipse(QRectF(10, -10, 1, 1)); |
|
839 |
path3 = QPainterPath(); path3.addEllipse(QRectF(10, 10, 1, 1)); |
|
840 |
path4 = QPainterPath(); path4.addEllipse(QRectF(-10, 10, 1, 1)); |
|
841 |
||
842 |
QCOMPARE(scene.items(path1), QList<QGraphicsItem *>() << item1); |
|
843 |
QCOMPARE(scene.items(path2), QList<QGraphicsItem *>() << item2); |
|
844 |
QCOMPARE(scene.items(path3), QList<QGraphicsItem *>() << item3); |
|
845 |
QCOMPARE(scene.items(path4), QList<QGraphicsItem *>() << item4); |
|
846 |
||
847 |
path1 = QPainterPath(); path1.addRect(QRectF(-10, -10, 40, 10)); |
|
848 |
path2 = QPainterPath(); path2.addRect(QRectF(-10, 10, 40, 10)); |
|
849 |
||
850 |
QCOMPARE(scene.items(path1), QList<QGraphicsItem *>() << item2 << item1); |
|
851 |
QCOMPARE(scene.items(path2), QList<QGraphicsItem *>() << item4 << item3); |
|
852 |
||
853 |
item1->setZValue(3); |
|
854 |
item2->setZValue(2); |
|
855 |
item3->setZValue(1); |
|
856 |
item4->setZValue(0); |
|
857 |
||
858 |
QCOMPARE(scene.items(path1), QList<QGraphicsItem *>() << item1 << item2); |
|
859 |
QCOMPARE(scene.items(path2), QList<QGraphicsItem *>() << item3 << item4); |
|
860 |
} |
|
861 |
||
862 |
void tst_QGraphicsScene::items_QPainterPath_2() |
|
863 |
{ |
|
864 |
QGraphicsScene scene; |
|
865 |
QGraphicsItem *ellipse = scene.addEllipse(QRectF(0, 0, 100, 100)); |
|
866 |
||
867 |
QPainterPath p1; p1.addRect(QRectF(1, 1, 10, 10)); |
|
868 |
QPainterPath p2; p2.addRect(QRectF(1, 89, 10, 10)); |
|
869 |
QPainterPath p3; p3.addRect(QRectF(89, 1, 10, 10)); |
|
870 |
QPainterPath p4; p4.addRect(QRectF(89, 89, 10, 10)); |
|
871 |
||
872 |
// None of the rects contain the ellipse's shape nor bounding rect |
|
873 |
QVERIFY(scene.items(p1, Qt::ContainsItemShape).isEmpty()); |
|
874 |
QVERIFY(scene.items(p2, Qt::ContainsItemShape).isEmpty()); |
|
875 |
QVERIFY(scene.items(p3, Qt::ContainsItemShape).isEmpty()); |
|
876 |
QVERIFY(scene.items(p4, Qt::ContainsItemShape).isEmpty()); |
|
877 |
QVERIFY(scene.items(p1, Qt::ContainsItemBoundingRect).isEmpty()); |
|
878 |
QVERIFY(scene.items(p2, Qt::ContainsItemBoundingRect).isEmpty()); |
|
879 |
QVERIFY(scene.items(p3, Qt::ContainsItemBoundingRect).isEmpty()); |
|
880 |
QVERIFY(scene.items(p4, Qt::ContainsItemBoundingRect).isEmpty()); |
|
881 |
||
882 |
// None intersects with the item's shape, but they all intersects with the |
|
883 |
// item's bounding rect. |
|
884 |
QVERIFY(scene.items(p1, Qt::IntersectsItemShape).isEmpty()); |
|
885 |
QVERIFY(scene.items(p2, Qt::IntersectsItemShape).isEmpty()); |
|
886 |
QVERIFY(scene.items(p3, Qt::IntersectsItemShape).isEmpty()); |
|
887 |
QVERIFY(scene.items(p4, Qt::IntersectsItemShape).isEmpty()); |
|
888 |
QCOMPARE(scene.items(p1, Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
889 |
QCOMPARE(scene.items(p2, Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
890 |
QCOMPARE(scene.items(p3, Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
891 |
QCOMPARE(scene.items(p4, Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
892 |
||
893 |
QPainterPath p5; |
|
894 |
p5.addRect(QRectF(5, 5, 90, 90)); |
|
895 |
||
896 |
// This rect does not contain the shape nor the bounding rect |
|
897 |
QVERIFY(scene.items(p5, Qt::ContainsItemShape).isEmpty()); |
|
898 |
QVERIFY(scene.items(p5, Qt::ContainsItemBoundingRect).isEmpty()); |
|
899 |
||
900 |
// It will, however, intersect with both |
|
901 |
QCOMPARE(scene.items(p5, Qt::IntersectsItemShape).first(), ellipse); |
|
902 |
QCOMPARE(scene.items(p5, Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
903 |
||
904 |
QPainterPath p6; |
|
905 |
p6.addRect(QRectF(-5, -5, 110, 110)); |
|
906 |
||
907 |
// A rect that contains the whole ellipse will both contain and intersect |
|
908 |
// with both the ellipse's shape and bounding rect. |
|
909 |
QCOMPARE(scene.items(p6, Qt::IntersectsItemShape).first(), ellipse); |
|
910 |
QCOMPARE(scene.items(p6, Qt::ContainsItemShape).first(), ellipse); |
|
911 |
QCOMPARE(scene.items(p6, Qt::IntersectsItemBoundingRect).first(), ellipse); |
|
912 |
QCOMPARE(scene.items(p6, Qt::ContainsItemBoundingRect).first(), ellipse); |
|
913 |
} |
|
914 |
||
915 |
void tst_QGraphicsScene::selection() |
|
916 |
{ |
|
917 |
// ### This test is difficult to make work for all platforms; instead, a |
|
918 |
// hand crafted data set would make it stable. Its behavior is thoroughly |
|
919 |
// covered by other tests. Todo: Fix this test. |
|
920 |
||
921 |
/* |
|
922 |
QGraphicsScene scene; |
|
923 |
QMap<QGraphicsItem *, int> itemIndexes; |
|
924 |
for (int i = 0; i < 256; ++i) { |
|
925 |
QPainterPath path; |
|
926 |
path.addRect(randomX[i], randomY[i], 25, 25); |
|
927 |
||
928 |
QGraphicsPathItem *pathItem = scene.addPath(path); |
|
929 |
pathItem->setFlag(QGraphicsItem::ItemIsSelectable); |
|
930 |
itemIndexes.insert(pathItem, i); |
|
931 |
} |
|
932 |
||
933 |
#if 0 |
|
934 |
// Write data |
|
935 |
QFile::remove("graphicsScene_selection.data"); |
|
936 |
QFile file("graphicsScene_selection.data"); |
|
937 |
if (!file.open(QFile::WriteOnly)) |
|
938 |
QFAIL("Unable to generate data file graphicsScene_selection.data"); |
|
939 |
QDataStream stream(&file); |
|
940 |
for (qreal y = -1000; y < 1000; y += 33) { |
|
941 |
for (qreal x = -1000; x < 1000; x += 33) { |
|
942 |
for (qreal size = 1; size < 200; size += 33) { |
|
943 |
QPainterPath path; |
|
944 |
path.addRect(QRectF(x, y, size, size)); |
|
945 |
scene.setSelectionArea(path); |
|
946 |
QCOMPARE(scene.selectionArea(), path); |
|
947 |
||
948 |
QList<int> indexes; |
|
949 |
foreach (QGraphicsItem *item, scene.selectedItems()) |
|
950 |
indexes << itemIndexes.value(item); |
|
951 |
||
952 |
stream << x << y << size << indexes; |
|
953 |
} |
|
954 |
} |
|
955 |
} |
|
956 |
#else |
|
957 |
// Read data |
|
958 |
QFile file("graphicsScene_selection.data"); |
|
959 |
if (!file.open(QFile::ReadOnly)) |
|
960 |
QFAIL("Unable to load data file graphicsScene_selection.data"); |
|
961 |
||
962 |
QDataStream stream(&file); |
|
963 |
||
964 |
while (!stream.atEnd()) { |
|
965 |
QList<int> expectedIndexes; |
|
966 |
||
967 |
qreal x, y, size; |
|
968 |
stream >> x >> y >> size >> expectedIndexes; |
|
969 |
||
970 |
QPainterPath path; |
|
971 |
path.addRect(QRectF(x, y, size, size)); |
|
972 |
scene.setSelectionArea(path); |
|
973 |
QCOMPARE(scene.selectionArea(), path); |
|
974 |
||
975 |
QList<int> indexes; |
|
976 |
foreach (QGraphicsItem *item, scene.selectedItems()) |
|
977 |
indexes << itemIndexes.value(item); |
|
978 |
||
979 |
qSort(indexes); |
|
980 |
qSort(expectedIndexes); |
|
981 |
||
982 |
QCOMPARE(indexes, expectedIndexes); |
|
983 |
||
984 |
scene.clearSelection(); |
|
985 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
986 |
} |
|
987 |
#endif |
|
988 |
*/ |
|
989 |
} |
|
990 |
||
991 |
class CustomView : public QGraphicsView |
|
992 |
{ |
|
993 |
public: |
|
994 |
CustomView() : repaints(0) |
|
995 |
{ } |
|
996 |
||
997 |
int repaints; |
|
998 |
protected: |
|
999 |
void paintEvent(QPaintEvent *event) |
|
1000 |
{ |
|
1001 |
++repaints; |
|
1002 |
QGraphicsView::paintEvent(event); |
|
1003 |
} |
|
1004 |
}; |
|
1005 |
||
1006 |
void tst_QGraphicsScene::selectionChanged() |
|
1007 |
{ |
|
1008 |
QGraphicsScene scene(0, 0, 1000, 1000); |
|
1009 |
QSignalSpy spy(&scene, SIGNAL(selectionChanged())); |
|
1010 |
QCOMPARE(spy.count(), 0); |
|
1011 |
||
1012 |
QPainterPath path; |
|
1013 |
path.addRect(scene.sceneRect()); |
|
1014 |
QCOMPARE(scene.selectionArea(), QPainterPath()); |
|
1015 |
scene.setSelectionArea(path); |
|
1016 |
QCOMPARE(scene.selectionArea(), path); |
|
1017 |
QCOMPARE(spy.count(), 0); // selection didn't change |
|
1018 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
1019 |
||
1020 |
QGraphicsItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); |
|
1021 |
QCOMPARE(spy.count(), 0); // selection didn't change |
|
1022 |
||
1023 |
rect->setSelected(true); |
|
1024 |
QVERIFY(!rect->isSelected()); |
|
1025 |
QCOMPARE(spy.count(), 0); // selection didn't change, item isn't selectable |
|
1026 |
||
1027 |
rect->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1028 |
rect->setSelected(true); |
|
1029 |
QVERIFY(rect->isSelected()); |
|
1030 |
QCOMPARE(spy.count(), 1); // selection changed |
|
1031 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << rect); |
|
1032 |
||
1033 |
rect->setSelected(false); |
|
1034 |
QVERIFY(!rect->isSelected()); |
|
1035 |
QCOMPARE(spy.count(), 2); // selection changed |
|
1036 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
1037 |
||
1038 |
QGraphicsEllipseItem *parentItem = new QGraphicsEllipseItem(QRectF(0, 0, 100, 100)); |
|
1039 |
QGraphicsEllipseItem *childItem = new QGraphicsEllipseItem(QRectF(0, 0, 100, 100), parentItem); |
|
1040 |
QGraphicsEllipseItem *grandChildItem = new QGraphicsEllipseItem(QRectF(0, 0, 100, 100), childItem); |
|
1041 |
grandChildItem->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1042 |
grandChildItem->setSelected(true); |
|
1043 |
grandChildItem->setSelected(false); |
|
1044 |
grandChildItem->setSelected(true); |
|
1045 |
scene.addItem(parentItem); |
|
1046 |
||
1047 |
QCOMPARE(spy.count(), 3); // the grandchild was added, so the selection changed once |
|
1048 |
||
1049 |
scene.removeItem(parentItem); |
|
1050 |
QCOMPARE(spy.count(), 4); // the grandchild was removed, so the selection changed |
|
1051 |
||
1052 |
rect->setSelected(true); |
|
1053 |
QCOMPARE(spy.count(), 5); // the rect was reselected, so the selection changed |
|
1054 |
||
1055 |
scene.clearSelection(); |
|
1056 |
QCOMPARE(spy.count(), 6); // the scene selection was cleared |
|
1057 |
||
1058 |
rect->setSelected(true); |
|
1059 |
QCOMPARE(spy.count(), 7); // the rect was reselected, so the selection changed |
|
1060 |
||
1061 |
rect->setFlag(QGraphicsItem::ItemIsSelectable, false); |
|
1062 |
QCOMPARE(spy.count(), 8); // the rect was unselected, so the selection changed |
|
1063 |
||
1064 |
rect->setSelected(true); |
|
1065 |
QCOMPARE(spy.count(), 8); // the rect is not longer selectable, so the selection does not change |
|
1066 |
||
1067 |
||
1068 |
rect->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
1069 |
rect->setSelected(true); |
|
1070 |
QCOMPARE(spy.count(), 9); // the rect is again selectable, so the selection changed |
|
1071 |
||
1072 |
delete rect; |
|
1073 |
QCOMPARE(spy.count(), 10); // a selected item was deleted; selection changed |
|
1074 |
} |
|
1075 |
||
1076 |
void tst_QGraphicsScene::selectionChanged2() |
|
1077 |
{ |
|
1078 |
QGraphicsScene scene; |
|
1079 |
QSignalSpy spy(&scene, SIGNAL(selectionChanged())); |
|
1080 |
||
1081 |
QGraphicsItem *item1 = scene.addRect(0, 0, 100, 100); |
|
1082 |
QGraphicsItem *item2 = scene.addRect(100, 100, 100, 100); |
|
1083 |
item1->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1084 |
item2->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1085 |
||
1086 |
QCOMPARE(spy.count(), 0); |
|
1087 |
{ |
|
1088 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1089 |
event.setScenePos(QPointF(50, 50)); |
|
1090 |
event.setButton(Qt::LeftButton); |
|
1091 |
qApp->sendEvent(&scene, &event); |
|
1092 |
} |
|
1093 |
{ |
|
1094 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
1095 |
event.setScenePos(QPointF(50, 50)); |
|
1096 |
event.setButton(Qt::LeftButton); |
|
1097 |
qApp->sendEvent(&scene, &event); |
|
1098 |
} |
|
1099 |
QVERIFY(item1->isSelected()); |
|
1100 |
QVERIFY(!item2->isSelected()); |
|
1101 |
QCOMPARE(spy.count(), 1); |
|
1102 |
{ |
|
1103 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1104 |
event.setScenePos(QPointF(150, 150)); |
|
1105 |
event.setButton(Qt::LeftButton); |
|
1106 |
qApp->sendEvent(&scene, &event); |
|
1107 |
} |
|
1108 |
{ |
|
1109 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
1110 |
event.setScenePos(QPointF(150, 150)); |
|
1111 |
event.setButton(Qt::LeftButton); |
|
1112 |
qApp->sendEvent(&scene, &event); |
|
1113 |
} |
|
1114 |
QVERIFY(!item1->isSelected()); |
|
1115 |
QVERIFY(item2->isSelected()); |
|
1116 |
QCOMPARE(spy.count(), 2); |
|
1117 |
{ |
|
1118 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1119 |
event.setScenePos(QPointF(50, 50)); |
|
1120 |
event.setButton(Qt::LeftButton); |
|
1121 |
event.setModifiers(Qt::ControlModifier); |
|
1122 |
qApp->sendEvent(&scene, &event); |
|
1123 |
} |
|
1124 |
QVERIFY(!item1->isSelected()); |
|
1125 |
QVERIFY(item2->isSelected()); |
|
1126 |
QCOMPARE(spy.count(), 2); |
|
1127 |
{ |
|
1128 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
1129 |
event.setScenePos(QPointF(50, 50)); |
|
1130 |
event.setButton(Qt::LeftButton); |
|
1131 |
qApp->sendEvent(&scene, &event); |
|
1132 |
} |
|
1133 |
QVERIFY(item1->isSelected()); |
|
1134 |
QVERIFY(!item2->isSelected()); |
|
1135 |
QCOMPARE(spy.count(), 3); |
|
1136 |
} |
|
1137 |
||
1138 |
void tst_QGraphicsScene::addItem() |
|
1139 |
{ |
|
1140 |
Q_CHECK_PAINTEVENTS |
|
1141 |
{ |
|
1142 |
// 1) Create item, then scene, then add item |
|
1143 |
QGraphicsItem *path = new QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)); |
|
1144 |
QGraphicsScene scene; |
|
1145 |
||
1146 |
CustomView view; |
|
1147 |
view.setScene(&scene); |
|
1148 |
view.show(); |
|
1149 |
#ifdef Q_WS_X11 |
|
1150 |
qt_x11_wait_for_window_manager(&view); |
|
1151 |
#endif |
|
1152 |
qApp->processEvents(); |
|
1153 |
view.repaints = 0; |
|
1154 |
||
1155 |
scene.addItem(path); |
|
1156 |
||
1157 |
// Adding an item should always issue a repaint. |
|
1158 |
qApp->processEvents(); // <- delayed update is called |
|
1159 |
qApp->processEvents(); // <- scene schedules pending update |
|
1160 |
qApp->processEvents(); // <- pending update is sent to view |
|
1161 |
QVERIFY(view.repaints > 0); |
|
1162 |
view.repaints = 0; |
|
1163 |
||
1164 |
QCOMPARE(scene.itemAt(0, 0), path); |
|
1165 |
||
1166 |
QGraphicsItem *path2 = new QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)); |
|
1167 |
path2->setPos(100, 100); |
|
1168 |
||
1169 |
QCOMPARE(scene.itemAt(0, 0), path); |
|
1170 |
QCOMPARE(scene.itemAt(100, 100), (QGraphicsItem *)0); |
|
1171 |
scene.addItem(path2); |
|
1172 |
||
1173 |
// Adding an item should always issue a repaint. |
|
1174 |
qApp->processEvents(); // <- delayed update is called |
|
1175 |
qApp->processEvents(); // <- scene schedules pending update |
|
1176 |
qApp->processEvents(); // <- pending update is sent to view |
|
1177 |
QVERIFY(view.repaints > 0); |
|
1178 |
||
1179 |
QCOMPARE(scene.itemAt(100, 100), path2); |
|
1180 |
} |
|
1181 |
{ |
|
1182 |
// 2) Create scene, then item, then add item |
|
1183 |
QGraphicsScene scene; |
|
1184 |
QGraphicsItem *path = new QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)); |
|
1185 |
scene.addItem(path); |
|
1186 |
||
1187 |
QGraphicsItem *path2 = new QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)); |
|
1188 |
path2->setPos(100, 100); |
|
1189 |
scene.addItem(path2); |
|
1190 |
||
1191 |
QCOMPARE(scene.itemAt(0, 0), path); |
|
1192 |
QCOMPARE(scene.itemAt(100, 100), path2); |
|
1193 |
} |
|
1194 |
} |
|
1195 |
||
1196 |
void tst_QGraphicsScene::addEllipse() |
|
1197 |
{ |
|
1198 |
QGraphicsScene scene; |
|
1199 |
QGraphicsEllipseItem *ellipse = scene.addEllipse(QRectF(-10, -10, 20, 20), |
|
1200 |
QPen(Qt::red), QBrush(Qt::blue)); |
|
1201 |
QCOMPARE(ellipse->pos(), QPointF()); |
|
1202 |
QCOMPARE(ellipse->pen(), QPen(Qt::red)); |
|
1203 |
QCOMPARE(ellipse->brush(), QBrush(Qt::blue)); |
|
1204 |
QCOMPARE(ellipse->rect(), QRectF(-10, -10, 20, 20)); |
|
1205 |
QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)ellipse); |
|
1206 |
QCOMPARE(scene.itemAt(-10, -10), (QGraphicsItem *)0); |
|
1207 |
QCOMPARE(scene.itemAt(-9.9, 0), (QGraphicsItem *)ellipse); |
|
1208 |
QCOMPARE(scene.itemAt(-10, 10), (QGraphicsItem *)0); |
|
1209 |
QCOMPARE(scene.itemAt(0, -9.9), (QGraphicsItem *)ellipse); |
|
1210 |
QCOMPARE(scene.itemAt(0, 9.9), (QGraphicsItem *)ellipse); |
|
1211 |
QCOMPARE(scene.itemAt(10, -10), (QGraphicsItem *)0); |
|
1212 |
QCOMPARE(scene.itemAt(9.9, 0), (QGraphicsItem *)ellipse); |
|
1213 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)0); |
|
1214 |
} |
|
1215 |
||
1216 |
void tst_QGraphicsScene::addLine() |
|
1217 |
{ |
|
1218 |
QGraphicsScene scene; |
|
1219 |
QPen pen(Qt::red); |
|
1220 |
pen.setWidthF(1.0); |
|
1221 |
QGraphicsLineItem *line = scene.addLine(QLineF(-10, -10, 20, 20), |
|
1222 |
pen); |
|
1223 |
QCOMPARE(line->pos(), QPointF()); |
|
1224 |
QCOMPARE(line->pen(), pen); |
|
1225 |
QCOMPARE(line->line(), QLineF(-10, -10, 20, 20)); |
|
1226 |
QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)line); |
|
1227 |
QCOMPARE(scene.itemAt(-10, -10), (QGraphicsItem *)line); |
|
1228 |
QCOMPARE(scene.itemAt(-9.9, 0), (QGraphicsItem *)0); |
|
1229 |
QCOMPARE(scene.itemAt(-10, 10), (QGraphicsItem *)0); |
|
1230 |
QCOMPARE(scene.itemAt(0, -9.9), (QGraphicsItem *)0); |
|
1231 |
QCOMPARE(scene.itemAt(0, 9.9), (QGraphicsItem *)0); |
|
1232 |
QCOMPARE(scene.itemAt(10, -10), (QGraphicsItem *)0); |
|
1233 |
QCOMPARE(scene.itemAt(9.9, 0), (QGraphicsItem *)0); |
|
1234 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)line); |
|
1235 |
} |
|
1236 |
||
1237 |
void tst_QGraphicsScene::addPath() |
|
1238 |
{ |
|
1239 |
QGraphicsScene scene; |
|
1240 |
QPainterPath p; |
|
1241 |
p.addEllipse(QRectF(-10, -10, 20, 20)); |
|
1242 |
p.addEllipse(QRectF(-10, 20, 20, 20)); |
|
1243 |
||
1244 |
QGraphicsPathItem *path = scene.addPath(p, QPen(Qt::red), QBrush(Qt::blue)); |
|
1245 |
QCOMPARE(path->pos(), QPointF()); |
|
1246 |
QCOMPARE(path->pen(), QPen(Qt::red)); |
|
1247 |
QCOMPARE(path->path(), p); |
|
1248 |
QCOMPARE(path->brush(), QBrush(Qt::blue)); |
|
1249 |
QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)path); |
|
1250 |
QCOMPARE(scene.itemAt(-9.9, 0), (QGraphicsItem *)path); |
|
1251 |
QCOMPARE(scene.itemAt(9.9, 0), (QGraphicsItem *)path); |
|
1252 |
QCOMPARE(scene.itemAt(0, -9.9), (QGraphicsItem *)path); |
|
1253 |
QCOMPARE(scene.itemAt(0, 9.9), (QGraphicsItem *)path); |
|
1254 |
QCOMPARE(scene.itemAt(0, 30), (QGraphicsItem *)path); |
|
1255 |
QCOMPARE(scene.itemAt(-9.9, 30), (QGraphicsItem *)path); |
|
1256 |
QCOMPARE(scene.itemAt(9.9, 30), (QGraphicsItem *)path); |
|
1257 |
QCOMPARE(scene.itemAt(0, 20.1), (QGraphicsItem *)path); |
|
1258 |
QCOMPARE(scene.itemAt(0, 39.9), (QGraphicsItem *)path); |
|
1259 |
QCOMPARE(scene.itemAt(-10, -10), (QGraphicsItem *)0); |
|
1260 |
QCOMPARE(scene.itemAt(10, -10), (QGraphicsItem *)0); |
|
1261 |
QCOMPARE(scene.itemAt(-10, 10), (QGraphicsItem *)0); |
|
1262 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)0); |
|
1263 |
QCOMPARE(scene.itemAt(-10, 20), (QGraphicsItem *)0); |
|
1264 |
QCOMPARE(scene.itemAt(10, 20), (QGraphicsItem *)0); |
|
1265 |
if (sizeof(qreal) != sizeof(double)) |
|
1266 |
QWARN("Skipping test because of rounding errors when qreal != double"); |
|
1267 |
else |
|
1268 |
QCOMPARE(scene.itemAt(-10, 30), (QGraphicsItem *)0); |
|
1269 |
QCOMPARE(scene.itemAt(10.1, 30), (QGraphicsItem *)0); |
|
1270 |
} |
|
1271 |
||
1272 |
void tst_QGraphicsScene::addPixmap() |
|
1273 |
{ |
|
1274 |
QGraphicsScene scene; |
|
1275 |
QPixmap pix(":/Ash_European.jpg"); |
|
1276 |
QGraphicsPixmapItem *pixmap = scene.addPixmap(pix); |
|
1277 |
||
1278 |
QCOMPARE(pixmap->pos(), QPointF()); |
|
1279 |
QCOMPARE(pixmap->pixmap(), pix); |
|
1280 |
QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)pixmap); |
|
1281 |
QCOMPARE(scene.itemAt(pix.width() - 1, 0), (QGraphicsItem *)pixmap); |
|
1282 |
QCOMPARE(scene.itemAt(0, pix.height() - 1), (QGraphicsItem *)pixmap); |
|
1283 |
QCOMPARE(scene.itemAt(pix.width() - 1, pix.height() - 1), (QGraphicsItem *)pixmap); |
|
1284 |
QCOMPARE(scene.itemAt(-1, -1), (QGraphicsItem *)0); |
|
1285 |
QCOMPARE(scene.itemAt(pix.width() - 1, -1), (QGraphicsItem *)0); |
|
1286 |
QCOMPARE(scene.itemAt(-1, pix.height() - 1), (QGraphicsItem *)0); |
|
1287 |
QCOMPARE(scene.itemAt(pix.width(), pix.height()), (QGraphicsItem *)0); |
|
1288 |
QCOMPARE(scene.itemAt(0, pix.height()), (QGraphicsItem *)0); |
|
1289 |
QCOMPARE(scene.itemAt(pix.width(), 0), (QGraphicsItem *)0); |
|
1290 |
} |
|
1291 |
||
1292 |
void tst_QGraphicsScene::addRect() |
|
1293 |
{ |
|
1294 |
QGraphicsScene scene; |
|
1295 |
QGraphicsRectItem *rect = scene.addRect(QRectF(-10, -10, 20, 20), |
|
1296 |
QPen(Qt::red), QBrush(Qt::blue)); |
|
1297 |
QCOMPARE(rect->pos(), QPointF()); |
|
1298 |
QCOMPARE(rect->pen(), QPen(Qt::red)); |
|
1299 |
QCOMPARE(rect->brush(), QBrush(Qt::blue)); |
|
1300 |
QCOMPARE(rect->rect(), QRectF(-10, -10, 20, 20)); |
|
1301 |
QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)rect); |
|
1302 |
QCOMPARE(scene.itemAt(-10, -10), (QGraphicsItem *)rect); |
|
1303 |
QCOMPARE(scene.itemAt(-9.9, 0), (QGraphicsItem *)rect); |
|
1304 |
QCOMPARE(scene.itemAt(-10, 10), (QGraphicsItem *)0); |
|
1305 |
QCOMPARE(scene.itemAt(0, -9.9), (QGraphicsItem *)rect); |
|
1306 |
QCOMPARE(scene.itemAt(0, 9.9), (QGraphicsItem *)rect); |
|
1307 |
QCOMPARE(scene.itemAt(10, -10), (QGraphicsItem *)0); |
|
1308 |
QCOMPARE(scene.itemAt(9.9, 0), (QGraphicsItem *)rect); |
|
1309 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)0); |
|
1310 |
} |
|
1311 |
||
1312 |
void tst_QGraphicsScene::addText() |
|
1313 |
{ |
|
1314 |
QGraphicsScene scene; |
|
1315 |
QGraphicsTextItem *text = scene.addText("Qt", QFont()); |
|
1316 |
QCOMPARE(text->pos(), QPointF()); |
|
1317 |
QCOMPARE(text->toPlainText(), QString("Qt")); |
|
1318 |
QCOMPARE(text->font(), QFont()); |
|
1319 |
} |
|
1320 |
||
1321 |
void tst_QGraphicsScene::removeItem() |
|
1322 |
{ |
|
1323 |
#if defined(Q_OS_WINCE) && !defined(GWES_ICONCURS) |
|
1324 |
QSKIP("No mouse cursor support", SkipAll); |
|
1325 |
#endif |
|
1326 |
QGraphicsScene scene; |
|
1327 |
QGraphicsItem *item = scene.addRect(QRectF(0, 0, 10, 10)); |
|
1328 |
QCOMPARE(scene.itemAt(0, 0), item); // forces indexing |
|
1329 |
scene.removeItem(item); |
|
1330 |
QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)0); |
|
1331 |
delete item; |
|
1332 |
||
1333 |
QGraphicsItem *item2 = scene.addRect(QRectF(0, 0, 10, 10)); |
|
1334 |
item2->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1335 |
QCOMPARE(scene.itemAt(0, 0), item2); |
|
1336 |
||
1337 |
// Removing a selected item |
|
1338 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
1339 |
item2->setSelected(true); |
|
1340 |
QVERIFY(scene.selectedItems().contains(item2)); |
|
1341 |
scene.removeItem(item2); |
|
1342 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
1343 |
||
1344 |
// Check that we are in a state that can receive paint events |
|
1345 |
// (i.e., not logged out on Windows). |
|
1346 |
Q_CHECK_PAINTEVENTS |
|
1347 |
||
1348 |
// Removing a hovered item |
|
1349 |
HoverItem *hoverItem = new HoverItem; |
|
1350 |
scene.addItem(hoverItem); |
|
1351 |
scene.setSceneRect(-50, -50, 100, 100); |
|
1352 |
||
1353 |
QGraphicsView view(&scene); |
|
1354 |
view.setFixedSize(150, 150); |
|
1355 |
view.show(); |
|
1356 |
#ifdef Q_WS_X11 |
|
1357 |
qt_x11_wait_for_window_manager(&view); |
|
1358 |
#endif |
|
1359 |
QTest::mouseMove(view.viewport(), QPoint(-1, -1)); |
|
1360 |
{ |
|
1361 |
QMouseEvent moveEvent(QEvent::MouseMove, view.mapFromScene(hoverItem->scenePos() + QPointF(20, 20)), Qt::NoButton, 0, 0); |
|
1362 |
QApplication::sendEvent(view.viewport(), &moveEvent); |
|
1363 |
} |
|
1364 |
qApp->processEvents(); // update |
|
1365 |
qApp->processEvents(); // draw |
|
1366 |
QVERIFY(!hoverItem->isHovered); |
|
1367 |
||
1368 |
{ |
|
1369 |
QTest::qWait(250); |
|
1370 |
QTest::mouseMove(view.viewport(), view.mapFromScene(hoverItem->scenePos()), Qt::NoButton); |
|
1371 |
QTest::qWait(10); |
|
1372 |
QMouseEvent moveEvent(QEvent::MouseMove, view.mapFromScene(hoverItem->scenePos()), Qt::NoButton, 0, 0); |
|
1373 |
QApplication::sendEvent(view.viewport(), &moveEvent); |
|
1374 |
} |
|
1375 |
qApp->processEvents(); // update |
|
1376 |
qApp->processEvents(); // draw |
|
1377 |
QVERIFY(hoverItem->isHovered); |
|
1378 |
||
1379 |
scene.removeItem(hoverItem); |
|
1380 |
hoverItem->setAcceptsHoverEvents(false); |
|
1381 |
scene.addItem(hoverItem); |
|
1382 |
qApp->processEvents(); // <- delayed update is called |
|
1383 |
qApp->processEvents(); // <- scene schedules pending update |
|
1384 |
qApp->processEvents(); // <- pending update is sent to view |
|
1385 |
QVERIFY(!hoverItem->isHovered); |
|
1386 |
} |
|
1387 |
||
1388 |
void tst_QGraphicsScene::focusItem() |
|
1389 |
{ |
|
1390 |
QGraphicsScene scene; |
|
1391 |
QEvent activate(QEvent::WindowActivate); |
|
1392 |
QApplication::sendEvent(&scene, &activate); |
|
1393 |
||
1394 |
QVERIFY(!scene.focusItem()); |
|
1395 |
QGraphicsItem *item = scene.addText("Qt"); |
|
1396 |
QVERIFY(!scene.focusItem()); |
|
1397 |
item->setFocus(); |
|
1398 |
QVERIFY(!scene.focusItem()); |
|
1399 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1400 |
QVERIFY(!scene.focusItem()); |
|
1401 |
item->setFocus(); |
|
1402 |
QCOMPARE(scene.focusItem(), item); |
|
1403 |
||
1404 |
QFocusEvent focusOut(QEvent::FocusOut); |
|
1405 |
QApplication::sendEvent(&scene, &focusOut); |
|
1406 |
||
1407 |
QVERIFY(!scene.focusItem()); |
|
1408 |
||
1409 |
QFocusEvent focusIn(QEvent::FocusIn); |
|
1410 |
QApplication::sendEvent(&scene, &focusIn); |
|
1411 |
QCOMPARE(scene.focusItem(), item); |
|
1412 |
||
1413 |
QGraphicsItem *item2 = scene.addText("Qt"); |
|
1414 |
item2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1415 |
QCOMPARE(scene.focusItem(), item); |
|
1416 |
||
1417 |
item2->setFocus(); |
|
1418 |
QCOMPARE(scene.focusItem(), item2); |
|
1419 |
item->setFocus(); |
|
1420 |
QCOMPARE(scene.focusItem(), item); |
|
1421 |
||
1422 |
item2->setFocus(); |
|
1423 |
QCOMPARE(scene.focusItem(), item2); |
|
1424 |
QApplication::sendEvent(&scene, &focusOut); |
|
1425 |
QVERIFY(!scene.hasFocus()); |
|
1426 |
QVERIFY(!scene.focusItem()); |
|
1427 |
QApplication::sendEvent(&scene, &focusIn); |
|
1428 |
QCOMPARE(scene.focusItem(), item2); |
|
1429 |
||
1430 |
QApplication::sendEvent(&scene, &focusOut); |
|
1431 |
||
1432 |
QVERIFY(!scene.focusItem()); |
|
1433 |
scene.removeItem(item2); |
|
1434 |
delete item2; |
|
1435 |
||
1436 |
QApplication::sendEvent(&scene, &focusIn); |
|
1437 |
QVERIFY(!scene.focusItem()); |
|
1438 |
} |
|
1439 |
||
1440 |
class FocusItem : public QGraphicsTextItem |
|
1441 |
{ |
|
1442 |
protected: |
|
1443 |
void focusOutEvent(QFocusEvent *) |
|
1444 |
{ |
|
1445 |
QVERIFY(!scene()->focusItem()); |
|
1446 |
} |
|
1447 |
}; |
|
1448 |
||
1449 |
void tst_QGraphicsScene::focusItemLostFocus() |
|
1450 |
{ |
|
1451 |
QGraphicsScene scene; |
|
1452 |
QEvent activate(QEvent::WindowActivate); |
|
1453 |
QApplication::sendEvent(&scene, &activate); |
|
1454 |
||
1455 |
FocusItem *item = new FocusItem; |
|
1456 |
item->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
1457 |
scene.addItem(item); |
|
1458 |
||
1459 |
item->setFocus(); |
|
1460 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *)item); |
|
1461 |
item->clearFocus(); |
|
1462 |
} |
|
1463 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1464 |
class ClearTestItem : public QGraphicsRectItem |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1465 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1466 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1467 |
ClearTestItem(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1468 |
~ClearTestItem() { qDeleteAll(items); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1469 |
QList<QGraphicsItem *> items; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1470 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1471 |
|
0 | 1472 |
void tst_QGraphicsScene::clear() |
1473 |
{ |
|
1474 |
QGraphicsScene scene; |
|
1475 |
scene.clear(); |
|
1476 |
QVERIFY(scene.items().isEmpty()); |
|
1477 |
scene.addRect(0, 0, 100, 100); |
|
1478 |
QCOMPARE(scene.sceneRect(), QRectF(0, 0, 100, 100)); |
|
1479 |
scene.clear(); |
|
1480 |
QVERIFY(scene.items().isEmpty()); |
|
1481 |
QCOMPARE(scene.sceneRect(), QRectF(0, 0, 100, 100)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1482 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1483 |
ClearTestItem *firstItem = new ClearTestItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1484 |
QGraphicsItem *secondItem = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1485 |
firstItem->items += secondItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1486 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1487 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1488 |
scene.addItem(firstItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1489 |
scene.addItem(secondItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1490 |
QCOMPARE(scene.items().at(0), firstItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1491 |
QCOMPARE(scene.items().at(1), secondItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1492 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1493 |
ClearTestItem *thirdItem = new ClearTestItem(firstItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1494 |
QGraphicsItem *forthItem = new QGraphicsRectItem(firstItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1495 |
thirdItem->items += forthItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1496 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1497 |
// must not crash even if firstItem deletes secondItem |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1498 |
scene.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1499 |
QVERIFY(scene.items().isEmpty()); |
0 | 1500 |
} |
1501 |
||
1502 |
void tst_QGraphicsScene::setFocusItem() |
|
1503 |
{ |
|
1504 |
QGraphicsScene scene; |
|
1505 |
QEvent activate(QEvent::WindowActivate); |
|
1506 |
QApplication::sendEvent(&scene, &activate); |
|
1507 |
||
1508 |
QGraphicsItem *item = scene.addText("Qt"); |
|
1509 |
QVERIFY(!scene.focusItem()); |
|
1510 |
QVERIFY(!scene.hasFocus()); |
|
1511 |
scene.setFocusItem(item); |
|
1512 |
QVERIFY(!scene.hasFocus()); |
|
1513 |
QVERIFY(!scene.focusItem()); |
|
1514 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1515 |
||
1516 |
for (int i = 0; i < 3; ++i) { |
|
1517 |
scene.setFocusItem(item); |
|
1518 |
QVERIFY(scene.hasFocus()); |
|
1519 |
QCOMPARE(scene.focusItem(), item); |
|
1520 |
QVERIFY(item->hasFocus()); |
|
1521 |
} |
|
1522 |
||
1523 |
QGraphicsItem *item2 = scene.addText("Qt"); |
|
1524 |
item2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1525 |
||
1526 |
scene.setFocusItem(item2); |
|
1527 |
QVERIFY(!item->hasFocus()); |
|
1528 |
QVERIFY(item2->hasFocus()); |
|
1529 |
||
1530 |
scene.setFocusItem(item); |
|
1531 |
QVERIFY(item->hasFocus()); |
|
1532 |
QVERIFY(!item2->hasFocus()); |
|
1533 |
||
1534 |
scene.clearFocus(); |
|
1535 |
QVERIFY(!item->hasFocus()); |
|
1536 |
QVERIFY(!item2->hasFocus()); |
|
1537 |
||
1538 |
scene.setFocus(); |
|
1539 |
QVERIFY(item->hasFocus()); |
|
1540 |
QVERIFY(!item2->hasFocus()); |
|
1541 |
||
1542 |
scene.setFocusItem(0); |
|
1543 |
QVERIFY(!item->hasFocus()); |
|
1544 |
QVERIFY(!item2->hasFocus()); |
|
1545 |
||
1546 |
scene.setFocus(); |
|
1547 |
QVERIFY(!item->hasFocus()); |
|
1548 |
QVERIFY(!item2->hasFocus()); |
|
1549 |
} |
|
1550 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1551 |
void tst_QGraphicsScene::setFocusItem_inactive() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1552 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1553 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1554 |
QGraphicsItem *item = scene.addText("Qt"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1555 |
QVERIFY(!scene.focusItem()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1556 |
QVERIFY(!scene.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1557 |
scene.setFocusItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1558 |
QVERIFY(!scene.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1559 |
QVERIFY(!scene.focusItem()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1560 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1561 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1562 |
for (int i = 0; i < 3; ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1563 |
scene.setFocusItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1564 |
QCOMPARE(scene.focusItem(), item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1565 |
QVERIFY(!item->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1566 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1567 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1568 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1569 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1570 |
|
0 | 1571 |
void tst_QGraphicsScene::mouseGrabberItem() |
1572 |
{ |
|
1573 |
QGraphicsScene scene; |
|
1574 |
QVERIFY(!scene.mouseGrabberItem()); |
|
1575 |
||
1576 |
QGraphicsItem *item = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1577 |
item->setFlag(QGraphicsItem::ItemIsMovable); |
|
1578 |
item->setZValue(1); |
|
1579 |
||
1580 |
QGraphicsItem *item2 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1581 |
item2->setFlag(QGraphicsItem::ItemIsMovable); |
|
1582 |
item2->setZValue(0); |
|
1583 |
||
1584 |
for (int i = 0; i < 3; ++i) { |
|
1585 |
item->setPos(0, 0); |
|
1586 |
item2->setPos(0, 0); |
|
1587 |
item->setZValue((i & 1) ? 0 : 1); |
|
1588 |
item2->setZValue((i & 1) ? 1 : 0); |
|
1589 |
QGraphicsItem *topMostItem = (i & 1) ? item2 : item; |
|
1590 |
||
1591 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
1592 |
pressEvent.setButton(Qt::LeftButton); |
|
1593 |
pressEvent.setScenePos(QPointF(0, 0)); |
|
1594 |
pressEvent.setScreenPos(QPoint(100, 100)); |
|
1595 |
||
1596 |
QApplication::sendEvent(&scene, &pressEvent); |
|
1597 |
QCOMPARE(scene.mouseGrabberItem(), topMostItem); |
|
1598 |
||
1599 |
for (int i = 0; i < 1000; ++i) { |
|
1600 |
QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove); |
|
1601 |
moveEvent.setButtons(Qt::LeftButton); |
|
1602 |
moveEvent.setScenePos(QPointF(i * 10, i * 10)); |
|
1603 |
moveEvent.setScreenPos(QPoint(100 + i * 10, 100 + i * 10)); |
|
1604 |
QApplication::sendEvent(&scene, &moveEvent); |
|
1605 |
QCOMPARE(scene.mouseGrabberItem(), topMostItem); |
|
1606 |
||
1607 |
// Geometrical changes should not affect the mouse grabber. |
|
1608 |
item->setZValue(rand() % 500); |
|
1609 |
item2->setZValue(rand() % 500); |
|
1610 |
item->setPos(rand() % 50000, rand() % 50000); |
|
1611 |
item2->setPos(rand() % 50000, rand() % 50000); |
|
1612 |
} |
|
1613 |
||
1614 |
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); |
|
1615 |
releaseEvent.setScenePos(QPointF(10000, 10000)); |
|
1616 |
releaseEvent.setScreenPos(QPoint(1000000, 1000000)); |
|
1617 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
1618 |
QVERIFY(!scene.mouseGrabberItem()); |
|
1619 |
} |
|
1620 |
||
1621 |
// Structural change: deleting the mouse grabber |
|
1622 |
item->setPos(0, 0); |
|
1623 |
item->setZValue(1); |
|
1624 |
item2->setPos(0, 0); |
|
1625 |
item2->setZValue(0); |
|
1626 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
1627 |
pressEvent.setButton(Qt::LeftButton); |
|
1628 |
pressEvent.setScenePos(QPointF(0, 0)); |
|
1629 |
pressEvent.setScreenPos(QPoint(100, 100)); |
|
1630 |
||
1631 |
QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove); |
|
1632 |
moveEvent.setButtons(Qt::LeftButton); |
|
1633 |
moveEvent.setScenePos(QPointF(0, 0)); |
|
1634 |
moveEvent.setScreenPos(QPoint(100, 100)); |
|
1635 |
||
1636 |
QApplication::sendEvent(&scene, &pressEvent); |
|
1637 |
QApplication::sendEvent(&scene, &moveEvent); |
|
1638 |
QCOMPARE(scene.mouseGrabberItem(), item); |
|
1639 |
item->setVisible(false); |
|
1640 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1641 |
QApplication::sendEvent(&scene, &pressEvent); |
|
1642 |
QCOMPARE(scene.mouseGrabberItem(), item2); |
|
1643 |
item2->setVisible(false); |
|
1644 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1645 |
QApplication::sendEvent(&scene, &moveEvent); |
|
1646 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1647 |
item2->setVisible(true); |
|
1648 |
QApplication::sendEvent(&scene, &moveEvent); |
|
1649 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1650 |
QApplication::sendEvent(&scene, &pressEvent); |
|
1651 |
QApplication::sendEvent(&scene, &moveEvent); |
|
1652 |
QCOMPARE(scene.mouseGrabberItem(), item2); |
|
1653 |
scene.removeItem(item2); |
|
1654 |
delete item2; |
|
1655 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1656 |
} |
|
1657 |
||
1658 |
void tst_QGraphicsScene::hoverEvents_siblings() |
|
1659 |
{ |
|
1660 |
Q_CHECK_PAINTEVENTS |
|
1661 |
||
1662 |
QGraphicsScene scene; |
|
1663 |
QGraphicsItem *lastItem = 0; |
|
1664 |
QList<HoverItem *> items; |
|
1665 |
for (int i = 0; i < 15; ++i) { |
|
1666 |
QGraphicsItem *item = new HoverItem; |
|
1667 |
scene.addItem(item); |
|
1668 |
items << (HoverItem *)item; |
|
1669 |
if (lastItem) { |
|
1670 |
item->setPos(lastItem->pos() + QPointF(sin(i / 3.0) * 17, cos(i / 3.0) * 17)); |
|
1671 |
} |
|
1672 |
item->setZValue(i); |
|
1673 |
lastItem = item; |
|
1674 |
} |
|
1675 |
||
1676 |
QGraphicsView view(&scene); |
|
1677 |
view.setRenderHint(QPainter::Antialiasing, true); |
|
1678 |
#if defined(Q_OS_WINCE) |
|
1679 |
view.setMinimumSize(230, 200); |
|
1680 |
#else |
|
1681 |
view.setMinimumSize(400, 300); |
|
1682 |
#endif |
|
1683 |
view.rotate(10); |
|
1684 |
view.scale(1.7, 1.7); |
|
1685 |
view.show(); |
|
1686 |
#ifdef Q_WS_X11 |
|
1687 |
qt_x11_wait_for_window_manager(&view); |
|
1688 |
#endif |
|
1689 |
qApp->setActiveWindow(&view); |
|
1690 |
view.activateWindow(); |
|
1691 |
QTest::qWait(70); |
|
1692 |
||
1693 |
QCursor::setPos(view.mapToGlobal(QPoint(-5, -5))); |
|
1694 |
||
1695 |
QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
1696 |
mouseEvent.setScenePos(QPointF(-1000, -1000)); |
|
1697 |
QApplication::sendEvent(&scene, &mouseEvent); |
|
1698 |
||
1699 |
QTest::qWait(50); |
|
1700 |
||
1701 |
for (int j = 1; j >= 0; --j) { |
|
1702 |
int i = j ? 0 : 14; |
|
1703 |
forever { |
|
1704 |
if (j) |
|
1705 |
QVERIFY(!items.at(i)->isHovered); |
|
1706 |
else |
|
1707 |
QVERIFY(!items.at(i)->isHovered); |
|
1708 |
QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
1709 |
mouseEvent.setScenePos(items.at(i)->mapToScene(0, 0)); |
|
1710 |
QApplication::sendEvent(&scene, &mouseEvent); |
|
1711 |
||
1712 |
qApp->processEvents(); // this posts updates from the scene to the view |
|
1713 |
qApp->processEvents(); // which trigger a repaint here |
|
1714 |
||
1715 |
QTRY_VERIFY(items.at(i)->isHovered); |
|
1716 |
if (j && i > 0) |
|
1717 |
QVERIFY(!items.at(i - 1)->isHovered); |
|
1718 |
if (!j && i < 14) |
|
1719 |
QVERIFY(!items.at(i + 1)->isHovered); |
|
1720 |
i += j ? 1 : -1; |
|
1721 |
if ((j && i == 15) || (!j && i == -1)) |
|
1722 |
break; |
|
1723 |
} |
|
1724 |
||
1725 |
QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
1726 |
mouseEvent.setScenePos(QPointF(-1000, -1000)); |
|
1727 |
QApplication::sendEvent(&scene, &mouseEvent); |
|
1728 |
||
1729 |
qApp->processEvents(); // this posts updates from the scene to the view |
|
1730 |
qApp->processEvents(); // which trigger a repaint here |
|
1731 |
} |
|
1732 |
} |
|
1733 |
||
1734 |
void tst_QGraphicsScene::hoverEvents_parentChild() |
|
1735 |
{ |
|
1736 |
Q_CHECK_PAINTEVENTS |
|
1737 |
||
1738 |
QGraphicsScene scene; |
|
1739 |
QGraphicsItem *lastItem = 0; |
|
1740 |
QList<HoverItem *> items; |
|
1741 |
for (int i = 0; i < 15; ++i) { |
|
1742 |
QGraphicsItem *item = new HoverItem; |
|
1743 |
scene.addItem(item); |
|
1744 |
items << (HoverItem *)item; |
|
1745 |
if (lastItem) { |
|
1746 |
item->setParentItem(lastItem); |
|
1747 |
item->setPos(sin(i / 3.0) * 17, cos(i / 3.0) * 17); |
|
1748 |
} |
|
1749 |
lastItem = item; |
|
1750 |
} |
|
1751 |
||
1752 |
QGraphicsView view(&scene); |
|
1753 |
view.setRenderHint(QPainter::Antialiasing, true); |
|
1754 |
#if defined(Q_OS_WINCE) |
|
1755 |
view.setMinimumSize(230, 200); |
|
1756 |
#else |
|
1757 |
view.setMinimumSize(400, 300); |
|
1758 |
#endif |
|
1759 |
view.rotate(10); |
|
1760 |
view.scale(1.7, 1.7); |
|
1761 |
view.show(); |
|
1762 |
QTest::qWaitForWindowShown(&view); |
|
1763 |
QTest::qWait(70); |
|
1764 |
||
1765 |
QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
1766 |
mouseEvent.setScenePos(QPointF(-1000, -1000)); |
|
1767 |
QApplication::sendEvent(&scene, &mouseEvent); |
|
1768 |
||
1769 |
for (int j = 1; j >= 0; --j) { |
|
1770 |
int i = j ? 0 : 14; |
|
1771 |
forever { |
|
1772 |
if (j) { |
|
1773 |
QVERIFY(!items.at(i)->isHovered); |
|
1774 |
} else { |
|
1775 |
if (i == 14) |
|
1776 |
QVERIFY(!items.at(13)->isHovered); |
|
1777 |
} |
|
1778 |
mouseEvent.setScenePos(items.at(i)->mapToScene(0, 0)); |
|
1779 |
QApplication::sendEvent(&scene, &mouseEvent); |
|
1780 |
||
1781 |
qApp->processEvents(); // this posts updates from the scene to the view |
|
1782 |
qApp->processEvents(); // which trigger a repaint here |
|
1783 |
||
1784 |
QTRY_VERIFY(items.at(i)->isHovered); |
|
1785 |
if (i < 14) |
|
1786 |
QVERIFY(!items.at(i + 1)->isHovered); |
|
1787 |
i += j ? 1 : -1; |
|
1788 |
if ((j && i == 15) || (!j && i == -1)) |
|
1789 |
break; |
|
1790 |
} |
|
1791 |
||
1792 |
mouseEvent.setScenePos(QPointF(-1000, -1000)); |
|
1793 |
QApplication::sendEvent(&scene, &mouseEvent); |
|
1794 |
||
1795 |
qApp->processEvents(); // this posts updates from the scene to the view |
|
1796 |
qApp->processEvents(); // which trigger a repaint here |
|
1797 |
} |
|
1798 |
} |
|
1799 |
||
1800 |
void tst_QGraphicsScene::createItemGroup() |
|
1801 |
{ |
|
1802 |
QGraphicsScene scene; |
|
1803 |
||
1804 |
QList<QGraphicsItem *> children1; |
|
1805 |
children1 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1806 |
children1 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1807 |
children1 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1808 |
children1 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1809 |
||
1810 |
QList<QGraphicsItem *> children2; |
|
1811 |
children2 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1812 |
children2 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1813 |
children2 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1814 |
children2 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1815 |
||
1816 |
QList<QGraphicsItem *> children3; |
|
1817 |
children3 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1818 |
children3 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1819 |
children3 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1820 |
children3 << scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1821 |
||
1822 |
// All items in children1 are children of parent1 |
|
1823 |
QGraphicsItem *parent1 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1824 |
foreach (QGraphicsItem *item, children1) |
|
1825 |
item->setParentItem(parent1); |
|
1826 |
||
1827 |
QGraphicsItemGroup *group = scene.createItemGroup(children1); |
|
1828 |
QCOMPARE(group->parentItem(), parent1); |
|
1829 |
QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); |
|
1830 |
scene.destroyItemGroup(group); |
|
1831 |
QCOMPARE(children1.first()->parentItem(), parent1); |
|
1832 |
group = scene.createItemGroup(children1); |
|
1833 |
QCOMPARE(group->parentItem(), parent1); |
|
1834 |
QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); |
|
1835 |
scene.destroyItemGroup(group); |
|
1836 |
QCOMPARE(children1.first()->parentItem(), parent1); |
|
1837 |
||
1838 |
// All items in children2 are children of parent2 |
|
1839 |
QGraphicsItem *parent2 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1840 |
foreach (QGraphicsItem *item, children2) |
|
1841 |
item->setParentItem(parent2); |
|
1842 |
||
1843 |
// Now make parent2 a child of parent1, so all children2 are also children |
|
1844 |
// of parent1. |
|
1845 |
parent2->setParentItem(parent1); |
|
1846 |
||
1847 |
// The children2 group should still have parent2 as their common ancestor. |
|
1848 |
group = scene.createItemGroup(children2); |
|
1849 |
QCOMPARE(group->parentItem(), parent2); |
|
1850 |
QCOMPARE(children2.first()->parentItem(), (QGraphicsItem *)group); |
|
1851 |
scene.destroyItemGroup(group); |
|
1852 |
QCOMPARE(children2.first()->parentItem(), parent2); |
|
1853 |
||
1854 |
// But the set of both children2 and children1 share only parent1. |
|
1855 |
group = scene.createItemGroup(children2 + children1); |
|
1856 |
QCOMPARE(group->parentItem(), parent1); |
|
1857 |
QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); |
|
1858 |
QCOMPARE(children2.first()->parentItem(), (QGraphicsItem *)group); |
|
1859 |
scene.destroyItemGroup(group); |
|
1860 |
QCOMPARE(children1.first()->parentItem(), parent1); |
|
1861 |
QCOMPARE(children2.first()->parentItem(), parent1); |
|
1862 |
||
1863 |
// Fixup the parent-child chain |
|
1864 |
foreach (QGraphicsItem *item, children2) |
|
1865 |
item->setParentItem(parent2); |
|
1866 |
||
1867 |
// These share no common parent |
|
1868 |
group = scene.createItemGroup(children3); |
|
1869 |
QCOMPARE(group->parentItem(), (QGraphicsItem *)0); |
|
1870 |
scene.destroyItemGroup(group); |
|
1871 |
||
1872 |
// Make children3 children of parent3 |
|
1873 |
QGraphicsItem *parent3 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1874 |
foreach (QGraphicsItem *item, children3) |
|
1875 |
item->setParentItem(parent3); |
|
1876 |
||
1877 |
// These should have parent3 as a parent |
|
1878 |
group = scene.createItemGroup(children3); |
|
1879 |
QCOMPARE(group->parentItem(), parent3); |
|
1880 |
scene.destroyItemGroup(group); |
|
1881 |
||
1882 |
// Now make them all children of parent1 |
|
1883 |
parent3->setParentItem(parent1); |
|
1884 |
||
1885 |
group = scene.createItemGroup(children3); |
|
1886 |
QCOMPARE(group->parentItem(), parent3); |
|
1887 |
scene.destroyItemGroup(group); |
|
1888 |
||
1889 |
group = scene.createItemGroup(children2); |
|
1890 |
QCOMPARE(group->parentItem(), parent2); |
|
1891 |
scene.destroyItemGroup(group); |
|
1892 |
||
1893 |
group = scene.createItemGroup(children1); |
|
1894 |
QCOMPARE(group->parentItem(), parent1); |
|
1895 |
scene.destroyItemGroup(group); |
|
1896 |
||
1897 |
QGraphicsItemGroup *emptyGroup = scene.createItemGroup(QList<QGraphicsItem *>()); |
|
1898 |
QCOMPARE(emptyGroup->children(), QList<QGraphicsItem *>()); |
|
1899 |
QVERIFY(!emptyGroup->parentItem()); |
|
1900 |
QCOMPARE(emptyGroup->scene(), &scene); |
|
1901 |
} |
|
1902 |
||
1903 |
class EventTester : public QGraphicsEllipseItem |
|
1904 |
{ |
|
1905 |
public: |
|
1906 |
EventTester() |
|
1907 |
: QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)), ignoreMouse(false) |
|
1908 |
{ } |
|
1909 |
||
1910 |
bool ignoreMouse; |
|
1911 |
QList<QEvent::Type> eventTypes; |
|
1912 |
||
1913 |
protected: |
|
1914 |
bool sceneEvent(QEvent *event) |
|
1915 |
{ |
|
1916 |
eventTypes << QEvent::Type(event->type()); |
|
1917 |
switch (event->type()) { |
|
1918 |
case QEvent::GraphicsSceneMousePress: |
|
1919 |
case QEvent::GraphicsSceneMouseMove: |
|
1920 |
case QEvent::GraphicsSceneMouseRelease: |
|
1921 |
if (ignoreMouse) { |
|
1922 |
event->ignore(); |
|
1923 |
return true; |
|
1924 |
} |
|
1925 |
default: |
|
1926 |
break; |
|
1927 |
} |
|
1928 |
||
1929 |
return QGraphicsEllipseItem::sceneEvent(event); |
|
1930 |
} |
|
1931 |
}; |
|
1932 |
||
1933 |
void tst_QGraphicsScene::mouseEventPropagation() |
|
1934 |
{ |
|
1935 |
EventTester *a = new EventTester; |
|
1936 |
EventTester *b = new EventTester; |
|
1937 |
EventTester *c = new EventTester; |
|
1938 |
EventTester *d = new EventTester; |
|
1939 |
b->setParentItem(a); |
|
1940 |
c->setParentItem(b); |
|
1941 |
d->setParentItem(c); |
|
1942 |
||
1943 |
a->setFlag(QGraphicsItem::ItemIsMovable); |
|
1944 |
b->setFlag(QGraphicsItem::ItemIsMovable); |
|
1945 |
c->setFlag(QGraphicsItem::ItemIsMovable); |
|
1946 |
d->setFlag(QGraphicsItem::ItemIsMovable); |
|
1947 |
||
1948 |
a->setData(0, "A"); |
|
1949 |
b->setData(0, "B"); |
|
1950 |
c->setData(0, "C"); |
|
1951 |
d->setData(0, "D"); |
|
1952 |
||
1953 |
// scene -> a -> b -> c -> d |
|
1954 |
QGraphicsScene scene; |
|
1955 |
QEvent activate(QEvent::WindowActivate); |
|
1956 |
QApplication::sendEvent(&scene, &activate); |
|
1957 |
||
1958 |
scene.addItem(a); |
|
1959 |
||
1960 |
// Prepare some events |
|
1961 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
1962 |
pressEvent.setButton(Qt::LeftButton); |
|
1963 |
pressEvent.setScenePos(QPointF(0, 0)); |
|
1964 |
QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove); |
|
1965 |
moveEvent.setButton(Qt::LeftButton); |
|
1966 |
moveEvent.setScenePos(QPointF(0, 0)); |
|
1967 |
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); |
|
1968 |
releaseEvent.setButton(Qt::LeftButton); |
|
1969 |
releaseEvent.setScenePos(QPointF(0, 0)); |
|
1970 |
||
1971 |
// Send a press |
|
1972 |
QApplication::sendEvent(&scene, &pressEvent); |
|
1973 |
QCOMPARE(d->eventTypes.size(), 2); |
|
1974 |
QCOMPARE(d->eventTypes.at(0), QEvent::GrabMouse); |
|
1975 |
QCOMPARE(d->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
1976 |
QCOMPARE(c->eventTypes.size(), 0); |
|
1977 |
QCOMPARE(b->eventTypes.size(), 0); |
|
1978 |
QCOMPARE(a->eventTypes.size(), 0); |
|
1979 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)d); |
|
1980 |
||
1981 |
// Send a move |
|
1982 |
QApplication::sendEvent(&scene, &moveEvent); |
|
1983 |
QCOMPARE(d->eventTypes.size(), 3); |
|
1984 |
QCOMPARE(d->eventTypes.at(2), QEvent::GraphicsSceneMouseMove); |
|
1985 |
QCOMPARE(c->eventTypes.size(), 0); |
|
1986 |
QCOMPARE(b->eventTypes.size(), 0); |
|
1987 |
QCOMPARE(a->eventTypes.size(), 0); |
|
1988 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)d); |
|
1989 |
||
1990 |
// Send a release |
|
1991 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
1992 |
QCOMPARE(d->eventTypes.size(), 5); |
|
1993 |
QCOMPARE(d->eventTypes.at(3), QEvent::GraphicsSceneMouseRelease); |
|
1994 |
QCOMPARE(d->eventTypes.at(4), QEvent::UngrabMouse); |
|
1995 |
QCOMPARE(c->eventTypes.size(), 0); |
|
1996 |
QCOMPARE(b->eventTypes.size(), 0); |
|
1997 |
QCOMPARE(a->eventTypes.size(), 0); |
|
1998 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1999 |
||
2000 |
d->setAcceptedMouseButtons(Qt::RightButton); |
|
2001 |
||
2002 |
// Send a press |
|
2003 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2004 |
QCOMPARE(d->eventTypes.size(), 5); |
|
2005 |
QCOMPARE(c->eventTypes.size(), 2); |
|
2006 |
QCOMPARE(c->eventTypes.at(0), QEvent::GrabMouse); |
|
2007 |
QCOMPARE(c->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2008 |
QCOMPARE(b->eventTypes.size(), 0); |
|
2009 |
QCOMPARE(a->eventTypes.size(), 0); |
|
2010 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); |
|
2011 |
||
2012 |
// Send another press, with a button that isn't actually accepted |
|
2013 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2014 |
pressEvent.setButton(Qt::RightButton); |
|
2015 |
QCOMPARE(d->eventTypes.size(), 5); |
|
2016 |
QCOMPARE(c->eventTypes.size(), 3); |
|
2017 |
QCOMPARE(c->eventTypes.at(2), QEvent::GraphicsSceneMousePress); |
|
2018 |
QCOMPARE(b->eventTypes.size(), 0); |
|
2019 |
QCOMPARE(a->eventTypes.size(), 0); |
|
2020 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); |
|
2021 |
||
2022 |
// Send a move |
|
2023 |
QApplication::sendEvent(&scene, &moveEvent); |
|
2024 |
QCOMPARE(d->eventTypes.size(), 5); |
|
2025 |
QCOMPARE(c->eventTypes.size(), 4); |
|
2026 |
QCOMPARE(c->eventTypes.at(3), QEvent::GraphicsSceneMouseMove); |
|
2027 |
QCOMPARE(b->eventTypes.size(), 0); |
|
2028 |
QCOMPARE(a->eventTypes.size(), 0); |
|
2029 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); |
|
2030 |
||
2031 |
// Send a release |
|
2032 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
2033 |
QCOMPARE(d->eventTypes.size(), 5); |
|
2034 |
QCOMPARE(c->eventTypes.size(), 6); |
|
2035 |
QCOMPARE(c->eventTypes.at(4), QEvent::GraphicsSceneMouseRelease); |
|
2036 |
QCOMPARE(c->eventTypes.at(5), QEvent::UngrabMouse); |
|
2037 |
QCOMPARE(b->eventTypes.size(), 0); |
|
2038 |
QCOMPARE(a->eventTypes.size(), 0); |
|
2039 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
2040 |
||
2041 |
// Disabled items eat events. c should not get this. |
|
2042 |
d->setEnabled(false); |
|
2043 |
d->setAcceptedMouseButtons(Qt::RightButton); |
|
2044 |
||
2045 |
// Send a right press. This disappears in d. |
|
2046 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2047 |
QCOMPARE(d->eventTypes.size(), 5); |
|
2048 |
QCOMPARE(c->eventTypes.size(), 6); |
|
2049 |
QCOMPARE(b->eventTypes.size(), 0); |
|
2050 |
QCOMPARE(a->eventTypes.size(), 0); |
|
2051 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
2052 |
||
2053 |
// Send a left press. This goes to c. |
|
2054 |
pressEvent.setButton(Qt::LeftButton); |
|
2055 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2056 |
QCOMPARE(d->eventTypes.size(), 5); |
|
2057 |
QCOMPARE(c->eventTypes.size(), 8); |
|
2058 |
QCOMPARE(c->eventTypes.at(6), QEvent::GrabMouse); |
|
2059 |
QCOMPARE(c->eventTypes.at(7), QEvent::GraphicsSceneMousePress); |
|
2060 |
QCOMPARE(b->eventTypes.size(), 0); |
|
2061 |
QCOMPARE(a->eventTypes.size(), 0); |
|
2062 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); |
|
2063 |
||
2064 |
// Clicking outside the items removes the mouse grabber |
|
2065 |
} |
|
2066 |
||
2067 |
void tst_QGraphicsScene::mouseEventPropagation_ignore() |
|
2068 |
{ |
|
2069 |
EventTester *a = new EventTester; |
|
2070 |
EventTester *b = new EventTester; |
|
2071 |
EventTester *c = new EventTester; |
|
2072 |
EventTester *d = new EventTester; |
|
2073 |
b->setParentItem(a); |
|
2074 |
c->setParentItem(b); |
|
2075 |
d->setParentItem(c); |
|
2076 |
||
2077 |
a->setFlags(QGraphicsItem::ItemIsMovable); |
|
2078 |
b->setFlags(QGraphicsItem::ItemIsMovable); |
|
2079 |
c->setFlags(QGraphicsItem::ItemIsMovable); |
|
2080 |
d->setFlags(QGraphicsItem::ItemIsMovable); |
|
2081 |
||
2082 |
// scene -> a -> b -> c -> d |
|
2083 |
QGraphicsScene scene; |
|
2084 |
scene.addItem(a); |
|
2085 |
||
2086 |
// Prepare some events |
|
2087 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
2088 |
pressEvent.setButton(Qt::LeftButton); |
|
2089 |
pressEvent.setScenePos(QPointF(0, 0)); |
|
2090 |
||
2091 |
b->ignoreMouse = true; |
|
2092 |
c->ignoreMouse = true; |
|
2093 |
d->ignoreMouse = true; |
|
2094 |
||
2095 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2096 |
QCOMPARE(a->eventTypes.size(), 2); |
|
2097 |
QCOMPARE(a->eventTypes.at(0), QEvent::GrabMouse); |
|
2098 |
QCOMPARE(a->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2099 |
QCOMPARE(b->eventTypes.size(), 3); |
|
2100 |
QCOMPARE(b->eventTypes.at(0), QEvent::GrabMouse); |
|
2101 |
QCOMPARE(b->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2102 |
QCOMPARE(b->eventTypes.at(2), QEvent::UngrabMouse); |
|
2103 |
QCOMPARE(c->eventTypes.size(), 3); |
|
2104 |
QCOMPARE(c->eventTypes.at(0), QEvent::GrabMouse); |
|
2105 |
QCOMPARE(c->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2106 |
QCOMPARE(c->eventTypes.at(2), QEvent::UngrabMouse); |
|
2107 |
QCOMPARE(d->eventTypes.size(), 3); |
|
2108 |
QCOMPARE(d->eventTypes.at(0), QEvent::GrabMouse); |
|
2109 |
QCOMPARE(d->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2110 |
QCOMPARE(d->eventTypes.at(2), QEvent::UngrabMouse); |
|
2111 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)a); |
|
2112 |
||
2113 |
a->ignoreMouse = true; |
|
2114 |
||
2115 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2116 |
QCOMPARE(a->eventTypes.size(), 3); |
|
2117 |
QCOMPARE(a->eventTypes.at(2), QEvent::GraphicsSceneMousePress); |
|
2118 |
QCOMPARE(b->eventTypes.size(), 3); |
|
2119 |
QCOMPARE(c->eventTypes.size(), 3); |
|
2120 |
QCOMPARE(d->eventTypes.size(), 3); |
|
2121 |
||
2122 |
QVERIFY(!pressEvent.isAccepted()); |
|
2123 |
} |
|
2124 |
||
2125 |
void tst_QGraphicsScene::mouseEventPropagation_focus() |
|
2126 |
{ |
|
2127 |
EventTester *a = new EventTester; |
|
2128 |
EventTester *b = new EventTester; |
|
2129 |
EventTester *c = new EventTester; |
|
2130 |
EventTester *d = new EventTester; |
|
2131 |
b->setParentItem(a); |
|
2132 |
c->setParentItem(b); |
|
2133 |
d->setParentItem(c); |
|
2134 |
||
2135 |
a->setFlag(QGraphicsItem::ItemIsMovable); |
|
2136 |
b->setFlag(QGraphicsItem::ItemIsMovable); |
|
2137 |
c->setFlag(QGraphicsItem::ItemIsMovable); |
|
2138 |
d->setFlag(QGraphicsItem::ItemIsMovable); |
|
2139 |
||
2140 |
// scene -> a -> b -> c -> d |
|
2141 |
QGraphicsScene scene; |
|
2142 |
QEvent activate(QEvent::WindowActivate); |
|
2143 |
QApplication::sendEvent(&scene, &activate); |
|
2144 |
||
2145 |
scene.addItem(a); |
|
2146 |
||
2147 |
// Prepare some events |
|
2148 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
2149 |
pressEvent.setButton(Qt::LeftButton); |
|
2150 |
pressEvent.setScenePos(QPointF(0, 0)); |
|
2151 |
||
2152 |
a->setFlag(QGraphicsItem::ItemIsFocusable); |
|
2153 |
QVERIFY(!a->hasFocus()); |
|
2154 |
||
2155 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2156 |
||
2157 |
QVERIFY(a->hasFocus()); |
|
2158 |
QCOMPARE(a->eventTypes.size(), 1); |
|
2159 |
QCOMPARE(a->eventTypes.first(), QEvent::FocusIn); |
|
2160 |
QCOMPARE(d->eventTypes.size(), 2); |
|
2161 |
QCOMPARE(d->eventTypes.at(0), QEvent::GrabMouse); |
|
2162 |
QCOMPARE(d->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2163 |
} |
|
2164 |
||
2165 |
void tst_QGraphicsScene::mouseEventPropagation_doubleclick() |
|
2166 |
{ |
|
2167 |
EventTester *a = new EventTester; |
|
2168 |
EventTester *b = new EventTester; |
|
2169 |
a->setFlags(QGraphicsItem::ItemIsMovable); |
|
2170 |
b->setFlags(QGraphicsItem::ItemIsMovable); |
|
2171 |
||
2172 |
a->setPos(-50, 0); |
|
2173 |
b->setPos(50, 0); |
|
2174 |
||
2175 |
QGraphicsScene scene; |
|
2176 |
scene.addItem(a); |
|
2177 |
scene.addItem(b); |
|
2178 |
||
2179 |
// Prepare some events |
|
2180 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
2181 |
pressEvent.setButton(Qt::LeftButton); |
|
2182 |
pressEvent.setScenePos(QPointF(0, 0)); |
|
2183 |
QGraphicsSceneMouseEvent doubleClickEvent(QEvent::GraphicsSceneMouseDoubleClick); |
|
2184 |
doubleClickEvent.setButton(Qt::LeftButton); |
|
2185 |
doubleClickEvent.setScenePos(QPointF(0, 0)); |
|
2186 |
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); |
|
2187 |
releaseEvent.setButton(Qt::LeftButton); |
|
2188 |
releaseEvent.setScenePos(QPointF(0, 0)); |
|
2189 |
||
2190 |
// Send press to A |
|
2191 |
pressEvent.setScenePos(a->mapToScene(0, 0)); |
|
2192 |
QApplication::sendEvent(&scene, &pressEvent); |
|
2193 |
QCOMPARE(a->eventTypes.size(), 2); |
|
2194 |
QCOMPARE(a->eventTypes.at(0), QEvent::GrabMouse); |
|
2195 |
QCOMPARE(a->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2196 |
||
2197 |
// Send release to A |
|
2198 |
releaseEvent.setScenePos(a->mapToScene(0, 0)); |
|
2199 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
2200 |
QCOMPARE(a->eventTypes.size(), 4); |
|
2201 |
QCOMPARE(a->eventTypes.at(2), QEvent::GraphicsSceneMouseRelease); |
|
2202 |
QCOMPARE(a->eventTypes.at(3), QEvent::UngrabMouse); |
|
2203 |
||
2204 |
// Send doubleclick to B |
|
2205 |
doubleClickEvent.setScenePos(b->mapToScene(0, 0)); |
|
2206 |
QApplication::sendEvent(&scene, &doubleClickEvent); |
|
2207 |
QCOMPARE(a->eventTypes.size(), 4); |
|
2208 |
QCOMPARE(b->eventTypes.size(), 2); |
|
2209 |
QCOMPARE(b->eventTypes.at(0), QEvent::GrabMouse); |
|
2210 |
QCOMPARE(b->eventTypes.at(1), QEvent::GraphicsSceneMousePress); |
|
2211 |
||
2212 |
// Send release to B |
|
2213 |
releaseEvent.setScenePos(b->mapToScene(0, 0)); |
|
2214 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
2215 |
QCOMPARE(a->eventTypes.size(), 4); |
|
2216 |
QCOMPARE(b->eventTypes.size(), 4); |
|
2217 |
QCOMPARE(b->eventTypes.at(2), QEvent::GraphicsSceneMouseRelease); |
|
2218 |
QCOMPARE(b->eventTypes.at(3), QEvent::UngrabMouse); |
|
2219 |
} |
|
2220 |
||
2221 |
class Scene : public QGraphicsScene |
|
2222 |
{ |
|
2223 |
public: |
|
2224 |
QList<QPointF> mouseMovePoints; |
|
2225 |
||
2226 |
protected: |
|
2227 |
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
2228 |
{ |
|
2229 |
mouseMovePoints << event->scenePos(); |
|
2230 |
} |
|
2231 |
}; |
|
2232 |
||
2233 |
void tst_QGraphicsScene::mouseEventPropagation_mouseMove() |
|
2234 |
{ |
|
2235 |
Scene scene; |
|
2236 |
scene.addRect(QRectF(5, 0, 12, 12)); |
|
2237 |
scene.addRect(QRectF(15, 0, 12, 12))->setAcceptsHoverEvents(true); |
|
2238 |
for (int i = 0; i < 30; ++i) { |
|
2239 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
2240 |
event.setScenePos(QPointF(i, 5)); |
|
2241 |
QApplication::sendEvent(&scene, &event); |
|
2242 |
} |
|
2243 |
||
2244 |
QCOMPARE(scene.mouseMovePoints.size(), 30); |
|
2245 |
for (int i = 0; i < 30; ++i) |
|
2246 |
QCOMPARE(scene.mouseMovePoints.at(i), QPointF(i, 5)); |
|
2247 |
} |
|
2248 |
||
2249 |
class DndTester : public QGraphicsEllipseItem |
|
2250 |
{ |
|
2251 |
public: |
|
2252 |
DndTester(const QRectF &rect) |
|
2253 |
: QGraphicsEllipseItem(rect), lastEvent(0), |
|
2254 |
ignoresDragEnter(false), ignoresDragMove(false) |
|
2255 |
||
2256 |
{ |
|
2257 |
} |
|
2258 |
||
2259 |
~DndTester() |
|
2260 |
{ |
|
2261 |
delete lastEvent; |
|
2262 |
} |
|
2263 |
||
2264 |
QGraphicsSceneDragDropEvent *lastEvent; |
|
2265 |
QList<QEvent::Type> eventList; |
|
2266 |
bool ignoresDragEnter; |
|
2267 |
bool ignoresDragMove; |
|
2268 |
||
2269 |
protected: |
|
2270 |
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) |
|
2271 |
{ |
|
2272 |
storeLastEvent(event); |
|
2273 |
event->setAccepted(!ignoresDragEnter); |
|
2274 |
if (!ignoresDragEnter) |
|
2275 |
event->setDropAction(Qt::IgnoreAction); |
|
2276 |
eventList << event->type(); |
|
2277 |
} |
|
2278 |
||
2279 |
void dragMoveEvent(QGraphicsSceneDragDropEvent *event) |
|
2280 |
{ |
|
2281 |
storeLastEvent(event); |
|
2282 |
event->setAccepted(!ignoresDragMove); |
|
2283 |
eventList << event->type(); |
|
2284 |
} |
|
2285 |
||
2286 |
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) |
|
2287 |
{ |
|
2288 |
storeLastEvent(event); |
|
2289 |
eventList << event->type(); |
|
2290 |
} |
|
2291 |
||
2292 |
void dropEvent(QGraphicsSceneDragDropEvent *event) |
|
2293 |
{ |
|
2294 |
storeLastEvent(event); |
|
2295 |
eventList << event->type(); |
|
2296 |
} |
|
2297 |
||
2298 |
private: |
|
2299 |
void storeLastEvent(QGraphicsSceneDragDropEvent *event) |
|
2300 |
{ |
|
2301 |
delete lastEvent; |
|
2302 |
lastEvent = new QGraphicsSceneDragDropEvent(event->type()); |
|
2303 |
lastEvent->setScenePos(event->scenePos()); |
|
2304 |
lastEvent->setScreenPos(event->screenPos()); |
|
2305 |
lastEvent->setButtons(event->buttons()); |
|
2306 |
lastEvent->setModifiers(event->modifiers()); |
|
2307 |
lastEvent->setPossibleActions(event->possibleActions()); |
|
2308 |
lastEvent->setProposedAction(event->proposedAction()); |
|
2309 |
lastEvent->setDropAction(event->dropAction()); |
|
2310 |
lastEvent->setMimeData(event->mimeData()); |
|
2311 |
lastEvent->setWidget(event->widget()); |
|
2312 |
lastEvent->setSource(event->source()); |
|
2313 |
} |
|
2314 |
}; |
|
2315 |
||
2316 |
#ifndef QT_NO_DRAGANDDROP |
|
2317 |
void tst_QGraphicsScene::dragAndDrop_simple() |
|
2318 |
{ |
|
2319 |
DndTester *item = new DndTester(QRectF(-10, -10, 20, 20)); |
|
2320 |
||
2321 |
QGraphicsScene scene; |
|
2322 |
scene.addItem(item); |
|
2323 |
||
2324 |
QGraphicsView view(&scene); |
|
2325 |
view.setFixedSize(100, 100); |
|
2326 |
||
2327 |
QMimeData mimeData; |
|
2328 |
||
2329 |
// Initial drag enter for the scene |
|
2330 |
QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2331 |
QApplication::sendEvent(view.viewport(), &dragEnter); |
|
2332 |
QVERIFY(dragEnter.isAccepted()); |
|
2333 |
QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); |
|
2334 |
||
2335 |
{ |
|
2336 |
// Move outside the item |
|
2337 |
QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2338 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2339 |
QVERIFY(!dragMove.isAccepted()); |
|
2340 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2341 |
} |
|
2342 |
{ |
|
2343 |
// Move inside the item without setAcceptDrops |
|
2344 |
QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2345 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2346 |
QVERIFY(!dragMove.isAccepted()); |
|
2347 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2348 |
QCOMPARE(item->eventList.size(), 0); |
|
2349 |
} |
|
2350 |
item->setAcceptDrops(true); |
|
2351 |
{ |
|
2352 |
// Move inside the item with setAcceptDrops |
|
2353 |
QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2354 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2355 |
QVERIFY(dragMove.isAccepted()); |
|
2356 |
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); |
|
2357 |
QCOMPARE(item->eventList.size(), 2); |
|
2358 |
QCOMPARE(item->eventList.at(0), QEvent::GraphicsSceneDragEnter); |
|
2359 |
QCOMPARE(item->eventList.at(1), QEvent::GraphicsSceneDragMove); |
|
2360 |
QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos())); |
|
2361 |
QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos())); |
|
2362 |
QVERIFY(item->lastEvent->isAccepted()); |
|
2363 |
QCOMPARE(item->lastEvent->dropAction(), Qt::IgnoreAction); |
|
2364 |
} |
|
2365 |
{ |
|
2366 |
// Another move inside the item |
|
2367 |
QDragMoveEvent dragMove(view.mapFromScene(item->mapToScene(5, 5)), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2368 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2369 |
QVERIFY(dragMove.isAccepted()); |
|
2370 |
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); |
|
2371 |
QCOMPARE(item->eventList.size(), 3); |
|
2372 |
QCOMPARE(item->eventList.at(2), QEvent::GraphicsSceneDragMove); |
|
2373 |
QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos())); |
|
2374 |
QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos())); |
|
2375 |
QVERIFY(item->lastEvent->isAccepted()); |
|
2376 |
QCOMPARE(item->lastEvent->dropAction(), Qt::IgnoreAction); |
|
2377 |
} |
|
2378 |
{ |
|
2379 |
// Move outside the item |
|
2380 |
QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2381 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2382 |
QVERIFY(!dragMove.isAccepted()); |
|
2383 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2384 |
QCOMPARE(item->eventList.size(), 4); |
|
2385 |
QCOMPARE(item->eventList.at(3), QEvent::GraphicsSceneDragLeave); |
|
2386 |
QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos())); |
|
2387 |
QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos())); |
|
2388 |
QVERIFY(item->lastEvent->isAccepted()); |
|
2389 |
QCOMPARE(item->lastEvent->dropAction(), Qt::CopyAction); |
|
2390 |
} |
|
2391 |
{ |
|
2392 |
// Move inside the item again |
|
2393 |
QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2394 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2395 |
QVERIFY(dragMove.isAccepted()); |
|
2396 |
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); |
|
2397 |
QCOMPARE(item->eventList.size(), 6); |
|
2398 |
QCOMPARE(item->eventList.at(4), QEvent::GraphicsSceneDragEnter); |
|
2399 |
QCOMPARE(item->eventList.at(5), QEvent::GraphicsSceneDragMove); |
|
2400 |
QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos())); |
|
2401 |
QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos())); |
|
2402 |
QVERIFY(item->lastEvent->isAccepted()); |
|
2403 |
QCOMPARE(item->lastEvent->dropAction(), Qt::IgnoreAction); |
|
2404 |
} |
|
2405 |
{ |
|
2406 |
// Drop inside the item |
|
2407 |
QDropEvent drop(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2408 |
QApplication::sendEvent(view.viewport(), &drop); |
|
2409 |
QVERIFY(drop.isAccepted()); |
|
2410 |
QCOMPARE(drop.dropAction(), Qt::CopyAction); |
|
2411 |
QCOMPARE(item->eventList.size(), 7); |
|
2412 |
QCOMPARE(item->eventList.at(6), QEvent::GraphicsSceneDrop); |
|
2413 |
QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(drop.pos())); |
|
2414 |
QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(drop.pos())); |
|
2415 |
QVERIFY(item->lastEvent->isAccepted()); |
|
2416 |
QCOMPARE(item->lastEvent->dropAction(), Qt::CopyAction); |
|
2417 |
} |
|
2418 |
} |
|
2419 |
||
2420 |
void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() |
|
2421 |
{ |
|
2422 |
DndTester *item = new DndTester(QRectF(-10, -10, 20, 20)); |
|
2423 |
item->setAcceptDrops(true); |
|
2424 |
||
2425 |
QGraphicsScene scene; |
|
2426 |
scene.addItem(item); |
|
2427 |
||
2428 |
QGraphicsView view(&scene); |
|
2429 |
view.setFixedSize(100, 100); |
|
2430 |
||
2431 |
QMimeData mimeData; |
|
2432 |
||
2433 |
// Initial drag enter for the scene |
|
2434 |
QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2435 |
QApplication::sendEvent(view.viewport(), &dragEnter); |
|
2436 |
QVERIFY(dragEnter.isAccepted()); |
|
2437 |
QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); |
|
2438 |
{ |
|
2439 |
// Move inside the item |
|
2440 |
QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2441 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2442 |
QVERIFY(dragMove.isAccepted()); |
|
2443 |
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); |
|
2444 |
QCOMPARE(item->eventList.size(), 2); |
|
2445 |
QCOMPARE(item->eventList.at(0), QEvent::GraphicsSceneDragEnter); |
|
2446 |
QCOMPARE(item->eventList.at(1), QEvent::GraphicsSceneDragMove); |
|
2447 |
} |
|
2448 |
{ |
|
2449 |
// Move outside the item |
|
2450 |
QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2451 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2452 |
QVERIFY(!dragMove.isAccepted()); |
|
2453 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2454 |
QCOMPARE(item->eventList.size(), 3); |
|
2455 |
QCOMPARE(item->eventList.at(2), QEvent::GraphicsSceneDragLeave); |
|
2456 |
} |
|
2457 |
||
2458 |
// Now disable the item |
|
2459 |
item->setEnabled(false); |
|
2460 |
QVERIFY(!item->isEnabled()); |
|
2461 |
QVERIFY(item->isVisible()); |
|
2462 |
||
2463 |
{ |
|
2464 |
// Move inside the item |
|
2465 |
QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2466 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2467 |
QVERIFY(!dragMove.isAccepted()); |
|
2468 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2469 |
QCOMPARE(item->eventList.size(), 3); |
|
2470 |
QCOMPARE(item->eventList.at(2), QEvent::GraphicsSceneDragLeave); |
|
2471 |
} |
|
2472 |
||
2473 |
// Reenable it, and make it invisible |
|
2474 |
item->setEnabled(true); |
|
2475 |
item->setVisible(false); |
|
2476 |
QVERIFY(item->isEnabled()); |
|
2477 |
QVERIFY(!item->isVisible()); |
|
2478 |
||
2479 |
{ |
|
2480 |
// Move inside the item |
|
2481 |
QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2482 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2483 |
QVERIFY(!dragMove.isAccepted()); |
|
2484 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2485 |
QCOMPARE(item->eventList.size(), 3); |
|
2486 |
QCOMPARE(item->eventList.at(2), QEvent::GraphicsSceneDragLeave); |
|
2487 |
} |
|
2488 |
||
2489 |
// Dummy drop event to keep the Mac from crashing. |
|
2490 |
QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2491 |
QApplication::sendEvent(view.viewport(), &dropEvent); |
|
2492 |
} |
|
2493 |
||
2494 |
void tst_QGraphicsScene::dragAndDrop_propagate() |
|
2495 |
{ |
|
2496 |
DndTester *item1 = new DndTester(QRectF(-10, -10, 20, 20)); |
|
2497 |
DndTester *item2 = new DndTester(QRectF(0, 0, 20, 20)); |
|
2498 |
item1->setAcceptDrops(true); |
|
2499 |
item2->setAcceptDrops(true); |
|
2500 |
item2->ignoresDragMove = true; |
|
2501 |
item2->ignoresDragEnter = false; |
|
2502 |
item2->setZValue(1); |
|
2503 |
||
2504 |
item1->setData(0, "item1"); |
|
2505 |
item2->setData(0, "item2"); |
|
2506 |
||
2507 |
QGraphicsScene scene; |
|
2508 |
scene.addItem(item1); |
|
2509 |
scene.addItem(item2); |
|
2510 |
||
2511 |
QGraphicsView view(&scene); |
|
2512 |
view.setFixedSize(100, 100); |
|
2513 |
||
2514 |
QMimeData mimeData; |
|
2515 |
||
2516 |
// Initial drag enter for the scene |
|
2517 |
QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2518 |
QApplication::sendEvent(view.viewport(), &dragEnter); |
|
2519 |
QVERIFY(dragEnter.isAccepted()); |
|
2520 |
QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); |
|
2521 |
||
2522 |
{ |
|
2523 |
// Move outside the items |
|
2524 |
QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2525 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2526 |
QVERIFY(!dragMove.isAccepted()); |
|
2527 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2528 |
QVERIFY(item1->eventList.isEmpty()); |
|
2529 |
QVERIFY(item2->eventList.isEmpty()); |
|
2530 |
} |
|
2531 |
{ |
|
2532 |
// Move inside item1 |
|
2533 |
QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2534 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2535 |
QVERIFY(dragMove.isAccepted()); |
|
2536 |
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); |
|
2537 |
QCOMPARE(item1->eventList.size(), 2); |
|
2538 |
QCOMPARE(item1->eventList.at(0), QEvent::GraphicsSceneDragEnter); |
|
2539 |
QCOMPARE(item1->eventList.at(1), QEvent::GraphicsSceneDragMove); |
|
2540 |
} |
|
2541 |
||
2542 |
{ |
|
2543 |
// Move into the intersection item1-item2 |
|
2544 |
QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2545 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2546 |
QVERIFY(!dragMove.isAccepted()); // move does not propagate, (ignoresDragMove = true) |
|
2547 |
QCOMPARE(item1->eventList.size(), 3); |
|
2548 |
QCOMPARE(item1->eventList.at(2), QEvent::GraphicsSceneDragLeave); |
|
2549 |
QCOMPARE(item2->eventList.size(), 2); |
|
2550 |
QCOMPARE(item2->eventList.at(0), QEvent::GraphicsSceneDragEnter); |
|
2551 |
QCOMPARE(item2->eventList.at(1), QEvent::GraphicsSceneDragMove); |
|
2552 |
} |
|
2553 |
{ |
|
2554 |
// Move into the item2 |
|
2555 |
QDragMoveEvent dragMove(view.mapFromScene(15, 15), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2556 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2557 |
QVERIFY(!dragMove.isAccepted()); |
|
2558 |
QCOMPARE(dragMove.dropAction(), Qt::CopyAction); |
|
2559 |
QCOMPARE(item1->eventList.size(), 3); |
|
2560 |
QCOMPARE(item2->eventList.size(), 3); |
|
2561 |
QCOMPARE(item2->eventList.at(2), QEvent::GraphicsSceneDragMove); |
|
2562 |
} |
|
2563 |
{ |
|
2564 |
// Move inside item1 |
|
2565 |
QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2566 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2567 |
QVERIFY(dragMove.isAccepted()); |
|
2568 |
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); |
|
2569 |
QCOMPARE(item1->eventList.size(), 5); |
|
2570 |
QCOMPARE(item1->eventList.at(3), QEvent::GraphicsSceneDragEnter); |
|
2571 |
QCOMPARE(item1->eventList.at(4), QEvent::GraphicsSceneDragMove); |
|
2572 |
QCOMPARE(item2->eventList.size(), 4); |
|
2573 |
QCOMPARE(item2->eventList.at(3), QEvent::GraphicsSceneDragLeave); |
|
2574 |
} |
|
2575 |
||
2576 |
{ |
|
2577 |
item2->ignoresDragEnter = true; |
|
2578 |
// Move into the intersection item1-item2 |
|
2579 |
QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2580 |
QApplication::sendEvent(view.viewport(), &dragMove); |
|
2581 |
QVERIFY(dragMove.isAccepted()); // dragEnter propagates down to item1, which then accepts the move event. |
|
2582 |
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); |
|
2583 |
QCOMPARE(item1->eventList.size(), 6); |
|
2584 |
QCOMPARE(item1->eventList.at(5), QEvent::GraphicsSceneDragMove); |
|
2585 |
QCOMPARE(item2->eventList.size(), 5); |
|
2586 |
QCOMPARE(item2->eventList.at(4), QEvent::GraphicsSceneDragEnter); |
|
2587 |
} |
|
2588 |
||
2589 |
{ |
|
2590 |
item2->ignoresDragEnter = false; |
|
2591 |
// Drop on the intersection item1-item2 |
|
2592 |
QDropEvent drop(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2593 |
QApplication::sendEvent(view.viewport(), &drop); |
|
2594 |
QVERIFY(drop.isAccepted()); |
|
2595 |
QCOMPARE(drop.dropAction(), Qt::CopyAction); |
|
2596 |
||
2597 |
QCOMPARE(item1->eventList.size(), 7); |
|
2598 |
QCOMPARE(item1->eventList.at(6), QEvent::GraphicsSceneDrop); |
|
2599 |
QCOMPARE(item2->eventList.size(), 5); |
|
2600 |
} |
|
2601 |
||
2602 |
// Dummy drop event to keep the Mac from crashing. |
|
2603 |
QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); |
|
2604 |
QApplication::sendEvent(view.viewport(), &dropEvent); |
|
2605 |
} |
|
2606 |
#endif |
|
2607 |
||
2608 |
void tst_QGraphicsScene::render_data() |
|
2609 |
{ |
|
2610 |
QTest::addColumn<QRectF>("targetRect"); |
|
2611 |
QTest::addColumn<QRectF>("sourceRect"); |
|
2612 |
QTest::addColumn<Qt::AspectRatioMode>("aspectRatioMode"); |
|
2613 |
QTest::addColumn<QMatrix>("matrix"); |
|
2614 |
||
2615 |
QTest::newRow("all-all-untransformed") << QRectF() << QRectF() |
|
2616 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2617 |
QTest::newRow("all-topleft-untransformed") << QRectF(0, 0, 150, 150) |
|
2618 |
<< QRectF() << Qt::IgnoreAspectRatio << QMatrix(); |
|
2619 |
QTest::newRow("all-topright-untransformed") << QRectF(150, 0, 150, 150) |
|
2620 |
<< QRectF() << Qt::IgnoreAspectRatio << QMatrix(); |
|
2621 |
QTest::newRow("all-bottomleft-untransformed") << QRectF(0, 150, 150, 150) |
|
2622 |
<< QRectF() << Qt::IgnoreAspectRatio << QMatrix(); |
|
2623 |
QTest::newRow("all-bottomright-untransformed") << QRectF(150, 150, 150, 150) |
|
2624 |
<< QRectF() << Qt::IgnoreAspectRatio << QMatrix(); |
|
2625 |
QTest::newRow("topleft-all-untransformed") << QRectF() << QRectF(-10, -10, 10, 10) |
|
2626 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2627 |
QTest::newRow("topright-all-untransformed") << QRectF() << QRectF(0, -10, 10, 10) |
|
2628 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2629 |
QTest::newRow("bottomleft-all-untransformed") << QRectF() << QRectF(-10, 0, 10, 10) |
|
2630 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2631 |
QTest::newRow("bottomright-all-untransformed") << QRectF() << QRectF(0, 0, 10, 10) |
|
2632 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2633 |
QTest::newRow("topleft-topleft-untransformed") << QRectF(0, 0, 150, 150) << QRectF(-10, -10, 10, 10) |
|
2634 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2635 |
QTest::newRow("topright-topleft-untransformed") << QRectF(150, 0, 150, 150) << QRectF(-10, -10, 10, 10) |
|
2636 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2637 |
QTest::newRow("bottomleft-topleft-untransformed") << QRectF(0, 150, 150, 150) << QRectF(-10, -10, 10, 10) |
|
2638 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2639 |
QTest::newRow("bottomright-topleft-untransformed") << QRectF(150, 150, 150, 150) << QRectF(-10, -10, 10, 10) |
|
2640 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2641 |
QTest::newRow("top-topleft-untransformed") << QRectF(0, 0, 300, 150) << QRectF(-10, -10, 10, 10) |
|
2642 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2643 |
QTest::newRow("bottom-topleft-untransformed") << QRectF(0, 150, 300, 150) << QRectF(-10, -10, 10, 10) |
|
2644 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2645 |
QTest::newRow("left-topleft-untransformed") << QRectF(0, 0, 150, 300) << QRectF(-10, -10, 10, 10) |
|
2646 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2647 |
QTest::newRow("right-topleft-untransformed") << QRectF(150, 0, 150, 300) << QRectF(-10, -10, 10, 10) |
|
2648 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2649 |
QTest::newRow("top-bottomright-untransformed") << QRectF(0, 0, 300, 150) << QRectF(0, 0, 10, 10) |
|
2650 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2651 |
QTest::newRow("bottom-bottomright-untransformed") << QRectF(0, 150, 300, 150) << QRectF(0, 0, 10, 10) |
|
2652 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2653 |
QTest::newRow("left-bottomright-untransformed") << QRectF(0, 0, 150, 300) << QRectF(0, 0, 10, 10) |
|
2654 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2655 |
QTest::newRow("right-bottomright-untransformed") << QRectF(150, 0, 150, 300) << QRectF(0, 0, 10, 10) |
|
2656 |
<< Qt::IgnoreAspectRatio << QMatrix(); |
|
2657 |
QTest::newRow("all-all-45-deg-right") << QRectF() << QRectF() |
|
2658 |
<< Qt::IgnoreAspectRatio << QMatrix().rotate(-45); |
|
2659 |
QTest::newRow("all-all-45-deg-left") << QRectF() << QRectF() |
|
2660 |
<< Qt::IgnoreAspectRatio << QMatrix().rotate(45); |
|
2661 |
QTest::newRow("all-all-scale-2x") << QRectF() << QRectF() |
|
2662 |
<< Qt::IgnoreAspectRatio << QMatrix().scale(2, 2); |
|
2663 |
QTest::newRow("all-all-translate-50-0") << QRectF() << QRectF() |
|
2664 |
<< Qt::IgnoreAspectRatio << QMatrix().translate(50, 0); |
|
2665 |
QTest::newRow("all-all-translate-0-50") << QRectF() << QRectF() |
|
2666 |
<< Qt::IgnoreAspectRatio << QMatrix().translate(0, 50); |
|
2667 |
} |
|
2668 |
||
2669 |
void tst_QGraphicsScene::render() |
|
2670 |
{ |
|
2671 |
QFETCH(QRectF, targetRect); |
|
2672 |
QFETCH(QRectF, sourceRect); |
|
2673 |
QFETCH(Qt::AspectRatioMode, aspectRatioMode); |
|
2674 |
QFETCH(QMatrix, matrix); |
|
2675 |
||
2676 |
QPixmap pix(30, 30); |
|
2677 |
pix.fill(Qt::blue); |
|
2678 |
||
2679 |
QGraphicsScene scene; |
|
2680 |
scene.addEllipse(QRectF(-10, -10, 20, 20), QPen(Qt::black), QBrush(Qt::white)); |
|
2681 |
scene.addEllipse(QRectF(-2, -7, 4, 4), QPen(Qt::black), QBrush(Qt::yellow))->setZValue(1); |
|
2682 |
QGraphicsPixmapItem *item = scene.addPixmap(pix); |
|
2683 |
item->setZValue(2); |
|
2684 |
item->setOffset(QPointF(3, 3)); |
|
2685 |
||
2686 |
scene.setSceneRect(scene.itemsBoundingRect()); |
|
2687 |
||
2688 |
QImage bigImage(300, 300, QImage::Format_RGB32); |
|
2689 |
bigImage.fill(0); |
|
2690 |
QPainter painter(&bigImage); |
|
2691 |
painter.setPen(Qt::lightGray); |
|
2692 |
for (int i = 0; i <= 300; i += 25) { |
|
2693 |
painter.drawLine(0, i, 300, i); |
|
2694 |
painter.drawLine(i, 0, i, 300); |
|
2695 |
} |
|
2696 |
painter.setPen(QPen(Qt::darkGray, 2)); |
|
2697 |
painter.drawLine(0, 150, 300, 150); |
|
2698 |
painter.drawLine(150, 0, 150, 300); |
|
2699 |
painter.setMatrix(matrix); |
|
2700 |
scene.render(&painter, targetRect, sourceRect, aspectRatioMode); |
|
2701 |
painter.end(); |
|
2702 |
||
2703 |
const QString renderPath = QLatin1String(SRCDIR) + "/testData/render"; |
|
2704 |
QString fileName = renderPath + QString("/%1.png").arg(QTest::currentDataTag()); |
|
2705 |
QImage original(fileName); |
|
2706 |
QVERIFY(!original.isNull()); |
|
2707 |
||
2708 |
// Compare |
|
2709 |
int wrongPixels = 0; |
|
2710 |
for (int y = 0; y < original.height(); ++y) { |
|
2711 |
for (int x = 0; x < original.width(); ++x) { |
|
2712 |
if (bigImage.pixel(x, y) != original.pixel(x, y)) |
|
2713 |
++wrongPixels; |
|
2714 |
} |
|
2715 |
} |
|
2716 |
||
2717 |
// This is a pixmap compare test - because of rounding errors on diverse |
|
2718 |
// platforms, and especially because tests are compiled in release mode, |
|
2719 |
// we set a 95% acceptance threshold for comparing images. This number may |
|
2720 |
// have to be adjusted if this test fails. |
|
2721 |
qreal threshold = 0.95; |
|
2722 |
qreal similarity = (1 - (wrongPixels / qreal(original.width() * original.height()))); |
|
2723 |
if (similarity < threshold) { |
|
2724 |
#if 1 |
|
2725 |
// fail |
|
2726 |
QLabel *expectedLabel = new QLabel; |
|
2727 |
expectedLabel->setPixmap(QPixmap::fromImage(original)); |
|
2728 |
||
2729 |
QLabel *newLabel = new QLabel; |
|
2730 |
newLabel->setPixmap(QPixmap::fromImage(bigImage)); |
|
2731 |
||
2732 |
QGridLayout *gridLayout = new QGridLayout; |
|
2733 |
gridLayout->addWidget(new QLabel(tr("MISMATCH: %1").arg(QTest::currentDataTag())), 0, 0, 1, 2); |
|
2734 |
gridLayout->addWidget(new QLabel(tr("Current")), 1, 0); |
|
2735 |
gridLayout->addWidget(new QLabel(tr("Expected")), 1, 1); |
|
2736 |
gridLayout->addWidget(expectedLabel, 2, 1); |
|
2737 |
gridLayout->addWidget(newLabel, 2, 0); |
|
2738 |
||
2739 |
QWidget widget; |
|
2740 |
widget.setLayout(gridLayout); |
|
2741 |
widget.show(); |
|
2742 |
||
2743 |
QTestEventLoop::instance().enterLoop(1); |
|
2744 |
||
2745 |
QFAIL("Images are not identical."); |
|
2746 |
#else |
|
2747 |
// generate |
|
2748 |
qDebug() << "Updating" << QTest::currentDataTag() << ":" << bigImage.save(fileName, "png"); |
|
2749 |
#endif |
|
2750 |
} |
|
2751 |
} |
|
2752 |
||
2753 |
void tst_QGraphicsScene::contextMenuEvent() |
|
2754 |
{ |
|
2755 |
QGraphicsScene scene; |
|
2756 |
QEvent activate(QEvent::WindowActivate); |
|
2757 |
QApplication::sendEvent(&scene, &activate); |
|
2758 |
||
2759 |
EventTester *item = new EventTester; |
|
2760 |
scene.addItem(item); |
|
2761 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
2762 |
item->setFocus(); |
|
2763 |
||
2764 |
QVERIFY(item->hasFocus()); |
|
2765 |
QVERIFY(scene.hasFocus()); |
|
2766 |
||
2767 |
QGraphicsView view(&scene); |
|
2768 |
view.show(); |
|
2769 |
#ifdef Q_WS_X11 |
|
2770 |
qt_x11_wait_for_window_manager(&view); |
|
2771 |
#endif |
|
2772 |
view.centerOn(item); |
|
2773 |
||
2774 |
{ |
|
2775 |
QContextMenuEvent event(QContextMenuEvent::Keyboard, view.viewport()->rect().center(), |
|
2776 |
view.mapToGlobal(view.viewport()->rect().center())); |
|
2777 |
QApplication::sendEvent(view.viewport(), &event); |
|
2778 |
QCOMPARE(item->eventTypes.last(), QEvent::GraphicsSceneContextMenu); |
|
2779 |
} |
|
2780 |
} |
|
2781 |
||
2782 |
class ContextMenuItem : public QGraphicsRectItem |
|
2783 |
{ |
|
2784 |
public: |
|
2785 |
ContextMenuItem() : QGraphicsRectItem(0, 0, 100, 100) |
|
2786 |
{ setBrush(Qt::red); } |
|
2787 |
||
2788 |
protected: |
|
2789 |
void contextMenuEvent(QGraphicsSceneContextMenuEvent *) |
|
2790 |
{ /* just accept */ } |
|
2791 |
}; |
|
2792 |
||
2793 |
void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() |
|
2794 |
{ |
|
2795 |
QGraphicsScene scene(0, 0, 200, 200); |
|
2796 |
ContextMenuItem *item = new ContextMenuItem; |
|
2797 |
item->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
2798 |
scene.addItem(item); |
|
2799 |
||
2800 |
QGraphicsView view(&scene); |
|
2801 |
view.resize(200, 200); |
|
2802 |
view.show(); |
|
2803 |
#ifdef Q_WS_X11 |
|
2804 |
qt_x11_wait_for_window_manager(&view); |
|
2805 |
#endif |
|
2806 |
||
2807 |
{ |
|
2808 |
QPoint pos(50, 50); |
|
2809 |
QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); |
|
2810 |
event.ignore(); |
|
2811 |
QApplication::sendEvent(view.viewport(), &event); |
|
2812 |
QVERIFY(event.isAccepted()); |
|
2813 |
} |
|
2814 |
{ |
|
2815 |
QPoint pos(150, 150); |
|
2816 |
QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); |
|
2817 |
event.ignore(); |
|
2818 |
QApplication::sendEvent(view.viewport(), &event); |
|
2819 |
QVERIFY(!event.isAccepted()); |
|
2820 |
} |
|
2821 |
view.scale(1.5, 1.5); |
|
2822 |
{ |
|
2823 |
QPoint pos(25, 25); |
|
2824 |
QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); |
|
2825 |
event.ignore(); |
|
2826 |
QApplication::sendEvent(view.viewport(), &event); |
|
2827 |
QVERIFY(event.isAccepted()); |
|
2828 |
} |
|
2829 |
{ |
|
2830 |
QPoint pos(55, 55); |
|
2831 |
QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.mapToGlobal(pos)); |
|
2832 |
event.ignore(); |
|
2833 |
QApplication::sendEvent(view.viewport(), &event); |
|
2834 |
QVERIFY(!event.isAccepted()); |
|
2835 |
} |
|
2836 |
} |
|
2837 |
||
2838 |
void tst_QGraphicsScene::update() |
|
2839 |
{ |
|
2840 |
QGraphicsScene scene; |
|
2841 |
||
2842 |
QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 100, 100); |
|
2843 |
scene.addItem(rect); |
|
2844 |
qApp->processEvents(); |
|
2845 |
rect->setPos(-100, -100); |
|
2846 |
||
2847 |
// This function forces indexing |
|
2848 |
scene.itemAt(0, 0); |
|
2849 |
||
2850 |
qRegisterMetaType<QList<QRectF> >("QList<QRectF>"); |
|
2851 |
QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>))); |
|
2852 |
||
2853 |
// We update the scene. |
|
2854 |
scene.update(); |
|
2855 |
||
2856 |
// This function forces a purge, which will post an update signal |
|
2857 |
scene.itemAt(0, 0); |
|
2858 |
||
2859 |
// This will process the pending update |
|
2860 |
QApplication::instance()->processEvents(); |
|
2861 |
||
2862 |
// Check that the update region is correct |
|
2863 |
QCOMPARE(spy.count(), 1); |
|
2864 |
QRectF region; |
|
2865 |
foreach (QRectF rectF, qVariantValue<QList<QRectF> >(spy.at(0).at(0))) |
|
2866 |
region |= rectF; |
|
2867 |
QCOMPARE(region, QRectF(-100, -100, 200, 200)); |
|
2868 |
} |
|
2869 |
||
2870 |
void tst_QGraphicsScene::update2() |
|
2871 |
{ |
|
2872 |
QGraphicsScene scene; |
|
2873 |
scene.setSceneRect(-200, -200, 200, 200); |
|
2874 |
CustomView view; |
|
2875 |
view.setScene(&scene); |
|
2876 |
view.show(); |
|
2877 |
QTest::qWaitForWindowShown(&view); |
|
2878 |
QTRY_VERIFY(view.repaints >= 1); |
|
2879 |
view.repaints = 0; |
|
2880 |
||
2881 |
// Make sure QGraphicsScene::update only requires one event-loop iteration |
|
2882 |
// before the view is updated. |
|
2883 |
scene.update(); |
|
2884 |
qApp->processEvents(); |
|
2885 |
QTRY_COMPARE(view.repaints, 1); |
|
2886 |
view.repaints = 0; |
|
2887 |
||
2888 |
// The same for partial scene updates. |
|
2889 |
scene.update(QRectF(-100, -100, 100, 100)); |
|
2890 |
qApp->processEvents(); |
|
2891 |
QCOMPARE(view.repaints, 1); |
|
2892 |
} |
|
2893 |
||
2894 |
void tst_QGraphicsScene::views() |
|
2895 |
{ |
|
2896 |
QGraphicsScene scene; |
|
2897 |
QGraphicsView view(&scene); |
|
2898 |
||
2899 |
QCOMPARE(scene.views().size(), 1); |
|
2900 |
QCOMPARE(scene.views().at(0), &view); |
|
2901 |
||
2902 |
QGraphicsView view1(&scene); |
|
2903 |
QCOMPARE(scene.views().size(), 2); |
|
2904 |
QVERIFY(scene.views().contains(&view1)); |
|
2905 |
||
2906 |
view.setScene(0); |
|
2907 |
QCOMPARE(scene.views().size(), 1); |
|
2908 |
QCOMPARE(scene.views().at(0), &view1); |
|
2909 |
||
2910 |
QGraphicsView *view2 = new QGraphicsView(&scene); |
|
2911 |
QCOMPARE(scene.views().size(), 2); |
|
2912 |
QCOMPARE(scene.views().at(0), &view1); |
|
2913 |
QCOMPARE(scene.views().at(1), view2); |
|
2914 |
||
2915 |
delete view2; |
|
2916 |
||
2917 |
QCOMPARE(scene.views().size(), 1); |
|
2918 |
QCOMPARE(scene.views().at(0), &view1); |
|
2919 |
} |
|
2920 |
||
2921 |
class CustomScene : public QGraphicsScene |
|
2922 |
{ |
|
2923 |
public: |
|
2924 |
CustomScene() : gotTimerEvent(false) |
|
2925 |
{ startTimer(10); } |
|
2926 |
||
2927 |
bool gotTimerEvent; |
|
2928 |
protected: |
|
2929 |
void timerEvent(QTimerEvent *) |
|
2930 |
{ |
|
2931 |
gotTimerEvent = true; |
|
2932 |
} |
|
2933 |
}; |
|
2934 |
||
2935 |
void tst_QGraphicsScene::event() |
|
2936 |
{ |
|
2937 |
// Test that QGraphicsScene properly propagates events to QObject. |
|
2938 |
CustomScene scene; |
|
2939 |
QTestEventLoop::instance().enterLoop(1); |
|
2940 |
QVERIFY(scene.gotTimerEvent); |
|
2941 |
} |
|
2942 |
||
2943 |
class DisabledItemTester : public QGraphicsRectItem |
|
2944 |
{ |
|
2945 |
public: |
|
2946 |
DisabledItemTester(const QRectF &rect, QGraphicsItem *parent = 0) |
|
2947 |
: QGraphicsRectItem(rect, parent) |
|
2948 |
{ } |
|
2949 |
||
2950 |
QList<QEvent::Type> receivedSceneEvents; |
|
2951 |
QList<QEvent::Type> receivedSceneEventFilters; |
|
2952 |
||
2953 |
protected: |
|
2954 |
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
2955 |
{ |
|
2956 |
receivedSceneEventFilters << event->type(); |
|
2957 |
return QGraphicsRectItem::sceneEventFilter(watched, event); |
|
2958 |
} |
|
2959 |
||
2960 |
bool sceneEvent(QEvent *event) |
|
2961 |
{ |
|
2962 |
receivedSceneEvents << event->type(); |
|
2963 |
return QGraphicsRectItem::sceneEvent(event); |
|
2964 |
} |
|
2965 |
}; |
|
2966 |
||
2967 |
void tst_QGraphicsScene::eventsToDisabledItems() |
|
2968 |
{ |
|
2969 |
QGraphicsScene scene; |
|
2970 |
||
2971 |
DisabledItemTester *item1 = new DisabledItemTester(QRectF(-50, -50, 100, 100)); |
|
2972 |
DisabledItemTester *item2 = new DisabledItemTester(QRectF(-50, -50, 100, 100)); |
|
2973 |
item1->setZValue(1); // on top |
|
2974 |
||
2975 |
scene.addItem(item1); |
|
2976 |
scene.addItem(item2); |
|
2977 |
||
2978 |
item1->installSceneEventFilter(item2); |
|
2979 |
||
2980 |
QVERIFY(item1->receivedSceneEvents.isEmpty()); |
|
2981 |
QVERIFY(item2->receivedSceneEvents.isEmpty()); |
|
2982 |
QVERIFY(item1->receivedSceneEventFilters.isEmpty()); |
|
2983 |
QVERIFY(item2->receivedSceneEventFilters.isEmpty()); |
|
2984 |
||
2985 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
2986 |
event.setButton(Qt::LeftButton); |
|
2987 |
QApplication::sendEvent(&scene, &event); |
|
2988 |
||
2989 |
// First item2 receives a scene event filter. Then item1 receives the |
|
2990 |
// actual event. Finally the event propagates to item2. So both items |
|
2991 |
// should have received the event, and item1 also got the filter. |
|
2992 |
QCOMPARE(item1->receivedSceneEvents.size(), 3); |
|
2993 |
QCOMPARE(item2->receivedSceneEvents.size(), 3); |
|
2994 |
QCOMPARE(item1->receivedSceneEventFilters.size(), 0); |
|
2995 |
QCOMPARE(item2->receivedSceneEventFilters.size(), 3); |
|
2996 |
||
2997 |
item1->receivedSceneEvents.clear(); |
|
2998 |
item1->receivedSceneEventFilters.clear(); |
|
2999 |
item2->receivedSceneEvents.clear(); |
|
3000 |
item2->receivedSceneEventFilters.clear(); |
|
3001 |
||
3002 |
item1->setEnabled(false); // disable the topmost item, eat mouse events |
|
3003 |
||
3004 |
event.setButton(Qt::LeftButton); |
|
3005 |
event.setAccepted(false); |
|
3006 |
QApplication::sendEvent(&scene, &event); |
|
3007 |
||
3008 |
// Check that only item1 received anything - it only got the filter. |
|
3009 |
QCOMPARE(item1->receivedSceneEvents.size(), 0); |
|
3010 |
QCOMPARE(item2->receivedSceneEvents.size(), 0); |
|
3011 |
QCOMPARE(item1->receivedSceneEventFilters.size(), 0); |
|
3012 |
QCOMPARE(item2->receivedSceneEventFilters.size(), 3); |
|
3013 |
} |
|
3014 |
||
3015 |
class ExposedPixmapItem : public QGraphicsPixmapItem |
|
3016 |
{ |
|
3017 |
public: |
|
3018 |
ExposedPixmapItem(QGraphicsItem *item = 0) |
|
3019 |
: QGraphicsPixmapItem(item) |
|
3020 |
{ } |
|
3021 |
||
3022 |
void paint(QPainter *, const QStyleOptionGraphicsItem *option, QWidget *) |
|
3023 |
{ |
|
3024 |
exposed = option->exposedRect; |
|
3025 |
} |
|
3026 |
||
3027 |
QRectF exposed; |
|
3028 |
}; |
|
3029 |
||
3030 |
void tst_QGraphicsScene::exposedRect() |
|
3031 |
{ |
|
3032 |
ExposedPixmapItem *item = new ExposedPixmapItem; |
|
3033 |
item->setPixmap(QPixmap(":/Ash_European.jpg")); |
|
3034 |
QGraphicsScene scene; |
|
3035 |
scene.addItem(item); |
|
3036 |
||
3037 |
QCOMPARE(item->exposed, QRectF()); |
|
3038 |
||
3039 |
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
3040 |
QPainter painter(&image); |
|
3041 |
||
3042 |
scene.render(&painter); |
|
3043 |
QCOMPARE(item->exposed, item->boundingRect()); |
|
3044 |
||
3045 |
painter.rotate(180); |
|
3046 |
painter.translate(100, 100); |
|
3047 |
||
3048 |
scene.render(&painter); |
|
3049 |
QCOMPARE(item->exposed, item->boundingRect()); |
|
3050 |
} |
|
3051 |
||
3052 |
void tst_QGraphicsScene::tabFocus_emptyScene() |
|
3053 |
{ |
|
3054 |
QGraphicsScene scene; |
|
3055 |
QDial *dial1 = new QDial; |
|
3056 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
3057 |
QDial *dial2 = new QDial; |
|
3058 |
||
3059 |
QHBoxLayout *layout = new QHBoxLayout; |
|
3060 |
layout->addWidget(dial1); |
|
3061 |
layout->addWidget(view); |
|
3062 |
layout->addWidget(dial2); |
|
3063 |
||
3064 |
QWidget widget; |
|
3065 |
widget.setLayout(layout); |
|
3066 |
widget.show(); |
|
3067 |
qApp->setActiveWindow(&widget); |
|
3068 |
widget.activateWindow(); |
|
3069 |
QTest::qWait(125); |
|
3070 |
||
3071 |
dial1->setFocus(); |
|
3072 |
QVERIFY(dial1->hasFocus()); |
|
3073 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3074 |
QVERIFY(!dial1->hasFocus()); |
|
3075 |
QVERIFY(view->hasFocus()); |
|
3076 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3077 |
QVERIFY(!view->hasFocus()); |
|
3078 |
QVERIFY(dial2->hasFocus()); |
|
3079 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3080 |
QVERIFY(!dial2->hasFocus()); |
|
3081 |
QVERIFY(view->hasFocus()); |
|
3082 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3083 |
QVERIFY(dial1->hasFocus()); |
|
3084 |
QVERIFY(!dial2->hasFocus()); |
|
3085 |
} |
|
3086 |
||
3087 |
void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() |
|
3088 |
{ |
|
3089 |
QGraphicsScene scene; |
|
3090 |
QGraphicsTextItem *item = scene.addText("Qt rocks!"); |
|
3091 |
item->setTabChangesFocus(true); |
|
3092 |
item->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
3093 |
QVERIFY(item->flags() & QGraphicsItem::ItemIsFocusable); |
|
3094 |
item->setFocus(); |
|
3095 |
item->clearFocus(); |
|
3096 |
||
3097 |
QGraphicsTextItem *item2 = scene.addText("Trolltech rocks!"); |
|
3098 |
item2->setTabChangesFocus(true); |
|
3099 |
item2->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
3100 |
item2->setPos(0, item->boundingRect().bottom()); |
|
3101 |
QVERIFY(item2->flags() & QGraphicsItem::ItemIsFocusable); |
|
3102 |
||
3103 |
QDial *dial1 = new QDial; |
|
3104 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
3105 |
QDial *dial2 = new QDial; |
|
3106 |
||
3107 |
QHBoxLayout *layout = new QHBoxLayout; |
|
3108 |
layout->addWidget(dial1); |
|
3109 |
layout->addWidget(view); |
|
3110 |
layout->addWidget(dial2); |
|
3111 |
||
3112 |
QWidget widget; |
|
3113 |
widget.setLayout(layout); |
|
3114 |
widget.show(); |
|
3115 |
qApp->setActiveWindow(&widget); |
|
3116 |
widget.activateWindow(); |
|
3117 |
QTest::qWaitForWindowShown(&widget); |
|
3118 |
QApplication::processEvents(); |
|
3119 |
||
3120 |
dial1->setFocus(); |
|
3121 |
QTRY_VERIFY(dial1->hasFocus()); |
|
3122 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3123 |
QApplication::processEvents(); |
|
3124 |
QTRY_VERIFY(view->hasFocus()); |
|
3125 |
QVERIFY(view->viewport()->hasFocus()); |
|
3126 |
QVERIFY(scene.hasFocus()); |
|
3127 |
QVERIFY(item->hasFocus()); |
|
3128 |
||
3129 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3130 |
QApplication::processEvents(); |
|
3131 |
QTRY_VERIFY(dial2->hasFocus()); |
|
3132 |
||
3133 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3134 |
QApplication::processEvents(); |
|
3135 |
QTRY_VERIFY(view->hasFocus()); |
|
3136 |
QTRY_VERIFY(view->viewport()->hasFocus()); |
|
3137 |
QTRY_VERIFY(scene.hasFocus()); |
|
3138 |
QTRY_VERIFY(item->hasFocus()); |
|
3139 |
||
3140 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3141 |
QApplication::processEvents(); |
|
3142 |
QTRY_VERIFY(dial1->hasFocus()); |
|
3143 |
||
3144 |
// If the item requests input focus, it can only ensure that the scene |
|
3145 |
// sets focus on itself, but the scene cannot request focus from any view. |
|
3146 |
item->setFocus(); |
|
3147 |
QApplication::processEvents(); |
|
3148 |
QTRY_VERIFY(!view->hasFocus()); |
|
3149 |
QVERIFY(!view->viewport()->hasFocus()); |
|
3150 |
QTRY_VERIFY(scene.hasFocus()); |
|
3151 |
QVERIFY(item->hasFocus()); |
|
3152 |
||
3153 |
view->setFocus(); |
|
3154 |
QApplication::processEvents(); |
|
3155 |
QTRY_VERIFY(view->hasFocus()); |
|
3156 |
QTRY_VERIFY(view->viewport()->hasFocus()); |
|
3157 |
QTRY_VERIFY(scene.hasFocus()); |
|
3158 |
QTRY_VERIFY(item->hasFocus()); |
|
3159 |
||
3160 |
// Check that everyone loses focus when the widget is hidden. |
|
3161 |
widget.hide(); |
|
3162 |
QTest::qWait(15); |
|
3163 |
QTRY_VERIFY(!view->hasFocus()); |
|
3164 |
QVERIFY(!view->viewport()->hasFocus()); |
|
3165 |
QVERIFY(!scene.hasFocus()); |
|
3166 |
QVERIFY(!item->hasFocus()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3167 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3168 |
|
3169 |
// Check that the correct item regains focus. |
|
3170 |
widget.show(); |
|
3171 |
qApp->setActiveWindow(&widget); |
|
3172 |
widget.activateWindow(); |
|
3173 |
QTest::qWaitForWindowShown(&widget); |
|
3174 |
QTRY_VERIFY(view->hasFocus()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3175 |
QTRY_VERIFY(scene.isActive()); |
0 | 3176 |
QVERIFY(view->viewport()->hasFocus()); |
3177 |
QVERIFY(scene.hasFocus()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3178 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3179 |
QVERIFY(item->hasFocus()); |
3180 |
} |
|
3181 |
||
3182 |
class FocusWidget : public QGraphicsWidget |
|
3183 |
{ |
|
3184 |
Q_OBJECT |
|
3185 |
public: |
|
3186 |
FocusWidget(QGraphicsItem *parent = 0) |
|
3187 |
: QGraphicsWidget(parent), tabs(0), backTabs(0) |
|
3188 |
{ |
|
3189 |
setFocusPolicy(Qt::StrongFocus); |
|
3190 |
resize(100, 100); |
|
3191 |
} |
|
3192 |
||
3193 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) |
|
3194 |
{ |
|
3195 |
if (option->state & QStyle::State_HasFocus) { |
|
3196 |
painter->fillRect(rect(), Qt::blue); |
|
3197 |
} |
|
3198 |
painter->setBrush(Qt::green); |
|
3199 |
painter->drawEllipse(rect()); |
|
3200 |
if (option->state & QStyle::State_HasFocus) { |
|
3201 |
painter->setPen(QPen(Qt::black, 1, Qt::DashLine)); |
|
3202 |
painter->setBrush(Qt::NoBrush); |
|
3203 |
painter->drawEllipse(rect().adjusted(5, 5, -5, -5)); |
|
3204 |
} |
|
3205 |
} |
|
3206 |
||
3207 |
int tabs; |
|
3208 |
int backTabs; |
|
3209 |
||
3210 |
protected: |
|
3211 |
bool sceneEvent(QEvent *event) |
|
3212 |
{ |
|
3213 |
if (event->type() == QEvent::KeyPress) { |
|
3214 |
QKeyEvent *k = static_cast<QKeyEvent *>(event); |
|
3215 |
if (k->key() == Qt::Key_Tab) |
|
3216 |
++tabs; |
|
3217 |
if (k->key() == Qt::Key_Backtab) |
|
3218 |
++backTabs; |
|
3219 |
} |
|
3220 |
return QGraphicsWidget::sceneEvent(event); |
|
3221 |
} |
|
3222 |
||
3223 |
void focusInEvent(QFocusEvent *) |
|
3224 |
{ update(); } |
|
3225 |
void focusOutEvent(QFocusEvent *) |
|
3226 |
{ update(); } |
|
3227 |
}; |
|
3228 |
||
3229 |
void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets() |
|
3230 |
{ |
|
3231 |
QGraphicsScene scene; |
|
3232 |
||
3233 |
FocusWidget *widget1 = new FocusWidget; |
|
3234 |
FocusWidget *widget2 = new FocusWidget; |
|
3235 |
widget2->setPos(widget1->boundingRect().right(), 0); |
|
3236 |
scene.addItem(widget1); |
|
3237 |
scene.addItem(widget2); |
|
3238 |
||
3239 |
QDial *dial1 = new QDial; |
|
3240 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
3241 |
view->setRenderHint(QPainter::Antialiasing); |
|
3242 |
QDial *dial2 = new QDial; |
|
3243 |
||
3244 |
QHBoxLayout *layout = new QHBoxLayout; |
|
3245 |
layout->addWidget(dial1); |
|
3246 |
layout->addWidget(view); |
|
3247 |
layout->addWidget(dial2); |
|
3248 |
||
3249 |
QWidget widget; |
|
3250 |
widget.setLayout(layout); |
|
3251 |
widget.show(); |
|
3252 |
qApp->setActiveWindow(&widget); |
|
3253 |
widget.activateWindow(); |
|
3254 |
QTest::qWaitForWindowShown(&widget); |
|
3255 |
QApplication::processEvents(); |
|
3256 |
||
3257 |
dial1->setFocus(); |
|
3258 |
QTRY_VERIFY(dial1->hasFocus()); |
|
3259 |
||
3260 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3261 |
QApplication::processEvents(); |
|
3262 |
QTRY_VERIFY(view->hasFocus()); |
|
3263 |
QTRY_VERIFY(view->viewport()->hasFocus()); |
|
3264 |
QTRY_VERIFY(scene.hasFocus()); |
|
3265 |
QCOMPARE(widget1->tabs, 0); |
|
3266 |
QVERIFY(widget1->hasFocus()); |
|
3267 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3268 |
QApplication::processEvents(); |
|
3269 |
QTRY_COMPARE(widget1->tabs, 1); |
|
3270 |
QTRY_VERIFY(widget2->hasFocus()); |
|
3271 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3272 |
QApplication::processEvents(); |
|
3273 |
QTRY_COMPARE(widget2->tabs, 1); |
|
3274 |
QTRY_VERIFY(dial2->hasFocus()); |
|
3275 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3276 |
QApplication::processEvents(); |
|
3277 |
QTRY_VERIFY(widget2->hasFocus()); |
|
3278 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3279 |
QApplication::processEvents(); |
|
3280 |
QTRY_COMPARE(widget2->backTabs, 1); |
|
3281 |
QTRY_VERIFY(widget1->hasFocus()); |
|
3282 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3283 |
QApplication::processEvents(); |
|
3284 |
QTRY_COMPARE(widget1->backTabs, 1); |
|
3285 |
QTRY_VERIFY(dial1->hasFocus()); |
|
3286 |
||
3287 |
widget1->setFocus(); |
|
3288 |
view->viewport()->setFocus(); |
|
3289 |
widget.hide(); |
|
3290 |
QTest::qWait(15); |
|
3291 |
widget.show(); |
|
3292 |
qApp->setActiveWindow(&widget); |
|
3293 |
widget.activateWindow(); |
|
3294 |
QTest::qWaitForWindowShown(&widget); |
|
3295 |
QTRY_VERIFY(widget1->hasFocus()); |
|
3296 |
} |
|
3297 |
||
3298 |
void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets() |
|
3299 |
{ |
|
3300 |
QGraphicsScene scene; |
|
3301 |
||
3302 |
FocusWidget *widget1 = new FocusWidget; |
|
3303 |
FocusWidget *widget1_1 = new FocusWidget; |
|
3304 |
FocusWidget *widget1_2 = new FocusWidget; |
|
3305 |
widget1_1->setParentItem(widget1); |
|
3306 |
widget1_1->scale(0.5, 0.5); |
|
3307 |
widget1_1->setPos(0, widget1->boundingRect().height() / 2); |
|
3308 |
widget1_2->setParentItem(widget1); |
|
3309 |
widget1_2->scale(0.5, 0.5); |
|
3310 |
widget1_2->setPos(widget1->boundingRect().width() / 2, widget1->boundingRect().height() / 2); |
|
3311 |
||
3312 |
FocusWidget *widget2 = new FocusWidget; |
|
3313 |
widget2->setPos(widget1->boundingRect().right(), 0); |
|
3314 |
||
3315 |
widget1->setData(0, "widget1"); |
|
3316 |
widget1_1->setData(0, "widget1_1"); |
|
3317 |
widget1_2->setData(0, "widget1_2"); |
|
3318 |
widget2->setData(0, "widget2"); |
|
3319 |
||
3320 |
scene.addItem(widget1); |
|
3321 |
scene.addItem(widget2); |
|
3322 |
||
3323 |
QDial *dial1 = new QDial; |
|
3324 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
3325 |
view->setRenderHint(QPainter::Antialiasing); |
|
3326 |
QDial *dial2 = new QDial; |
|
3327 |
||
3328 |
QHBoxLayout *layout = new QHBoxLayout; |
|
3329 |
layout->addWidget(dial1); |
|
3330 |
layout->addWidget(view); |
|
3331 |
layout->addWidget(dial2); |
|
3332 |
||
3333 |
QWidget widget; |
|
3334 |
widget.setLayout(layout); |
|
3335 |
widget.show(); |
|
3336 |
qApp->setActiveWindow(&widget); |
|
3337 |
widget.activateWindow(); |
|
3338 |
QTest::qWaitForWindowShown(&widget); |
|
3339 |
||
3340 |
dial1->setFocus(); |
|
3341 |
QTRY_VERIFY(dial1->hasFocus()); |
|
3342 |
||
3343 |
EventSpy focusInSpy_1(widget1, QEvent::FocusIn); |
|
3344 |
EventSpy focusOutSpy_1(widget1, QEvent::FocusOut); |
|
3345 |
EventSpy focusInSpy_1_1(widget1_1, QEvent::FocusIn); |
|
3346 |
EventSpy focusOutSpy_1_1(widget1_1, QEvent::FocusOut); |
|
3347 |
EventSpy focusInSpy_1_2(widget1_2, QEvent::FocusIn); |
|
3348 |
EventSpy focusOutSpy_1_2(widget1_2, QEvent::FocusOut); |
|
3349 |
EventSpy focusInSpy_2(widget2, QEvent::FocusIn); |
|
3350 |
EventSpy focusOutSpy_2(widget2, QEvent::FocusOut); |
|
3351 |
||
3352 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3353 |
QApplication::processEvents(); |
|
3354 |
QTRY_VERIFY(widget1->hasFocus()); |
|
3355 |
QCOMPARE(focusInSpy_1.count(), 1); |
|
3356 |
||
3357 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3358 |
QApplication::processEvents(); |
|
3359 |
QTRY_VERIFY(!widget1->hasFocus()); |
|
3360 |
QVERIFY(widget1_1->hasFocus()); |
|
3361 |
QCOMPARE(focusOutSpy_1.count(), 1); |
|
3362 |
QCOMPARE(focusInSpy_1_1.count(), 1); |
|
3363 |
||
3364 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3365 |
QApplication::processEvents(); |
|
3366 |
QTRY_VERIFY(!widget1_1->hasFocus()); |
|
3367 |
QVERIFY(widget1_2->hasFocus()); |
|
3368 |
QCOMPARE(focusOutSpy_1_1.count(), 1); |
|
3369 |
QCOMPARE(focusInSpy_1_2.count(), 1); |
|
3370 |
||
3371 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3372 |
QApplication::processEvents(); |
|
3373 |
QTRY_VERIFY(!widget1_2->hasFocus()); |
|
3374 |
QVERIFY(widget2->hasFocus()); |
|
3375 |
QCOMPARE(focusOutSpy_1_2.count(), 1); |
|
3376 |
QCOMPARE(focusInSpy_2.count(), 1); |
|
3377 |
||
3378 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
3379 |
QApplication::processEvents(); |
|
3380 |
QTRY_VERIFY(!widget2->hasFocus()); |
|
3381 |
QVERIFY(dial2->hasFocus()); |
|
3382 |
QCOMPARE(focusOutSpy_2.count(), 1); |
|
3383 |
||
3384 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3385 |
QApplication::processEvents(); |
|
3386 |
QTRY_VERIFY(widget2->hasFocus()); |
|
3387 |
QCOMPARE(focusInSpy_2.count(), 2); |
|
3388 |
||
3389 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3390 |
QApplication::processEvents(); |
|
3391 |
QTRY_VERIFY(!widget2->hasFocus()); |
|
3392 |
QTRY_VERIFY(widget1_2->hasFocus()); |
|
3393 |
QCOMPARE(focusOutSpy_2.count(), 2); |
|
3394 |
QCOMPARE(focusInSpy_1_2.count(), 2); |
|
3395 |
||
3396 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3397 |
QApplication::processEvents(); |
|
3398 |
QTRY_VERIFY(!widget1_2->hasFocus()); |
|
3399 |
QTRY_VERIFY(widget1_1->hasFocus()); |
|
3400 |
QCOMPARE(focusOutSpy_1_2.count(), 2); |
|
3401 |
QCOMPARE(focusInSpy_1_1.count(), 2); |
|
3402 |
||
3403 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3404 |
QApplication::processEvents(); |
|
3405 |
QTRY_VERIFY(!widget1_1->hasFocus()); |
|
3406 |
QTRY_VERIFY(widget1->hasFocus()); |
|
3407 |
QCOMPARE(focusOutSpy_1_1.count(), 2); |
|
3408 |
QCOMPARE(focusInSpy_1.count(), 2); |
|
3409 |
||
3410 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
3411 |
QApplication::processEvents(); |
|
3412 |
QTRY_VERIFY(!widget1->hasFocus()); |
|
3413 |
QTRY_VERIFY(dial1->hasFocus()); |
|
3414 |
QCOMPARE(focusOutSpy_1.count(), 2); |
|
3415 |
||
3416 |
widget1->setFocus(); |
|
3417 |
view->viewport()->setFocus(); |
|
3418 |
widget.hide(); |
|
3419 |
QTest::qWait(12); |
|
3420 |
widget.show(); |
|
3421 |
qApp->setActiveWindow(&widget); |
|
3422 |
widget.activateWindow(); |
|
3423 |
QTest::qWaitForWindowShown(&widget); |
|
3424 |
QApplication::processEvents(); |
|
3425 |
QTRY_VERIFY(widget1->hasFocus()); |
|
3426 |
} |
|
3427 |
||
3428 |
void tst_QGraphicsScene::style() |
|
3429 |
{ |
|
3430 |
QPointer<QWindowsStyle> windowsStyle = new QWindowsStyle; |
|
3431 |
||
3432 |
QGraphicsScene scene; |
|
3433 |
QLineEdit *edit = new QLineEdit; |
|
3434 |
QGraphicsProxyWidget *proxy = scene.addWidget(edit); |
|
3435 |
||
3436 |
EventSpy sceneSpy(&scene, QEvent::StyleChange); |
|
3437 |
EventSpy proxySpy(proxy, QEvent::StyleChange); |
|
3438 |
EventSpy editSpy(edit, QEvent::StyleChange); |
|
3439 |
||
3440 |
QCOMPARE(scene.style(), QApplication::style()); |
|
3441 |
||
3442 |
scene.setStyle(windowsStyle); |
|
3443 |
QCOMPARE(sceneSpy.count(), 1); |
|
3444 |
QCOMPARE(proxySpy.count(), 1); |
|
3445 |
QCOMPARE(editSpy.count(), 1); |
|
3446 |
QCOMPARE(scene.style(), (QStyle *)windowsStyle); |
|
3447 |
QCOMPARE(proxy->style(), (QStyle *)windowsStyle); |
|
3448 |
QCOMPARE(edit->style(), (QStyle *)windowsStyle); |
|
3449 |
||
3450 |
scene.setStyle(0); |
|
3451 |
QCOMPARE(sceneSpy.count(), 2); |
|
3452 |
QCOMPARE(proxySpy.count(), 2); |
|
3453 |
QCOMPARE(editSpy.count(), 2); |
|
3454 |
QCOMPARE(scene.style(), QApplication::style()); |
|
3455 |
QCOMPARE(proxy->style(), QApplication::style()); |
|
3456 |
QCOMPARE(edit->style(), QApplication::style()); |
|
3457 |
QVERIFY(!windowsStyle); // deleted |
|
3458 |
} |
|
3459 |
||
3460 |
void tst_QGraphicsScene::task139710_bspTreeCrash() |
|
3461 |
{ |
|
3462 |
// create a scene with 2000 items |
|
3463 |
QGraphicsScene scene(0, 0, 1000, 1000); |
|
3464 |
||
3465 |
for (int i = 0; i < 2; ++i) { |
|
3466 |
// trigger delayed item indexing |
|
3467 |
qApp->processEvents(); |
|
3468 |
scene.setSceneRect(0, 0, 10000, 10000); |
|
3469 |
||
3470 |
// delete all items in the scene - pointers are now likely to be recycled |
|
3471 |
foreach (QGraphicsItem *item, scene.items()) { |
|
3472 |
scene.removeItem(item); |
|
3473 |
delete item; |
|
3474 |
} |
|
3475 |
||
3476 |
// add 1000 more items - the BSP tree is now resized |
|
3477 |
for (int i = 0; i < 1000; ++i) { |
|
3478 |
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200)); |
|
3479 |
item->setPos(qrand() % 10000, qrand() % 10000); |
|
3480 |
} |
|
3481 |
||
3482 |
// trigger delayed item indexing for the first 1000 items |
|
3483 |
qApp->processEvents(); |
|
3484 |
||
3485 |
// add 1000 more items - the BSP tree is now resized |
|
3486 |
for (int i = 0; i < 1000; ++i) { |
|
3487 |
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200)); |
|
3488 |
item->setPos(qrand() % 10000, qrand() % 10000); |
|
3489 |
} |
|
3490 |
||
3491 |
// get items from the BSP tree and use them. there was junk in the tree |
|
3492 |
// the second time this happened. |
|
3493 |
foreach (QGraphicsItem *item, scene.items(QRectF(0, 0, 1000, 1000))) |
|
3494 |
item->moveBy(0, 0); |
|
3495 |
} |
|
3496 |
} |
|
3497 |
||
3498 |
void tst_QGraphicsScene::task139782_containsItemBoundingRect() |
|
3499 |
{ |
|
3500 |
// The item in question has a scene bounding rect of (10, 10, 50, 50) |
|
3501 |
QGraphicsScene scene(0.0, 0.0, 200.0, 200.0); |
|
3502 |
QGraphicsRectItem *item = new QGraphicsRectItem(0.0, 0.0, 50.0, 50.0, 0, &scene); |
|
3503 |
item->setPos(10.0, 10.0); |
|
3504 |
||
3505 |
// The (0, 0, 50, 50) scene rect should not include the item's bounding rect |
|
3506 |
QVERIFY(!scene.items(QRectF(0.0, 0.0, 50.0, 50.0), Qt::ContainsItemBoundingRect).contains(item)); |
|
3507 |
||
3508 |
// The (9, 9, 500, 500) scene rect _should_ include the item's bounding rect |
|
3509 |
QVERIFY(scene.items(QRectF(9.0, 9.0, 500.0, 500.0), Qt::ContainsItemBoundingRect).contains(item)); |
|
3510 |
||
3511 |
// The (25, 25, 5, 5) scene rect should not include the item's bounding rect |
|
3512 |
QVERIFY(!scene.items(QRectF(25.0, 25.0, 5.0, 5.0), Qt::ContainsItemBoundingRect).contains(item)); |
|
3513 |
} |
|
3514 |
||
3515 |
void tst_QGraphicsScene::task176178_itemIndexMethodBreaksSceneRect() |
|
3516 |
{ |
|
3517 |
QGraphicsScene scene; |
|
3518 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); |
|
3519 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
3520 |
rect->setRect(0,0,100,100); |
|
3521 |
scene.addItem(rect); |
|
3522 |
QCOMPARE(scene.sceneRect(), rect->rect()); |
|
3523 |
} |
|
3524 |
||
3525 |
void tst_QGraphicsScene::task160653_selectionChanged() |
|
3526 |
{ |
|
3527 |
QGraphicsScene scene(0, 0, 100, 100); |
|
3528 |
scene.addItem(new QGraphicsRectItem(0, 0, 20, 20)); |
|
3529 |
scene.addItem(new QGraphicsRectItem(30, 30, 20, 20)); |
|
3530 |
foreach (QGraphicsItem *item, scene.items()) { |
|
3531 |
item->setFlags( |
|
3532 |
item->flags() | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); |
|
3533 |
item->setSelected(true); |
|
3534 |
} |
|
3535 |
Q_ASSERT(scene.items().size() > 1); |
|
3536 |
QCOMPARE(scene.items().size(), scene.selectedItems().size()); |
|
3537 |
||
3538 |
QSignalSpy spy(&scene, SIGNAL(selectionChanged())); |
|
3539 |
QGraphicsView view(&scene); |
|
3540 |
QTest::mouseClick( |
|
3541 |
view.viewport(), Qt::LeftButton, 0, view.mapFromScene(scene.items().first()->scenePos())); |
|
3542 |
QCOMPARE(spy.count(), 1); |
|
3543 |
} |
|
3544 |
||
3545 |
void tst_QGraphicsScene::task250680_childClip() |
|
3546 |
{ |
|
3547 |
QGraphicsRectItem *clipper = new QGraphicsRectItem; |
|
3548 |
clipper->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
3549 |
clipper->setPen(QPen(Qt::green)); |
|
3550 |
clipper->setRect(200, 200, 640, 480); |
|
3551 |
||
3552 |
QGraphicsRectItem *rect = new QGraphicsRectItem(clipper); |
|
3553 |
rect->setPen(QPen(Qt::red)); |
|
3554 |
rect->setBrush(QBrush(QColor(255, 0, 0, 75))); |
|
3555 |
rect->setPos(320, 240); |
|
3556 |
rect->setRect(-25, -25, 50, 50); |
|
3557 |
||
3558 |
QGraphicsScene scene; |
|
3559 |
scene.addItem(clipper); |
|
3560 |
||
3561 |
QPainterPath path; |
|
3562 |
path.addRect(-25, -25, 50, 50); |
|
3563 |
QCOMPARE(rect->clipPath(), path); |
|
3564 |
||
3565 |
QCOMPARE(scene.items(QRectF(320, 240, 5, 5)).size(), 2); |
|
3566 |
rect->rotate(45); |
|
3567 |
QCOMPARE(scene.items(QRectF(320, 240, 5, 5)).size(), 2); |
|
3568 |
} |
|
3569 |
||
3570 |
void tst_QGraphicsScene::sorting_data() |
|
3571 |
{ |
|
3572 |
QTest::addColumn<bool>("cache"); |
|
3573 |
||
3574 |
QTest::newRow("Normal sorting") << false; |
|
3575 |
QTest::newRow("Cached sorting") << true; |
|
3576 |
} |
|
3577 |
||
3578 |
void tst_QGraphicsScene::sorting() |
|
3579 |
{ |
|
3580 |
QFETCH(bool, cache); |
|
3581 |
||
3582 |
QGraphicsScene scene; |
|
3583 |
scene.setSortCacheEnabled(cache); |
|
3584 |
||
3585 |
QGraphicsRectItem *t_1 = new QGraphicsRectItem(0, 0, 50, 50); |
|
3586 |
QGraphicsRectItem *c_1 = new QGraphicsRectItem(0, 0, 40, 40, t_1); |
|
3587 |
QGraphicsRectItem *c_1_1 = new QGraphicsRectItem(0, 0, 30, 30, c_1); |
|
3588 |
QGraphicsRectItem *c_1_1_1 = new QGraphicsRectItem(0, 0, 20, 20, c_1_1); |
|
3589 |
QGraphicsRectItem *c_1_2 = new QGraphicsRectItem(0, 0, 30, 30, c_1); |
|
3590 |
QGraphicsRectItem *c_2 = new QGraphicsRectItem(0, 0, 40, 40, t_1); |
|
3591 |
QGraphicsRectItem *c_2_1 = new QGraphicsRectItem(0, 0, 30, 30, c_2); |
|
3592 |
QGraphicsRectItem *c_2_1_1 = new QGraphicsRectItem(0, 0, 20, 20, c_2_1); |
|
3593 |
QGraphicsRectItem *c_2_2 = new QGraphicsRectItem(0, 0, 30, 30, c_2); |
|
3594 |
t_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3595 |
c_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3596 |
c_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3597 |
c_1_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3598 |
c_1_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3599 |
c_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3600 |
c_2_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3601 |
c_2_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3602 |
c_2_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
3603 |
||
3604 |
c_1->setPos(23, 18); |
|
3605 |
c_1_1->setPos(24, 28); |
|
3606 |
c_1_1_1->setPos(-16, 16); |
|
3607 |
c_1_2->setPos(-16, 28); |
|
3608 |
c_1_2->setZValue(1); |
|
3609 |
c_2->setPos(-23, 18); |
|
3610 |
c_2->setZValue(1); |
|
3611 |
c_2_1->setPos(24, 28); |
|
3612 |
c_2_1_1->setPos(-16, 16); |
|
3613 |
c_2_2->setPos(-16, 28); |
|
3614 |
c_2_2->setZValue(1); |
|
3615 |
||
3616 |
c_1->setFlag(QGraphicsItem::ItemIsMovable); |
|
3617 |
c_1_1->setFlag(QGraphicsItem::ItemIsMovable); |
|
3618 |
c_1_1_1->setFlag(QGraphicsItem::ItemIsMovable); |
|
3619 |
c_1_2->setFlag(QGraphicsItem::ItemIsMovable); |
|
3620 |
c_2->setFlag(QGraphicsItem::ItemIsMovable); |
|
3621 |
c_2_1->setFlag(QGraphicsItem::ItemIsMovable); |
|
3622 |
c_2_1_1->setFlag(QGraphicsItem::ItemIsMovable); |
|
3623 |
c_2_2->setFlag(QGraphicsItem::ItemIsMovable); |
|
3624 |
||
3625 |
t_1->setData(0, "t_1"); |
|
3626 |
c_1->setData(0, "c_1"); |
|
3627 |
c_1_1->setData(0, "c_1_1"); |
|
3628 |
c_1_1_1->setData(0, "c_1_1_1"); |
|
3629 |
c_1_2->setData(0, "c_1_2"); |
|
3630 |
c_2->setData(0, "c_2"); |
|
3631 |
c_2_1->setData(0, "c_2_1"); |
|
3632 |
c_2_1_1->setData(0, "c_2_1_1"); |
|
3633 |
c_2_2->setData(0, "c_2_2"); |
|
3634 |
||
3635 |
scene.addItem(t_1); |
|
3636 |
||
3637 |
foreach (QGraphicsItem *item, scene.items()) |
|
3638 |
item->setFlag(QGraphicsItem::ItemIsSelectable); |
|
3639 |
||
3640 |
// QGraphicsView view(&scene); |
|
3641 |
// view.setDragMode(QGraphicsView::RubberBandDrag); |
|
3642 |
// view.show(); |
|
3643 |
||
3644 |
qDebug() << "items: {"; |
|
3645 |
foreach (QGraphicsItem *item, scene.items(32, 31, 4, 55)) |
|
3646 |
qDebug() << "\t" << item->data(0).toString(); |
|
3647 |
qDebug() << "}"; |
|
3648 |
||
3649 |
QCOMPARE(scene.items(32, 31, 4, 55), |
|
3650 |
QList<QGraphicsItem *>() |
|
3651 |
<< c_1_2 << c_1_1_1 << c_1 << t_1); |
|
3652 |
QCOMPARE(scene.items(-53, 47, 136, 3), |
|
3653 |
QList<QGraphicsItem *>() |
|
3654 |
<< c_2_2 << c_2_1 << c_2 << c_1_2 << c_1_1 << c_1 << t_1); |
|
3655 |
QCOMPARE(scene.items(-23, 79, 104, 3), |
|
3656 |
QList<QGraphicsItem *>() |
|
3657 |
<< c_2_1_1 << c_1_1_1); |
|
3658 |
QCOMPARE(scene.items(-26, -3, 92, 79), |
|
3659 |
QList<QGraphicsItem *>() |
|
3660 |
<< c_2_2 << c_2_1_1 << c_2_1 << c_2 |
|
3661 |
<< c_1_2 << c_1_1_1 << c_1_1 << c_1 |
|
3662 |
<< t_1); |
|
3663 |
} |
|
3664 |
||
3665 |
class ChangedListener : public QObject |
|
3666 |
{ |
|
3667 |
Q_OBJECT |
|
3668 |
public: |
|
3669 |
QList<QList<QRectF> > changes; |
|
3670 |
||
3671 |
public slots: |
|
3672 |
void changed(const QList<QRectF> &dirty) |
|
3673 |
{ |
|
3674 |
changes << dirty; |
|
3675 |
} |
|
3676 |
}; |
|
3677 |
||
3678 |
void tst_QGraphicsScene::changedSignal_data() |
|
3679 |
{ |
|
3680 |
QTest::addColumn<bool>("withView"); |
|
3681 |
||
3682 |
QTest::newRow("without view") << false; |
|
3683 |
QTest::newRow("with view") << true; |
|
3684 |
} |
|
3685 |
||
3686 |
void tst_QGraphicsScene::changedSignal() |
|
3687 |
{ |
|
3688 |
QFETCH(bool, withView); |
|
3689 |
QGraphicsScene scene; |
|
3690 |
ChangedListener cl; |
|
3691 |
connect(&scene, SIGNAL(changed(const QList<QRectF> &)), &cl, SLOT(changed(const QList<QRectF> &))); |
|
3692 |
||
3693 |
QGraphicsView *view = 0; |
|
3694 |
if (withView) |
|
3695 |
view = new QGraphicsView(&scene); |
|
3696 |
||
3697 |
QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 10, 10); |
|
3698 |
scene.addItem(rect); |
|
3699 |
||
3700 |
QCOMPARE(cl.changes.size(), 0); |
|
3701 |
QTRY_COMPARE(cl.changes.size(), 1); |
|
3702 |
QCOMPARE(cl.changes.at(0).size(), 1); |
|
3703 |
QCOMPARE(cl.changes.at(0).first(), QRectF(0, 0, 10, 10)); |
|
3704 |
||
3705 |
rect->setPos(20, 0); |
|
3706 |
||
3707 |
QCOMPARE(cl.changes.size(), 1); |
|
3708 |
qApp->processEvents(); |
|
3709 |
QCOMPARE(cl.changes.size(), 2); |
|
3710 |
QCOMPARE(cl.changes.at(1).size(), 2); |
|
3711 |
QCOMPARE(cl.changes.at(1).first(), QRectF(0, 0, 10, 10)); |
|
3712 |
QCOMPARE(cl.changes.at(1).last(), QRectF(20, 0, 10, 10)); |
|
3713 |
||
3714 |
QCOMPARE(scene.sceneRect(), QRectF(0, 0, 30, 10)); |
|
3715 |
||
3716 |
if (withView) |
|
3717 |
delete view; |
|
3718 |
} |
|
3719 |
||
3720 |
void tst_QGraphicsScene::stickyFocus_data() |
|
3721 |
{ |
|
3722 |
QTest::addColumn<bool>("sticky"); |
|
3723 |
QTest::newRow("sticky") << true; |
|
3724 |
QTest::newRow("not sticky") << false; |
|
3725 |
} |
|
3726 |
||
3727 |
void tst_QGraphicsScene::stickyFocus() |
|
3728 |
{ |
|
3729 |
QFETCH(bool, sticky); |
|
3730 |
||
3731 |
QGraphicsScene scene; |
|
3732 |
QEvent activate(QEvent::WindowActivate); |
|
3733 |
QApplication::sendEvent(&scene, &activate); |
|
3734 |
||
3735 |
QGraphicsTextItem *text = scene.addText("Hei"); |
|
3736 |
text->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
3737 |
text->setFocus(); |
|
3738 |
||
3739 |
scene.setStickyFocus(sticky); |
|
3740 |
||
3741 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
3742 |
event.setScenePos(QPointF(-10, -10)); // outside item |
|
3743 |
event.setButton(Qt::LeftButton); |
|
3744 |
qApp->sendEvent(&scene, &event); |
|
3745 |
||
3746 |
QCOMPARE(text->hasFocus(), sticky); |
|
3747 |
} |
|
3748 |
||
3749 |
void tst_QGraphicsScene::sendEvent() |
|
3750 |
{ |
|
3751 |
QGraphicsScene scene; |
|
3752 |
QGraphicsTextItem *item = scene.addText(QString()); |
|
3753 |
EventSpy *spy = new EventSpy(&scene, item, QEvent::User); |
|
3754 |
QCOMPARE(spy->count(), 0); |
|
3755 |
QEvent event(QEvent::User); |
|
3756 |
scene.sendEvent(item, &event); |
|
3757 |
QCOMPARE(spy->count(), 1); |
|
3758 |
} |
|
3759 |
||
3760 |
void tst_QGraphicsScene::inputMethod_data() |
|
3761 |
{ |
|
3762 |
QTest::addColumn<int>("flags"); |
|
3763 |
QTest::addColumn<bool>("callFocusItem"); |
|
3764 |
QTest::newRow("0") << 0 << false; |
|
3765 |
QTest::newRow("1") << (int)QGraphicsItem::ItemAcceptsInputMethod << false; |
|
3766 |
QTest::newRow("2") << (int)QGraphicsItem::ItemIsFocusable << false; |
|
3767 |
QTest::newRow("3") << |
|
3768 |
(int)(QGraphicsItem::ItemAcceptsInputMethod|QGraphicsItem::ItemIsFocusable) << true; |
|
3769 |
} |
|
3770 |
||
3771 |
class InputMethodTester : public QGraphicsRectItem |
|
3772 |
{ |
|
3773 |
void inputMethodEvent(QInputMethodEvent *) { ++eventCalls; } |
|
3774 |
QVariant inputMethodQuery(Qt::InputMethodQuery) const { ++queryCalls; return QVariant(); } |
|
3775 |
public: |
|
3776 |
int eventCalls; |
|
3777 |
mutable int queryCalls; |
|
3778 |
}; |
|
3779 |
||
3780 |
void tst_QGraphicsScene::inputMethod() |
|
3781 |
{ |
|
3782 |
QFETCH(int, flags); |
|
3783 |
QFETCH(bool, callFocusItem); |
|
3784 |
||
3785 |
InputMethodTester *item = new InputMethodTester; |
|
3786 |
item->setFlags((QGraphicsItem::GraphicsItemFlags)flags); |
|
3787 |
||
3788 |
QGraphicsScene scene; |
|
3789 |
QEvent activate(QEvent::WindowActivate); |
|
3790 |
QApplication::sendEvent(&scene, &activate); |
|
3791 |
||
3792 |
scene.addItem(item); |
|
3793 |
QInputMethodEvent event; |
|
3794 |
||
3795 |
scene.setFocusItem(item); |
|
3796 |
QCOMPARE(!!(item->flags() & QGraphicsItem::ItemIsFocusable), scene.focusItem() == item); |
|
3797 |
||
3798 |
item->eventCalls = 0; |
|
3799 |
qApp->sendEvent(&scene, &event); |
|
3800 |
QCOMPARE(item->eventCalls, callFocusItem ? 1 : 0); |
|
3801 |
||
3802 |
item->queryCalls = 0; |
|
3803 |
scene.inputMethodQuery((Qt::InputMethodQuery)0); |
|
3804 |
QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0); |
|
3805 |
||
3806 |
scene.setFocusItem(0); |
|
3807 |
QCOMPARE(item->eventCalls, callFocusItem ? 2 : 0); // verify correct delivery of "reset" event |
|
3808 |
QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0); // verify that value is unaffected |
|
3809 |
||
3810 |
item->eventCalls = 0; |
|
3811 |
qApp->sendEvent(&scene, &event); |
|
3812 |
QCOMPARE(item->eventCalls, 0); |
|
3813 |
||
3814 |
item->queryCalls = 0; |
|
3815 |
scene.inputMethodQuery((Qt::InputMethodQuery)0); |
|
3816 |
QCOMPARE(item->queryCalls, 0); |
|
3817 |
} |
|
3818 |
||
3819 |
void tst_QGraphicsScene::dispatchHoverOnPress() |
|
3820 |
{ |
|
3821 |
QGraphicsScene scene; |
|
3822 |
EventTester *tester1 = new EventTester; |
|
3823 |
tester1->setAcceptHoverEvents(true); |
|
3824 |
EventTester *tester2 = new EventTester; |
|
3825 |
tester2->setAcceptHoverEvents(true); |
|
3826 |
tester2->setPos(30, 30); |
|
3827 |
scene.addItem(tester1); |
|
3828 |
scene.addItem(tester2); |
|
3829 |
||
3830 |
tester1->eventTypes.clear(); |
|
3831 |
tester2->eventTypes.clear(); |
|
3832 |
||
3833 |
{ |
|
3834 |
QGraphicsSceneMouseEvent me(QEvent::GraphicsSceneMousePress); |
|
3835 |
me.setButton(Qt::LeftButton); |
|
3836 |
me.setButtons(Qt::LeftButton); |
|
3837 |
QGraphicsSceneMouseEvent me2(QEvent::GraphicsSceneMouseRelease); |
|
3838 |
me2.setButton(Qt::LeftButton); |
|
3839 |
qApp->sendEvent(&scene, &me); |
|
3840 |
qApp->sendEvent(&scene, &me2); |
|
3841 |
QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() |
|
3842 |
<< QEvent::GraphicsSceneHoverEnter |
|
3843 |
<< QEvent::GraphicsSceneHoverMove |
|
3844 |
<< QEvent::GrabMouse |
|
3845 |
<< QEvent::GraphicsSceneMousePress |
|
3846 |
<< QEvent::UngrabMouse); |
|
3847 |
tester1->eventTypes.clear(); |
|
3848 |
qApp->sendEvent(&scene, &me); |
|
3849 |
qApp->sendEvent(&scene, &me2); |
|
3850 |
QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() |
|
3851 |
<< QEvent::GraphicsSceneHoverMove |
|
3852 |
<< QEvent::GrabMouse |
|
3853 |
<< QEvent::GraphicsSceneMousePress |
|
3854 |
<< QEvent::UngrabMouse); |
|
3855 |
} |
|
3856 |
{ |
|
3857 |
QGraphicsSceneMouseEvent me(QEvent::GraphicsSceneMousePress); |
|
3858 |
me.setScenePos(QPointF(30, 30)); |
|
3859 |
me.setButton(Qt::LeftButton); |
|
3860 |
me.setButtons(Qt::LeftButton); |
|
3861 |
QGraphicsSceneMouseEvent me2(QEvent::GraphicsSceneMouseRelease); |
|
3862 |
me2.setScenePos(QPointF(30, 30)); |
|
3863 |
me2.setButton(Qt::LeftButton); |
|
3864 |
tester1->eventTypes.clear(); |
|
3865 |
qApp->sendEvent(&scene, &me); |
|
3866 |
qApp->sendEvent(&scene, &me2); |
|
3867 |
qDebug() << tester1->eventTypes; |
|
3868 |
QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() |
|
3869 |
<< QEvent::GraphicsSceneHoverLeave); |
|
3870 |
QCOMPARE(tester2->eventTypes, QList<QEvent::Type>() |
|
3871 |
<< QEvent::GraphicsSceneHoverEnter |
|
3872 |
<< QEvent::GraphicsSceneHoverMove |
|
3873 |
<< QEvent::GrabMouse |
|
3874 |
<< QEvent::GraphicsSceneMousePress |
|
3875 |
<< QEvent::UngrabMouse); |
|
3876 |
tester2->eventTypes.clear(); |
|
3877 |
qApp->sendEvent(&scene, &me); |
|
3878 |
qApp->sendEvent(&scene, &me2); |
|
3879 |
QCOMPARE(tester2->eventTypes, QList<QEvent::Type>() |
|
3880 |
<< QEvent::GraphicsSceneHoverMove |
|
3881 |
<< QEvent::GrabMouse |
|
3882 |
<< QEvent::GraphicsSceneMousePress |
|
3883 |
<< QEvent::UngrabMouse); |
|
3884 |
} |
|
3885 |
} |
|
3886 |
||
3887 |
void tst_QGraphicsScene::initialFocus_data() |
|
3888 |
{ |
|
3889 |
QTest::addColumn<bool>("activeScene"); |
|
3890 |
QTest::addColumn<bool>("explicitSetFocus"); |
|
3891 |
QTest::addColumn<bool>("isPanel"); |
|
3892 |
QTest::addColumn<bool>("shouldHaveFocus"); |
|
3893 |
||
3894 |
QTest::newRow("inactive scene, normal item") << false << false << false << false; |
|
3895 |
QTest::newRow("inactive scene, panel item") << false << false << true << false; |
|
3896 |
QTest::newRow("inactive scene, normal item, explicit focus") << false << true << false << true; |
|
3897 |
QTest::newRow("inactive scene, panel, explicit focus") << false << true << true << true; |
|
3898 |
QTest::newRow("active scene, normal item") << true << false << false << false; |
|
3899 |
QTest::newRow("active scene, panel item") << true << false << true << false; |
|
3900 |
QTest::newRow("active scene, normal item, explicit focus") << true << true << false << true; |
|
3901 |
QTest::newRow("active scene, panel, explicit focus") << true << true << true << true; |
|
3902 |
} |
|
3903 |
||
3904 |
void tst_QGraphicsScene::initialFocus() |
|
3905 |
{ |
|
3906 |
QFETCH(bool, activeScene); |
|
3907 |
QFETCH(bool, explicitSetFocus); |
|
3908 |
QFETCH(bool, isPanel); |
|
3909 |
QFETCH(bool, shouldHaveFocus); |
|
3910 |
||
3911 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
3912 |
rect->setFlag(QGraphicsItem::ItemIsFocusable); |
|
3913 |
QVERIFY(!rect->hasFocus()); |
|
3914 |
||
3915 |
if (isPanel) |
|
3916 |
rect->setFlag(QGraphicsItem::ItemIsPanel); |
|
3917 |
||
3918 |
// Setting focus on an item before adding to the scene will ensure |
|
3919 |
// it gets focus when the scene is activated. |
|
3920 |
if (explicitSetFocus) |
|
3921 |
rect->setFocus(); |
|
3922 |
||
3923 |
QGraphicsScene scene; |
|
3924 |
QVERIFY(!scene.isActive()); |
|
3925 |
||
3926 |
if (activeScene) { |
|
3927 |
QEvent windowActivate(QEvent::WindowActivate); |
|
3928 |
qApp->sendEvent(&scene, &windowActivate); |
|
3929 |
scene.setFocus(); |
|
3930 |
} |
|
3931 |
||
3932 |
scene.addItem(rect); |
|
3933 |
||
3934 |
if (!activeScene) { |
|
3935 |
QEvent windowActivate(QEvent::WindowActivate); |
|
3936 |
qApp->sendEvent(&scene, &windowActivate); |
|
3937 |
scene.setFocus(); |
|
3938 |
} |
|
3939 |
||
3940 |
QCOMPARE(rect->hasFocus(), shouldHaveFocus); |
|
3941 |
} |
|
3942 |
||
3943 |
class PolishItem : public QGraphicsTextItem |
|
3944 |
{ |
|
3945 |
public: |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3946 |
PolishItem(QGraphicsItem *parent = 0) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3947 |
: QGraphicsTextItem(parent), polished(false), deleteChildrenInPolish(true), addChildrenInPolish(false) { } |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3948 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3949 |
bool polished; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3950 |
bool deleteChildrenInPolish; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3951 |
bool addChildrenInPolish; |
0 | 3952 |
protected: |
3953 |
QVariant itemChange(GraphicsItemChange change, const QVariant& value) |
|
3954 |
{ |
|
3955 |
if (change == ItemVisibleChange) { |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3956 |
polished = true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3957 |
if (deleteChildrenInPolish) |
0 | 3958 |
qDeleteAll(childItems()); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3959 |
if (addChildrenInPolish) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3960 |
for (int i = 0; i < 10; ++i) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3961 |
new PolishItem(this); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3962 |
} |
0 | 3963 |
} |
3964 |
return QGraphicsItem::itemChange(change, value); |
|
3965 |
} |
|
3966 |
}; |
|
3967 |
||
3968 |
void tst_QGraphicsScene::polishItems() |
|
3969 |
{ |
|
3970 |
QGraphicsScene scene; |
|
3971 |
PolishItem *parent = new PolishItem; |
|
3972 |
scene.addItem(parent); |
|
3973 |
PolishItem *child = new PolishItem(parent); |
|
3974 |
Q_UNUSED(child) |
|
3975 |
// test that QGraphicsScenePrivate::_q_polishItems() doesn't crash |
|
3976 |
QMetaObject::invokeMethod(&scene,"_q_polishItems"); |
|
3977 |
} |
|
3978 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3979 |
void tst_QGraphicsScene::polishItems2() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3980 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3981 |
QGraphicsScene scene; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3982 |
PolishItem *item = new PolishItem; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3983 |
item->addChildrenInPolish = true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3984 |
item->deleteChildrenInPolish = true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3985 |
// These children should be deleted in the polish. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3986 |
for (int i = 0; i < 20; ++i) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3987 |
new PolishItem(item); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3988 |
scene.addItem(item); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3989 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3990 |
// Wait for the polish event to be delivered. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3991 |
QVERIFY(!item->polished); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3992 |
QApplication::sendPostedEvents(&scene, QEvent::MetaCall); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3993 |
QVERIFY(item->polished); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3994 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3995 |
// We deleted the children we added above, but we also |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3996 |
// added 10 new children. These should be polished in the next |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3997 |
// event loop iteration. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3998 |
QList<QGraphicsItem *> children = item->childItems(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3999 |
QCOMPARE(children.count(), 10); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4000 |
foreach (QGraphicsItem *child, children) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4001 |
QVERIFY(!static_cast<PolishItem *>(child)->polished); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4002 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4003 |
QApplication::sendPostedEvents(&scene, QEvent::MetaCall); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4004 |
foreach (QGraphicsItem *child, children) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4005 |
QVERIFY(static_cast<PolishItem *>(child)->polished); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4006 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4007 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4008 |
void tst_QGraphicsScene::isActive() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4009 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4010 |
QGraphicsScene scene1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4011 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4012 |
QGraphicsScene scene2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4013 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4014 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4015 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4016 |
QWidget toplevel1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4017 |
QHBoxLayout *layout = new QHBoxLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4018 |
toplevel1.setLayout(layout); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4019 |
QGraphicsView *view1 = new QGraphicsView(&scene1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4020 |
QGraphicsView *view2 = new QGraphicsView(&scene2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4021 |
layout->addWidget(view1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4022 |
layout->addWidget(view2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4023 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4024 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4025 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4026 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4027 |
view1->setVisible(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4028 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4029 |
toplevel1.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4030 |
QApplication::setActiveWindow(&toplevel1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4031 |
QTest::qWaitForWindowShown(&toplevel1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4032 |
QTRY_COMPARE(QApplication::activeWindow(), &toplevel1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4033 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4034 |
QVERIFY(!scene1.isActive()); //it is hidden; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4035 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4036 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4037 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4038 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4039 |
view1->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4040 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4041 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4042 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4043 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4044 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4045 |
view2->hide(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4046 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4047 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4048 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4049 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4050 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4051 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4052 |
toplevel1.hide(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4053 |
QTest::qWait(50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4054 |
QTRY_VERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4055 |
QTRY_VERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4056 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4057 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4058 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4059 |
toplevel1.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4060 |
QApplication::setActiveWindow(&toplevel1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4061 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4062 |
QTRY_COMPARE(QApplication::activeWindow(), &toplevel1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4063 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4064 |
QTRY_VERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4065 |
QTRY_VERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4066 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4067 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4068 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4069 |
view2->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4070 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4071 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4072 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4073 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4074 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4075 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4076 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4077 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4078 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4079 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4080 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4081 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4082 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4083 |
QWidget toplevel2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4084 |
QHBoxLayout *layout = new QHBoxLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4085 |
toplevel2.setLayout(layout); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4086 |
QGraphicsView *view1 = new QGraphicsView(&scene1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4087 |
QGraphicsView *view2 = new QGraphicsView(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4088 |
layout->addWidget(view1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4089 |
layout->addWidget(view2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4090 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4091 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4092 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4093 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4094 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4095 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4096 |
toplevel2.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4097 |
QApplication::setActiveWindow(&toplevel2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4098 |
QTest::qWaitForWindowShown(&toplevel2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4099 |
QTRY_COMPARE(QApplication::activeWindow(), &toplevel2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4100 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4101 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4102 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4103 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4104 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4105 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4106 |
view2->setScene(&scene2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4107 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4108 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4109 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4110 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4111 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4112 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4113 |
view1->setScene(&scene2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4114 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4115 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4116 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4117 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4118 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4119 |
view1->hide(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4120 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4121 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4122 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4123 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4124 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4125 |
view1->setScene(&scene1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4126 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4127 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4128 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4129 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4130 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4131 |
view1->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4132 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4133 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4134 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4135 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4136 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4137 |
view2->hide(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4138 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4139 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4140 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4141 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4142 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4143 |
QGraphicsView topLevelView; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4144 |
topLevelView.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4145 |
QApplication::setActiveWindow(&topLevelView); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4146 |
topLevelView.setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4147 |
QTest::qWaitForWindowShown(&topLevelView); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4148 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&topLevelView)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4149 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4150 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4151 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4152 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4153 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4154 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4155 |
topLevelView.setScene(&scene1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4156 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4157 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4158 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4159 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4160 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4161 |
view2->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4162 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4163 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4164 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4165 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4166 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4167 |
view1->hide(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4168 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4169 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4170 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4171 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4172 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4173 |
QApplication::setActiveWindow(&toplevel2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4174 |
QTRY_COMPARE(QApplication::activeWindow(), &toplevel2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4175 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4176 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4177 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4178 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4179 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4180 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4181 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4182 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4183 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4184 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4185 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4186 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4187 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4188 |
QWidget toplevel3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4189 |
QHBoxLayout *layout = new QHBoxLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4190 |
toplevel3.setLayout(layout); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4191 |
QGraphicsView *view1 = new QGraphicsView(&scene1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4192 |
QGraphicsView *view2 = new QGraphicsView(&scene2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4193 |
layout->addWidget(view1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4194 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4195 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4196 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4197 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4198 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4199 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4200 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4201 |
toplevel3.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4202 |
QApplication::setActiveWindow(&toplevel3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4203 |
QTest::qWaitForWindowShown(&toplevel3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4204 |
QTRY_COMPARE(QApplication::activeWindow(), &toplevel3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4205 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4206 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4207 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4208 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4209 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4210 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4211 |
layout->addWidget(view2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4212 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4213 |
QVERIFY(scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4214 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4215 |
QVERIFY(scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4216 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4217 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4218 |
view1->setParent(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4219 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4220 |
QVERIFY(scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4221 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4222 |
QVERIFY(scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4223 |
delete view1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4224 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4225 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4226 |
QVERIFY(!scene1.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4227 |
QVERIFY(!scene2.isActive()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4228 |
QVERIFY(!scene1.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4229 |
QVERIFY(!scene2.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4230 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4231 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4232 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4233 |
void tst_QGraphicsScene::siblingIndexAlwaysValid() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4234 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4235 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4236 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4237 |
QGraphicsWidget *parent = new QGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4238 |
parent->setZValue(350); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4239 |
parent->setGeometry(0, 0, 100, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4240 |
QGraphicsWidget *parent2 = new QGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4241 |
parent2->setGeometry(10, 10, 50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4242 |
QGraphicsWidget *child = new QGraphicsWidget(parent2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4243 |
child->setGeometry(15, 15, 25, 25); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4244 |
child->setZValue(150); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4245 |
//Both are top level |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4246 |
scene.addItem(parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4247 |
scene.addItem(parent2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4248 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4249 |
//Then we make the child a top level |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4250 |
child->setParentItem(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4251 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4252 |
//This is trigerred by a repaint... |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4253 |
QGraphicsScenePrivate::get(&scene)->index->estimateTopLevelItems(QRectF(), Qt::AscendingOrder); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4254 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4255 |
delete child; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4256 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4257 |
//If there are in the list that's bad, we crash... |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4258 |
QVERIFY(!QGraphicsScenePrivate::get(&scene)->topLevelItems.contains(static_cast<QGraphicsItem *>(child))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4259 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4260 |
//Other case |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4261 |
QGraphicsScene scene2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4262 |
// works with bsp tree index |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4263 |
scene2.setItemIndexMethod(QGraphicsScene::NoIndex); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4264 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4265 |
QGraphicsView view2(&scene2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4266 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4267 |
// first add the blue rect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4268 |
QGraphicsRectItem* const item1 = new QGraphicsRectItem(QRect( 10, 10, 10, 10 )); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4269 |
item1->setPen(QColor(Qt::blue)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4270 |
item1->setBrush(Qt::blue); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4271 |
scene2.addItem(item1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4272 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4273 |
// then add the red rect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4274 |
QGraphicsRectItem* const item2 = new QGraphicsRectItem(5, 5, 10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4275 |
item2->setPen(QColor(Qt::red)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4276 |
item2->setBrush(Qt::red); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4277 |
scene2.addItem(item2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4278 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4279 |
// now the blue one is visible on top of the red one -> swap them (important for the bug) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4280 |
item1->setZValue(1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4281 |
item2->setZValue(0.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4282 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4283 |
view2.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4284 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4285 |
// handle events as a real life app would do |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4286 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4287 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4288 |
// now delete the red rect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4289 |
delete item2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4290 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4291 |
// handle events as a real life app would do |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4292 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4293 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4294 |
//We should not crash |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4295 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4296 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4297 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4298 |
void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4299 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4300 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4301 |
QGraphicsRectItem *rectItem = scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4302 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4303 |
rectItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4304 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4305 |
QPixmap pixmap(100,200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4306 |
QPainter painter(&pixmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4307 |
painter.setRenderHint(QPainter::Antialiasing); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4308 |
scene.render(&painter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4309 |
painter.end(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4310 |
// No crash, then it passed! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4311 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4312 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4313 |
void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4314 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4315 |
QWidget *w = new QWidget(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4316 |
w->setPalette(Qt::blue); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4317 |
w->setGeometry(0, 0, 50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4318 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4319 |
QGraphicsScene *scene = new QGraphicsScene(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4320 |
QGraphicsView *view = new QGraphicsView(scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4321 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4322 |
QGraphicsProxyWidget *proxy = scene->addWidget(w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4323 |
proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4324 |
proxy->rotate(15); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4325 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4326 |
view->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4327 |
QTest::qWaitForWindowShown(view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4328 |
w->update(10,10,10,10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4329 |
QTest::qWait(50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4330 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4331 |
QPixmap pix; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4332 |
QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(proxy); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4333 |
QPixmapCache::Key key = itemp->extraItemCache()->deviceData.value(view->viewport()).key; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4334 |
QVERIFY(QPixmapCache::find(key, &pix)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4335 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4336 |
QTransform t = proxy->sceneTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4337 |
// Map from scene coordinates to pixmap coordinates. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4338 |
// X origin in the pixmap is the most-left point |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4339 |
// of the item's boundingRect in the scene. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4340 |
qreal adjust = t.mapRect(proxy->boundingRect().toRect()).left(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4341 |
QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4342 |
QPixmap subpix = pix.copy(rect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4343 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4344 |
QImage im = subpix.toImage(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4345 |
for(int i = 0; i < im.width(); i++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4346 |
for(int j = 0; j < im.height(); j++) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4347 |
QCOMPARE(qAlpha(im.pixel(i, j)), 255); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4348 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4349 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4350 |
|
0 | 4351 |
QTEST_MAIN(tst_QGraphicsScene) |
4352 |
#include "tst_qgraphicsscene.moc" |