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