author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 09:15:16 +0300 | |
branch | RCL_3 |
changeset 10 | 68d3b337861b |
parent 7 | 3f74d0d4af4c |
child 13 | c0432d11811c |
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 |
||
45 |
#include <private/qtextcontrol_p.h> |
|
46 |
#include <private/qgraphicsitem_p.h> |
|
47 |
#include <private/qgraphicsview_p.h> |
|
48 |
#include <QStyleOptionGraphicsItem> |
|
49 |
#include <QAbstractTextDocumentLayout> |
|
50 |
#include <QBitmap> |
|
51 |
#include <QCursor> |
|
52 |
#include <QLabel> |
|
53 |
#include <QDial> |
|
54 |
#include <QGraphicsItem> |
|
55 |
#include <QGraphicsScene> |
|
56 |
#include <QGraphicsSceneEvent> |
|
57 |
#include <QGraphicsView> |
|
58 |
#include <QGraphicsWidget> |
|
59 |
#include <QGraphicsProxyWidget> |
|
60 |
#include <QPainter> |
|
61 |
#include <QScrollBar> |
|
62 |
#include <QVBoxLayout> |
|
63 |
#include <QGraphicsEffect> |
|
64 |
||
65 |
#include "../../shared/util.h" |
|
66 |
||
67 |
//TESTED_CLASS= |
|
68 |
//TESTED_FILES= |
|
69 |
||
70 |
Q_DECLARE_METATYPE(QList<int>) |
|
71 |
Q_DECLARE_METATYPE(QList<QRectF>) |
|
72 |
Q_DECLARE_METATYPE(QPainterPath) |
|
73 |
Q_DECLARE_METATYPE(QPointF) |
|
74 |
Q_DECLARE_METATYPE(QRectF) |
|
75 |
||
76 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
77 |
#include <windows.h> |
|
78 |
#define Q_CHECK_PAINTEVENTS \ |
|
79 |
if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \ |
|
80 |
QSKIP("The Graphics View doesn't get the paint events", SkipSingle); |
|
81 |
#else |
|
82 |
#define Q_CHECK_PAINTEVENTS |
|
83 |
#endif |
|
84 |
||
85 |
#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) |
|
86 |
// On mac (cocoa) we always get full update. |
|
87 |
// So check that the expected region is contained inside the actual |
|
88 |
#define COMPARE_REGIONS(ACTUAL, EXPECTED) QVERIFY((EXPECTED).subtracted(ACTUAL).isEmpty()) |
|
89 |
#else |
|
90 |
#define COMPARE_REGIONS QTRY_COMPARE |
|
91 |
#endif |
|
92 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
93 |
static QGraphicsRectItem staticItem; //QTBUG-7629, we should not crash at exit. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
94 |
|
0 | 95 |
static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) |
96 |
{ |
|
97 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
98 |
event.setScenePos(point); |
|
99 |
event.setButton(button); |
|
100 |
event.setButtons(button); |
|
101 |
QApplication::sendEvent(scene, &event); |
|
102 |
} |
|
103 |
||
104 |
static void sendMouseMove(QGraphicsScene *scene, const QPointF &point, |
|
105 |
Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = 0) |
|
106 |
{ |
|
107 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
108 |
event.setScenePos(point); |
|
109 |
event.setButton(button); |
|
110 |
event.setButtons(button); |
|
111 |
QApplication::sendEvent(scene, &event); |
|
112 |
} |
|
113 |
||
114 |
static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) |
|
115 |
{ |
|
116 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
117 |
event.setScenePos(point); |
|
118 |
event.setButton(button); |
|
119 |
QApplication::sendEvent(scene, &event); |
|
120 |
} |
|
121 |
||
122 |
static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) |
|
123 |
{ |
|
124 |
sendMousePress(scene, point, button); |
|
125 |
sendMouseRelease(scene, point, button); |
|
126 |
} |
|
127 |
||
128 |
static void sendKeyPress(QGraphicsScene *scene, Qt::Key key) |
|
129 |
{ |
|
130 |
QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier); |
|
131 |
QApplication::sendEvent(scene, &keyEvent); |
|
132 |
} |
|
133 |
||
134 |
static void sendKeyRelease(QGraphicsScene *scene, Qt::Key key) |
|
135 |
{ |
|
136 |
QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier); |
|
137 |
QApplication::sendEvent(scene, &keyEvent); |
|
138 |
} |
|
139 |
||
140 |
static void sendKeyClick(QGraphicsScene *scene, Qt::Key key) |
|
141 |
{ |
|
142 |
sendKeyPress(scene, key); |
|
143 |
sendKeyRelease(scene, key); |
|
144 |
} |
|
145 |
||
146 |
class EventSpy : public QGraphicsWidget |
|
147 |
{ |
|
148 |
Q_OBJECT |
|
149 |
public: |
|
150 |
EventSpy(QObject *watched, QEvent::Type type) |
|
151 |
: _count(0), spied(type) |
|
152 |
{ |
|
153 |
watched->installEventFilter(this); |
|
154 |
} |
|
155 |
||
156 |
EventSpy(QGraphicsScene *scene, QGraphicsItem *watched, QEvent::Type type) |
|
157 |
: _count(0), spied(type) |
|
158 |
{ |
|
159 |
scene->addItem(this); |
|
160 |
watched->installSceneEventFilter(this); |
|
161 |
} |
|
162 |
||
163 |
int count() const { return _count; } |
|
164 |
||
165 |
protected: |
|
166 |
bool eventFilter(QObject *watched, QEvent *event) |
|
167 |
{ |
|
168 |
Q_UNUSED(watched); |
|
169 |
if (event->type() == spied) |
|
170 |
++_count; |
|
171 |
return false; |
|
172 |
} |
|
173 |
||
174 |
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
175 |
{ |
|
176 |
Q_UNUSED(watched); |
|
177 |
if (event->type() == spied) |
|
178 |
++_count; |
|
179 |
return false; |
|
180 |
} |
|
181 |
||
182 |
int _count; |
|
183 |
QEvent::Type spied; |
|
184 |
}; |
|
185 |
||
186 |
class EventSpy2 : public QGraphicsWidget |
|
187 |
{ |
|
188 |
Q_OBJECT |
|
189 |
public: |
|
190 |
EventSpy2(QObject *watched) |
|
191 |
{ |
|
192 |
watched->installEventFilter(this); |
|
193 |
} |
|
194 |
||
195 |
EventSpy2(QGraphicsScene *scene, QGraphicsItem *watched) |
|
196 |
{ |
|
197 |
scene->addItem(this); |
|
198 |
watched->installSceneEventFilter(this); |
|
199 |
} |
|
200 |
||
201 |
QMap<QEvent::Type, int> counts; |
|
202 |
||
203 |
protected: |
|
204 |
bool eventFilter(QObject *watched, QEvent *event) |
|
205 |
{ |
|
206 |
Q_UNUSED(watched); |
|
207 |
++counts[event->type()]; |
|
208 |
return false; |
|
209 |
} |
|
210 |
||
211 |
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
212 |
{ |
|
213 |
Q_UNUSED(watched); |
|
214 |
++counts[event->type()]; |
|
215 |
return false; |
|
216 |
} |
|
217 |
}; |
|
218 |
||
219 |
class EventTester : public QGraphicsItem |
|
220 |
{ |
|
221 |
public: |
|
222 |
EventTester(QGraphicsItem *parent = 0) : QGraphicsItem(parent), repaints(0) |
|
223 |
{ br = QRectF(-10, -10, 20, 20); } |
|
224 |
||
225 |
void setGeometry(const QRectF &rect) |
|
226 |
{ |
|
227 |
prepareGeometryChange(); |
|
228 |
br = rect; |
|
229 |
update(); |
|
230 |
} |
|
231 |
||
232 |
QRectF boundingRect() const |
|
233 |
{ return br; } |
|
234 |
||
235 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
236 |
{ |
|
237 |
hints = painter->renderHints(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
painter->setBrush(brush); |
0 | 239 |
painter->drawRect(boundingRect()); |
240 |
++repaints; |
|
241 |
} |
|
242 |
||
243 |
bool sceneEvent(QEvent *event) |
|
244 |
{ |
|
245 |
events << event->type(); |
|
246 |
return QGraphicsItem::sceneEvent(event); |
|
247 |
} |
|
248 |
||
249 |
QList<QEvent::Type> events; |
|
250 |
QPainter::RenderHints hints; |
|
251 |
int repaints; |
|
252 |
QRectF br; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
QBrush brush; |
0 | 254 |
}; |
255 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
256 |
class MyGraphicsView : public QGraphicsView |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
257 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
258 |
public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
259 |
int repaints; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
260 |
QRegion paintedRegion; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
261 |
MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
262 |
void paintEvent(QPaintEvent *e) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
263 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
264 |
paintedRegion += e->region(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
265 |
++repaints; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
266 |
QGraphicsView::paintEvent(e); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
267 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
268 |
void reset() { repaints = 0; paintedRegion = QRegion(); } |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
269 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
270 |
|
0 | 271 |
class tst_QGraphicsItem : public QObject |
272 |
{ |
|
273 |
Q_OBJECT |
|
274 |
||
275 |
public slots: |
|
276 |
void init(); |
|
277 |
||
278 |
private slots: |
|
279 |
void construction(); |
|
280 |
void constructionWithParent(); |
|
281 |
void destruction(); |
|
282 |
void deleteChildItem(); |
|
283 |
void scene(); |
|
284 |
void parentItem(); |
|
285 |
void setParentItem(); |
|
286 |
void children(); |
|
287 |
void flags(); |
|
288 |
void inputMethodHints(); |
|
289 |
void toolTip(); |
|
290 |
void visible(); |
|
291 |
void explicitlyVisible(); |
|
292 |
void enabled(); |
|
293 |
void explicitlyEnabled(); |
|
294 |
void selected(); |
|
295 |
void selected2(); |
|
296 |
void selected_group(); |
|
297 |
void selected_textItem(); |
|
298 |
void selected_multi(); |
|
299 |
void acceptedMouseButtons(); |
|
300 |
void acceptsHoverEvents(); |
|
301 |
void childAcceptsHoverEvents(); |
|
302 |
void hasFocus(); |
|
303 |
void pos(); |
|
304 |
void scenePos(); |
|
305 |
void matrix(); |
|
306 |
void sceneMatrix(); |
|
307 |
void setMatrix(); |
|
308 |
void zValue(); |
|
309 |
void shape(); |
|
310 |
void contains(); |
|
311 |
void collidesWith_item(); |
|
312 |
void collidesWith_path_data(); |
|
313 |
void collidesWith_path(); |
|
314 |
void collidesWithItemWithClip(); |
|
315 |
void isObscuredBy(); |
|
316 |
void isObscured(); |
|
317 |
void mapFromToParent(); |
|
318 |
void mapFromToScene(); |
|
319 |
void mapFromToItem(); |
|
320 |
void mapRectFromToParent_data(); |
|
321 |
void mapRectFromToParent(); |
|
322 |
void isAncestorOf(); |
|
323 |
void commonAncestorItem(); |
|
324 |
void data(); |
|
325 |
void type(); |
|
326 |
void graphicsitem_cast(); |
|
327 |
void hoverEventsGenerateRepaints(); |
|
328 |
void boundingRects_data(); |
|
329 |
void boundingRects(); |
|
330 |
void boundingRects2(); |
|
331 |
void sceneBoundingRect(); |
|
332 |
void childrenBoundingRect(); |
|
333 |
void childrenBoundingRectTransformed(); |
|
334 |
void childrenBoundingRect2(); |
|
335 |
void childrenBoundingRect3(); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
336 |
void childrenBoundingRect4(); |
0 | 337 |
void group(); |
338 |
void setGroup(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
void setGroup2(); |
0 | 340 |
void nestedGroups(); |
341 |
void warpChildrenIntoGroup(); |
|
342 |
void removeFromGroup(); |
|
343 |
void handlesChildEvents(); |
|
344 |
void handlesChildEvents2(); |
|
345 |
void handlesChildEvents3(); |
|
346 |
void filtersChildEvents(); |
|
347 |
void filtersChildEvents2(); |
|
348 |
void ensureVisible(); |
|
349 |
void cursor(); |
|
350 |
//void textControlGetterSetter(); |
|
351 |
void defaultItemTest_QGraphicsLineItem(); |
|
352 |
void defaultItemTest_QGraphicsPixmapItem(); |
|
353 |
void defaultItemTest_QGraphicsTextItem(); |
|
354 |
void defaultItemTest_QGraphicsEllipseItem(); |
|
355 |
void itemChange(); |
|
356 |
void sceneEventFilter(); |
|
357 |
void prepareGeometryChange(); |
|
358 |
void paint(); |
|
359 |
void deleteItemInEventHandlers(); |
|
360 |
void itemClipsToShape(); |
|
361 |
void itemClipsChildrenToShape(); |
|
362 |
void itemClipsChildrenToShape2(); |
|
363 |
void itemClipsChildrenToShape3(); |
|
364 |
void itemClipsChildrenToShape4(); |
|
365 |
void itemClipsTextChildToShape(); |
|
366 |
void itemClippingDiscovery(); |
|
367 |
void ancestorFlags(); |
|
368 |
void untransformable(); |
|
369 |
void contextMenuEventPropagation(); |
|
370 |
void itemIsMovable(); |
|
371 |
void boundingRegion_data(); |
|
372 |
void boundingRegion(); |
|
373 |
void itemTransform_parentChild(); |
|
374 |
void itemTransform_siblings(); |
|
375 |
void itemTransform_unrelated(); |
|
376 |
void opacity_data(); |
|
377 |
void opacity(); |
|
378 |
void opacity2(); |
|
379 |
void opacityZeroUpdates(); |
|
380 |
void itemStacksBehindParent(); |
|
381 |
void nestedClipping(); |
|
382 |
void nestedClippingTransforms(); |
|
383 |
void sceneTransformCache(); |
|
384 |
void tabChangesFocus(); |
|
385 |
void tabChangesFocus_data(); |
|
386 |
void cacheMode(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
387 |
void cacheMode2(); |
0 | 388 |
void updateCachedItemAfterMove(); |
389 |
void deviceTransform_data(); |
|
390 |
void deviceTransform(); |
|
391 |
void update(); |
|
392 |
void setTransformProperties_data(); |
|
393 |
void setTransformProperties(); |
|
394 |
void itemUsesExtendedStyleOption(); |
|
395 |
void itemSendsGeometryChanges(); |
|
396 |
void moveItem(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
void moveLineItem(); |
0 | 398 |
void sorting_data(); |
399 |
void sorting(); |
|
400 |
void itemHasNoContents(); |
|
401 |
void hitTestUntransformableItem(); |
|
402 |
void hitTestGraphicsEffectItem(); |
|
403 |
void focusProxy(); |
|
404 |
void subFocus(); |
|
405 |
void focusProxyDeletion(); |
|
406 |
void negativeZStacksBehindParent(); |
|
407 |
void setGraphicsEffect(); |
|
408 |
void panel(); |
|
409 |
void addPanelToActiveScene(); |
|
410 |
void activate(); |
|
411 |
void setActivePanelOnInactiveScene(); |
|
412 |
void activationOnShowHide(); |
|
413 |
void moveWhileDeleting(); |
|
414 |
void ensureDirtySceneTransform(); |
|
415 |
void focusScope(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
void focusScope2(); |
0 | 417 |
void stackBefore(); |
418 |
void sceneModality(); |
|
419 |
void panelModality(); |
|
420 |
void mixedModality(); |
|
421 |
void modality_hover(); |
|
422 |
void modality_mouseGrabber(); |
|
423 |
void modality_clickFocus(); |
|
424 |
void modality_keyEvents(); |
|
425 |
void itemIsInFront(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
void scenePosChange(); |
0 | 427 |
|
428 |
// task specific tests below me |
|
429 |
void task141694_textItemEnsureVisible(); |
|
430 |
void task128696_textItemEnsureMovable(); |
|
431 |
void ensureUpdateOnTextItem(); |
|
432 |
void task177918_lineItemUndetected(); |
|
433 |
void task240400_clickOnTextItem_data(); |
|
434 |
void task240400_clickOnTextItem(); |
|
435 |
void task243707_addChildBeforeParent(); |
|
436 |
void task197802_childrenVisibility(); |
|
437 |
void QTBUG_4233_updateCachedWithSceneRect(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
void QTBUG_5418_textItemSetDefaultColor(); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
439 |
void QTBUG_6738_missingUpdateWithSetParent(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
440 |
void QTBUG_7714_fullUpdateDiscardingOpacityUpdate2(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
441 |
void QT_2653_fullUpdateDiscardingOpacityUpdate(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
442 |
void QT_2649_focusScope(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
443 |
void sortItemsWhileAdding(); |
0 | 444 |
|
445 |
private: |
|
446 |
QList<QGraphicsItem *> paintedItems; |
|
447 |
}; |
|
448 |
||
449 |
void tst_QGraphicsItem::init() |
|
450 |
{ |
|
451 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
452 |
qApp->setAutoMaximizeThreshold(-1); |
|
453 |
#endif |
|
454 |
} |
|
455 |
||
456 |
void tst_QGraphicsItem::construction() |
|
457 |
{ |
|
458 |
for (int i = 0; i < 7; ++i) { |
|
459 |
QGraphicsItem *item; |
|
460 |
switch (i) { |
|
461 |
case 0: |
|
462 |
item = new QGraphicsEllipseItem; |
|
463 |
QCOMPARE(int(item->type()), int(QGraphicsEllipseItem::Type)); |
|
464 |
QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), (QGraphicsEllipseItem *)item); |
|
465 |
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0); |
|
466 |
QCOMPARE(item->flags(), 0); |
|
467 |
break; |
|
468 |
case 1: |
|
469 |
item = new QGraphicsLineItem; |
|
470 |
QCOMPARE(int(item->type()), int(QGraphicsLineItem::Type)); |
|
471 |
QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), (QGraphicsLineItem *)item); |
|
472 |
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0); |
|
473 |
QCOMPARE(item->flags(), 0); |
|
474 |
break; |
|
475 |
case 2: |
|
476 |
item = new QGraphicsPathItem; |
|
477 |
QCOMPARE(int(item->type()), int(QGraphicsPathItem::Type)); |
|
478 |
QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), (QGraphicsPathItem *)item); |
|
479 |
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0); |
|
480 |
QCOMPARE(item->flags(), 0); |
|
481 |
break; |
|
482 |
case 3: |
|
483 |
item = new QGraphicsPixmapItem; |
|
484 |
QCOMPARE(int(item->type()), int(QGraphicsPixmapItem::Type)); |
|
485 |
QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), (QGraphicsPixmapItem *)item); |
|
486 |
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0); |
|
487 |
QCOMPARE(item->flags(), 0); |
|
488 |
break; |
|
489 |
case 4: |
|
490 |
item = new QGraphicsPolygonItem; |
|
491 |
QCOMPARE(int(item->type()), int(QGraphicsPolygonItem::Type)); |
|
492 |
QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), (QGraphicsPolygonItem *)item); |
|
493 |
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0); |
|
494 |
QCOMPARE(item->flags(), 0); |
|
495 |
break; |
|
496 |
case 5: |
|
497 |
item = new QGraphicsRectItem; |
|
498 |
QCOMPARE(int(item->type()), int(QGraphicsRectItem::Type)); |
|
499 |
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)item); |
|
500 |
QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), (QGraphicsLineItem *)0); |
|
501 |
QCOMPARE(item->flags(), 0); |
|
502 |
break; |
|
503 |
case 6: |
|
504 |
item = new QGraphicsTextItem; |
|
505 |
QCOMPARE(int(item->type()), int(QGraphicsTextItem::Type)); |
|
506 |
QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), (QGraphicsTextItem *)item); |
|
507 |
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0); |
|
508 |
// This is the only item that uses an extended style option. |
|
509 |
QCOMPARE(item->flags(), QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemUsesExtendedStyleOption)); |
|
510 |
break; |
|
511 |
default: |
|
512 |
qFatal("You broke the logic, please fix!"); |
|
513 |
break; |
|
514 |
} |
|
515 |
||
516 |
QCOMPARE(item->scene(), (QGraphicsScene *)0); |
|
517 |
QCOMPARE(item->parentItem(), (QGraphicsItem *)0); |
|
518 |
QVERIFY(item->children().isEmpty()); |
|
519 |
QVERIFY(item->isVisible()); |
|
520 |
QVERIFY(item->isEnabled()); |
|
521 |
QVERIFY(!item->isSelected()); |
|
522 |
QCOMPARE(item->acceptedMouseButtons(), Qt::MouseButtons(0x1f)); |
|
523 |
if (item->type() == QGraphicsTextItem::Type) |
|
524 |
QVERIFY(item->acceptsHoverEvents()); |
|
525 |
else |
|
526 |
QVERIFY(!item->acceptsHoverEvents()); |
|
527 |
QVERIFY(!item->hasFocus()); |
|
528 |
QCOMPARE(item->pos(), QPointF()); |
|
529 |
QCOMPARE(item->matrix(), QMatrix()); |
|
530 |
QCOMPARE(item->sceneMatrix(), QMatrix()); |
|
531 |
QCOMPARE(item->zValue(), qreal(0)); |
|
532 |
QCOMPARE(item->sceneBoundingRect(), QRectF()); |
|
533 |
QCOMPARE(item->shape(), QPainterPath()); |
|
534 |
QVERIFY(!item->contains(QPointF(0, 0))); |
|
535 |
QVERIFY(!item->collidesWithItem(0)); |
|
536 |
QVERIFY(item->collidesWithItem(item)); |
|
537 |
QVERIFY(!item->collidesWithPath(QPainterPath())); |
|
538 |
QVERIFY(!item->isAncestorOf(0)); |
|
539 |
QVERIFY(!item->isAncestorOf(item)); |
|
540 |
QCOMPARE(item->data(0), QVariant()); |
|
541 |
delete item; |
|
542 |
} |
|
543 |
} |
|
544 |
||
545 |
class BoundingRectItem : public QGraphicsRectItem |
|
546 |
{ |
|
547 |
public: |
|
548 |
BoundingRectItem(QGraphicsItem *parent = 0) |
|
549 |
: QGraphicsRectItem(0, 0, parent ? 200 : 100, parent ? 200 : 100, |
|
550 |
parent) |
|
551 |
{} |
|
552 |
||
553 |
QRectF boundingRect() const |
|
554 |
{ |
|
555 |
QRectF tmp = QGraphicsRectItem::boundingRect(); |
|
556 |
foreach (QGraphicsItem *child, children()) |
|
557 |
tmp |= child->boundingRect(); // <- might be pure virtual |
|
558 |
return tmp; |
|
559 |
} |
|
560 |
}; |
|
561 |
||
562 |
void tst_QGraphicsItem::constructionWithParent() |
|
563 |
{ |
|
564 |
// This test causes a crash if item1 calls item2's pure virtuals before the |
|
565 |
// object has been constructed. |
|
566 |
QGraphicsItem *item0 = new BoundingRectItem; |
|
567 |
QGraphicsItem *item1 = new BoundingRectItem; |
|
568 |
QGraphicsScene scene; |
|
569 |
scene.addItem(item0); |
|
570 |
scene.addItem(item1); |
|
571 |
QGraphicsItem *item2 = new BoundingRectItem(item1); |
|
572 |
QCOMPARE(item1->children(), QList<QGraphicsItem *>() << item2); |
|
573 |
QCOMPARE(item1->boundingRect(), QRectF(0, 0, 200, 200)); |
|
574 |
||
575 |
item2->setParentItem(item0); |
|
576 |
QCOMPARE(item0->children(), QList<QGraphicsItem *>() << item2); |
|
577 |
QCOMPARE(item0->boundingRect(), QRectF(0, 0, 200, 200)); |
|
578 |
} |
|
579 |
||
580 |
static int itemDeleted = 0; |
|
581 |
class Item : public QGraphicsRectItem |
|
582 |
{ |
|
583 |
public: |
|
584 |
~Item() |
|
585 |
{ ++itemDeleted; } |
|
586 |
}; |
|
587 |
||
588 |
void tst_QGraphicsItem::destruction() |
|
589 |
{ |
|
590 |
QCOMPARE(itemDeleted, 0); |
|
591 |
{ |
|
592 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
593 |
Item *child = new Item; |
|
594 |
child->setParentItem(parent); |
|
595 |
QCOMPARE(child->parentItem(), parent); |
|
596 |
delete parent; |
|
597 |
QCOMPARE(itemDeleted, 1); |
|
598 |
} |
|
599 |
{ |
|
600 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
601 |
Item *child = new Item; |
|
602 |
child->setParentItem(parent); |
|
603 |
QCOMPARE(parent->children().size(), 1); |
|
604 |
delete child; |
|
605 |
QCOMPARE(parent->children().size(), 0); |
|
606 |
delete parent; |
|
607 |
QCOMPARE(itemDeleted, 2); |
|
608 |
} |
|
609 |
{ |
|
610 |
QGraphicsScene scene; |
|
611 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
612 |
Item *child = new Item; |
|
613 |
QCOMPARE(child->parentItem(), (QGraphicsItem *)0); |
|
614 |
child->setParentItem(parent); |
|
615 |
QCOMPARE(child->parentItem(), parent); |
|
616 |
scene.addItem(parent); |
|
617 |
QCOMPARE(child->parentItem(), parent); |
|
618 |
delete parent; |
|
619 |
QCOMPARE(itemDeleted, 3); |
|
620 |
} |
|
621 |
{ |
|
622 |
QGraphicsScene scene; |
|
623 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
624 |
Item *child = new Item; |
|
625 |
child->setParentItem(parent); |
|
626 |
scene.addItem(parent); |
|
627 |
QCOMPARE(child->scene(), &scene); |
|
628 |
QCOMPARE(parent->children().size(), 1); |
|
629 |
delete child; |
|
630 |
QCOMPARE(parent->children().size(), 0); |
|
631 |
delete parent; |
|
632 |
QCOMPARE(itemDeleted, 4); |
|
633 |
} |
|
634 |
{ |
|
635 |
QGraphicsScene scene; |
|
636 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
637 |
Item *child = new Item; |
|
638 |
child->setParentItem(parent); |
|
639 |
scene.addItem(parent); |
|
640 |
QCOMPARE(child->scene(), &scene); |
|
641 |
scene.removeItem(parent); |
|
642 |
QCOMPARE(child->scene(), (QGraphicsScene *)0); |
|
643 |
delete parent; |
|
644 |
QCOMPARE(itemDeleted, 5); |
|
645 |
} |
|
646 |
{ |
|
647 |
QGraphicsScene scene; |
|
648 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
649 |
Item *child = new Item; |
|
650 |
child->setParentItem(parent); |
|
651 |
QCOMPARE(child->scene(), (QGraphicsScene *)0); |
|
652 |
QCOMPARE(parent->scene(), (QGraphicsScene *)0); |
|
653 |
scene.addItem(parent); |
|
654 |
QCOMPARE(child->scene(), &scene); |
|
655 |
scene.removeItem(child); |
|
656 |
QCOMPARE(child->scene(), (QGraphicsScene *)0); |
|
657 |
QCOMPARE(parent->scene(), &scene); |
|
658 |
QCOMPARE(child->parentItem(), (QGraphicsItem *)0); |
|
659 |
QVERIFY(parent->children().isEmpty()); |
|
660 |
delete parent; |
|
661 |
QCOMPARE(itemDeleted, 5); |
|
662 |
delete child; |
|
663 |
QCOMPARE(itemDeleted, 6); |
|
664 |
} |
|
665 |
{ |
|
666 |
QGraphicsScene scene; |
|
667 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
668 |
Item *child = new Item; |
|
669 |
child->setParentItem(parent); |
|
670 |
scene.addItem(parent); |
|
671 |
scene.removeItem(child); |
|
672 |
scene.removeItem(parent); |
|
673 |
delete child; |
|
674 |
delete parent; |
|
675 |
QCOMPARE(itemDeleted, 7); |
|
676 |
} |
|
677 |
{ |
|
678 |
QGraphicsScene scene; |
|
679 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
680 |
Item *child = new Item; |
|
681 |
child->setParentItem(parent); |
|
682 |
scene.addItem(parent); |
|
683 |
QGraphicsScene scene2; |
|
684 |
scene2.addItem(parent); |
|
685 |
delete parent; |
|
686 |
QCOMPARE(itemDeleted, 8); |
|
687 |
} |
|
688 |
{ |
|
689 |
QGraphicsScene scene; |
|
690 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
691 |
Item *child = new Item; |
|
692 |
child->setParentItem(parent); |
|
693 |
scene.addItem(parent); |
|
694 |
QCOMPARE(child->scene(), &scene); |
|
695 |
QGraphicsScene scene2; |
|
696 |
scene2.addItem(parent); |
|
697 |
QCOMPARE(child->scene(), &scene2); |
|
698 |
scene.addItem(parent); |
|
699 |
QCOMPARE(child->scene(), &scene); |
|
700 |
scene2.addItem(parent); |
|
701 |
QCOMPARE(child->scene(), &scene2); |
|
702 |
delete parent; |
|
703 |
QCOMPARE(itemDeleted, 9); |
|
704 |
} |
|
705 |
{ |
|
706 |
QGraphicsScene scene; |
|
707 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
708 |
Item *child = new Item; |
|
709 |
child->setParentItem(parent); |
|
710 |
scene.addItem(parent); |
|
711 |
QCOMPARE(child->scene(), &scene); |
|
712 |
QGraphicsScene scene2; |
|
713 |
scene2.addItem(child); |
|
714 |
QCOMPARE(child->scene(), &scene2); |
|
715 |
delete parent; |
|
716 |
QCOMPARE(itemDeleted, 9); |
|
717 |
delete child; |
|
718 |
QCOMPARE(itemDeleted, 10); |
|
719 |
} |
|
720 |
{ |
|
721 |
QGraphicsScene scene; |
|
722 |
QGraphicsItem *root = new QGraphicsRectItem; |
|
723 |
QGraphicsItem *parent = root; |
|
724 |
QGraphicsItem *middleItem = 0; |
|
725 |
for (int i = 0; i < 99; ++i) { |
|
726 |
Item *child = new Item; |
|
727 |
child->setParentItem(parent); |
|
728 |
parent = child; |
|
729 |
if (i == 50) |
|
730 |
middleItem = parent; |
|
731 |
} |
|
732 |
scene.addItem(root); |
|
733 |
||
734 |
QCOMPARE(scene.items().size(), 100); |
|
735 |
||
736 |
QGraphicsScene scene2; |
|
737 |
scene2.addItem(middleItem); |
|
738 |
||
739 |
delete middleItem; |
|
740 |
QCOMPARE(itemDeleted, 59); |
|
741 |
} |
|
742 |
QCOMPARE(itemDeleted, 109); |
|
743 |
{ |
|
744 |
QGraphicsScene *scene = new QGraphicsScene; |
|
745 |
QGraphicsRectItem *parent = new QGraphicsRectItem; |
|
746 |
Item *child = new Item; |
|
747 |
child->setParentItem(parent); |
|
748 |
parent->setVisible(false); |
|
749 |
scene->addItem(parent); |
|
750 |
QCOMPARE(child->parentItem(), static_cast<QGraphicsItem*>(parent)); |
|
751 |
delete scene; |
|
752 |
QCOMPARE(itemDeleted, 110); |
|
753 |
} |
|
754 |
} |
|
755 |
||
756 |
void tst_QGraphicsItem::deleteChildItem() |
|
757 |
{ |
|
758 |
QGraphicsScene scene; |
|
759 |
QGraphicsItem *rect = scene.addRect(QRectF()); |
|
760 |
QGraphicsItem *child1 = new QGraphicsRectItem(rect); |
|
761 |
QGraphicsItem *child2 = new QGraphicsRectItem(rect); |
|
762 |
QGraphicsItem *child3 = new QGraphicsRectItem(rect); |
|
763 |
delete child1; |
|
764 |
child2->setParentItem(0); |
|
765 |
delete child2; |
|
766 |
} |
|
767 |
||
768 |
void tst_QGraphicsItem::scene() |
|
769 |
{ |
|
770 |
QGraphicsRectItem *item = new QGraphicsRectItem; |
|
771 |
QCOMPARE(item->scene(), (QGraphicsScene *)0); |
|
772 |
||
773 |
QGraphicsScene scene; |
|
774 |
scene.addItem(item); |
|
775 |
QCOMPARE(item->scene(), (QGraphicsScene *)&scene); |
|
776 |
||
777 |
QGraphicsScene scene2; |
|
778 |
scene2.addItem(item); |
|
779 |
QCOMPARE(item->scene(), (QGraphicsScene *)&scene2); |
|
780 |
||
781 |
scene2.removeItem(item); |
|
782 |
QCOMPARE(item->scene(), (QGraphicsScene *)0); |
|
783 |
||
784 |
delete item; |
|
785 |
} |
|
786 |
||
787 |
void tst_QGraphicsItem::parentItem() |
|
788 |
{ |
|
789 |
QGraphicsRectItem item; |
|
790 |
QCOMPARE(item.parentItem(), (QGraphicsItem *)0); |
|
791 |
||
792 |
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item); |
|
793 |
QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item); |
|
794 |
item2->setParentItem(&item); |
|
795 |
QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item); |
|
796 |
item2->setParentItem(0); |
|
797 |
QCOMPARE(item2->parentItem(), (QGraphicsItem *)0); |
|
798 |
||
799 |
delete item2; |
|
800 |
} |
|
801 |
||
802 |
void tst_QGraphicsItem::setParentItem() |
|
803 |
{ |
|
804 |
QGraphicsScene scene; |
|
805 |
QGraphicsItem *item = scene.addRect(QRectF(0, 0, 10, 10)); |
|
806 |
QCOMPARE(item->scene(), &scene); |
|
807 |
||
808 |
QGraphicsRectItem *child = new QGraphicsRectItem; |
|
809 |
QCOMPARE(child->scene(), (QGraphicsScene *)0); |
|
810 |
||
811 |
// This implicitly adds the item to the parent's scene |
|
812 |
child->setParentItem(item); |
|
813 |
QCOMPARE(child->scene(), &scene); |
|
814 |
||
815 |
// This just makes it a toplevel |
|
816 |
child->setParentItem(0); |
|
817 |
QCOMPARE(child->scene(), &scene); |
|
818 |
||
819 |
// Add the child back to the parent, then remove the parent from the scene |
|
820 |
child->setParentItem(item); |
|
821 |
scene.removeItem(item); |
|
822 |
QCOMPARE(child->scene(), (QGraphicsScene *)0); |
|
823 |
} |
|
824 |
||
825 |
void tst_QGraphicsItem::children() |
|
826 |
{ |
|
827 |
QGraphicsRectItem item; |
|
828 |
QVERIFY(item.children().isEmpty()); |
|
829 |
||
830 |
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item); |
|
831 |
QCOMPARE(item.children().size(), 1); |
|
832 |
QCOMPARE(item.children().first(), (QGraphicsItem *)item2); |
|
833 |
QVERIFY(item2->children().isEmpty()); |
|
834 |
||
835 |
delete item2; |
|
836 |
QVERIFY(item.children().isEmpty()); |
|
837 |
} |
|
838 |
||
839 |
void tst_QGraphicsItem::flags() |
|
840 |
{ |
|
841 |
QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(-10, -10, 20, 20)); |
|
842 |
QCOMPARE(item->flags(), 0); |
|
843 |
||
844 |
QGraphicsScene scene; |
|
845 |
QEvent activate(QEvent::WindowActivate); |
|
846 |
QApplication::sendEvent(&scene, &activate); |
|
847 |
||
848 |
scene.addItem(item); |
|
849 |
||
850 |
{ |
|
851 |
// Focus |
|
852 |
item->setFlag(QGraphicsItem::ItemIsFocusable, false); |
|
853 |
QVERIFY(!item->hasFocus()); |
|
854 |
item->setFocus(); |
|
855 |
QVERIFY(!item->hasFocus()); |
|
856 |
||
857 |
item->setFlag(QGraphicsItem::ItemIsFocusable, true); |
|
858 |
QVERIFY(!item->hasFocus()); |
|
859 |
item->setFocus(); |
|
860 |
QVERIFY(item->hasFocus()); |
|
861 |
QVERIFY(scene.hasFocus()); |
|
862 |
||
863 |
item->setFlag(QGraphicsItem::ItemIsFocusable, false); |
|
864 |
QVERIFY(!item->hasFocus()); |
|
865 |
QVERIFY(scene.hasFocus()); |
|
866 |
} |
|
867 |
{ |
|
868 |
// Selectable |
|
869 |
item->setFlag(QGraphicsItem::ItemIsSelectable, false); |
|
870 |
QVERIFY(!item->isSelected()); |
|
871 |
item->setSelected(true); |
|
872 |
QVERIFY(!item->isSelected()); |
|
873 |
||
874 |
item->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
875 |
QVERIFY(!item->isSelected()); |
|
876 |
item->setSelected(true); |
|
877 |
QVERIFY(item->isSelected()); |
|
878 |
item->setFlag(QGraphicsItem::ItemIsSelectable, false); |
|
879 |
QVERIFY(!item->isSelected()); |
|
880 |
} |
|
881 |
{ |
|
882 |
// Movable |
|
883 |
item->setFlag(QGraphicsItem::ItemIsMovable, false); |
|
884 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
885 |
event.setScenePos(QPointF(0, 0)); |
|
886 |
event.setButton(Qt::LeftButton); |
|
887 |
event.setButtons(Qt::LeftButton); |
|
888 |
QApplication::sendEvent(&scene, &event); |
|
889 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); // mouse grabber is reset |
|
890 |
||
891 |
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove); |
|
892 |
event2.setScenePos(QPointF(10, 10)); |
|
893 |
event2.setButton(Qt::LeftButton); |
|
894 |
event2.setButtons(Qt::LeftButton); |
|
895 |
QApplication::sendEvent(&scene, &event2); |
|
896 |
QCOMPARE(item->pos(), QPointF()); |
|
897 |
||
898 |
QGraphicsSceneMouseEvent event3(QEvent::GraphicsSceneMouseRelease); |
|
899 |
event3.setScenePos(QPointF(10, 10)); |
|
900 |
event3.setButtons(0); |
|
901 |
QApplication::sendEvent(&scene, &event3); |
|
902 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
903 |
||
904 |
item->setFlag(QGraphicsItem::ItemIsMovable, true); |
|
905 |
QGraphicsSceneMouseEvent event4(QEvent::GraphicsSceneMousePress); |
|
906 |
event4.setScenePos(QPointF(0, 0)); |
|
907 |
event4.setButton(Qt::LeftButton); |
|
908 |
event4.setButtons(Qt::LeftButton); |
|
909 |
QApplication::sendEvent(&scene, &event4); |
|
910 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); |
|
911 |
QGraphicsSceneMouseEvent event5(QEvent::GraphicsSceneMouseMove); |
|
912 |
event5.setScenePos(QPointF(10, 10)); |
|
913 |
event5.setButton(Qt::LeftButton); |
|
914 |
event5.setButtons(Qt::LeftButton); |
|
915 |
QApplication::sendEvent(&scene, &event5); |
|
916 |
QCOMPARE(item->pos(), QPointF(10, 10)); |
|
917 |
} |
|
918 |
{ |
|
919 |
QGraphicsItem* clippingParent = new QGraphicsRectItem; |
|
920 |
clippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); |
|
921 |
||
922 |
QGraphicsItem* nonClippingParent = new QGraphicsRectItem; |
|
923 |
nonClippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); |
|
924 |
||
925 |
QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent); |
|
926 |
QVERIFY(!child->isClipped()); |
|
927 |
||
928 |
child->setParentItem(clippingParent); |
|
929 |
QVERIFY(child->isClipped()); |
|
930 |
||
931 |
child->setParentItem(nonClippingParent); |
|
932 |
QVERIFY(!child->isClipped()); |
|
933 |
} |
|
934 |
} |
|
935 |
||
936 |
class ImhTester : public QGraphicsItem |
|
937 |
{ |
|
938 |
QRectF boundingRect() const { return QRectF(); } |
|
939 |
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} |
|
940 |
}; |
|
941 |
||
942 |
void tst_QGraphicsItem::inputMethodHints() |
|
943 |
{ |
|
944 |
ImhTester item; |
|
945 |
QCOMPARE(item.inputMethodHints(), Qt::ImhNone); |
|
946 |
} |
|
947 |
||
948 |
void tst_QGraphicsItem::toolTip() |
|
949 |
{ |
|
950 |
QString toolTip = "Qt rocks!"; |
|
951 |
||
952 |
QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); |
|
953 |
item->setPen(QPen(Qt::red, 1)); |
|
954 |
item->setBrush(QBrush(Qt::blue)); |
|
955 |
QVERIFY(item->toolTip().isEmpty()); |
|
956 |
item->setToolTip(toolTip); |
|
957 |
QCOMPARE(item->toolTip(), toolTip); |
|
958 |
||
959 |
QGraphicsScene scene; |
|
960 |
scene.addItem(item); |
|
961 |
||
962 |
QGraphicsView view(&scene); |
|
963 |
view.setFixedSize(200, 200); |
|
964 |
view.show(); |
|
965 |
QTest::qWait(250); |
|
966 |
{ |
|
967 |
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), |
|
968 |
view.viewport()->mapToGlobal(view.viewport()->rect().topLeft())); |
|
969 |
QApplication::sendEvent(view.viewport(), &helpEvent); |
|
970 |
QTest::qWait(250); |
|
971 |
||
972 |
bool foundView = false; |
|
973 |
bool foundTipLabel = false; |
|
974 |
foreach (QWidget *widget, QApplication::topLevelWidgets()) { |
|
975 |
if (widget == &view) |
|
976 |
foundView = true; |
|
977 |
if (widget->inherits("QTipLabel")) |
|
978 |
foundTipLabel = true; |
|
979 |
} |
|
980 |
QVERIFY(foundView); |
|
981 |
QVERIFY(!foundTipLabel); |
|
982 |
} |
|
983 |
||
984 |
{ |
|
985 |
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().center(), |
|
986 |
view.viewport()->mapToGlobal(view.viewport()->rect().center())); |
|
987 |
QApplication::sendEvent(view.viewport(), &helpEvent); |
|
988 |
QTest::qWait(250); |
|
989 |
||
990 |
bool foundView = false; |
|
991 |
bool foundTipLabel = false; |
|
992 |
foreach (QWidget *widget, QApplication::topLevelWidgets()) { |
|
993 |
if (widget == &view) |
|
994 |
foundView = true; |
|
995 |
if (widget->inherits("QTipLabel")) |
|
996 |
foundTipLabel = true; |
|
997 |
} |
|
998 |
QVERIFY(foundView); |
|
999 |
QVERIFY(foundTipLabel); |
|
1000 |
} |
|
1001 |
||
1002 |
{ |
|
1003 |
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), |
|
1004 |
view.viewport()->mapToGlobal(view.viewport()->rect().topLeft())); |
|
1005 |
QApplication::sendEvent(view.viewport(), &helpEvent); |
|
1006 |
QTest::qWait(1000); |
|
1007 |
||
1008 |
bool foundView = false; |
|
1009 |
bool foundTipLabel = false; |
|
1010 |
foreach (QWidget *widget, QApplication::topLevelWidgets()) { |
|
1011 |
if (widget == &view) |
|
1012 |
foundView = true; |
|
1013 |
if (widget->inherits("QTipLabel") && widget->isVisible()) |
|
1014 |
foundTipLabel = true; |
|
1015 |
} |
|
1016 |
QVERIFY(foundView); |
|
1017 |
QVERIFY(!foundTipLabel); |
|
1018 |
} |
|
1019 |
} |
|
1020 |
||
1021 |
void tst_QGraphicsItem::visible() |
|
1022 |
{ |
|
1023 |
QGraphicsItem *item = new QGraphicsRectItem(QRectF(-10, -10, 20, 20)); |
|
1024 |
item->setFlag(QGraphicsItem::ItemIsMovable); |
|
1025 |
QVERIFY(item->isVisible()); |
|
1026 |
item->setVisible(false); |
|
1027 |
QVERIFY(!item->isVisible()); |
|
1028 |
item->setVisible(true); |
|
1029 |
QVERIFY(item->isVisible()); |
|
1030 |
||
1031 |
QGraphicsScene scene; |
|
1032 |
QEvent activate(QEvent::WindowActivate); |
|
1033 |
QApplication::sendEvent(&scene, &activate); |
|
1034 |
||
1035 |
scene.addItem(item); |
|
1036 |
QVERIFY(item->isVisible()); |
|
1037 |
QCOMPARE(scene.itemAt(0, 0), item); |
|
1038 |
item->setVisible(false); |
|
1039 |
QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)0); |
|
1040 |
item->setVisible(true); |
|
1041 |
QCOMPARE(scene.itemAt(0, 0), item); |
|
1042 |
||
1043 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1044 |
event.setButton(Qt::LeftButton); |
|
1045 |
event.setScenePos(QPointF(0, 0)); |
|
1046 |
QApplication::sendEvent(&scene, &event); |
|
1047 |
QCOMPARE(scene.mouseGrabberItem(), item); |
|
1048 |
item->setVisible(false); |
|
1049 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1050 |
item->setVisible(true); |
|
1051 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1052 |
||
1053 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1054 |
item->setFocus(); |
|
1055 |
QVERIFY(item->hasFocus()); |
|
1056 |
item->setVisible(false); |
|
1057 |
QVERIFY(!item->hasFocus()); |
|
1058 |
item->setVisible(true); |
|
1059 |
QVERIFY(!item->hasFocus()); |
|
1060 |
} |
|
1061 |
||
1062 |
void tst_QGraphicsItem::explicitlyVisible() |
|
1063 |
{ |
|
1064 |
QGraphicsScene scene; |
|
1065 |
QGraphicsItem *parent = scene.addRect(QRectF(0, 0, 100, 100)); |
|
1066 |
QGraphicsItem *child = scene.addRect(QRectF(25, 25, 50, 50)); |
|
1067 |
child->setParentItem(parent); |
|
1068 |
||
1069 |
QVERIFY(parent->isVisible()); |
|
1070 |
QVERIFY(child->isVisible()); |
|
1071 |
||
1072 |
parent->hide(); |
|
1073 |
||
1074 |
QVERIFY(!parent->isVisible()); |
|
1075 |
QVERIFY(!child->isVisible()); |
|
1076 |
||
1077 |
parent->show(); |
|
1078 |
child->hide(); |
|
1079 |
||
1080 |
QVERIFY(parent->isVisible()); |
|
1081 |
QVERIFY(!child->isVisible()); |
|
1082 |
||
1083 |
parent->hide(); |
|
1084 |
||
1085 |
QVERIFY(!parent->isVisible()); |
|
1086 |
QVERIFY(!child->isVisible()); |
|
1087 |
||
1088 |
parent->show(); |
|
1089 |
||
1090 |
QVERIFY(parent->isVisible()); |
|
1091 |
QVERIFY(!child->isVisible()); // <- explicitly hidden |
|
1092 |
||
1093 |
child->show(); |
|
1094 |
||
1095 |
QVERIFY(child->isVisible()); |
|
1096 |
||
1097 |
parent->hide(); |
|
1098 |
||
1099 |
QVERIFY(!parent->isVisible()); |
|
1100 |
QVERIFY(!child->isVisible()); // <- explicit show doesn't work |
|
1101 |
||
1102 |
parent->show(); |
|
1103 |
||
1104 |
QVERIFY(parent->isVisible()); |
|
1105 |
QVERIFY(child->isVisible()); // <- no longer explicitly hidden |
|
1106 |
||
1107 |
// ------------------- Reparenting ------------------------------ |
|
1108 |
||
1109 |
QGraphicsItem *parent2 = scene.addRect(-50, -50, 200, 200); |
|
1110 |
QVERIFY(parent2->isVisible()); |
|
1111 |
||
1112 |
// Reparent implicitly hidden item to a visible parent. |
|
1113 |
parent->hide(); |
|
1114 |
QVERIFY(!parent->isVisible()); |
|
1115 |
QVERIFY(!child->isVisible()); |
|
1116 |
child->setParentItem(parent2); |
|
1117 |
QVERIFY(parent2->isVisible()); |
|
1118 |
QVERIFY(child->isVisible()); |
|
1119 |
||
1120 |
// Reparent implicitly hidden item to a hidden parent. |
|
1121 |
child->setParentItem(parent); |
|
1122 |
parent2->hide(); |
|
1123 |
child->setParentItem(parent2); |
|
1124 |
QVERIFY(!parent2->isVisible()); |
|
1125 |
QVERIFY(!child->isVisible()); |
|
1126 |
||
1127 |
// Reparent explicitly hidden item to a visible parent. |
|
1128 |
child->hide(); |
|
1129 |
parent->show(); |
|
1130 |
child->setParentItem(parent); |
|
1131 |
QVERIFY(parent->isVisible()); |
|
1132 |
QVERIFY(!child->isVisible()); |
|
1133 |
||
1134 |
// Reparent explicitly hidden item to a hidden parent. |
|
1135 |
child->setParentItem(parent2); |
|
1136 |
QVERIFY(!parent2->isVisible()); |
|
1137 |
QVERIFY(!child->isVisible()); |
|
1138 |
||
1139 |
// Reparent explicitly hidden item to a visible parent. |
|
1140 |
parent->show(); |
|
1141 |
child->setParentItem(parent); |
|
1142 |
QVERIFY(parent->isVisible()); |
|
1143 |
QVERIFY(!child->isVisible()); |
|
1144 |
||
1145 |
// Reparent visible item to a hidden parent. |
|
1146 |
child->show(); |
|
1147 |
parent2->hide(); |
|
1148 |
child->setParentItem(parent2); |
|
1149 |
QVERIFY(!parent2->isVisible()); |
|
1150 |
QVERIFY(!child->isVisible()); |
|
1151 |
parent2->show(); |
|
1152 |
QVERIFY(parent2->isVisible()); |
|
1153 |
QVERIFY(child->isVisible()); |
|
1154 |
||
1155 |
// Reparent implicitly hidden child to root. |
|
1156 |
parent2->hide(); |
|
1157 |
QVERIFY(!child->isVisible()); |
|
1158 |
child->setParentItem(0); |
|
1159 |
QVERIFY(child->isVisible()); |
|
1160 |
||
1161 |
// Reparent an explicitly hidden child to root. |
|
1162 |
child->hide(); |
|
1163 |
child->setParentItem(parent2); |
|
1164 |
parent2->show(); |
|
1165 |
QVERIFY(!child->isVisible()); |
|
1166 |
child->setParentItem(0); |
|
1167 |
QVERIFY(!child->isVisible()); |
|
1168 |
} |
|
1169 |
||
1170 |
void tst_QGraphicsItem::enabled() |
|
1171 |
{ |
|
1172 |
QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(-10, -10, 20, 20)); |
|
1173 |
item->setFlag(QGraphicsItem::ItemIsMovable); |
|
1174 |
QVERIFY(item->isEnabled()); |
|
1175 |
item->setEnabled(false); |
|
1176 |
QVERIFY(!item->isEnabled()); |
|
1177 |
item->setEnabled(true); |
|
1178 |
QVERIFY(item->isEnabled()); |
|
1179 |
item->setEnabled(false); |
|
1180 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1181 |
QGraphicsScene scene; |
|
1182 |
QEvent activate(QEvent::WindowActivate); |
|
1183 |
QApplication::sendEvent(&scene, &activate); |
|
1184 |
||
1185 |
scene.addItem(item); |
|
1186 |
item->setFocus(); |
|
1187 |
QVERIFY(!item->hasFocus()); |
|
1188 |
item->setEnabled(true); |
|
1189 |
item->setFocus(); |
|
1190 |
QVERIFY(item->hasFocus()); |
|
1191 |
item->setEnabled(false); |
|
1192 |
QVERIFY(!item->hasFocus()); |
|
1193 |
||
1194 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1195 |
event.setButton(Qt::LeftButton); |
|
1196 |
event.setScenePos(QPointF(0, 0)); |
|
1197 |
QApplication::sendEvent(&scene, &event); |
|
1198 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1199 |
item->setEnabled(true); |
|
1200 |
QApplication::sendEvent(&scene, &event); |
|
1201 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); |
|
1202 |
item->setEnabled(false); |
|
1203 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1204 |
} |
|
1205 |
||
1206 |
void tst_QGraphicsItem::explicitlyEnabled() |
|
1207 |
{ |
|
1208 |
QGraphicsScene scene; |
|
1209 |
QGraphicsItem *parent = scene.addRect(QRectF(0, 0, 100, 100)); |
|
1210 |
QGraphicsItem *child = scene.addRect(QRectF(25, 25, 50, 50)); |
|
1211 |
child->setParentItem(parent); |
|
1212 |
||
1213 |
QVERIFY(parent->isEnabled()); |
|
1214 |
QVERIFY(child->isEnabled()); |
|
1215 |
||
1216 |
parent->setEnabled(false); |
|
1217 |
||
1218 |
QVERIFY(!parent->isEnabled()); |
|
1219 |
QVERIFY(!child->isEnabled()); |
|
1220 |
||
1221 |
parent->setEnabled(true); |
|
1222 |
child->setEnabled(false); |
|
1223 |
||
1224 |
QVERIFY(parent->isEnabled()); |
|
1225 |
QVERIFY(!child->isEnabled()); |
|
1226 |
||
1227 |
parent->setEnabled(false); |
|
1228 |
||
1229 |
QVERIFY(!parent->isEnabled()); |
|
1230 |
QVERIFY(!child->isEnabled()); |
|
1231 |
||
1232 |
parent->setEnabled(true); |
|
1233 |
||
1234 |
QVERIFY(parent->isEnabled()); |
|
1235 |
QVERIFY(!child->isEnabled()); // <- explicitly disabled |
|
1236 |
||
1237 |
child->setEnabled(true); |
|
1238 |
||
1239 |
QVERIFY(child->isEnabled()); |
|
1240 |
||
1241 |
parent->setEnabled(false); |
|
1242 |
||
1243 |
QVERIFY(!parent->isEnabled()); |
|
1244 |
QVERIFY(!child->isEnabled()); // <- explicit enabled doesn't work |
|
1245 |
||
1246 |
parent->setEnabled(true); |
|
1247 |
||
1248 |
QVERIFY(parent->isEnabled()); |
|
1249 |
QVERIFY(child->isEnabled()); // <- no longer explicitly disabled |
|
1250 |
||
1251 |
// ------------------- Reparenting ------------------------------ |
|
1252 |
||
1253 |
QGraphicsItem *parent2 = scene.addRect(-50, -50, 200, 200); |
|
1254 |
QVERIFY(parent2->isEnabled()); |
|
1255 |
||
1256 |
// Reparent implicitly hidden item to a enabled parent. |
|
1257 |
parent->setEnabled(false); |
|
1258 |
QVERIFY(!parent->isEnabled()); |
|
1259 |
QVERIFY(!child->isEnabled()); |
|
1260 |
child->setParentItem(parent2); |
|
1261 |
QVERIFY(parent2->isEnabled()); |
|
1262 |
QVERIFY(child->isEnabled()); |
|
1263 |
||
1264 |
// Reparent implicitly hidden item to a hidden parent. |
|
1265 |
child->setParentItem(parent); |
|
1266 |
parent2->setEnabled(false); |
|
1267 |
child->setParentItem(parent2); |
|
1268 |
QVERIFY(!parent2->isEnabled()); |
|
1269 |
QVERIFY(!child->isEnabled()); |
|
1270 |
||
1271 |
// Reparent explicitly hidden item to a enabled parent. |
|
1272 |
child->setEnabled(false); |
|
1273 |
parent->setEnabled(true); |
|
1274 |
child->setParentItem(parent); |
|
1275 |
QVERIFY(parent->isEnabled()); |
|
1276 |
QVERIFY(!child->isEnabled()); |
|
1277 |
||
1278 |
// Reparent explicitly hidden item to a hidden parent. |
|
1279 |
child->setParentItem(parent2); |
|
1280 |
QVERIFY(!parent2->isEnabled()); |
|
1281 |
QVERIFY(!child->isEnabled()); |
|
1282 |
||
1283 |
// Reparent explicitly hidden item to a enabled parent. |
|
1284 |
parent->setEnabled(true); |
|
1285 |
child->setParentItem(parent); |
|
1286 |
QVERIFY(parent->isEnabled()); |
|
1287 |
QVERIFY(!child->isEnabled()); |
|
1288 |
||
1289 |
// Reparent enabled item to a hidden parent. |
|
1290 |
child->setEnabled(true); |
|
1291 |
parent2->setEnabled(false); |
|
1292 |
child->setParentItem(parent2); |
|
1293 |
QVERIFY(!parent2->isEnabled()); |
|
1294 |
QVERIFY(!child->isEnabled()); |
|
1295 |
parent2->setEnabled(true); |
|
1296 |
QVERIFY(parent2->isEnabled()); |
|
1297 |
QVERIFY(child->isEnabled()); |
|
1298 |
||
1299 |
// Reparent implicitly hidden child to root. |
|
1300 |
parent2->setEnabled(false); |
|
1301 |
QVERIFY(!child->isEnabled()); |
|
1302 |
child->setParentItem(0); |
|
1303 |
QVERIFY(child->isEnabled()); |
|
1304 |
||
1305 |
// Reparent an explicitly hidden child to root. |
|
1306 |
child->setEnabled(false); |
|
1307 |
child->setParentItem(parent2); |
|
1308 |
parent2->setEnabled(true); |
|
1309 |
QVERIFY(!child->isEnabled()); |
|
1310 |
child->setParentItem(0); |
|
1311 |
QVERIFY(!child->isEnabled()); |
|
1312 |
} |
|
1313 |
||
1314 |
class SelectChangeItem : public QGraphicsRectItem |
|
1315 |
{ |
|
1316 |
public: |
|
1317 |
SelectChangeItem() : QGraphicsRectItem(-50, -50, 100, 100) { setBrush(Qt::blue); } |
|
1318 |
QList<bool> values; |
|
1319 |
||
1320 |
protected: |
|
1321 |
QVariant itemChange(GraphicsItemChange change, const QVariant &value) |
|
1322 |
{ |
|
1323 |
if (change == ItemSelectedChange) |
|
1324 |
values << value.toBool(); |
|
1325 |
return QGraphicsRectItem::itemChange(change, value); |
|
1326 |
} |
|
1327 |
}; |
|
1328 |
||
1329 |
void tst_QGraphicsItem::selected() |
|
1330 |
{ |
|
1331 |
SelectChangeItem *item = new SelectChangeItem; |
|
1332 |
item->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1333 |
QVERIFY(!item->isSelected()); |
|
1334 |
QVERIFY(item->values.isEmpty()); |
|
1335 |
item->setSelected(true); |
|
1336 |
QCOMPARE(item->values.size(), 1); |
|
1337 |
QCOMPARE(item->values.last(), true); |
|
1338 |
QVERIFY(item->isSelected()); |
|
1339 |
item->setSelected(false); |
|
1340 |
QCOMPARE(item->values.size(), 2); |
|
1341 |
QCOMPARE(item->values.last(), false); |
|
1342 |
QVERIFY(!item->isSelected()); |
|
1343 |
item->setSelected(true); |
|
1344 |
QCOMPARE(item->values.size(), 3); |
|
1345 |
item->setEnabled(false); |
|
1346 |
QCOMPARE(item->values.size(), 4); |
|
1347 |
QCOMPARE(item->values.last(), false); |
|
1348 |
QVERIFY(!item->isSelected()); |
|
1349 |
item->setEnabled(true); |
|
1350 |
QCOMPARE(item->values.size(), 4); |
|
1351 |
item->setSelected(true); |
|
1352 |
QCOMPARE(item->values.size(), 5); |
|
1353 |
QCOMPARE(item->values.last(), true); |
|
1354 |
QVERIFY(item->isSelected()); |
|
1355 |
item->setVisible(false); |
|
1356 |
QCOMPARE(item->values.size(), 6); |
|
1357 |
QCOMPARE(item->values.last(), false); |
|
1358 |
QVERIFY(!item->isSelected()); |
|
1359 |
item->setVisible(true); |
|
1360 |
QCOMPARE(item->values.size(), 6); |
|
1361 |
item->setSelected(true); |
|
1362 |
QCOMPARE(item->values.size(), 7); |
|
1363 |
QCOMPARE(item->values.last(), true); |
|
1364 |
QVERIFY(item->isSelected()); |
|
1365 |
||
1366 |
QGraphicsScene scene(-100, -100, 200, 200); |
|
1367 |
scene.addItem(item); |
|
1368 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item); |
|
1369 |
item->setSelected(false); |
|
1370 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
1371 |
item->setSelected(true); |
|
1372 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item); |
|
1373 |
item->setSelected(false); |
|
1374 |
QVERIFY(scene.selectedItems().isEmpty()); |
|
1375 |
||
1376 |
// Interactive selection |
|
1377 |
QGraphicsView view(&scene); |
|
1378 |
view.setFixedSize(250, 250); |
|
1379 |
view.show(); |
|
1380 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1381 |
QTest::qWaitForWindowShown(&view); |
0 | 1382 |
qApp->processEvents(); |
1383 |
qApp->processEvents(); |
|
1384 |
||
1385 |
scene.clearSelection(); |
|
1386 |
QCOMPARE(item->values.size(), 10); |
|
1387 |
QCOMPARE(item->values.last(), false); |
|
1388 |
QVERIFY(!item->isSelected()); |
|
1389 |
||
1390 |
// Click inside and check that it's selected |
|
1391 |
QTest::mouseMove(view.viewport()); |
|
1392 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); |
|
1393 |
QCOMPARE(item->values.size(), 11); |
|
1394 |
QCOMPARE(item->values.last(), true); |
|
1395 |
QVERIFY(item->isSelected()); |
|
1396 |
||
1397 |
// Click outside and check that it's not selected |
|
1398 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos() + QPointF(item->boundingRect().width(), item->boundingRect().height()))); |
|
1399 |
QCOMPARE(item->values.size(), 12); |
|
1400 |
QCOMPARE(item->values.last(), false); |
|
1401 |
QVERIFY(!item->isSelected()); |
|
1402 |
||
1403 |
SelectChangeItem *item2 = new SelectChangeItem; |
|
1404 |
item2->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1405 |
item2->setPos(100, 0); |
|
1406 |
scene.addItem(item2); |
|
1407 |
||
1408 |
// Click inside and check that it's selected |
|
1409 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); |
|
1410 |
QCOMPARE(item->values.size(), 13); |
|
1411 |
QCOMPARE(item->values.last(), true); |
|
1412 |
QVERIFY(item->isSelected()); |
|
1413 |
||
1414 |
// Click inside item2 and check that it's selected, and item is not |
|
1415 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); |
|
1416 |
QCOMPARE(item->values.size(), 14); |
|
1417 |
QCOMPARE(item->values.last(), false); |
|
1418 |
QVERIFY(!item->isSelected()); |
|
1419 |
QCOMPARE(item2->values.size(), 1); |
|
1420 |
QCOMPARE(item2->values.last(), true); |
|
1421 |
QVERIFY(item2->isSelected()); |
|
1422 |
} |
|
1423 |
||
1424 |
void tst_QGraphicsItem::selected2() |
|
1425 |
{ |
|
1426 |
// Selecting an item, then moving another previously caused a crash. |
|
1427 |
QGraphicsScene scene; |
|
1428 |
QGraphicsItem *line1 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
1429 |
line1->setPos(-105, 0); |
|
1430 |
line1->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1431 |
||
1432 |
QGraphicsItem *line2 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
1433 |
line2->setFlag(QGraphicsItem::ItemIsMovable); |
|
1434 |
||
1435 |
line1->setSelected(true); |
|
1436 |
||
1437 |
{ |
|
1438 |
QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress); |
|
1439 |
mousePress.setScenePos(QPointF(50, 50)); |
|
1440 |
mousePress.setButton(Qt::LeftButton); |
|
1441 |
QApplication::sendEvent(&scene, &mousePress); |
|
1442 |
QVERIFY(mousePress.isAccepted()); |
|
1443 |
} |
|
1444 |
{ |
|
1445 |
QGraphicsSceneMouseEvent mouseMove(QEvent::GraphicsSceneMouseMove); |
|
1446 |
mouseMove.setScenePos(QPointF(60, 60)); |
|
1447 |
mouseMove.setButton(Qt::LeftButton); |
|
1448 |
mouseMove.setButtons(Qt::LeftButton); |
|
1449 |
QApplication::sendEvent(&scene, &mouseMove); |
|
1450 |
QVERIFY(mouseMove.isAccepted()); |
|
1451 |
} |
|
1452 |
} |
|
1453 |
||
1454 |
void tst_QGraphicsItem::selected_group() |
|
1455 |
{ |
|
1456 |
QGraphicsScene scene; |
|
1457 |
QGraphicsItem *item1 = scene.addRect(QRectF()); |
|
1458 |
QGraphicsItem *item2 = scene.addRect(QRectF()); |
|
1459 |
item1->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1460 |
item2->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1461 |
scene.addRect(QRectF())->setParentItem(item1); |
|
1462 |
QGraphicsItem *leaf = scene.addRect(QRectF()); |
|
1463 |
leaf->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1464 |
leaf->setParentItem(item2); |
|
1465 |
||
1466 |
QGraphicsItemGroup *group = scene.createItemGroup(QList<QGraphicsItem *>() << item1 << item2); |
|
1467 |
QCOMPARE(group->scene(), &scene); |
|
1468 |
group->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1469 |
foreach (QGraphicsItem *item, scene.items()) { |
|
1470 |
if (item == group) |
|
1471 |
QVERIFY(!item->group()); |
|
1472 |
else |
|
1473 |
QCOMPARE(item->group(), group); |
|
1474 |
} |
|
1475 |
||
1476 |
QVERIFY(group->handlesChildEvents()); |
|
1477 |
QVERIFY(!group->isSelected()); |
|
1478 |
group->setSelected(false); |
|
1479 |
QVERIFY(!group->isSelected()); |
|
1480 |
group->setSelected(true); |
|
1481 |
QVERIFY(group->isSelected()); |
|
1482 |
foreach (QGraphicsItem *item, scene.items()) |
|
1483 |
QVERIFY(item->isSelected()); |
|
1484 |
group->setSelected(false); |
|
1485 |
QVERIFY(!group->isSelected()); |
|
1486 |
foreach (QGraphicsItem *item, scene.items()) |
|
1487 |
QVERIFY(!item->isSelected()); |
|
1488 |
leaf->setSelected(true); |
|
1489 |
foreach (QGraphicsItem *item, scene.items()) |
|
1490 |
QVERIFY(item->isSelected()); |
|
1491 |
leaf->setSelected(false); |
|
1492 |
foreach (QGraphicsItem *item, scene.items()) |
|
1493 |
QVERIFY(!item->isSelected()); |
|
1494 |
||
1495 |
leaf->setSelected(true); |
|
1496 |
QGraphicsScene scene2; |
|
1497 |
scene2.addItem(item1); |
|
1498 |
QVERIFY(!item1->isSelected()); |
|
1499 |
QVERIFY(item2->isSelected()); |
|
1500 |
} |
|
1501 |
||
1502 |
void tst_QGraphicsItem::selected_textItem() |
|
1503 |
{ |
|
1504 |
QGraphicsScene scene; |
|
1505 |
QGraphicsTextItem *text = scene.addText(QLatin1String("Text")); |
|
1506 |
text->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1507 |
||
1508 |
QGraphicsView view(&scene); |
|
1509 |
view.show(); |
|
1510 |
QTest::qWaitForWindowShown(&view); |
|
1511 |
QTest::qWait(20); |
|
1512 |
||
1513 |
QTRY_VERIFY(!text->isSelected()); |
|
1514 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
1515 |
view.mapFromScene(text->mapToScene(0, 0))); |
|
1516 |
QTRY_VERIFY(text->isSelected()); |
|
1517 |
||
1518 |
text->setSelected(false); |
|
1519 |
text->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
1520 |
||
1521 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
1522 |
view.mapFromScene(text->mapToScene(0, 0))); |
|
1523 |
QTRY_VERIFY(text->isSelected()); |
|
1524 |
} |
|
1525 |
||
1526 |
void tst_QGraphicsItem::selected_multi() |
|
1527 |
{ |
|
1528 |
// Test multiselection behavior |
|
1529 |
QGraphicsScene scene; |
|
1530 |
||
1531 |
// Create two disjoint items |
|
1532 |
QGraphicsItem *item1 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1533 |
QGraphicsItem *item2 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1534 |
item1->setPos(-15, 0); |
|
1535 |
item2->setPos(15, 20); |
|
1536 |
||
1537 |
// Make both items selectable |
|
1538 |
item1->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1539 |
item2->setFlag(QGraphicsItem::ItemIsSelectable); |
|
1540 |
||
1541 |
// Create and show a view |
|
1542 |
QGraphicsView view(&scene); |
|
1543 |
view.show(); |
|
1544 |
view.fitInView(scene.sceneRect()); |
|
1545 |
qApp->processEvents(); |
|
1546 |
||
1547 |
QVERIFY(!item1->isSelected()); |
|
1548 |
QVERIFY(!item2->isSelected()); |
|
1549 |
||
1550 |
// Start clicking |
|
1551 |
QTest::qWait(200); |
|
1552 |
||
1553 |
// Click on item1 |
|
1554 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); |
|
1555 |
QTest::qWait(20); |
|
1556 |
QVERIFY(item1->isSelected()); |
|
1557 |
QVERIFY(!item2->isSelected()); |
|
1558 |
||
1559 |
// Click on item2 |
|
1560 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); |
|
1561 |
QTest::qWait(20); |
|
1562 |
QVERIFY(item2->isSelected()); |
|
1563 |
QVERIFY(!item1->isSelected()); |
|
1564 |
||
1565 |
// Ctrl-click on item1 |
|
1566 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); |
|
1567 |
QTest::qWait(20); |
|
1568 |
QVERIFY(item2->isSelected()); |
|
1569 |
QVERIFY(item1->isSelected()); |
|
1570 |
||
1571 |
// Ctrl-click on item1 again |
|
1572 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); |
|
1573 |
QTest::qWait(20); |
|
1574 |
QVERIFY(item2->isSelected()); |
|
1575 |
QVERIFY(!item1->isSelected()); |
|
1576 |
||
1577 |
// Ctrl-click on item2 |
|
1578 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item2->scenePos())); |
|
1579 |
QTest::qWait(20); |
|
1580 |
QVERIFY(!item2->isSelected()); |
|
1581 |
QVERIFY(!item1->isSelected()); |
|
1582 |
||
1583 |
// Click on item1 |
|
1584 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); |
|
1585 |
QTest::qWait(20); |
|
1586 |
QVERIFY(item1->isSelected()); |
|
1587 |
QVERIFY(!item2->isSelected()); |
|
1588 |
||
1589 |
// Click on scene |
|
1590 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0)); |
|
1591 |
QTest::qWait(20); |
|
1592 |
QVERIFY(!item1->isSelected()); |
|
1593 |
QVERIFY(!item2->isSelected()); |
|
1594 |
||
1595 |
// Click on item1 |
|
1596 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); |
|
1597 |
QTest::qWait(20); |
|
1598 |
QVERIFY(item1->isSelected()); |
|
1599 |
QVERIFY(!item2->isSelected()); |
|
1600 |
||
1601 |
// Ctrl-click on scene |
|
1602 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(0, 0)); |
|
1603 |
QTest::qWait(20); |
|
1604 |
QVERIFY(!item1->isSelected()); |
|
1605 |
QVERIFY(!item2->isSelected()); |
|
1606 |
||
1607 |
// Click on item1 |
|
1608 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); |
|
1609 |
QTest::qWait(20); |
|
1610 |
QVERIFY(item1->isSelected()); |
|
1611 |
QVERIFY(!item2->isSelected()); |
|
1612 |
||
1613 |
// Press on item2 |
|
1614 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); |
|
1615 |
QTest::qWait(20); |
|
1616 |
QVERIFY(!item1->isSelected()); |
|
1617 |
QVERIFY(item2->isSelected()); |
|
1618 |
||
1619 |
// Release on item2 |
|
1620 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); |
|
1621 |
QTest::qWait(20); |
|
1622 |
QVERIFY(!item1->isSelected()); |
|
1623 |
QVERIFY(item2->isSelected()); |
|
1624 |
||
1625 |
// Click on item1 |
|
1626 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); |
|
1627 |
QTest::qWait(20); |
|
1628 |
QVERIFY(item1->isSelected()); |
|
1629 |
QVERIFY(!item2->isSelected()); |
|
1630 |
||
1631 |
// Ctrl-click on item1 |
|
1632 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); |
|
1633 |
QTest::qWait(20); |
|
1634 |
QVERIFY(!item1->isSelected()); |
|
1635 |
QVERIFY(!item2->isSelected()); |
|
1636 |
||
1637 |
// Ctrl-press on item1 |
|
1638 |
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); |
|
1639 |
QTest::qWait(20); |
|
1640 |
QVERIFY(!item1->isSelected()); |
|
1641 |
QVERIFY(!item2->isSelected()); |
|
1642 |
||
1643 |
{ |
|
1644 |
// Ctrl-move on item1 |
|
1645 |
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); |
|
1646 |
QApplication::sendEvent(view.viewport(), &event); |
|
1647 |
QTest::qWait(20); |
|
1648 |
QVERIFY(!item1->isSelected()); |
|
1649 |
QVERIFY(!item2->isSelected()); |
|
1650 |
} |
|
1651 |
||
1652 |
// Release on item1 |
|
1653 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); |
|
1654 |
QTest::qWait(20); |
|
1655 |
QVERIFY(item1->isSelected()); |
|
1656 |
QVERIFY(!item2->isSelected()); |
|
1657 |
||
1658 |
item1->setFlag(QGraphicsItem::ItemIsMovable); |
|
1659 |
item1->setSelected(false); |
|
1660 |
||
1661 |
// Ctrl-press on item1 |
|
1662 |
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); |
|
1663 |
QTest::qWait(20); |
|
1664 |
QVERIFY(!item1->isSelected()); |
|
1665 |
QVERIFY(!item2->isSelected()); |
|
1666 |
||
1667 |
{ |
|
1668 |
// Ctrl-move on item1 |
|
1669 |
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); |
|
1670 |
QApplication::sendEvent(view.viewport(), &event); |
|
1671 |
QTest::qWait(20); |
|
1672 |
QVERIFY(item1->isSelected()); |
|
1673 |
QVERIFY(!item2->isSelected()); |
|
1674 |
} |
|
1675 |
||
1676 |
// Release on item1 |
|
1677 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, view.mapFromScene(item1->scenePos())); |
|
1678 |
QTest::qWait(20); |
|
1679 |
QVERIFY(item1->isSelected()); |
|
1680 |
QVERIFY(!item2->isSelected()); |
|
1681 |
} |
|
1682 |
||
1683 |
void tst_QGraphicsItem::acceptedMouseButtons() |
|
1684 |
{ |
|
1685 |
QGraphicsScene scene; |
|
1686 |
QGraphicsRectItem *item1 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1687 |
QGraphicsRectItem *item2 = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
1688 |
item2->setZValue(1); |
|
1689 |
||
1690 |
item1->setFlag(QGraphicsItem::ItemIsMovable); |
|
1691 |
item2->setFlag(QGraphicsItem::ItemIsMovable); |
|
1692 |
||
1693 |
QCOMPARE(item1->acceptedMouseButtons(), Qt::MouseButtons(0x1f)); |
|
1694 |
QCOMPARE(item2->acceptedMouseButtons(), Qt::MouseButtons(0x1f)); |
|
1695 |
||
1696 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1697 |
event.setButton(Qt::LeftButton); |
|
1698 |
event.setScenePos(QPointF(0, 0)); |
|
1699 |
QApplication::sendEvent(&scene, &event); |
|
1700 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item2); |
|
1701 |
item2->setAcceptedMouseButtons(0); |
|
1702 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1703 |
QApplication::sendEvent(&scene, &event); |
|
1704 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item1); |
|
1705 |
} |
|
1706 |
||
1707 |
class HoverItem : public QGraphicsRectItem |
|
1708 |
{ |
|
1709 |
public: |
|
1710 |
HoverItem(const QRectF &rect) |
|
1711 |
: QGraphicsRectItem(rect), hoverInCount(0), |
|
1712 |
hoverMoveCount(0), hoverOutCount(0) |
|
1713 |
{ } |
|
1714 |
||
1715 |
int hoverInCount; |
|
1716 |
int hoverMoveCount; |
|
1717 |
int hoverOutCount; |
|
1718 |
protected: |
|
1719 |
void hoverEnterEvent(QGraphicsSceneHoverEvent *) |
|
1720 |
{ ++hoverInCount; } |
|
1721 |
||
1722 |
void hoverMoveEvent(QGraphicsSceneHoverEvent *) |
|
1723 |
{ ++hoverMoveCount; } |
|
1724 |
||
1725 |
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) |
|
1726 |
{ ++hoverOutCount; } |
|
1727 |
}; |
|
1728 |
||
1729 |
void tst_QGraphicsItem::acceptsHoverEvents() |
|
1730 |
{ |
|
1731 |
QGraphicsScene scene; |
|
1732 |
HoverItem *item1 = new HoverItem(QRectF(-10, -10, 20, 20)); |
|
1733 |
HoverItem *item2 = new HoverItem(QRectF(-5, -5, 10, 10)); |
|
1734 |
scene.addItem(item1); |
|
1735 |
scene.addItem(item2); |
|
1736 |
item2->setZValue(1); |
|
1737 |
||
1738 |
QVERIFY(!item1->acceptsHoverEvents()); |
|
1739 |
QVERIFY(!item2->acceptsHoverEvents()); |
|
1740 |
item1->setAcceptsHoverEvents(true); |
|
1741 |
item2->setAcceptsHoverEvents(true); |
|
1742 |
||
1743 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
1744 |
event.setScenePos(QPointF(-100, -100)); |
|
1745 |
QApplication::sendEvent(&scene, &event); |
|
1746 |
event.setScenePos(QPointF(-2.5, -2.5)); |
|
1747 |
QApplication::sendEvent(&scene, &event); |
|
1748 |
||
1749 |
QCOMPARE(item1->hoverInCount, 0); |
|
1750 |
QCOMPARE(item2->hoverInCount, 1); |
|
1751 |
||
1752 |
item1->setAcceptsHoverEvents(false); |
|
1753 |
item2->setAcceptsHoverEvents(false); |
|
1754 |
||
1755 |
event.setScenePos(QPointF(-100, -100)); |
|
1756 |
QApplication::sendEvent(&scene, &event); |
|
1757 |
event.setScenePos(QPointF(-2.5, -2.5)); |
|
1758 |
QApplication::sendEvent(&scene, &event); |
|
1759 |
||
1760 |
QCOMPARE(item1->hoverInCount, 0); |
|
1761 |
QCOMPARE(item2->hoverInCount, 1); |
|
1762 |
||
1763 |
item1->setAcceptsHoverEvents(true); |
|
1764 |
item2->setAcceptsHoverEvents(false); |
|
1765 |
||
1766 |
event.setScenePos(QPointF(-100, -100)); |
|
1767 |
QApplication::sendEvent(&scene, &event); |
|
1768 |
event.setScenePos(QPointF(-2.5, -2.5)); |
|
1769 |
QApplication::sendEvent(&scene, &event); |
|
1770 |
||
1771 |
QCOMPARE(item1->hoverInCount, 1); |
|
1772 |
QCOMPARE(item2->hoverInCount, 1); |
|
1773 |
} |
|
1774 |
||
1775 |
void tst_QGraphicsItem::childAcceptsHoverEvents() |
|
1776 |
{ |
|
1777 |
QGraphicsScene scene; |
|
1778 |
HoverItem *item1 = new HoverItem(QRectF(-10, -10, 20, 20)); |
|
1779 |
HoverItem *item2 = new HoverItem(QRectF(-5, -5, 10, 10)); |
|
1780 |
||
1781 |
scene.addItem(item1); |
|
1782 |
scene.addItem(item2); |
|
1783 |
item2->setParentItem(item1); |
|
1784 |
item2->setAcceptHoverEvents(true); |
|
1785 |
||
1786 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
1787 |
event.setScenePos(QPointF(-100, -100)); |
|
1788 |
QApplication::sendEvent(&scene, &event); |
|
1789 |
QCOMPARE(item2->hoverInCount, 0); |
|
1790 |
QCOMPARE(item2->hoverMoveCount, 0); |
|
1791 |
QCOMPARE(item2->hoverOutCount, 0); |
|
1792 |
QCOMPARE(item1->hoverInCount, 0); |
|
1793 |
QCOMPARE(item1->hoverMoveCount, 0); |
|
1794 |
QCOMPARE(item1->hoverOutCount, 0); |
|
1795 |
||
1796 |
event.setScenePos(QPointF(-2.5, -2.5)); |
|
1797 |
QApplication::sendEvent(&scene, &event); |
|
1798 |
||
1799 |
QCOMPARE(item2->hoverInCount, 1); |
|
1800 |
QCOMPARE(item2->hoverMoveCount, 1); |
|
1801 |
QCOMPARE(item2->hoverOutCount, 0); |
|
1802 |
QCOMPARE(item1->hoverInCount, 0); |
|
1803 |
QCOMPARE(item1->hoverMoveCount, 0); |
|
1804 |
QCOMPARE(item1->hoverOutCount, 0); |
|
1805 |
||
1806 |
event.setScenePos(QPointF(0, 0)); |
|
1807 |
QApplication::sendEvent(&scene, &event); |
|
1808 |
||
1809 |
QCOMPARE(item2->hoverInCount, 1); |
|
1810 |
QCOMPARE(item2->hoverMoveCount, 2); |
|
1811 |
QCOMPARE(item2->hoverOutCount, 0); |
|
1812 |
QCOMPARE(item1->hoverInCount, 0); |
|
1813 |
QCOMPARE(item1->hoverMoveCount, 0); |
|
1814 |
QCOMPARE(item1->hoverOutCount, 0); |
|
1815 |
||
1816 |
event.setScenePos(QPointF(-7, -7)); |
|
1817 |
QApplication::sendEvent(&scene, &event); |
|
1818 |
||
1819 |
QCOMPARE(item2->hoverInCount, 1); |
|
1820 |
QCOMPARE(item2->hoverMoveCount, 2); |
|
1821 |
QCOMPARE(item2->hoverOutCount, 1); |
|
1822 |
QCOMPARE(item1->hoverInCount, 0); |
|
1823 |
QCOMPARE(item1->hoverMoveCount, 0); |
|
1824 |
QCOMPARE(item1->hoverOutCount, 0); |
|
1825 |
||
1826 |
event.setScenePos(QPointF(0, 0)); |
|
1827 |
QApplication::sendEvent(&scene, &event); |
|
1828 |
||
1829 |
QCOMPARE(item2->hoverInCount, 2); |
|
1830 |
QCOMPARE(item2->hoverMoveCount, 3); |
|
1831 |
QCOMPARE(item2->hoverOutCount, 1); |
|
1832 |
QCOMPARE(item1->hoverInCount, 0); |
|
1833 |
QCOMPARE(item1->hoverMoveCount, 0); |
|
1834 |
QCOMPARE(item1->hoverOutCount, 0); |
|
1835 |
||
1836 |
HoverItem *item0 = new HoverItem(QRectF(-20, -20, 20, 20)); |
|
1837 |
scene.addItem(item0); |
|
1838 |
item1->setParentItem(item0); |
|
1839 |
item0->setAcceptHoverEvents(true); |
|
1840 |
||
1841 |
event.setScenePos(QPointF(-100, -100)); |
|
1842 |
QApplication::sendEvent(&scene, &event); |
|
1843 |
||
1844 |
event.setScenePos(QPointF(-15, -15)); |
|
1845 |
QApplication::sendEvent(&scene, &event); |
|
1846 |
||
1847 |
QCOMPARE(item2->hoverInCount, 2); |
|
1848 |
QCOMPARE(item2->hoverMoveCount, 3); |
|
1849 |
QCOMPARE(item2->hoverOutCount, 2); |
|
1850 |
QCOMPARE(item1->hoverInCount, 0); |
|
1851 |
QCOMPARE(item1->hoverMoveCount, 0); |
|
1852 |
QCOMPARE(item1->hoverOutCount, 0); |
|
1853 |
QCOMPARE(item0->hoverInCount, 1); |
|
1854 |
QCOMPARE(item0->hoverMoveCount, 1); |
|
1855 |
QCOMPARE(item0->hoverOutCount, 0); |
|
1856 |
} |
|
1857 |
||
1858 |
void tst_QGraphicsItem::hasFocus() |
|
1859 |
{ |
|
1860 |
QGraphicsLineItem *line = new QGraphicsLineItem; |
|
1861 |
QVERIFY(!line->hasFocus()); |
|
1862 |
line->setFocus(); |
|
1863 |
QVERIFY(!line->hasFocus()); |
|
1864 |
||
1865 |
QGraphicsScene scene; |
|
1866 |
QEvent activate(QEvent::WindowActivate); |
|
1867 |
QApplication::sendEvent(&scene, &activate); |
|
1868 |
||
1869 |
scene.addItem(line); |
|
1870 |
||
1871 |
line->setFocus(); |
|
1872 |
QVERIFY(!line->hasFocus()); |
|
1873 |
line->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1874 |
line->setFocus(); |
|
1875 |
QVERIFY(line->hasFocus()); |
|
1876 |
||
1877 |
QGraphicsScene scene2; |
|
1878 |
QApplication::sendEvent(&scene2, &activate); |
|
1879 |
||
1880 |
scene2.addItem(line); |
|
1881 |
QVERIFY(!line->hasFocus()); |
|
1882 |
||
1883 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *)0); |
|
1884 |
QCOMPARE(scene2.focusItem(), (QGraphicsItem *)0); |
|
1885 |
||
1886 |
line->setFocus(); |
|
1887 |
QVERIFY(line->hasFocus()); |
|
1888 |
line->clearFocus(); |
|
1889 |
QVERIFY(!line->hasFocus()); |
|
1890 |
||
1891 |
QGraphicsLineItem *line2 = new QGraphicsLineItem; |
|
1892 |
line2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1893 |
scene2.addItem(line2); |
|
1894 |
||
1895 |
line2->setFocus(); |
|
1896 |
QVERIFY(!line->hasFocus()); |
|
1897 |
QVERIFY(line2->hasFocus()); |
|
1898 |
line->setFocus(); |
|
1899 |
QVERIFY(line->hasFocus()); |
|
1900 |
QVERIFY(!line2->hasFocus()); |
|
1901 |
} |
|
1902 |
||
1903 |
void tst_QGraphicsItem::pos() |
|
1904 |
{ |
|
1905 |
QGraphicsItem *child = new QGraphicsLineItem; |
|
1906 |
QGraphicsItem *parent = new QGraphicsLineItem; |
|
1907 |
||
1908 |
QCOMPARE(child->pos(), QPointF()); |
|
1909 |
QCOMPARE(parent->pos(), QPointF()); |
|
1910 |
||
1911 |
child->setParentItem(parent); |
|
1912 |
child->setPos(10, 10); |
|
1913 |
||
1914 |
QCOMPARE(child->pos(), QPointF(10, 10)); |
|
1915 |
||
1916 |
parent->setPos(10, 10); |
|
1917 |
||
1918 |
QCOMPARE(parent->pos(), QPointF(10, 10)); |
|
1919 |
QCOMPARE(child->pos(), QPointF(10, 10)); |
|
1920 |
||
1921 |
delete child; |
|
1922 |
delete parent; |
|
1923 |
} |
|
1924 |
||
1925 |
void tst_QGraphicsItem::scenePos() |
|
1926 |
{ |
|
1927 |
QGraphicsItem *child = new QGraphicsLineItem; |
|
1928 |
QGraphicsItem *parent = new QGraphicsLineItem; |
|
1929 |
||
1930 |
QCOMPARE(child->scenePos(), QPointF()); |
|
1931 |
QCOMPARE(parent->scenePos(), QPointF()); |
|
1932 |
||
1933 |
child->setParentItem(parent); |
|
1934 |
child->setPos(10, 10); |
|
1935 |
||
1936 |
QCOMPARE(child->scenePos(), QPointF(10, 10)); |
|
1937 |
||
1938 |
parent->setPos(10, 10); |
|
1939 |
||
1940 |
QCOMPARE(parent->scenePos(), QPointF(10, 10)); |
|
1941 |
QCOMPARE(child->scenePos(), QPointF(20, 20)); |
|
1942 |
||
1943 |
parent->setPos(20, 20); |
|
1944 |
||
1945 |
QCOMPARE(parent->scenePos(), QPointF(20, 20)); |
|
1946 |
QCOMPARE(child->scenePos(), QPointF(30, 30)); |
|
1947 |
||
1948 |
delete child; |
|
1949 |
delete parent; |
|
1950 |
} |
|
1951 |
||
1952 |
void tst_QGraphicsItem::matrix() |
|
1953 |
{ |
|
1954 |
QGraphicsLineItem line; |
|
1955 |
QCOMPARE(line.matrix(), QMatrix()); |
|
1956 |
line.setMatrix(QMatrix().rotate(90)); |
|
1957 |
QCOMPARE(line.matrix(), QMatrix().rotate(90)); |
|
1958 |
line.setMatrix(QMatrix().rotate(90)); |
|
1959 |
QCOMPARE(line.matrix(), QMatrix().rotate(90)); |
|
1960 |
line.setMatrix(QMatrix().rotate(90), true); |
|
1961 |
QCOMPARE(line.matrix(), QMatrix().rotate(180)); |
|
1962 |
line.setMatrix(QMatrix().rotate(-90), true); |
|
1963 |
QCOMPARE(line.matrix(), QMatrix().rotate(90)); |
|
1964 |
line.resetMatrix(); |
|
1965 |
QCOMPARE(line.matrix(), QMatrix()); |
|
1966 |
||
1967 |
line.rotate(90); |
|
1968 |
QCOMPARE(line.matrix(), QMatrix().rotate(90)); |
|
1969 |
line.rotate(90); |
|
1970 |
QCOMPARE(line.matrix(), QMatrix().rotate(90).rotate(90)); |
|
1971 |
line.resetMatrix(); |
|
1972 |
||
1973 |
line.scale(2, 4); |
|
1974 |
QCOMPARE(line.matrix(), QMatrix().scale(2, 4)); |
|
1975 |
line.scale(2, 4); |
|
1976 |
QCOMPARE(line.matrix(), QMatrix().scale(2, 4).scale(2, 4)); |
|
1977 |
line.resetMatrix(); |
|
1978 |
||
1979 |
line.shear(2, 4); |
|
1980 |
QCOMPARE(line.matrix(), QMatrix().shear(2, 4)); |
|
1981 |
line.shear(2, 4); |
|
1982 |
QCOMPARE(line.matrix(), QMatrix().shear(2, 4).shear(2, 4)); |
|
1983 |
line.resetMatrix(); |
|
1984 |
||
1985 |
line.translate(10, 10); |
|
1986 |
QCOMPARE(line.matrix(), QMatrix().translate(10, 10)); |
|
1987 |
line.translate(10, 10); |
|
1988 |
QCOMPARE(line.matrix(), QMatrix().translate(10, 10).translate(10, 10)); |
|
1989 |
line.resetMatrix(); |
|
1990 |
} |
|
1991 |
||
1992 |
void tst_QGraphicsItem::sceneMatrix() |
|
1993 |
{ |
|
1994 |
QGraphicsLineItem *parent = new QGraphicsLineItem; |
|
1995 |
QGraphicsLineItem *child = new QGraphicsLineItem(QLineF(), parent); |
|
1996 |
||
1997 |
QCOMPARE(parent->sceneMatrix(), QMatrix()); |
|
1998 |
QCOMPARE(child->sceneMatrix(), QMatrix()); |
|
1999 |
||
2000 |
parent->translate(10, 10); |
|
2001 |
QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10)); |
|
2002 |
QCOMPARE(child->sceneMatrix(), QMatrix().translate(10, 10)); |
|
2003 |
||
2004 |
child->translate(10, 10); |
|
2005 |
QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10)); |
|
2006 |
QCOMPARE(child->sceneMatrix(), QMatrix().translate(20, 20)); |
|
2007 |
||
2008 |
parent->rotate(90); |
|
2009 |
QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10).rotate(90)); |
|
2010 |
QCOMPARE(child->sceneMatrix(), QMatrix().translate(10, 10).rotate(90).translate(10, 10)); |
|
2011 |
||
2012 |
delete child; |
|
2013 |
delete parent; |
|
2014 |
} |
|
2015 |
||
2016 |
void tst_QGraphicsItem::setMatrix() |
|
2017 |
{ |
|
2018 |
QGraphicsScene scene; |
|
2019 |
qRegisterMetaType<QList<QRectF> >("QList<QRectF>"); |
|
2020 |
QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>))); |
|
2021 |
QRectF unrotatedRect(-12, -34, 56, 78); |
|
2022 |
QGraphicsRectItem item(unrotatedRect, 0, &scene); |
|
2023 |
scene.update(scene.sceneRect()); |
|
2024 |
QApplication::instance()->processEvents(); |
|
2025 |
||
2026 |
QCOMPARE(spy.count(), 1); |
|
2027 |
||
2028 |
item.setMatrix(QMatrix().rotate(qreal(12.34))); |
|
2029 |
QRectF rotatedRect = scene.sceneRect(); |
|
2030 |
QVERIFY(unrotatedRect != rotatedRect); |
|
2031 |
scene.update(scene.sceneRect()); |
|
2032 |
QApplication::instance()->processEvents(); |
|
2033 |
||
2034 |
QCOMPARE(spy.count(), 2); |
|
2035 |
||
2036 |
item.setMatrix(QMatrix()); |
|
2037 |
||
2038 |
scene.update(scene.sceneRect()); |
|
2039 |
QApplication::instance()->processEvents(); |
|
2040 |
||
2041 |
QCOMPARE(spy.count(), 3); |
|
2042 |
QList<QRectF> rlist = qVariantValue<QList<QRectF> >(spy.last().at(0)); |
|
2043 |
||
2044 |
QCOMPARE(rlist.size(), 3); |
|
2045 |
QCOMPARE(rlist.at(0), rotatedRect); // From item.setMatrix() (clearing rotated rect) |
|
2046 |
QCOMPARE(rlist.at(1), rotatedRect); // From scene.update() (updating scene rect) |
|
2047 |
QCOMPARE(rlist.at(2), unrotatedRect); // From post-update (update current state) |
|
2048 |
} |
|
2049 |
||
2050 |
static QList<QGraphicsItem *> _paintedItems; |
|
2051 |
class PainterItem : public QGraphicsItem |
|
2052 |
{ |
|
2053 |
protected: |
|
2054 |
QRectF boundingRect() const |
|
2055 |
{ return QRectF(-10, -10, 20, 20); } |
|
2056 |
||
2057 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
2058 |
{ _paintedItems << this; painter->fillRect(boundingRect(), Qt::red); } |
|
2059 |
}; |
|
2060 |
||
2061 |
void tst_QGraphicsItem::zValue() |
|
2062 |
{ |
|
2063 |
Q_CHECK_PAINTEVENTS |
|
2064 |
||
2065 |
QGraphicsScene scene; |
|
2066 |
||
2067 |
QGraphicsItem *item1 = new PainterItem; |
|
2068 |
QGraphicsItem *item2 = new PainterItem; |
|
2069 |
QGraphicsItem *item3 = new PainterItem; |
|
2070 |
QGraphicsItem *item4 = new PainterItem; |
|
2071 |
scene.addItem(item1); |
|
2072 |
scene.addItem(item2); |
|
2073 |
scene.addItem(item3); |
|
2074 |
scene.addItem(item4); |
|
2075 |
item2->setZValue(-3); |
|
2076 |
item4->setZValue(-2); |
|
2077 |
item1->setZValue(-1); |
|
2078 |
item3->setZValue(0); |
|
2079 |
||
2080 |
QGraphicsView view(&scene); |
|
2081 |
view.show(); |
|
2082 |
#ifdef Q_WS_X11 |
|
2083 |
qt_x11_wait_for_window_manager(&view); |
|
2084 |
#endif |
|
2085 |
QApplication::processEvents(); |
|
2086 |
#ifdef Q_WS_QWS |
|
2087 |
QApplication::sendPostedEvents(); //glib workaround |
|
2088 |
#endif |
|
2089 |
||
2090 |
QTRY_VERIFY(!_paintedItems.isEmpty()); |
|
2091 |
QVERIFY((_paintedItems.size() % 4) == 0); |
|
2092 |
for (int i = 0; i < 3; ++i) |
|
2093 |
QVERIFY(_paintedItems.at(i)->zValue() < _paintedItems.at(i + 1)->zValue()); |
|
2094 |
} |
|
2095 |
||
2096 |
void tst_QGraphicsItem::shape() |
|
2097 |
{ |
|
2098 |
QGraphicsLineItem line(QLineF(-10, -10, 20, 20)); |
|
2099 |
||
2100 |
// We unfortunately need this hack as QPainterPathStroker will set a width of 1.0 |
|
2101 |
// if we pass a value of 0.0 to QPainterPathStroker::setWidth() |
|
2102 |
const qreal penWidthZero = qreal(0.00000001); |
|
2103 |
||
2104 |
QPainterPathStroker ps; |
|
2105 |
ps.setWidth(penWidthZero); |
|
2106 |
||
2107 |
QPainterPath path(line.line().p1()); |
|
2108 |
path.lineTo(line.line().p2()); |
|
2109 |
QPainterPath p = ps.createStroke(path); |
|
2110 |
p.addPath(path); |
|
2111 |
QCOMPARE(line.shape(), p); |
|
2112 |
||
2113 |
QPen linePen; |
|
2114 |
linePen.setWidthF(5.0); |
|
2115 |
linePen.setCapStyle(Qt::RoundCap); |
|
2116 |
line.setPen(linePen); |
|
2117 |
||
2118 |
ps.setCapStyle(line.pen().capStyle()); |
|
2119 |
ps.setWidth(line.pen().widthF()); |
|
2120 |
p = ps.createStroke(path); |
|
2121 |
p.addPath(path); |
|
2122 |
QCOMPARE(line.shape(), p); |
|
2123 |
||
2124 |
linePen.setCapStyle(Qt::FlatCap); |
|
2125 |
line.setPen(linePen); |
|
2126 |
ps.setCapStyle(line.pen().capStyle()); |
|
2127 |
p = ps.createStroke(path); |
|
2128 |
p.addPath(path); |
|
2129 |
QCOMPARE(line.shape(), p); |
|
2130 |
||
2131 |
linePen.setCapStyle(Qt::SquareCap); |
|
2132 |
line.setPen(linePen); |
|
2133 |
ps.setCapStyle(line.pen().capStyle()); |
|
2134 |
p = ps.createStroke(path); |
|
2135 |
p.addPath(path); |
|
2136 |
QCOMPARE(line.shape(), p); |
|
2137 |
||
2138 |
QGraphicsRectItem rect(QRectF(-10, -10, 20, 20)); |
|
2139 |
QPainterPathStroker ps1; |
|
2140 |
ps1.setWidth(penWidthZero); |
|
2141 |
path = QPainterPath(); |
|
2142 |
path.addRect(rect.rect()); |
|
2143 |
p = ps1.createStroke(path); |
|
2144 |
p.addPath(path); |
|
2145 |
QCOMPARE(rect.shape(), p); |
|
2146 |
||
2147 |
QGraphicsEllipseItem ellipse(QRectF(-10, -10, 20, 20)); |
|
2148 |
QPainterPathStroker ps2; |
|
2149 |
ps2.setWidth(ellipse.pen().widthF() <= 0.0 ? penWidthZero : ellipse.pen().widthF()); |
|
2150 |
path = QPainterPath(); |
|
2151 |
path.addEllipse(ellipse.rect()); |
|
2152 |
p = ps2.createStroke(path); |
|
2153 |
p.addPath(path); |
|
2154 |
QCOMPARE(ellipse.shape(), p); |
|
2155 |
||
2156 |
QPainterPathStroker ps3; |
|
2157 |
ps3.setWidth(penWidthZero); |
|
2158 |
p = ps3.createStroke(path); |
|
2159 |
p.addPath(path); |
|
2160 |
QGraphicsPathItem pathItem(path); |
|
2161 |
QCOMPARE(pathItem.shape(), p); |
|
2162 |
||
2163 |
QRegion region(QRect(0, 0, 300, 200)); |
|
2164 |
region = region.subtracted(QRect(50, 50, 200, 100)); |
|
2165 |
||
2166 |
QImage image(300, 200, QImage::Format_ARGB32_Premultiplied); |
|
2167 |
image.fill(0); |
|
2168 |
QPainter painter(&image); |
|
2169 |
painter.setClipRegion(region); |
|
2170 |
painter.fillRect(0, 0, 300, 200, Qt::green); |
|
2171 |
painter.end(); |
|
2172 |
QPixmap pixmap = QPixmap::fromImage(image); |
|
2173 |
||
2174 |
QGraphicsPixmapItem pixmapItem(pixmap); |
|
2175 |
path = QPainterPath(); |
|
2176 |
path.addRegion(region); |
|
2177 |
||
2178 |
{ |
|
2179 |
QBitmap bitmap(300, 200); |
|
2180 |
bitmap.clear(); |
|
2181 |
QPainter painter(&bitmap); |
|
2182 |
painter.setClipRegion(region); |
|
2183 |
painter.fillRect(0, 0, 300, 200, Qt::color1); |
|
2184 |
painter.end(); |
|
2185 |
||
2186 |
QBitmap bitmap2(300, 200); |
|
2187 |
bitmap2.clear(); |
|
2188 |
painter.begin(&bitmap2); |
|
2189 |
painter.setClipPath(pixmapItem.shape()); |
|
2190 |
painter.fillRect(0, 0, 300, 200, Qt::color1); |
|
2191 |
painter.end(); |
|
2192 |
||
2193 |
QCOMPARE(bitmap.toImage(), bitmap2.toImage()); |
|
2194 |
} |
|
2195 |
||
2196 |
QPolygonF poly; |
|
2197 |
poly << QPointF(0, 0) << QPointF(10, 0) << QPointF(0, 10); |
|
2198 |
QGraphicsPolygonItem polygon(poly); |
|
2199 |
path = QPainterPath(); |
|
2200 |
path.addPolygon(poly); |
|
2201 |
||
2202 |
QPainterPathStroker ps4; |
|
2203 |
ps4.setWidth(penWidthZero); |
|
2204 |
p = ps4.createStroke(path); |
|
2205 |
p.addPath(path); |
|
2206 |
QCOMPARE(polygon.shape(), p); |
|
2207 |
} |
|
2208 |
||
2209 |
void tst_QGraphicsItem::contains() |
|
2210 |
{ |
|
2211 |
if (sizeof(qreal) != sizeof(double)) { |
|
2212 |
QSKIP("Skipped due to rounding errors", SkipAll); |
|
2213 |
} |
|
2214 |
||
2215 |
// Rect |
|
2216 |
QGraphicsRectItem rect(QRectF(-10, -10, 20, 20)); |
|
2217 |
QVERIFY(!rect.contains(QPointF(-11, -10))); |
|
2218 |
QVERIFY(rect.contains(QPointF(-10, -10))); |
|
2219 |
QVERIFY(!rect.contains(QPointF(-11, 0))); |
|
2220 |
QVERIFY(rect.contains(QPointF(-10, 0))); |
|
2221 |
QVERIFY(rect.contains(QPointF(0, -10))); |
|
2222 |
QVERIFY(rect.contains(QPointF(0, 0))); |
|
2223 |
QVERIFY(rect.contains(QPointF(9, 9))); |
|
2224 |
||
2225 |
// Ellipse |
|
2226 |
QGraphicsEllipseItem ellipse(QRectF(-10, -10, 20, 20)); |
|
2227 |
QVERIFY(!ellipse.contains(QPointF(-10, -10))); |
|
2228 |
QVERIFY(ellipse.contains(QPointF(-9, 0))); |
|
2229 |
QVERIFY(ellipse.contains(QPointF(0, -9))); |
|
2230 |
QVERIFY(ellipse.contains(QPointF(0, 0))); |
|
2231 |
QVERIFY(!ellipse.contains(QPointF(9, 9))); |
|
2232 |
||
2233 |
// Line |
|
2234 |
QGraphicsLineItem line(QLineF(-10, -10, 20, 20)); |
|
2235 |
QVERIFY(!line.contains(QPointF(-10, 0))); |
|
2236 |
QVERIFY(!line.contains(QPointF(0, -10))); |
|
2237 |
QVERIFY(!line.contains(QPointF(10, 0))); |
|
2238 |
QVERIFY(!line.contains(QPointF(0, 10))); |
|
2239 |
QVERIFY(line.contains(QPointF(0, 0))); |
|
2240 |
QVERIFY(line.contains(QPointF(-9, -9))); |
|
2241 |
QVERIFY(line.contains(QPointF(9, 9))); |
|
2242 |
||
2243 |
// Polygon |
|
2244 |
QGraphicsPolygonItem polygon(QPolygonF() |
|
2245 |
<< QPointF(0, 0) |
|
2246 |
<< QPointF(10, 0) |
|
2247 |
<< QPointF(0, 10)); |
|
2248 |
QVERIFY(polygon.contains(QPointF(1, 1))); |
|
2249 |
QVERIFY(polygon.contains(QPointF(4, 4))); |
|
2250 |
QVERIFY(polygon.contains(QPointF(1, 4))); |
|
2251 |
QVERIFY(polygon.contains(QPointF(4, 1))); |
|
2252 |
QVERIFY(!polygon.contains(QPointF(8, 8))); |
|
2253 |
QVERIFY(polygon.contains(QPointF(1, 8))); |
|
2254 |
QVERIFY(polygon.contains(QPointF(8, 1))); |
|
2255 |
} |
|
2256 |
||
2257 |
void tst_QGraphicsItem::collidesWith_item() |
|
2258 |
{ |
|
2259 |
// Rectangle |
|
2260 |
QGraphicsRectItem rect(QRectF(-10, -10, 20, 20)); |
|
2261 |
QGraphicsRectItem rect2(QRectF(-10, -10, 20, 20)); |
|
2262 |
QVERIFY(rect.collidesWithItem(&rect2)); |
|
2263 |
QVERIFY(rect2.collidesWithItem(&rect)); |
|
2264 |
rect2.setPos(21, 21); |
|
2265 |
QVERIFY(!rect.collidesWithItem(&rect2)); |
|
2266 |
QVERIFY(!rect2.collidesWithItem(&rect)); |
|
2267 |
rect2.setPos(-21, -21); |
|
2268 |
QVERIFY(!rect.collidesWithItem(&rect2)); |
|
2269 |
QVERIFY(!rect2.collidesWithItem(&rect)); |
|
2270 |
rect2.setPos(-17, -17); |
|
2271 |
QVERIFY(rect.collidesWithItem(&rect2)); |
|
2272 |
QVERIFY(rect2.collidesWithItem(&rect)); |
|
2273 |
||
2274 |
QGraphicsEllipseItem ellipse(QRectF(-10, -10, 20, 20)); |
|
2275 |
QGraphicsEllipseItem ellipse2(QRectF(-10, -10, 20, 20)); |
|
2276 |
QVERIFY(ellipse.collidesWithItem(&ellipse2)); |
|
2277 |
QVERIFY(ellipse2.collidesWithItem(&ellipse)); |
|
2278 |
ellipse2.setPos(21, 21); |
|
2279 |
QVERIFY(!ellipse.collidesWithItem(&ellipse2)); |
|
2280 |
QVERIFY(!ellipse2.collidesWithItem(&ellipse)); |
|
2281 |
ellipse2.setPos(-21, -21); |
|
2282 |
QVERIFY(!ellipse.collidesWithItem(&ellipse2)); |
|
2283 |
QVERIFY(!ellipse2.collidesWithItem(&ellipse)); |
|
2284 |
||
2285 |
ellipse2.setPos(-17, -17); |
|
2286 |
QVERIFY(!ellipse.collidesWithItem(&ellipse2)); |
|
2287 |
QVERIFY(!ellipse2.collidesWithItem(&ellipse)); |
|
2288 |
||
2289 |
{ |
|
2290 |
QGraphicsScene scene; |
|
2291 |
QGraphicsRectItem rect(20, 20, 100, 100, 0, &scene); |
|
2292 |
QGraphicsRectItem rect2(40, 40, 50, 50, 0, &scene); |
|
2293 |
rect2.setZValue(1); |
|
2294 |
QGraphicsLineItem line(0, 0, 200, 200, 0, &scene); |
|
2295 |
line.setZValue(2); |
|
2296 |
||
2297 |
QCOMPARE(scene.items().size(), 3); |
|
2298 |
||
2299 |
QList<QGraphicsItem *> col1 = rect.collidingItems(); |
|
2300 |
QCOMPARE(col1.size(), 2); |
|
2301 |
QCOMPARE(col1.first(), static_cast<QGraphicsItem *>(&line)); |
|
2302 |
QCOMPARE(col1.last(), static_cast<QGraphicsItem *>(&rect2)); |
|
2303 |
||
2304 |
QList<QGraphicsItem *> col2 = rect2.collidingItems(); |
|
2305 |
QCOMPARE(col2.size(), 2); |
|
2306 |
QCOMPARE(col2.first(), static_cast<QGraphicsItem *>(&line)); |
|
2307 |
QCOMPARE(col2.last(), static_cast<QGraphicsItem *>(&rect)); |
|
2308 |
||
2309 |
QList<QGraphicsItem *> col3 = line.collidingItems(); |
|
2310 |
QCOMPARE(col3.size(), 2); |
|
2311 |
QCOMPARE(col3.first(), static_cast<QGraphicsItem *>(&rect2)); |
|
2312 |
QCOMPARE(col3.last(), static_cast<QGraphicsItem *>(&rect)); |
|
2313 |
} |
|
2314 |
} |
|
2315 |
||
2316 |
void tst_QGraphicsItem::collidesWith_path_data() |
|
2317 |
{ |
|
2318 |
QTest::addColumn<QPointF>("pos"); |
|
2319 |
QTest::addColumn<QMatrix>("matrix"); |
|
2320 |
QTest::addColumn<QPainterPath>("shape"); |
|
2321 |
QTest::addColumn<bool>("rectCollides"); |
|
2322 |
QTest::addColumn<bool>("ellipseCollides"); |
|
2323 |
||
2324 |
QTest::newRow("nothing") << QPointF(0, 0) << QMatrix() << QPainterPath() << false << false; |
|
2325 |
||
2326 |
QPainterPath rect; |
|
2327 |
rect.addRect(0, 0, 20, 20); |
|
2328 |
||
2329 |
QTest::newRow("rect1") << QPointF(0, 0) << QMatrix() << rect << true << true; |
|
2330 |
QTest::newRow("rect2") << QPointF(0, 0) << QMatrix().translate(21, 21) << rect << false << false; |
|
2331 |
QTest::newRow("rect3") << QPointF(21, 21) << QMatrix() << rect << false << false; |
|
2332 |
} |
|
2333 |
||
2334 |
void tst_QGraphicsItem::collidesWith_path() |
|
2335 |
{ |
|
2336 |
QFETCH(QPointF, pos); |
|
2337 |
QFETCH(QMatrix, matrix); |
|
2338 |
QFETCH(QPainterPath, shape); |
|
2339 |
QFETCH(bool, rectCollides); |
|
2340 |
QFETCH(bool, ellipseCollides); |
|
2341 |
||
2342 |
QGraphicsRectItem rect(QRectF(0, 0, 20, 20)); |
|
2343 |
QGraphicsEllipseItem ellipse(QRectF(0, 0, 20, 20)); |
|
2344 |
||
2345 |
rect.setPos(pos); |
|
2346 |
rect.setMatrix(matrix); |
|
2347 |
||
2348 |
ellipse.setPos(pos); |
|
2349 |
ellipse.setMatrix(matrix); |
|
2350 |
||
2351 |
QPainterPath mappedShape = rect.sceneMatrix().inverted().map(shape); |
|
2352 |
||
2353 |
if (rectCollides) |
|
2354 |
QVERIFY(rect.collidesWithPath(mappedShape)); |
|
2355 |
else |
|
2356 |
QVERIFY(!rect.collidesWithPath(mappedShape)); |
|
2357 |
||
2358 |
if (ellipseCollides) |
|
2359 |
QVERIFY(ellipse.collidesWithPath(mappedShape)); |
|
2360 |
else |
|
2361 |
QVERIFY(!ellipse.collidesWithPath(mappedShape)); |
|
2362 |
} |
|
2363 |
||
2364 |
void tst_QGraphicsItem::collidesWithItemWithClip() |
|
2365 |
{ |
|
2366 |
QGraphicsScene scene; |
|
2367 |
||
2368 |
QGraphicsEllipseItem *ellipse = scene.addEllipse(0, 0, 100, 100); |
|
2369 |
ellipse->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
2370 |
QGraphicsEllipseItem *ellipse2 = scene.addEllipse(0, 0, 10, 10); |
|
2371 |
ellipse2->setParentItem(ellipse); |
|
2372 |
QGraphicsEllipseItem *ellipse3 = scene.addEllipse(0, 0, 10, 10); |
|
2373 |
ellipse3->setParentItem(ellipse); |
|
2374 |
QGraphicsEllipseItem *ellipse5 = scene.addEllipse(50, 50, 10, 10); |
|
2375 |
ellipse5->setParentItem(ellipse); |
|
2376 |
QGraphicsEllipseItem *ellipse4 = scene.addEllipse(0, 0, 10, 10); |
|
2377 |
||
2378 |
QVERIFY(ellipse2->collidesWithItem(ellipse3)); |
|
2379 |
QVERIFY(ellipse3->collidesWithItem(ellipse2)); |
|
2380 |
QVERIFY(!ellipse2->collidesWithItem(ellipse)); |
|
2381 |
QVERIFY(!ellipse->collidesWithItem(ellipse2)); |
|
2382 |
QVERIFY(!ellipse4->collidesWithItem(ellipse)); |
|
2383 |
QVERIFY(!ellipse4->collidesWithItem(ellipse2)); |
|
2384 |
QVERIFY(!ellipse4->collidesWithItem(ellipse3)); |
|
2385 |
QVERIFY(!ellipse->collidesWithItem(ellipse4)); |
|
2386 |
QVERIFY(!ellipse2->collidesWithItem(ellipse4)); |
|
2387 |
QVERIFY(!ellipse3->collidesWithItem(ellipse4)); |
|
2388 |
QVERIFY(ellipse->collidesWithItem(ellipse5)); |
|
2389 |
QVERIFY(ellipse5->collidesWithItem(ellipse)); |
|
2390 |
} |
|
2391 |
||
2392 |
class MyItem : public QGraphicsEllipseItem |
|
2393 |
{ |
|
2394 |
public: |
|
2395 |
bool isObscuredBy(const QGraphicsItem *item) const |
|
2396 |
{ |
|
2397 |
const MyItem *myItem = qgraphicsitem_cast<const MyItem *>(item); |
|
2398 |
if (myItem) { |
|
2399 |
if (item->zValue() > zValue()) { |
|
2400 |
QRectF r = rect(); |
|
2401 |
QPointF topMid = (r.topRight()+r.topLeft())/2; |
|
2402 |
QPointF botMid = (r.bottomRight()+r.bottomLeft())/2; |
|
2403 |
QPointF leftMid = (r.topLeft()+r.bottomLeft())/2; |
|
2404 |
QPointF rightMid = (r.topRight()+r.bottomRight())/2; |
|
2405 |
||
2406 |
QPainterPath mappedShape = item->mapToItem(this, item->opaqueArea()); |
|
2407 |
||
2408 |
if (mappedShape.contains(topMid) && |
|
2409 |
mappedShape.contains(botMid) && |
|
2410 |
mappedShape.contains(leftMid) && |
|
2411 |
mappedShape.contains(rightMid)) |
|
2412 |
return true; |
|
2413 |
else |
|
2414 |
return false; |
|
2415 |
} |
|
2416 |
else return false; |
|
2417 |
} |
|
2418 |
else |
|
2419 |
return QGraphicsItem::isObscuredBy(item); |
|
2420 |
} |
|
2421 |
||
2422 |
QPainterPath opaqueArea() const |
|
2423 |
{ |
|
2424 |
return shape(); |
|
2425 |
} |
|
2426 |
||
2427 |
enum { |
|
2428 |
Type = UserType+1 |
|
2429 |
}; |
|
2430 |
int type() const { return Type; } |
|
2431 |
}; |
|
2432 |
||
2433 |
void tst_QGraphicsItem::isObscuredBy() |
|
2434 |
{ |
|
2435 |
QGraphicsScene scene; |
|
2436 |
||
2437 |
MyItem myitem1, myitem2; |
|
2438 |
||
2439 |
myitem1.setRect(QRectF(50, 50, 40, 200)); |
|
2440 |
myitem1.rotate(67); |
|
2441 |
||
2442 |
myitem2.setRect(QRectF(25, 25, 20, 20)); |
|
2443 |
myitem2.setZValue(-1.0); |
|
2444 |
scene.addItem(&myitem1); |
|
2445 |
scene.addItem(&myitem2); |
|
2446 |
||
2447 |
QVERIFY(!myitem2.isObscuredBy(&myitem1)); |
|
2448 |
QVERIFY(!myitem1.isObscuredBy(&myitem2)); |
|
2449 |
||
2450 |
myitem2.setRect(QRectF(-50, 85, 20, 20)); |
|
2451 |
QVERIFY(myitem2.isObscuredBy(&myitem1)); |
|
2452 |
QVERIFY(!myitem1.isObscuredBy(&myitem2)); |
|
2453 |
||
2454 |
myitem2.setRect(QRectF(-30, 70, 20, 20)); |
|
2455 |
QVERIFY(!myitem2.isObscuredBy(&myitem1)); |
|
2456 |
QVERIFY(!myitem1.isObscuredBy(&myitem2)); |
|
2457 |
||
2458 |
QGraphicsRectItem rect1, rect2; |
|
2459 |
||
2460 |
rect1.setRect(QRectF(-40, -40, 50, 50)); |
|
2461 |
rect1.setBrush(QBrush(Qt::red)); |
|
2462 |
rect2.setRect(QRectF(-30, -20, 20, 20)); |
|
2463 |
rect2.setZValue(-1.0); |
|
2464 |
rect2.setBrush(QBrush(Qt::blue)); |
|
2465 |
||
2466 |
QVERIFY(rect2.isObscuredBy(&rect1)); |
|
2467 |
QVERIFY(!rect1.isObscuredBy(&rect2)); |
|
2468 |
||
2469 |
rect2.setPos(QPointF(-20, -25)); |
|
2470 |
||
2471 |
QVERIFY(!rect2.isObscuredBy(&rect1)); |
|
2472 |
QVERIFY(!rect1.isObscuredBy(&rect2)); |
|
2473 |
||
2474 |
rect2.setPos(QPointF(-100, -100)); |
|
2475 |
||
2476 |
QVERIFY(!rect2.isObscuredBy(&rect1)); |
|
2477 |
QVERIFY(!rect1.isObscuredBy(&rect2)); |
|
2478 |
} |
|
2479 |
||
2480 |
class OpaqueItem : public QGraphicsRectItem |
|
2481 |
{ |
|
2482 |
protected: |
|
2483 |
QPainterPath opaqueArea() const |
|
2484 |
{ |
|
2485 |
return shape(); |
|
2486 |
} |
|
2487 |
}; |
|
2488 |
||
2489 |
void tst_QGraphicsItem::isObscured() |
|
2490 |
{ |
|
2491 |
if (sizeof(qreal) != sizeof(double)) { |
|
2492 |
QSKIP("Skipped due to rounding errors", SkipAll); |
|
2493 |
} |
|
2494 |
||
2495 |
OpaqueItem *item1 = new OpaqueItem; |
|
2496 |
item1->setRect(0, 0, 100, 100); |
|
2497 |
item1->setZValue(0); |
|
2498 |
||
2499 |
OpaqueItem *item2 = new OpaqueItem; |
|
2500 |
item2->setZValue(1); |
|
2501 |
item2->setRect(0, 0, 100, 100); |
|
2502 |
||
2503 |
QGraphicsScene scene; |
|
2504 |
scene.addItem(item1); |
|
2505 |
scene.addItem(item2); |
|
2506 |
||
2507 |
QVERIFY(item1->isObscured()); |
|
2508 |
QVERIFY(item1->isObscuredBy(item2)); |
|
2509 |
QVERIFY(item1->isObscured(QRectF(0, 0, 50, 50))); |
|
2510 |
QVERIFY(item1->isObscured(QRectF(50, 0, 50, 50))); |
|
2511 |
QVERIFY(item1->isObscured(QRectF(50, 50, 50, 50))); |
|
2512 |
QVERIFY(item1->isObscured(QRectF(0, 50, 50, 50))); |
|
2513 |
QVERIFY(item1->isObscured(0, 0, 50, 50)); |
|
2514 |
QVERIFY(item1->isObscured(50, 0, 50, 50)); |
|
2515 |
QVERIFY(item1->isObscured(50, 50, 50, 50)); |
|
2516 |
QVERIFY(item1->isObscured(0, 50, 50, 50)); |
|
2517 |
QVERIFY(!item2->isObscured()); |
|
2518 |
QVERIFY(!item2->isObscuredBy(item1)); |
|
2519 |
QVERIFY(!item2->isObscured(QRectF(0, 0, 50, 50))); |
|
2520 |
QVERIFY(!item2->isObscured(QRectF(50, 0, 50, 50))); |
|
2521 |
QVERIFY(!item2->isObscured(QRectF(50, 50, 50, 50))); |
|
2522 |
QVERIFY(!item2->isObscured(QRectF(0, 50, 50, 50))); |
|
2523 |
QVERIFY(!item2->isObscured(0, 0, 50, 50)); |
|
2524 |
QVERIFY(!item2->isObscured(50, 0, 50, 50)); |
|
2525 |
QVERIFY(!item2->isObscured(50, 50, 50, 50)); |
|
2526 |
QVERIFY(!item2->isObscured(0, 50, 50, 50)); |
|
2527 |
||
2528 |
item2->moveBy(50, 0); |
|
2529 |
||
2530 |
QVERIFY(!item1->isObscured()); |
|
2531 |
QVERIFY(!item1->isObscuredBy(item2)); |
|
2532 |
QVERIFY(!item1->isObscured(QRectF(0, 0, 50, 50))); |
|
2533 |
QVERIFY(item1->isObscured(QRectF(50, 0, 50, 50))); |
|
2534 |
QVERIFY(item1->isObscured(QRectF(50, 50, 50, 50))); |
|
2535 |
QVERIFY(!item1->isObscured(QRectF(0, 50, 50, 50))); |
|
2536 |
QVERIFY(!item1->isObscured(0, 0, 50, 50)); |
|
2537 |
QVERIFY(item1->isObscured(50, 0, 50, 50)); |
|
2538 |
QVERIFY(item1->isObscured(50, 50, 50, 50)); |
|
2539 |
QVERIFY(!item1->isObscured(0, 50, 50, 50)); |
|
2540 |
QVERIFY(!item2->isObscured()); |
|
2541 |
QVERIFY(!item2->isObscuredBy(item1)); |
|
2542 |
QVERIFY(!item2->isObscured(QRectF(0, 0, 50, 50))); |
|
2543 |
QVERIFY(!item2->isObscured(QRectF(50, 0, 50, 50))); |
|
2544 |
QVERIFY(!item2->isObscured(QRectF(50, 50, 50, 50))); |
|
2545 |
QVERIFY(!item2->isObscured(QRectF(0, 50, 50, 50))); |
|
2546 |
QVERIFY(!item2->isObscured(0, 0, 50, 50)); |
|
2547 |
QVERIFY(!item2->isObscured(50, 0, 50, 50)); |
|
2548 |
QVERIFY(!item2->isObscured(50, 50, 50, 50)); |
|
2549 |
QVERIFY(!item2->isObscured(0, 50, 50, 50)); |
|
2550 |
} |
|
2551 |
||
2552 |
void tst_QGraphicsItem::mapFromToParent() |
|
2553 |
{ |
|
2554 |
QPainterPath path1; |
|
2555 |
path1.addRect(0, 0, 200, 200); |
|
2556 |
||
2557 |
QPainterPath path2; |
|
2558 |
path2.addRect(0, 0, 100, 100); |
|
2559 |
||
2560 |
QPainterPath path3; |
|
2561 |
path3.addRect(0, 0, 50, 50); |
|
2562 |
||
2563 |
QPainterPath path4; |
|
2564 |
path4.addRect(0, 0, 25, 25); |
|
2565 |
||
2566 |
QGraphicsItem *item1 = new QGraphicsPathItem(path1); |
|
2567 |
QGraphicsItem *item2 = new QGraphicsPathItem(path2, item1); |
|
2568 |
QGraphicsItem *item3 = new QGraphicsPathItem(path3, item2); |
|
2569 |
QGraphicsItem *item4 = new QGraphicsPathItem(path4, item3); |
|
2570 |
||
2571 |
item1->setPos(10, 10); |
|
2572 |
item2->setPos(10, 10); |
|
2573 |
item3->setPos(10, 10); |
|
2574 |
item4->setPos(10, 10); |
|
2575 |
||
2576 |
for (int i = 0; i < 4; ++i) { |
|
2577 |
QMatrix matrix; |
|
2578 |
matrix.rotate(i * 90); |
|
2579 |
matrix.translate(i * 100, -i * 100); |
|
2580 |
matrix.scale(2, 4); |
|
2581 |
item1->setMatrix(matrix); |
|
2582 |
||
2583 |
QCOMPARE(item1->mapToParent(QPointF(0, 0)), item1->pos() + matrix.map(QPointF(0, 0))); |
|
2584 |
QCOMPARE(item2->mapToParent(QPointF(0, 0)), item2->pos()); |
|
2585 |
QCOMPARE(item3->mapToParent(QPointF(0, 0)), item3->pos()); |
|
2586 |
QCOMPARE(item4->mapToParent(QPointF(0, 0)), item4->pos()); |
|
2587 |
QCOMPARE(item1->mapToParent(QPointF(10, -10)), item1->pos() + matrix.map(QPointF(10, -10))); |
|
2588 |
QCOMPARE(item2->mapToParent(QPointF(10, -10)), item2->pos() + QPointF(10, -10)); |
|
2589 |
QCOMPARE(item3->mapToParent(QPointF(10, -10)), item3->pos() + QPointF(10, -10)); |
|
2590 |
QCOMPARE(item4->mapToParent(QPointF(10, -10)), item4->pos() + QPointF(10, -10)); |
|
2591 |
QCOMPARE(item1->mapToParent(QPointF(-10, 10)), item1->pos() + matrix.map(QPointF(-10, 10))); |
|
2592 |
QCOMPARE(item2->mapToParent(QPointF(-10, 10)), item2->pos() + QPointF(-10, 10)); |
|
2593 |
QCOMPARE(item3->mapToParent(QPointF(-10, 10)), item3->pos() + QPointF(-10, 10)); |
|
2594 |
QCOMPARE(item4->mapToParent(QPointF(-10, 10)), item4->pos() + QPointF(-10, 10)); |
|
2595 |
QCOMPARE(item1->mapFromParent(item1->pos()), matrix.inverted().map(QPointF(0, 0))); |
|
2596 |
QCOMPARE(item2->mapFromParent(item2->pos()), QPointF(0, 0)); |
|
2597 |
QCOMPARE(item3->mapFromParent(item3->pos()), QPointF(0, 0)); |
|
2598 |
QCOMPARE(item4->mapFromParent(item4->pos()), QPointF(0, 0)); |
|
2599 |
QCOMPARE(item1->mapFromParent(item1->pos() + QPointF(10, -10)), |
|
2600 |
matrix.inverted().map(QPointF(10, -10))); |
|
2601 |
QCOMPARE(item2->mapFromParent(item2->pos() + QPointF(10, -10)), QPointF(10, -10)); |
|
2602 |
QCOMPARE(item3->mapFromParent(item3->pos() + QPointF(10, -10)), QPointF(10, -10)); |
|
2603 |
QCOMPARE(item4->mapFromParent(item4->pos() + QPointF(10, -10)), QPointF(10, -10)); |
|
2604 |
QCOMPARE(item1->mapFromParent(item1->pos() + QPointF(-10, 10)), |
|
2605 |
matrix.inverted().map(QPointF(-10, 10))); |
|
2606 |
QCOMPARE(item2->mapFromParent(item2->pos() + QPointF(-10, 10)), QPointF(-10, 10)); |
|
2607 |
QCOMPARE(item3->mapFromParent(item3->pos() + QPointF(-10, 10)), QPointF(-10, 10)); |
|
2608 |
QCOMPARE(item4->mapFromParent(item4->pos() + QPointF(-10, 10)), QPointF(-10, 10)); |
|
2609 |
} |
|
2610 |
||
2611 |
delete item1; |
|
2612 |
} |
|
2613 |
||
2614 |
void tst_QGraphicsItem::mapFromToScene() |
|
2615 |
{ |
|
2616 |
QGraphicsItem *item1 = new QGraphicsPathItem(QPainterPath()); |
|
2617 |
QGraphicsItem *item2 = new QGraphicsPathItem(QPainterPath(), item1); |
|
2618 |
QGraphicsItem *item3 = new QGraphicsPathItem(QPainterPath(), item2); |
|
2619 |
QGraphicsItem *item4 = new QGraphicsPathItem(QPainterPath(), item3); |
|
2620 |
||
2621 |
item1->setPos(100, 100); |
|
2622 |
item2->setPos(100, 100); |
|
2623 |
item3->setPos(100, 100); |
|
2624 |
item4->setPos(100, 100); |
|
2625 |
QCOMPARE(item1->pos(), QPointF(100, 100)); |
|
2626 |
QCOMPARE(item2->pos(), QPointF(100, 100)); |
|
2627 |
QCOMPARE(item3->pos(), QPointF(100, 100)); |
|
2628 |
QCOMPARE(item4->pos(), QPointF(100, 100)); |
|
2629 |
QCOMPARE(item1->pos(), item1->mapToParent(0, 0)); |
|
2630 |
QCOMPARE(item2->pos(), item2->mapToParent(0, 0)); |
|
2631 |
QCOMPARE(item3->pos(), item3->mapToParent(0, 0)); |
|
2632 |
QCOMPARE(item4->pos(), item4->mapToParent(0, 0)); |
|
2633 |
QCOMPARE(item1->mapToParent(10, 10), QPointF(110, 110)); |
|
2634 |
QCOMPARE(item2->mapToParent(10, 10), QPointF(110, 110)); |
|
2635 |
QCOMPARE(item3->mapToParent(10, 10), QPointF(110, 110)); |
|
2636 |
QCOMPARE(item4->mapToParent(10, 10), QPointF(110, 110)); |
|
2637 |
QCOMPARE(item1->mapToScene(0, 0), QPointF(100, 100)); |
|
2638 |
QCOMPARE(item2->mapToScene(0, 0), QPointF(200, 200)); |
|
2639 |
QCOMPARE(item3->mapToScene(0, 0), QPointF(300, 300)); |
|
2640 |
QCOMPARE(item4->mapToScene(0, 0), QPointF(400, 400)); |
|
2641 |
QCOMPARE(item1->mapToScene(10, 0), QPointF(110, 100)); |
|
2642 |
QCOMPARE(item2->mapToScene(10, 0), QPointF(210, 200)); |
|
2643 |
QCOMPARE(item3->mapToScene(10, 0), QPointF(310, 300)); |
|
2644 |
QCOMPARE(item4->mapToScene(10, 0), QPointF(410, 400)); |
|
2645 |
QCOMPARE(item1->mapFromScene(100, 100), QPointF(0, 0)); |
|
2646 |
QCOMPARE(item2->mapFromScene(200, 200), QPointF(0, 0)); |
|
2647 |
QCOMPARE(item3->mapFromScene(300, 300), QPointF(0, 0)); |
|
2648 |
QCOMPARE(item4->mapFromScene(400, 400), QPointF(0, 0)); |
|
2649 |
QCOMPARE(item1->mapFromScene(110, 100), QPointF(10, 0)); |
|
2650 |
QCOMPARE(item2->mapFromScene(210, 200), QPointF(10, 0)); |
|
2651 |
QCOMPARE(item3->mapFromScene(310, 300), QPointF(10, 0)); |
|
2652 |
QCOMPARE(item4->mapFromScene(410, 400), QPointF(10, 0)); |
|
2653 |
||
2654 |
// Rotate item1 90 degrees clockwise |
|
2655 |
QMatrix matrix; matrix.rotate(90); |
|
2656 |
item1->setMatrix(matrix); |
|
2657 |
QCOMPARE(item1->pos(), item1->mapToParent(0, 0)); |
|
2658 |
QCOMPARE(item2->pos(), item2->mapToParent(0, 0)); |
|
2659 |
QCOMPARE(item3->pos(), item3->mapToParent(0, 0)); |
|
2660 |
QCOMPARE(item4->pos(), item4->mapToParent(0, 0)); |
|
2661 |
QCOMPARE(item1->mapToParent(10, 0), QPointF(100, 110)); |
|
2662 |
QCOMPARE(item2->mapToParent(10, 0), QPointF(110, 100)); |
|
2663 |
QCOMPARE(item3->mapToParent(10, 0), QPointF(110, 100)); |
|
2664 |
QCOMPARE(item4->mapToParent(10, 0), QPointF(110, 100)); |
|
2665 |
QCOMPARE(item1->mapToScene(0, 0), QPointF(100, 100)); |
|
2666 |
QCOMPARE(item2->mapToScene(0, 0), QPointF(0, 200)); |
|
2667 |
QCOMPARE(item3->mapToScene(0, 0), QPointF(-100, 300)); |
|
2668 |
QCOMPARE(item4->mapToScene(0, 0), QPointF(-200, 400)); |
|
2669 |
QCOMPARE(item1->mapToScene(10, 0), QPointF(100, 110)); |
|
2670 |
QCOMPARE(item2->mapToScene(10, 0), QPointF(0, 210)); |
|
2671 |
QCOMPARE(item3->mapToScene(10, 0), QPointF(-100, 310)); |
|
2672 |
QCOMPARE(item4->mapToScene(10, 0), QPointF(-200, 410)); |
|
2673 |
QCOMPARE(item1->mapFromScene(100, 100), QPointF(0, 0)); |
|
2674 |
QCOMPARE(item2->mapFromScene(0, 200), QPointF(0, 0)); |
|
2675 |
QCOMPARE(item3->mapFromScene(-100, 300), QPointF(0, 0)); |
|
2676 |
QCOMPARE(item4->mapFromScene(-200, 400), QPointF(0, 0)); |
|
2677 |
QCOMPARE(item1->mapFromScene(100, 110), QPointF(10, 0)); |
|
2678 |
QCOMPARE(item2->mapFromScene(0, 210), QPointF(10, 0)); |
|
2679 |
QCOMPARE(item3->mapFromScene(-100, 310), QPointF(10, 0)); |
|
2680 |
QCOMPARE(item4->mapFromScene(-200, 410), QPointF(10, 0)); |
|
2681 |
||
2682 |
// Rotate item2 90 degrees clockwise |
|
2683 |
item2->setMatrix(matrix); |
|
2684 |
QCOMPARE(item1->pos(), item1->mapToParent(0, 0)); |
|
2685 |
QCOMPARE(item2->pos(), item2->mapToParent(0, 0)); |
|
2686 |
QCOMPARE(item3->pos(), item3->mapToParent(0, 0)); |
|
2687 |
QCOMPARE(item4->pos(), item4->mapToParent(0, 0)); |
|
2688 |
QCOMPARE(item1->mapToParent(10, 0), QPointF(100, 110)); |
|
2689 |
QCOMPARE(item2->mapToParent(10, 0), QPointF(100, 110)); |
|
2690 |
QCOMPARE(item3->mapToParent(10, 0), QPointF(110, 100)); |
|
2691 |
QCOMPARE(item4->mapToParent(10, 0), QPointF(110, 100)); |
|
2692 |
QCOMPARE(item1->mapToScene(0, 0), QPointF(100, 100)); |
|
2693 |
QCOMPARE(item2->mapToScene(0, 0), QPointF(0, 200)); |
|
2694 |
QCOMPARE(item3->mapToScene(0, 0), QPointF(-100, 100)); |
|
2695 |
QCOMPARE(item4->mapToScene(0, 0), QPointF(-200, 0)); |
|
2696 |
QCOMPARE(item1->mapToScene(10, 0), QPointF(100, 110)); |
|
2697 |
QCOMPARE(item2->mapToScene(10, 0), QPointF(-10, 200)); |
|
2698 |
QCOMPARE(item3->mapToScene(10, 0), QPointF(-110, 100)); |
|
2699 |
QCOMPARE(item4->mapToScene(10, 0), QPointF(-210, 0)); |
|
2700 |
QCOMPARE(item1->mapFromScene(100, 100), QPointF(0, 0)); |
|
2701 |
QCOMPARE(item2->mapFromScene(0, 200), QPointF(0, 0)); |
|
2702 |
QCOMPARE(item3->mapFromScene(-100, 100), QPointF(0, 0)); |
|
2703 |
QCOMPARE(item4->mapFromScene(-200, 0), QPointF(0, 0)); |
|
2704 |
QCOMPARE(item1->mapFromScene(100, 110), QPointF(10, 0)); |
|
2705 |
QCOMPARE(item2->mapFromScene(-10, 200), QPointF(10, 0)); |
|
2706 |
QCOMPARE(item3->mapFromScene(-110, 100), QPointF(10, 0)); |
|
2707 |
QCOMPARE(item4->mapFromScene(-210, 0), QPointF(10, 0)); |
|
2708 |
||
2709 |
// Translate item3 50 points, then rotate 90 degrees counterclockwise |
|
2710 |
QMatrix matrix2; |
|
2711 |
matrix2.translate(50, 0); |
|
2712 |
matrix2.rotate(-90); |
|
2713 |
item3->setMatrix(matrix2); |
|
2714 |
QCOMPARE(item1->pos(), item1->mapToParent(0, 0)); |
|
2715 |
QCOMPARE(item2->pos(), item2->mapToParent(0, 0)); |
|
2716 |
QCOMPARE(item3->pos(), item3->mapToParent(0, 0) - QPointF(50, 0)); |
|
2717 |
QCOMPARE(item4->pos(), item4->mapToParent(0, 0)); |
|
2718 |
QCOMPARE(item1->mapToParent(10, 0), QPointF(100, 110)); |
|
2719 |
QCOMPARE(item2->mapToParent(10, 0), QPointF(100, 110)); |
|
2720 |
QCOMPARE(item3->mapToParent(10, 0), QPointF(150, 90)); |
|
2721 |
QCOMPARE(item4->mapToParent(10, 0), QPointF(110, 100)); |
|
2722 |
QCOMPARE(item1->mapToScene(0, 0), QPointF(100, 100)); |
|
2723 |
QCOMPARE(item2->mapToScene(0, 0), QPointF(0, 200)); |
|
2724 |
QCOMPARE(item3->mapToScene(0, 0), QPointF(-150, 100)); |
|
2725 |
QCOMPARE(item4->mapToScene(0, 0), QPointF(-250, 200)); |
|
2726 |
QCOMPARE(item1->mapToScene(10, 0), QPointF(100, 110)); |
|
2727 |
QCOMPARE(item2->mapToScene(10, 0), QPointF(-10, 200)); |
|
2728 |
QCOMPARE(item3->mapToScene(10, 0), QPointF(-150, 110)); |
|
2729 |
QCOMPARE(item4->mapToScene(10, 0), QPointF(-250, 210)); |
|
2730 |
QCOMPARE(item1->mapFromScene(100, 100), QPointF(0, 0)); |
|
2731 |
QCOMPARE(item2->mapFromScene(0, 200), QPointF(0, 0)); |
|
2732 |
QCOMPARE(item3->mapFromScene(-150, 100), QPointF(0, 0)); |
|
2733 |
QCOMPARE(item4->mapFromScene(-250, 200), QPointF(0, 0)); |
|
2734 |
QCOMPARE(item1->mapFromScene(100, 110), QPointF(10, 0)); |
|
2735 |
QCOMPARE(item2->mapFromScene(-10, 200), QPointF(10, 0)); |
|
2736 |
QCOMPARE(item3->mapFromScene(-150, 110), QPointF(10, 0)); |
|
2737 |
QCOMPARE(item4->mapFromScene(-250, 210), QPointF(10, 0)); |
|
2738 |
||
2739 |
delete item1; |
|
2740 |
} |
|
2741 |
||
2742 |
void tst_QGraphicsItem::mapFromToItem() |
|
2743 |
{ |
|
2744 |
QGraphicsItem *item1 = new QGraphicsPathItem; |
|
2745 |
QGraphicsItem *item2 = new QGraphicsPathItem; |
|
2746 |
QGraphicsItem *item3 = new QGraphicsPathItem; |
|
2747 |
QGraphicsItem *item4 = new QGraphicsPathItem; |
|
2748 |
||
2749 |
item1->setPos(-100, -100); |
|
2750 |
item2->setPos(100, -100); |
|
2751 |
item3->setPos(100, 100); |
|
2752 |
item4->setPos(-100, 100); |
|
2753 |
||
2754 |
QCOMPARE(item1->mapFromItem(item2, 0, 0), QPointF(200, 0)); |
|
2755 |
QCOMPARE(item2->mapFromItem(item3, 0, 0), QPointF(0, 200)); |
|
2756 |
QCOMPARE(item3->mapFromItem(item4, 0, 0), QPointF(-200, 0)); |
|
2757 |
QCOMPARE(item4->mapFromItem(item1, 0, 0), QPointF(0, -200)); |
|
2758 |
QCOMPARE(item1->mapFromItem(item4, 0, 0), QPointF(0, 200)); |
|
2759 |
QCOMPARE(item2->mapFromItem(item1, 0, 0), QPointF(-200, 0)); |
|
2760 |
QCOMPARE(item3->mapFromItem(item2, 0, 0), QPointF(0, -200)); |
|
2761 |
QCOMPARE(item4->mapFromItem(item3, 0, 0), QPointF(200, 0)); |
|
2762 |
||
2763 |
QMatrix matrix; |
|
2764 |
matrix.translate(100, 100); |
|
2765 |
item1->setMatrix(matrix); |
|
2766 |
||
2767 |
QCOMPARE(item1->mapFromItem(item2, 0, 0), QPointF(100, -100)); |
|
2768 |
QCOMPARE(item2->mapFromItem(item3, 0, 0), QPointF(0, 200)); |
|
2769 |
QCOMPARE(item3->mapFromItem(item4, 0, 0), QPointF(-200, 0)); |
|
2770 |
QCOMPARE(item4->mapFromItem(item1, 0, 0), QPointF(100, -100)); |
|
2771 |
QCOMPARE(item1->mapFromItem(item4, 0, 0), QPointF(-100, 100)); |
|
2772 |
QCOMPARE(item2->mapFromItem(item1, 0, 0), QPointF(-100, 100)); |
|
2773 |
QCOMPARE(item3->mapFromItem(item2, 0, 0), QPointF(0, -200)); |
|
2774 |
QCOMPARE(item4->mapFromItem(item3, 0, 0), QPointF(200, 0)); |
|
2775 |
||
2776 |
matrix.rotate(90); |
|
2777 |
item1->setMatrix(matrix); |
|
2778 |
item2->setMatrix(matrix); |
|
2779 |
item3->setMatrix(matrix); |
|
2780 |
item4->setMatrix(matrix); |
|
2781 |
||
2782 |
QCOMPARE(item1->mapFromItem(item2, 0, 0), QPointF(0, -200)); |
|
2783 |
QCOMPARE(item2->mapFromItem(item3, 0, 0), QPointF(200, 0)); |
|
2784 |
QCOMPARE(item3->mapFromItem(item4, 0, 0), QPointF(0, 200)); |
|
2785 |
QCOMPARE(item4->mapFromItem(item1, 0, 0), QPointF(-200, 0)); |
|
2786 |
QCOMPARE(item1->mapFromItem(item4, 0, 0), QPointF(200, 0)); |
|
2787 |
QCOMPARE(item2->mapFromItem(item1, 0, 0), QPointF(0, 200)); |
|
2788 |
QCOMPARE(item3->mapFromItem(item2, 0, 0), QPointF(-200, 0)); |
|
2789 |
QCOMPARE(item4->mapFromItem(item3, 0, 0), QPointF(0, -200)); |
|
2790 |
QCOMPARE(item1->mapFromItem(item2, 10, -5), QPointF(10, -205)); |
|
2791 |
QCOMPARE(item2->mapFromItem(item3, 10, -5), QPointF(210, -5)); |
|
2792 |
QCOMPARE(item3->mapFromItem(item4, 10, -5), QPointF(10, 195)); |
|
2793 |
QCOMPARE(item4->mapFromItem(item1, 10, -5), QPointF(-190, -5)); |
|
2794 |
QCOMPARE(item1->mapFromItem(item4, 10, -5), QPointF(210, -5)); |
|
2795 |
QCOMPARE(item2->mapFromItem(item1, 10, -5), QPointF(10, 195)); |
|
2796 |
QCOMPARE(item3->mapFromItem(item2, 10, -5), QPointF(-190, -5)); |
|
2797 |
QCOMPARE(item4->mapFromItem(item3, 10, -5), QPointF(10, -205)); |
|
2798 |
||
2799 |
QCOMPARE(item1->mapFromItem(0, 10, -5), item1->mapFromScene(10, -5)); |
|
2800 |
QCOMPARE(item2->mapFromItem(0, 10, -5), item2->mapFromScene(10, -5)); |
|
2801 |
QCOMPARE(item3->mapFromItem(0, 10, -5), item3->mapFromScene(10, -5)); |
|
2802 |
QCOMPARE(item4->mapFromItem(0, 10, -5), item4->mapFromScene(10, -5)); |
|
2803 |
QCOMPARE(item1->mapToItem(0, 10, -5), item1->mapToScene(10, -5)); |
|
2804 |
QCOMPARE(item2->mapToItem(0, 10, -5), item2->mapToScene(10, -5)); |
|
2805 |
QCOMPARE(item3->mapToItem(0, 10, -5), item3->mapToScene(10, -5)); |
|
2806 |
QCOMPARE(item4->mapToItem(0, 10, -5), item4->mapToScene(10, -5)); |
|
2807 |
||
2808 |
delete item1; |
|
2809 |
delete item2; |
|
2810 |
delete item3; |
|
2811 |
delete item4; |
|
2812 |
} |
|
2813 |
||
2814 |
void tst_QGraphicsItem::mapRectFromToParent_data() |
|
2815 |
{ |
|
2816 |
QTest::addColumn<bool>("parent"); |
|
2817 |
QTest::addColumn<QPointF>("parentPos"); |
|
2818 |
QTest::addColumn<QTransform>("parentTransform"); |
|
2819 |
QTest::addColumn<QPointF>("pos"); |
|
2820 |
QTest::addColumn<QTransform>("transform"); |
|
2821 |
QTest::addColumn<QRectF>("inputRect"); |
|
2822 |
QTest::addColumn<QRectF>("outputRect"); |
|
2823 |
||
2824 |
QTest::newRow("nil") << false << QPointF() << QTransform() << QPointF() << QTransform() << QRectF() << QRectF(); |
|
2825 |
QTest::newRow("simple") << false << QPointF() << QTransform() << QPointF() << QTransform() |
|
2826 |
<< QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); |
|
2827 |
QTest::newRow("simple w/parent") << true |
|
2828 |
<< QPointF() << QTransform() |
|
2829 |
<< QPointF() << QTransform() |
|
2830 |
<< QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); |
|
2831 |
QTest::newRow("simple w/parent parentPos") << true |
|
2832 |
<< QPointF(50, 50) << QTransform() |
|
2833 |
<< QPointF() << QTransform() |
|
2834 |
<< QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); |
|
2835 |
QTest::newRow("simple w/parent parentPos parentRotation") << true |
|
2836 |
<< QPointF(50, 50) << QTransform().rotate(45) |
|
2837 |
<< QPointF() << QTransform() |
|
2838 |
<< QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); |
|
2839 |
QTest::newRow("pos w/parent") << true |
|
2840 |
<< QPointF() << QTransform() |
|
2841 |
<< QPointF(50, 50) << QTransform() |
|
2842 |
<< QRectF(0, 0, 10, 10) << QRectF(50, 50, 10, 10); |
|
2843 |
QTest::newRow("rotation w/parent") << true |
|
2844 |
<< QPointF() << QTransform() |
|
2845 |
<< QPointF() << QTransform().rotate(90) |
|
2846 |
<< QRectF(0, 0, 10, 10) << QRectF(-10, 0, 10, 10); |
|
2847 |
QTest::newRow("pos rotation w/parent") << true |
|
2848 |
<< QPointF() << QTransform() |
|
2849 |
<< QPointF(50, 50) << QTransform().rotate(90) |
|
2850 |
<< QRectF(0, 0, 10, 10) << QRectF(40, 50, 10, 10); |
|
2851 |
QTest::newRow("pos rotation w/parent parentPos parentRotation") << true |
|
2852 |
<< QPointF(-170, -190) << QTransform().rotate(90) |
|
2853 |
<< QPointF(50, 50) << QTransform().rotate(90) |
|
2854 |
<< QRectF(0, 0, 10, 10) << QRectF(40, 50, 10, 10); |
|
2855 |
} |
|
2856 |
||
2857 |
void tst_QGraphicsItem::mapRectFromToParent() |
|
2858 |
{ |
|
2859 |
QFETCH(bool, parent); |
|
2860 |
QFETCH(QPointF, parentPos); |
|
2861 |
QFETCH(QTransform, parentTransform); |
|
2862 |
QFETCH(QPointF, pos); |
|
2863 |
QFETCH(QTransform, transform); |
|
2864 |
QFETCH(QRectF, inputRect); |
|
2865 |
QFETCH(QRectF, outputRect); |
|
2866 |
||
2867 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
2868 |
rect->setPos(pos); |
|
2869 |
rect->setTransform(transform); |
|
2870 |
||
2871 |
if (parent) { |
|
2872 |
QGraphicsRectItem *rectParent = new QGraphicsRectItem; |
|
2873 |
rect->setParentItem(rectParent); |
|
2874 |
rectParent->setPos(parentPos); |
|
2875 |
rectParent->setTransform(parentTransform); |
|
2876 |
} |
|
2877 |
||
2878 |
// Make sure we use non-destructive transform operations (e.g., 90 degree |
|
2879 |
// rotations). |
|
2880 |
QCOMPARE(rect->mapRectToParent(inputRect), outputRect); |
|
2881 |
QCOMPARE(rect->mapRectFromParent(outputRect), inputRect); |
|
2882 |
QCOMPARE(rect->itemTransform(rect->parentItem()).mapRect(inputRect), outputRect); |
|
2883 |
QCOMPARE(rect->mapToParent(inputRect).boundingRect(), outputRect); |
|
2884 |
QCOMPARE(rect->mapToParent(QPolygonF(inputRect)).boundingRect(), outputRect); |
|
2885 |
QCOMPARE(rect->mapFromParent(outputRect).boundingRect(), inputRect); |
|
2886 |
QCOMPARE(rect->mapFromParent(QPolygonF(outputRect)).boundingRect(), inputRect); |
|
2887 |
QPainterPath inputPath; |
|
2888 |
inputPath.addRect(inputRect); |
|
2889 |
QPainterPath outputPath; |
|
2890 |
outputPath.addRect(outputRect); |
|
2891 |
QCOMPARE(rect->mapToParent(inputPath).boundingRect(), outputPath.boundingRect()); |
|
2892 |
QCOMPARE(rect->mapFromParent(outputPath).boundingRect(), inputPath.boundingRect()); |
|
2893 |
} |
|
2894 |
||
2895 |
void tst_QGraphicsItem::isAncestorOf() |
|
2896 |
{ |
|
2897 |
QGraphicsItem *grandPa = new QGraphicsRectItem; |
|
2898 |
QGraphicsItem *parent = new QGraphicsRectItem; |
|
2899 |
QGraphicsItem *child = new QGraphicsRectItem; |
|
2900 |
||
2901 |
QVERIFY(!parent->isAncestorOf(0)); |
|
2902 |
QVERIFY(!child->isAncestorOf(0)); |
|
2903 |
QVERIFY(!parent->isAncestorOf(child)); |
|
2904 |
QVERIFY(!child->isAncestorOf(parent)); |
|
2905 |
QVERIFY(!parent->isAncestorOf(parent)); |
|
2906 |
||
2907 |
child->setParentItem(parent); |
|
2908 |
parent->setParentItem(grandPa); |
|
2909 |
||
2910 |
QVERIFY(parent->isAncestorOf(child)); |
|
2911 |
QVERIFY(grandPa->isAncestorOf(parent)); |
|
2912 |
QVERIFY(grandPa->isAncestorOf(child)); |
|
2913 |
QVERIFY(!child->isAncestorOf(parent)); |
|
2914 |
QVERIFY(!parent->isAncestorOf(grandPa)); |
|
2915 |
QVERIFY(!child->isAncestorOf(grandPa)); |
|
2916 |
QVERIFY(!child->isAncestorOf(child)); |
|
2917 |
QVERIFY(!parent->isAncestorOf(parent)); |
|
2918 |
QVERIFY(!grandPa->isAncestorOf(grandPa)); |
|
2919 |
||
2920 |
parent->setParentItem(0); |
|
2921 |
||
2922 |
delete child; |
|
2923 |
delete parent; |
|
2924 |
delete grandPa; |
|
2925 |
} |
|
2926 |
||
2927 |
void tst_QGraphicsItem::commonAncestorItem() |
|
2928 |
{ |
|
2929 |
QGraphicsItem *ancestor = new QGraphicsRectItem; |
|
2930 |
QGraphicsItem *grandMa = new QGraphicsRectItem; |
|
2931 |
QGraphicsItem *grandPa = new QGraphicsRectItem; |
|
2932 |
QGraphicsItem *brotherInLaw = new QGraphicsRectItem; |
|
2933 |
QGraphicsItem *cousin = new QGraphicsRectItem; |
|
2934 |
QGraphicsItem *husband = new QGraphicsRectItem; |
|
2935 |
QGraphicsItem *child = new QGraphicsRectItem; |
|
2936 |
QGraphicsItem *wife = new QGraphicsRectItem; |
|
2937 |
||
2938 |
child->setParentItem(husband); |
|
2939 |
husband->setParentItem(grandPa); |
|
2940 |
brotherInLaw->setParentItem(grandPa); |
|
2941 |
cousin->setParentItem(brotherInLaw); |
|
2942 |
wife->setParentItem(grandMa); |
|
2943 |
grandMa->setParentItem(ancestor); |
|
2944 |
grandPa->setParentItem(ancestor); |
|
2945 |
||
2946 |
QCOMPARE(grandMa->commonAncestorItem(grandMa), grandMa); |
|
2947 |
QCOMPARE(grandMa->commonAncestorItem(0), (QGraphicsItem *)0); |
|
2948 |
QCOMPARE(grandMa->commonAncestorItem(grandPa), ancestor); |
|
2949 |
QCOMPARE(grandPa->commonAncestorItem(grandMa), ancestor); |
|
2950 |
QCOMPARE(grandPa->commonAncestorItem(husband), grandPa); |
|
2951 |
QCOMPARE(grandPa->commonAncestorItem(wife), ancestor); |
|
2952 |
QCOMPARE(grandMa->commonAncestorItem(husband), ancestor); |
|
2953 |
QCOMPARE(grandMa->commonAncestorItem(wife), grandMa); |
|
2954 |
QCOMPARE(wife->commonAncestorItem(grandMa), grandMa); |
|
2955 |
QCOMPARE(child->commonAncestorItem(cousin), grandPa); |
|
2956 |
QCOMPARE(cousin->commonAncestorItem(child), grandPa); |
|
2957 |
QCOMPARE(wife->commonAncestorItem(child), ancestor); |
|
2958 |
QCOMPARE(child->commonAncestorItem(wife), ancestor); |
|
2959 |
} |
|
2960 |
||
2961 |
void tst_QGraphicsItem::data() |
|
2962 |
{ |
|
2963 |
QGraphicsTextItem text; |
|
2964 |
||
2965 |
QCOMPARE(text.data(0), QVariant()); |
|
2966 |
text.setData(0, "TextItem"); |
|
2967 |
QCOMPARE(text.data(0), QVariant(QString("TextItem"))); |
|
2968 |
text.setData(0, QVariant()); |
|
2969 |
QCOMPARE(text.data(0), QVariant()); |
|
2970 |
} |
|
2971 |
||
2972 |
void tst_QGraphicsItem::type() |
|
2973 |
{ |
|
2974 |
QCOMPARE(int(QGraphicsItem::Type), 1); |
|
2975 |
QCOMPARE(int(QGraphicsPathItem::Type), 2); |
|
2976 |
QCOMPARE(int(QGraphicsRectItem::Type), 3); |
|
2977 |
QCOMPARE(int(QGraphicsEllipseItem::Type), 4); |
|
2978 |
QCOMPARE(int(QGraphicsPolygonItem::Type), 5); |
|
2979 |
QCOMPARE(int(QGraphicsLineItem::Type), 6); |
|
2980 |
QCOMPARE(int(QGraphicsPixmapItem::Type), 7); |
|
2981 |
QCOMPARE(int(QGraphicsTextItem::Type), 8); |
|
2982 |
||
2983 |
QCOMPARE(QGraphicsPathItem().type(), 2); |
|
2984 |
QCOMPARE(QGraphicsRectItem().type(), 3); |
|
2985 |
QCOMPARE(QGraphicsEllipseItem().type(), 4); |
|
2986 |
QCOMPARE(QGraphicsPolygonItem().type(), 5); |
|
2987 |
QCOMPARE(QGraphicsLineItem().type(), 6); |
|
2988 |
QCOMPARE(QGraphicsPixmapItem().type(), 7); |
|
2989 |
QCOMPARE(QGraphicsTextItem().type(), 8); |
|
2990 |
} |
|
2991 |
||
2992 |
void tst_QGraphicsItem::graphicsitem_cast() |
|
2993 |
{ |
|
2994 |
QGraphicsPathItem pathItem; |
|
2995 |
const QGraphicsPathItem *pPathItem = &pathItem; |
|
2996 |
QGraphicsRectItem rectItem; |
|
2997 |
const QGraphicsRectItem *pRectItem = &rectItem; |
|
2998 |
QGraphicsEllipseItem ellipseItem; |
|
2999 |
const QGraphicsEllipseItem *pEllipseItem = &ellipseItem; |
|
3000 |
QGraphicsPolygonItem polygonItem; |
|
3001 |
const QGraphicsPolygonItem *pPolygonItem = &polygonItem; |
|
3002 |
QGraphicsLineItem lineItem; |
|
3003 |
const QGraphicsLineItem *pLineItem = &lineItem; |
|
3004 |
QGraphicsPixmapItem pixmapItem; |
|
3005 |
const QGraphicsPixmapItem *pPixmapItem = &pixmapItem; |
|
3006 |
QGraphicsTextItem textItem; |
|
3007 |
const QGraphicsTextItem *pTextItem = &textItem; |
|
3008 |
||
3009 |
QVERIFY(qgraphicsitem_cast<QGraphicsPathItem *>(&pathItem)); |
|
3010 |
//QVERIFY(qgraphicsitem_cast<QAbstractGraphicsPathItem *>(&pathItem)); |
|
3011 |
QVERIFY(qgraphicsitem_cast<QGraphicsItem *>(&pathItem)); |
|
3012 |
QVERIFY(qgraphicsitem_cast<const QGraphicsItem *>(pPathItem)); |
|
3013 |
QVERIFY(qgraphicsitem_cast<const QGraphicsPathItem *>(pPathItem)); |
|
3014 |
||
3015 |
QVERIFY(qgraphicsitem_cast<QGraphicsRectItem *>(&rectItem)); |
|
3016 |
QVERIFY(qgraphicsitem_cast<QGraphicsItem *>(&rectItem)); |
|
3017 |
QVERIFY(qgraphicsitem_cast<const QGraphicsItem *>(pRectItem)); |
|
3018 |
QVERIFY(qgraphicsitem_cast<const QGraphicsRectItem *>(pRectItem)); |
|
3019 |
||
3020 |
QVERIFY(qgraphicsitem_cast<QGraphicsEllipseItem *>(&ellipseItem)); |
|
3021 |
QVERIFY(qgraphicsitem_cast<QGraphicsItem *>(&ellipseItem)); |
|
3022 |
QVERIFY(qgraphicsitem_cast<const QGraphicsItem *>(pEllipseItem)); |
|
3023 |
QVERIFY(qgraphicsitem_cast<const QGraphicsEllipseItem *>(pEllipseItem)); |
|
3024 |
||
3025 |
QVERIFY(qgraphicsitem_cast<QGraphicsPolygonItem *>(&polygonItem)); |
|
3026 |
//QVERIFY(qgraphicsitem_cast<QAbstractGraphicsPathItem *>(&polygonItem)); |
|
3027 |
QVERIFY(qgraphicsitem_cast<QGraphicsItem *>(&polygonItem)); |
|
3028 |
QVERIFY(qgraphicsitem_cast<const QGraphicsItem *>(pPolygonItem)); |
|
3029 |
QVERIFY(qgraphicsitem_cast<const QGraphicsPolygonItem *>(pPolygonItem)); |
|
3030 |
||
3031 |
QVERIFY(qgraphicsitem_cast<QGraphicsLineItem *>(&lineItem)); |
|
3032 |
QVERIFY(qgraphicsitem_cast<QGraphicsItem *>(&lineItem)); |
|
3033 |
QVERIFY(qgraphicsitem_cast<const QGraphicsItem *>(pLineItem)); |
|
3034 |
QVERIFY(qgraphicsitem_cast<const QGraphicsLineItem *>(pLineItem)); |
|
3035 |
||
3036 |
QVERIFY(qgraphicsitem_cast<QGraphicsPixmapItem *>(&pixmapItem)); |
|
3037 |
QVERIFY(qgraphicsitem_cast<QGraphicsItem *>(&pixmapItem)); |
|
3038 |
QVERIFY(qgraphicsitem_cast<const QGraphicsItem *>(pPixmapItem)); |
|
3039 |
QVERIFY(qgraphicsitem_cast<const QGraphicsPixmapItem *>(pPixmapItem)); |
|
3040 |
||
3041 |
QVERIFY(qgraphicsitem_cast<QGraphicsTextItem *>(&textItem)); |
|
3042 |
QVERIFY(qgraphicsitem_cast<QGraphicsItem *>(&textItem)); |
|
3043 |
QVERIFY(qgraphicsitem_cast<const QGraphicsItem *>(pTextItem)); |
|
3044 |
QVERIFY(qgraphicsitem_cast<const QGraphicsTextItem *>(pTextItem)); |
|
3045 |
||
3046 |
// and some casts that _should_ fail: |
|
3047 |
QVERIFY(!qgraphicsitem_cast<QGraphicsEllipseItem *>(&pathItem)); |
|
3048 |
QVERIFY(!qgraphicsitem_cast<const QGraphicsTextItem *>(pPolygonItem)); |
|
3049 |
||
3050 |
// and this shouldn't crash |
|
3051 |
QGraphicsItem *ptr = 0; |
|
3052 |
QVERIFY(!qgraphicsitem_cast<QGraphicsTextItem *>(ptr)); |
|
3053 |
QVERIFY(!qgraphicsitem_cast<QGraphicsItem *>(ptr)); |
|
3054 |
} |
|
3055 |
||
3056 |
void tst_QGraphicsItem::hoverEventsGenerateRepaints() |
|
3057 |
{ |
|
3058 |
Q_CHECK_PAINTEVENTS |
|
3059 |
||
3060 |
QGraphicsScene scene; |
|
3061 |
QGraphicsView view(&scene); |
|
3062 |
view.show(); |
|
3063 |
QTest::qWaitForWindowShown(&view); |
|
3064 |
QTest::qWait(150); |
|
3065 |
||
3066 |
EventTester *tester = new EventTester; |
|
3067 |
scene.addItem(tester); |
|
3068 |
tester->setAcceptsHoverEvents(true); |
|
3069 |
||
3070 |
QTRY_COMPARE(tester->repaints, 1); |
|
3071 |
||
3072 |
// Send a hover enter event |
|
3073 |
QGraphicsSceneHoverEvent hoverEnterEvent(QEvent::GraphicsSceneHoverEnter); |
|
3074 |
hoverEnterEvent.setScenePos(QPointF(0, 0)); |
|
3075 |
hoverEnterEvent.setPos(QPointF(0, 0)); |
|
3076 |
QApplication::sendEvent(&scene, &hoverEnterEvent); |
|
3077 |
||
3078 |
// Check that we get a repaint |
|
3079 |
int npaints = tester->repaints; |
|
3080 |
qApp->processEvents(); |
|
3081 |
qApp->processEvents(); |
|
3082 |
QCOMPARE(tester->events.size(), 2); // enter + move |
|
3083 |
QCOMPARE(tester->repaints, npaints + 1); |
|
3084 |
QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove); |
|
3085 |
||
3086 |
// Send a hover move event |
|
3087 |
QGraphicsSceneHoverEvent hoverMoveEvent(QEvent::GraphicsSceneHoverMove); |
|
3088 |
hoverMoveEvent.setScenePos(QPointF(0, 0)); |
|
3089 |
hoverMoveEvent.setPos(QPointF(0, 0)); |
|
3090 |
QApplication::sendEvent(&scene, &hoverMoveEvent); |
|
3091 |
||
3092 |
// Check that we don't get a repaint |
|
3093 |
qApp->processEvents(); |
|
3094 |
qApp->processEvents(); |
|
3095 |
||
3096 |
QCOMPARE(tester->events.size(), 3); |
|
3097 |
QCOMPARE(tester->repaints, npaints + 1); |
|
3098 |
QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove); |
|
3099 |
||
3100 |
// Send a hover leave event |
|
3101 |
QGraphicsSceneHoverEvent hoverLeaveEvent(QEvent::GraphicsSceneHoverLeave); |
|
3102 |
hoverLeaveEvent.setScenePos(QPointF(-100, -100)); |
|
3103 |
hoverLeaveEvent.setPos(QPointF(0, 0)); |
|
3104 |
QApplication::sendEvent(&scene, &hoverLeaveEvent); |
|
3105 |
||
3106 |
// Check that we get a repaint |
|
3107 |
qApp->processEvents(); |
|
3108 |
qApp->processEvents(); |
|
3109 |
||
3110 |
QCOMPARE(tester->events.size(), 4); |
|
3111 |
QCOMPARE(tester->repaints, npaints + 2); |
|
3112 |
QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverLeave); |
|
3113 |
} |
|
3114 |
||
3115 |
void tst_QGraphicsItem::boundingRects_data() |
|
3116 |
{ |
|
3117 |
QTest::addColumn<QGraphicsItem *>("item"); |
|
3118 |
QTest::addColumn<QRectF>("boundingRect"); |
|
3119 |
||
3120 |
QRectF rect(0, 0, 100, 100); |
|
3121 |
QPainterPath path; |
|
3122 |
path.addRect(rect); |
|
3123 |
||
3124 |
QRectF adjustedRect(-0.5, -0.5, 101, 101); |
|
3125 |
||
3126 |
QTest::newRow("path") << (QGraphicsItem *)new QGraphicsPathItem(path) << adjustedRect; |
|
3127 |
QTest::newRow("rect") << (QGraphicsItem *)new QGraphicsRectItem(rect) << adjustedRect; |
|
3128 |
QTest::newRow("ellipse") << (QGraphicsItem *)new QGraphicsEllipseItem(rect) << adjustedRect; |
|
3129 |
QTest::newRow("polygon") << (QGraphicsItem *)new QGraphicsPolygonItem(rect) << adjustedRect; |
|
3130 |
} |
|
3131 |
||
3132 |
void tst_QGraphicsItem::boundingRects() |
|
3133 |
{ |
|
3134 |
QFETCH(QGraphicsItem *, item); |
|
3135 |
QFETCH(QRectF, boundingRect); |
|
3136 |
||
3137 |
((QAbstractGraphicsShapeItem *)item)->setPen(QPen(Qt::black, 1)); |
|
3138 |
QCOMPARE(item->boundingRect(), boundingRect); |
|
3139 |
} |
|
3140 |
||
3141 |
void tst_QGraphicsItem::boundingRects2() |
|
3142 |
{ |
|
3143 |
QGraphicsPixmapItem pixmap(QPixmap::fromImage(QImage(100, 100, QImage::Format_ARGB32_Premultiplied))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3144 |
QCOMPARE(pixmap.boundingRect(), QRectF(0, 0, 100, 100)); |
0 | 3145 |
|
3146 |
QGraphicsLineItem line(0, 0, 100, 0); |
|
3147 |
line.setPen(QPen(Qt::black, 1)); |
|
3148 |
QCOMPARE(line.boundingRect(), QRectF(-0.5, -0.5, 101, 1)); |
|
3149 |
} |
|
3150 |
||
3151 |
void tst_QGraphicsItem::sceneBoundingRect() |
|
3152 |
{ |
|
3153 |
QGraphicsScene scene; |
|
3154 |
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100), QPen(Qt::black, 0)); |
|
3155 |
item->setPos(100, 100); |
|
3156 |
||
3157 |
QCOMPARE(item->boundingRect(), QRectF(0, 0, 100, 100)); |
|
3158 |
QCOMPARE(item->sceneBoundingRect(), QRectF(100, 100, 100, 100)); |
|
3159 |
||
3160 |
item->rotate(90); |
|
3161 |
||
3162 |
QCOMPARE(item->boundingRect(), QRectF(0, 0, 100, 100)); |
|
3163 |
QCOMPARE(item->sceneBoundingRect(), QRectF(0, 100, 100, 100)); |
|
3164 |
} |
|
3165 |
||
3166 |
void tst_QGraphicsItem::childrenBoundingRect() |
|
3167 |
{ |
|
3168 |
QGraphicsScene scene; |
|
3169 |
QGraphicsRectItem *parent = scene.addRect(QRectF(0, 0, 100, 100), QPen(Qt::black, 0)); |
|
3170 |
QGraphicsRectItem *child = scene.addRect(QRectF(0, 0, 100, 100), QPen(Qt::black, 0)); |
|
3171 |
child->setParentItem(parent); |
|
3172 |
parent->setPos(100, 100); |
|
3173 |
child->setPos(100, 100); |
|
3174 |
||
3175 |
QCOMPARE(parent->boundingRect(), QRectF(0, 0, 100, 100)); |
|
3176 |
QCOMPARE(child->boundingRect(), QRectF(0, 0, 100, 100)); |
|
3177 |
QCOMPARE(child->childrenBoundingRect(), QRectF()); |
|
3178 |
QCOMPARE(parent->childrenBoundingRect(), QRectF(100, 100, 100, 100)); |
|
3179 |
||
3180 |
QGraphicsRectItem *child2 = scene.addRect(QRectF(0, 0, 100, 100), QPen(Qt::black, 0)); |
|
3181 |
child2->setParentItem(parent); |
|
3182 |
child2->setPos(-100, -100); |
|
3183 |
QCOMPARE(parent->childrenBoundingRect(), QRectF(-100, -100, 300, 300)); |
|
3184 |
||
3185 |
QGraphicsRectItem *childChild = scene.addRect(QRectF(0, 0, 100, 100), QPen(Qt::black, 0)); |
|
3186 |
childChild->setParentItem(child); |
|
3187 |
childChild->setPos(500, 500); |
|
3188 |
child->rotate(90); |
|
3189 |
||
3190 |
scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));; |
|
3191 |
||
3192 |
QGraphicsView view(&scene); |
|
3193 |
view.show(); |
|
3194 |
||
3195 |
QTest::qWaitForWindowShown(&view); |
|
3196 |
QTest::qWait(30); |
|
3197 |
||
3198 |
QCOMPARE(parent->childrenBoundingRect(), QRectF(-500, -100, 600, 800)); |
|
3199 |
} |
|
3200 |
||
3201 |
void tst_QGraphicsItem::childrenBoundingRectTransformed() |
|
3202 |
{ |
|
3203 |
QGraphicsScene scene; |
|
3204 |
||
3205 |
QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3206 |
QGraphicsRectItem *rect2 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3207 |
QGraphicsRectItem *rect3 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3208 |
QGraphicsRectItem *rect4 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3209 |
QGraphicsRectItem *rect5 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3210 |
rect2->setParentItem(rect); |
|
3211 |
rect3->setParentItem(rect2); |
|
3212 |
rect4->setParentItem(rect3); |
|
3213 |
rect5->setParentItem(rect4); |
|
3214 |
||
3215 |
rect2->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3216 |
rect2->setPos(25, 25); |
|
3217 |
rect3->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3218 |
rect3->setPos(25, 25); |
|
3219 |
rect4->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3220 |
rect4->setPos(25, 25); |
|
3221 |
rect5->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3222 |
rect5->setPos(25, 25); |
|
3223 |
||
3224 |
QRectF subTreeRect = rect->childrenBoundingRect(); |
|
3225 |
QCOMPARE(subTreeRect.left(), qreal(-206.0660171779821)); |
|
3226 |
QCOMPARE(subTreeRect.top(), qreal(75.0)); |
|
3227 |
QCOMPARE(subTreeRect.width(), qreal(351.7766952966369)); |
|
3228 |
QCOMPARE(subTreeRect.height(), qreal(251.7766952966369)); |
|
3229 |
||
3230 |
rect->rotate(45); |
|
3231 |
rect2->rotate(-45); |
|
3232 |
rect3->rotate(45); |
|
3233 |
rect4->rotate(-45); |
|
3234 |
rect5->rotate(45); |
|
3235 |
||
3236 |
subTreeRect = rect->childrenBoundingRect(); |
|
3237 |
QCOMPARE(rect->childrenBoundingRect(), QRectF(-100, 75, 275, 250)); |
|
3238 |
} |
|
3239 |
||
3240 |
void tst_QGraphicsItem::childrenBoundingRect2() |
|
3241 |
{ |
|
3242 |
QGraphicsItemGroup box; |
|
3243 |
QGraphicsLineItem l1(0, 0, 100, 0, &box); |
|
3244 |
QGraphicsLineItem l2(100, 0, 100, 100, &box); |
|
3245 |
QGraphicsLineItem l3(0, 0, 0, 100, &box); |
|
3246 |
// Make sure lines (zero with/height) are included in the childrenBoundingRect. |
|
3247 |
QCOMPARE(box.childrenBoundingRect(), QRectF(0, 0, 100, 100)); |
|
3248 |
} |
|
3249 |
||
3250 |
void tst_QGraphicsItem::childrenBoundingRect3() |
|
3251 |
{ |
|
3252 |
QGraphicsScene scene; |
|
3253 |
||
3254 |
QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3255 |
QGraphicsRectItem *rect2 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3256 |
QGraphicsRectItem *rect3 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3257 |
QGraphicsRectItem *rect4 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3258 |
QGraphicsRectItem *rect5 = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3259 |
rect2->setParentItem(rect); |
|
3260 |
rect3->setParentItem(rect2); |
|
3261 |
rect4->setParentItem(rect3); |
|
3262 |
rect5->setParentItem(rect4); |
|
3263 |
||
3264 |
rect2->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3265 |
rect2->setPos(25, 25); |
|
3266 |
rect3->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3267 |
rect3->setPos(25, 25); |
|
3268 |
rect4->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3269 |
rect4->setPos(25, 25); |
|
3270 |
rect5->setTransform(QTransform().translate(50, 50).rotate(45)); |
|
3271 |
rect5->setPos(25, 25); |
|
3272 |
||
3273 |
// Try to mess up the cached bounding rect. |
|
3274 |
(void)rect2->childrenBoundingRect(); |
|
3275 |
||
3276 |
QRectF subTreeRect = rect->childrenBoundingRect(); |
|
3277 |
QCOMPARE(subTreeRect.left(), qreal(-206.0660171779821)); |
|
3278 |
QCOMPARE(subTreeRect.top(), qreal(75.0)); |
|
3279 |
QCOMPARE(subTreeRect.width(), qreal(351.7766952966369)); |
|
3280 |
QCOMPARE(subTreeRect.height(), qreal(251.7766952966369)); |
|
3281 |
} |
|
3282 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3283 |
void tst_QGraphicsItem::childrenBoundingRect4() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3284 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3285 |
QGraphicsScene scene; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3286 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3287 |
QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 10, 10)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3288 |
QGraphicsRectItem *rect2 = scene.addRect(QRectF(0, 0, 20, 20)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3289 |
QGraphicsRectItem *rect3 = scene.addRect(QRectF(0, 0, 30, 30)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3290 |
rect2->setParentItem(rect); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3291 |
rect3->setParentItem(rect); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3292 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3293 |
QGraphicsView view(&scene); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3294 |
view.show(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3295 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3296 |
QTest::qWaitForWindowShown(&view); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3297 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3298 |
// Try to mess up the cached bounding rect. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3299 |
rect->childrenBoundingRect(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3300 |
rect2->childrenBoundingRect(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3301 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3302 |
rect3->setOpacity(0.0); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3303 |
rect3->setParentItem(rect2); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3304 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3305 |
QCOMPARE(rect->childrenBoundingRect(), rect3->boundingRect()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3306 |
QCOMPARE(rect2->childrenBoundingRect(), rect3->boundingRect()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3307 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3308 |
|
0 | 3309 |
void tst_QGraphicsItem::group() |
3310 |
{ |
|
3311 |
QGraphicsScene scene; |
|
3312 |
QGraphicsRectItem *parent = scene.addRect(QRectF(0, 0, 50, 50), QPen(Qt::black, 0), QBrush(Qt::green)); |
|
3313 |
QGraphicsRectItem *child = scene.addRect(QRectF(0, 0, 50, 50), QPen(Qt::black, 0), QBrush(Qt::blue)); |
|
3314 |
QGraphicsRectItem *parent2 = scene.addRect(QRectF(0, 0, 50, 50), QPen(Qt::black, 0), QBrush(Qt::red)); |
|
3315 |
parent2->setPos(-50, 50); |
|
3316 |
child->rotate(45); |
|
3317 |
child->setParentItem(parent); |
|
3318 |
parent->setPos(25, 25); |
|
3319 |
child->setPos(25, 25); |
|
3320 |
||
3321 |
QCOMPARE(parent->group(), (QGraphicsItemGroup *)0); |
|
3322 |
QCOMPARE(parent2->group(), (QGraphicsItemGroup *)0); |
|
3323 |
QCOMPARE(child->group(), (QGraphicsItemGroup *)0); |
|
3324 |
||
3325 |
QGraphicsView view(&scene); |
|
3326 |
view.show(); |
|
3327 |
QTest::qWaitForWindowShown(&view); |
|
3328 |
QApplication::processEvents(); |
|
3329 |
||
3330 |
QGraphicsItemGroup *group = new QGraphicsItemGroup; |
|
3331 |
group->setSelected(true); |
|
3332 |
scene.addItem(group); |
|
3333 |
||
3334 |
QRectF parentSceneBoundingRect = parent->sceneBoundingRect(); |
|
3335 |
group->addToGroup(parent); |
|
3336 |
QCOMPARE(parent->group(), group); |
|
3337 |
QCOMPARE(parent->sceneBoundingRect(), parentSceneBoundingRect); |
|
3338 |
||
3339 |
QCOMPARE(parent->parentItem(), (QGraphicsItem *)group); |
|
3340 |
QCOMPARE(group->children().size(), 1); |
|
3341 |
QCOMPARE(scene.items().size(), 4); |
|
3342 |
QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 3); |
|
3343 |
||
3344 |
QTest::qWait(25); |
|
3345 |
||
3346 |
QRectF parent2SceneBoundingRect = parent2->sceneBoundingRect(); |
|
3347 |
group->addToGroup(parent2); |
|
3348 |
QCOMPARE(parent2->group(), group); |
|
3349 |
QCOMPARE(parent2->sceneBoundingRect(), parent2SceneBoundingRect); |
|
3350 |
||
3351 |
QCOMPARE(parent2->parentItem(), (QGraphicsItem *)group); |
|
3352 |
QCOMPARE(group->children().size(), 2); |
|
3353 |
QCOMPARE(scene.items().size(), 4); |
|
3354 |
QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 4); |
|
3355 |
||
3356 |
QTest::qWait(25); |
|
3357 |
||
3358 |
QList<QGraphicsItem *> newItems; |
|
3359 |
for (int i = 0; i < 100; ++i) { |
|
3360 |
QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0), |
|
3361 |
QBrush(QColor(rand() % 255, rand() % 255, |
|
3362 |
rand() % 255, rand() % 255))); |
|
3363 |
newItems << item; |
|
3364 |
item->setPos(-1000 + rand() % 2000, |
|
3365 |
-1000 + rand() % 2000); |
|
3366 |
item->rotate(rand() % 90); |
|
3367 |
} |
|
3368 |
||
3369 |
view.fitInView(scene.itemsBoundingRect()); |
|
3370 |
||
3371 |
int n = 0; |
|
3372 |
foreach (QGraphicsItem *item, newItems) { |
|
3373 |
group->addToGroup(item); |
|
3374 |
QCOMPARE(item->group(), group); |
|
3375 |
if ((n++ % 100) == 0) |
|
3376 |
QTest::qWait(10); |
|
3377 |
} |
|
3378 |
} |
|
3379 |
||
3380 |
void tst_QGraphicsItem::setGroup() |
|
3381 |
{ |
|
3382 |
QGraphicsItemGroup group1; |
|
3383 |
QGraphicsItemGroup group2; |
|
3384 |
||
3385 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
3386 |
QCOMPARE(rect->group(), (QGraphicsItemGroup *)0); |
|
3387 |
QCOMPARE(rect->parentItem(), (QGraphicsItem *)0); |
|
3388 |
rect->setGroup(&group1); |
|
3389 |
QCOMPARE(rect->group(), &group1); |
|
3390 |
QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group1); |
|
3391 |
rect->setGroup(&group2); |
|
3392 |
QCOMPARE(rect->group(), &group2); |
|
3393 |
QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group2); |
|
3394 |
rect->setGroup(0); |
|
3395 |
QCOMPARE(rect->group(), (QGraphicsItemGroup *)0); |
|
3396 |
QCOMPARE(rect->parentItem(), (QGraphicsItem *)0); |
|
3397 |
} |
|
3398 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3399 |
void tst_QGraphicsItem::setGroup2() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3400 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3401 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3402 |
QGraphicsItemGroup group; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3403 |
scene.addItem(&group); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3404 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3405 |
QGraphicsRectItem *rect = scene.addRect(50,50,50,50,Qt::NoPen,Qt::black); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3406 |
rect->setTransformOriginPoint(50,50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3407 |
rect->setRotation(45); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3408 |
rect->setScale(1.5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3409 |
rect->translate(20,20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3410 |
group.translate(-30,-40); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3411 |
group.setRotation(180); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3412 |
group.setScale(0.5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3413 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3414 |
QTransform oldSceneTransform = rect->sceneTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3415 |
rect->setGroup(&group); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3416 |
QCOMPARE(rect->sceneTransform(), oldSceneTransform); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3417 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3418 |
group.setRotation(20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3419 |
group.setScale(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3420 |
rect->setRotation(90); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3421 |
rect->setScale(0.8); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3422 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3423 |
oldSceneTransform = rect->sceneTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3424 |
rect->setGroup(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3425 |
QCOMPARE(rect->sceneTransform(), oldSceneTransform); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3426 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3427 |
|
0 | 3428 |
void tst_QGraphicsItem::nestedGroups() |
3429 |
{ |
|
3430 |
QGraphicsItemGroup *group1 = new QGraphicsItemGroup; |
|
3431 |
QGraphicsItemGroup *group2 = new QGraphicsItemGroup; |
|
3432 |
||
3433 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
3434 |
QGraphicsRectItem *rect2 = new QGraphicsRectItem; |
|
3435 |
rect2->setParentItem(rect); |
|
3436 |
||
3437 |
group1->addToGroup(rect); |
|
3438 |
QCOMPARE(rect->group(), group1); |
|
3439 |
QCOMPARE(rect2->group(), group1); |
|
3440 |
||
3441 |
group2->addToGroup(group1); |
|
3442 |
QCOMPARE(rect->group(), group1); |
|
3443 |
QCOMPARE(rect2->group(), group1); |
|
3444 |
QCOMPARE(group1->group(), group2); |
|
3445 |
QCOMPARE(group2->group(), (QGraphicsItemGroup *)0); |
|
3446 |
||
3447 |
QGraphicsScene scene; |
|
3448 |
scene.addItem(group1); |
|
3449 |
||
3450 |
QCOMPARE(rect->group(), group1); |
|
3451 |
QCOMPARE(rect2->group(), group1); |
|
3452 |
QCOMPARE(group1->group(), (QGraphicsItemGroup *)0); |
|
3453 |
QVERIFY(group2->children().isEmpty()); |
|
3454 |
||
3455 |
delete group2; |
|
3456 |
} |
|
3457 |
||
3458 |
void tst_QGraphicsItem::warpChildrenIntoGroup() |
|
3459 |
{ |
|
3460 |
QGraphicsScene scene; |
|
3461 |
QGraphicsRectItem *parentRectItem = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3462 |
QGraphicsRectItem *childRectItem = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3463 |
parentRectItem->rotate(90); |
|
3464 |
childRectItem->setPos(-50, -25); |
|
3465 |
childRectItem->setParentItem(parentRectItem); |
|
3466 |
||
3467 |
QCOMPARE(childRectItem->mapToScene(50, 0), QPointF(25, 0)); |
|
3468 |
QCOMPARE(childRectItem->scenePos(), QPointF(25, -50)); |
|
3469 |
||
3470 |
QGraphicsRectItem *parentOfGroup = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3471 |
parentOfGroup->setPos(-200, -200); |
|
3472 |
parentOfGroup->scale(2, 2); |
|
3473 |
||
3474 |
QGraphicsItemGroup *group = new QGraphicsItemGroup; |
|
3475 |
group->setPos(50, 50); |
|
3476 |
group->setParentItem(parentOfGroup); |
|
3477 |
||
3478 |
QCOMPARE(group->scenePos(), QPointF(-100, -100)); |
|
3479 |
||
3480 |
group->addToGroup(childRectItem); |
|
3481 |
||
3482 |
QCOMPARE(childRectItem->mapToScene(50, 0), QPointF(25, 0)); |
|
3483 |
QCOMPARE(childRectItem->scenePos(), QPointF(25, -50)); |
|
3484 |
} |
|
3485 |
||
3486 |
void tst_QGraphicsItem::removeFromGroup() |
|
3487 |
{ |
|
3488 |
QGraphicsScene scene; |
|
3489 |
QGraphicsRectItem *rect1 = scene.addRect(QRectF(-100, -100, 200, 200)); |
|
3490 |
QGraphicsRectItem *rect2 = scene.addRect(QRectF(100, 100, 200, 200)); |
|
3491 |
rect1->setFlag(QGraphicsItem::ItemIsSelectable); |
|
3492 |
rect2->setFlag(QGraphicsItem::ItemIsSelectable); |
|
3493 |
rect1->setSelected(true); |
|
3494 |
rect2->setSelected(true); |
|
3495 |
||
3496 |
QGraphicsView view(&scene); |
|
3497 |
view.show(); |
|
3498 |
||
3499 |
qApp->processEvents(); // index items |
|
3500 |
qApp->processEvents(); // emit changed |
|
3501 |
||
3502 |
QGraphicsItemGroup *group = scene.createItemGroup(scene.selectedItems()); |
|
3503 |
QVERIFY(group); |
|
3504 |
QCOMPARE(group->children().size(), 2); |
|
3505 |
qApp->processEvents(); // index items |
|
3506 |
qApp->processEvents(); // emit changed |
|
3507 |
||
3508 |
scene.destroyItemGroup(group); // calls removeFromGroup. |
|
3509 |
||
3510 |
qApp->processEvents(); // index items |
|
3511 |
qApp->processEvents(); // emit changed |
|
3512 |
||
3513 |
QCOMPARE(scene.items().size(), 2); |
|
3514 |
QVERIFY(!rect1->group()); |
|
3515 |
QVERIFY(!rect2->group()); |
|
3516 |
} |
|
3517 |
||
3518 |
class ChildEventTester : public QGraphicsRectItem |
|
3519 |
{ |
|
3520 |
public: |
|
3521 |
ChildEventTester(const QRectF &rect, QGraphicsItem *parent = 0) |
|
3522 |
: QGraphicsRectItem(rect, parent), counter(0) |
|
3523 |
{ } |
|
3524 |
||
3525 |
int counter; |
|
3526 |
||
3527 |
protected: |
|
3528 |
void focusInEvent(QFocusEvent *event) |
|
3529 |
{ ++counter; QGraphicsRectItem::focusInEvent(event); } |
|
3530 |
void mousePressEvent(QGraphicsSceneMouseEvent *) |
|
3531 |
{ ++counter; } |
|
3532 |
void mouseMoveEvent(QGraphicsSceneMouseEvent *) |
|
3533 |
{ ++counter; } |
|
3534 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) |
|
3535 |
{ ++counter; } |
|
3536 |
}; |
|
3537 |
||
3538 |
void tst_QGraphicsItem::handlesChildEvents() |
|
3539 |
{ |
|
3540 |
ChildEventTester *blue = new ChildEventTester(QRectF(0, 0, 100, 100)); |
|
3541 |
ChildEventTester *red = new ChildEventTester(QRectF(0, 0, 50, 50)); |
|
3542 |
ChildEventTester *green = new ChildEventTester(QRectF(0, 0, 25, 25)); |
|
3543 |
ChildEventTester *gray = new ChildEventTester(QRectF(0, 0, 25, 25)); |
|
3544 |
ChildEventTester *yellow = new ChildEventTester(QRectF(0, 0, 50, 50)); |
|
3545 |
||
3546 |
blue->setBrush(QBrush(Qt::blue)); |
|
3547 |
red->setBrush(QBrush(Qt::red)); |
|
3548 |
yellow->setBrush(QBrush(Qt::yellow)); |
|
3549 |
green->setBrush(QBrush(Qt::green)); |
|
3550 |
gray->setBrush(QBrush(Qt::gray)); |
|
3551 |
red->setPos(50, 0); |
|
3552 |
yellow->setPos(50, 50); |
|
3553 |
green->setPos(25, 0); |
|
3554 |
gray->setPos(25, 25); |
|
3555 |
red->setParentItem(blue); |
|
3556 |
yellow->setParentItem(blue); |
|
3557 |
green->setParentItem(red); |
|
3558 |
gray->setParentItem(red); |
|
3559 |
||
3560 |
QGraphicsScene scene; |
|
3561 |
scene.addItem(blue); |
|
3562 |
||
3563 |
QGraphicsView view(&scene); |
|
3564 |
view.show(); |
|
3565 |
QTest::qWaitForWindowShown(&view); |
|
3566 |
QTest::qWait(20); |
|
3567 |
||
3568 |
// Pull out the items, closest item first |
|
3569 |
QList<QGraphicsItem *> items = scene.items(scene.itemsBoundingRect()); |
|
3570 |
QCOMPARE(items.at(0), (QGraphicsItem *)yellow); |
|
3571 |
QCOMPARE(items.at(1), (QGraphicsItem *)gray); |
|
3572 |
QCOMPARE(items.at(2), (QGraphicsItem *)green); |
|
3573 |
QCOMPARE(items.at(3), (QGraphicsItem *)red); |
|
3574 |
QCOMPARE(items.at(4), (QGraphicsItem *)blue); |
|
3575 |
||
3576 |
QCOMPARE(blue->counter, 0); |
|
3577 |
||
3578 |
// Send events to the toplevel item |
|
3579 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
3580 |
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); |
|
3581 |
||
3582 |
pressEvent.setButton(Qt::LeftButton); |
|
3583 |
pressEvent.setScenePos(blue->mapToScene(5, 5)); |
|
3584 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3585 |
releaseEvent.setButton(Qt::LeftButton); |
|
3586 |
releaseEvent.setScenePos(blue->mapToScene(5, 5)); |
|
3587 |
releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3588 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3589 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3590 |
||
3591 |
QCOMPARE(blue->counter, 2); |
|
3592 |
||
3593 |
// Send events to a level1 item |
|
3594 |
pressEvent.setScenePos(red->mapToScene(5, 5)); |
|
3595 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3596 |
releaseEvent.setScenePos(red->mapToScene(5, 5)); |
|
3597 |
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); |
|
3598 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3599 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3600 |
||
3601 |
QCOMPARE(blue->counter, 2); |
|
3602 |
QCOMPARE(red->counter, 2); |
|
3603 |
||
3604 |
// Send events to a level2 item |
|
3605 |
pressEvent.setScenePos(green->mapToScene(5, 5)); |
|
3606 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3607 |
releaseEvent.setScenePos(green->mapToScene(5, 5)); |
|
3608 |
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); |
|
3609 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3610 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3611 |
||
3612 |
QCOMPARE(blue->counter, 2); |
|
3613 |
QCOMPARE(red->counter, 2); |
|
3614 |
QCOMPARE(green->counter, 2); |
|
3615 |
||
3616 |
blue->setHandlesChildEvents(true); |
|
3617 |
||
3618 |
// Send events to a level1 item |
|
3619 |
pressEvent.setScenePos(red->mapToScene(5, 5)); |
|
3620 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3621 |
releaseEvent.setScenePos(red->mapToScene(5, 5)); |
|
3622 |
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); |
|
3623 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3624 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3625 |
||
3626 |
QCOMPARE(blue->counter, 4); |
|
3627 |
QCOMPARE(red->counter, 2); |
|
3628 |
||
3629 |
// Send events to a level2 item |
|
3630 |
pressEvent.setScenePos(green->mapToScene(5, 5)); |
|
3631 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3632 |
releaseEvent.setScenePos(green->mapToScene(5, 5)); |
|
3633 |
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); |
|
3634 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3635 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3636 |
||
3637 |
QCOMPARE(blue->counter, 6); |
|
3638 |
QCOMPARE(red->counter, 2); |
|
3639 |
QCOMPARE(green->counter, 2); |
|
3640 |
||
3641 |
blue->setHandlesChildEvents(false); |
|
3642 |
||
3643 |
// Send events to a level1 item |
|
3644 |
pressEvent.setScenePos(red->mapToScene(5, 5)); |
|
3645 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3646 |
releaseEvent.setScenePos(red->mapToScene(5, 5)); |
|
3647 |
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); |
|
3648 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3649 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3650 |
||
3651 |
QCOMPARE(blue->counter, 6); |
|
3652 |
QCOMPARE(red->counter, 4); |
|
3653 |
||
3654 |
// Send events to a level2 item |
|
3655 |
pressEvent.setScenePos(green->mapToScene(5, 5)); |
|
3656 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3657 |
releaseEvent.setScenePos(green->mapToScene(5, 5)); |
|
3658 |
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); |
|
3659 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3660 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3661 |
||
3662 |
QCOMPARE(blue->counter, 6); |
|
3663 |
QCOMPARE(red->counter, 4); |
|
3664 |
QCOMPARE(green->counter, 4); |
|
3665 |
} |
|
3666 |
||
3667 |
void tst_QGraphicsItem::handlesChildEvents2() |
|
3668 |
{ |
|
3669 |
ChildEventTester *root = new ChildEventTester(QRectF(0, 0, 10, 10)); |
|
3670 |
root->setHandlesChildEvents(true); |
|
3671 |
QVERIFY(root->handlesChildEvents()); |
|
3672 |
||
3673 |
ChildEventTester *child = new ChildEventTester(QRectF(0, 0, 10, 10), root); |
|
3674 |
QVERIFY(!child->handlesChildEvents()); |
|
3675 |
||
3676 |
ChildEventTester *child2 = new ChildEventTester(QRectF(0, 0, 10, 10)); |
|
3677 |
ChildEventTester *child3 = new ChildEventTester(QRectF(0, 0, 10, 10), child2); |
|
3678 |
ChildEventTester *child4 = new ChildEventTester(QRectF(0, 0, 10, 10), child3); |
|
3679 |
child2->setParentItem(root); |
|
3680 |
QVERIFY(!child2->handlesChildEvents()); |
|
3681 |
QVERIFY(!child3->handlesChildEvents()); |
|
3682 |
QVERIFY(!child4->handlesChildEvents()); |
|
3683 |
||
3684 |
QGraphicsScene scene; |
|
3685 |
scene.addItem(root); |
|
3686 |
||
3687 |
QGraphicsView view(&scene); |
|
3688 |
view.show(); |
|
3689 |
QTest::qWaitForWindowShown(&view); |
|
3690 |
QApplication::processEvents(); |
|
3691 |
||
3692 |
QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5), |
|
3693 |
view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0); |
|
3694 |
QApplication::sendEvent(view.viewport(), &event); |
|
3695 |
||
3696 |
QTRY_COMPARE(root->counter, 1); |
|
3697 |
} |
|
3698 |
||
3699 |
void tst_QGraphicsItem::handlesChildEvents3() |
|
3700 |
{ |
|
3701 |
QGraphicsScene scene; |
|
3702 |
QEvent activate(QEvent::WindowActivate); |
|
3703 |
QApplication::sendEvent(&scene, &activate); |
|
3704 |
||
3705 |
ChildEventTester *group2 = new ChildEventTester(QRectF(), 0); |
|
3706 |
ChildEventTester *group1 = new ChildEventTester(QRectF(), group2); |
|
3707 |
ChildEventTester *leaf = new ChildEventTester(QRectF(), group1); |
|
3708 |
scene.addItem(group2); |
|
3709 |
||
3710 |
leaf->setFlag(QGraphicsItem::ItemIsFocusable); |
|
3711 |
group1->setFlag(QGraphicsItem::ItemIsFocusable); |
|
3712 |
group1->setHandlesChildEvents(true); |
|
3713 |
group2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
3714 |
group2->setHandlesChildEvents(true); |
|
3715 |
||
3716 |
leaf->setFocus(); |
|
3717 |
QVERIFY(leaf->hasFocus()); // group2 stole the event, but leaf still got focus |
|
3718 |
QVERIFY(!group1->hasFocus()); |
|
3719 |
QVERIFY(!group2->hasFocus()); |
|
3720 |
QCOMPARE(leaf->counter, 0); |
|
3721 |
QCOMPARE(group1->counter, 0); |
|
3722 |
QCOMPARE(group2->counter, 1); |
|
3723 |
||
3724 |
group1->setFocus(); |
|
3725 |
QVERIFY(group1->hasFocus()); // group2 stole the event, but group1 still got focus |
|
3726 |
QVERIFY(!leaf->hasFocus()); |
|
3727 |
QVERIFY(!group2->hasFocus()); |
|
3728 |
QCOMPARE(leaf->counter, 0); |
|
3729 |
QCOMPARE(group1->counter, 0); |
|
3730 |
QCOMPARE(group2->counter, 2); |
|
3731 |
||
3732 |
group2->setFocus(); |
|
3733 |
QVERIFY(group2->hasFocus()); // group2 stole the event, and now group2 also has focus |
|
3734 |
QVERIFY(!leaf->hasFocus()); |
|
3735 |
QVERIFY(!group1->hasFocus()); |
|
3736 |
QCOMPARE(leaf->counter, 0); |
|
3737 |
QCOMPARE(group1->counter, 0); |
|
3738 |
QCOMPARE(group2->counter, 3); |
|
3739 |
} |
|
3740 |
||
3741 |
||
3742 |
class ChildEventFilterTester : public ChildEventTester |
|
3743 |
{ |
|
3744 |
public: |
|
3745 |
ChildEventFilterTester(const QRectF &rect, QGraphicsItem *parent = 0) |
|
3746 |
: ChildEventTester(rect, parent), filter(QEvent::None) |
|
3747 |
{ } |
|
3748 |
||
3749 |
QEvent::Type filter; |
|
3750 |
||
3751 |
protected: |
|
3752 |
bool sceneEventFilter(QGraphicsItem *item, QEvent *event) |
|
3753 |
{ |
|
3754 |
Q_UNUSED(item); |
|
3755 |
if (event->type() == filter) { |
|
3756 |
++counter; |
|
3757 |
return true; |
|
3758 |
} |
|
3759 |
return false; |
|
3760 |
} |
|
3761 |
}; |
|
3762 |
||
3763 |
void tst_QGraphicsItem::filtersChildEvents() |
|
3764 |
{ |
|
3765 |
QGraphicsScene scene; |
|
3766 |
ChildEventFilterTester *root = new ChildEventFilterTester(QRectF(0, 0, 10, 10)); |
|
3767 |
ChildEventFilterTester *filter = new ChildEventFilterTester(QRectF(10, 10, 10, 10), root); |
|
3768 |
ChildEventTester *child = new ChildEventTester(QRectF(20, 20, 10, 10), filter); |
|
3769 |
||
3770 |
// setup filter |
|
3771 |
filter->setFiltersChildEvents(true); |
|
3772 |
filter->filter = QEvent::GraphicsSceneMousePress; |
|
3773 |
||
3774 |
scene.addItem(root); |
|
3775 |
||
3776 |
QGraphicsView view(&scene); |
|
3777 |
view.show(); |
|
3778 |
QTest::qWaitForWindowShown(&view); |
|
3779 |
QTest::qWait(20); |
|
3780 |
||
3781 |
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); |
|
3782 |
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); |
|
3783 |
||
3784 |
// send event to child |
|
3785 |
pressEvent.setButton(Qt::LeftButton); |
|
3786 |
pressEvent.setScenePos(QPointF(25, 25));//child->mapToScene(5, 5)); |
|
3787 |
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3788 |
releaseEvent.setButton(Qt::LeftButton); |
|
3789 |
releaseEvent.setScenePos(QPointF(25, 25));//child->mapToScene(5, 5)); |
|
3790 |
releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); |
|
3791 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3792 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3793 |
||
3794 |
QTRY_COMPARE(child->counter, 1); // mouse release is not filtered |
|
3795 |
QCOMPARE(filter->counter, 1); // mouse press is filtered |
|
3796 |
QCOMPARE(root->counter, 0); |
|
3797 |
||
3798 |
// add another filter |
|
3799 |
root->setFiltersChildEvents(true); |
|
3800 |
root->filter = QEvent::GraphicsSceneMouseRelease; |
|
3801 |
||
3802 |
// send event to child |
|
3803 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3804 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3805 |
||
3806 |
QCOMPARE(child->counter, 1); |
|
3807 |
QCOMPARE(filter->counter, 2); // mouse press is filtered |
|
3808 |
QCOMPARE(root->counter, 1); // mouse release is filtered |
|
3809 |
||
3810 |
// reparent to another sub-graph |
|
3811 |
ChildEventTester *parent = new ChildEventTester(QRectF(10, 10, 10, 10), root); |
|
3812 |
child->setParentItem(parent); |
|
3813 |
||
3814 |
// send event to child |
|
3815 |
QApplication::sendEvent(&scene, &pressEvent); |
|
3816 |
QApplication::sendEvent(&scene, &releaseEvent); |
|
3817 |
||
3818 |
QCOMPARE(child->counter, 2); // mouse press is _not_ filtered |
|
3819 |
QCOMPARE(parent->counter, 0); |
|
3820 |
QCOMPARE(filter->counter, 2); |
|
3821 |
QCOMPARE(root->counter, 2); // mouse release is filtered |
|
3822 |
} |
|
3823 |
||
3824 |
void tst_QGraphicsItem::filtersChildEvents2() |
|
3825 |
{ |
|
3826 |
ChildEventFilterTester *root = new ChildEventFilterTester(QRectF(0, 0, 10, 10)); |
|
3827 |
root->setFiltersChildEvents(true); |
|
3828 |
root->filter = QEvent::GraphicsSceneMousePress; |
|
3829 |
QVERIFY(root->filtersChildEvents()); |
|
3830 |
||
3831 |
ChildEventTester *child = new ChildEventTester(QRectF(0, 0, 10, 10), root); |
|
3832 |
QVERIFY(!child->filtersChildEvents()); |
|
3833 |
||
3834 |
ChildEventTester *child2 = new ChildEventTester(QRectF(0, 0, 10, 10)); |
|
3835 |
ChildEventTester *child3 = new ChildEventTester(QRectF(0, 0, 10, 10), child2); |
|
3836 |
ChildEventTester *child4 = new ChildEventTester(QRectF(0, 0, 10, 10), child3); |
|
3837 |
||
3838 |
child2->setParentItem(root); |
|
3839 |
QVERIFY(!child2->filtersChildEvents()); |
|
3840 |
QVERIFY(!child3->filtersChildEvents()); |
|
3841 |
QVERIFY(!child4->filtersChildEvents()); |
|
3842 |
||
3843 |
QGraphicsScene scene; |
|
3844 |
scene.addItem(root); |
|
3845 |
||
3846 |
QGraphicsView view(&scene); |
|
3847 |
view.show(); |
|
3848 |
||
3849 |
QTest::qWaitForWindowShown(&view); |
|
3850 |
QApplication::processEvents(); |
|
3851 |
||
3852 |
QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5), |
|
3853 |
view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0); |
|
3854 |
QApplication::sendEvent(view.viewport(), &event); |
|
3855 |
||
3856 |
QTRY_COMPARE(root->counter, 1); |
|
3857 |
QCOMPARE(child->counter, 0); |
|
3858 |
QCOMPARE(child2->counter, 0); |
|
3859 |
QCOMPARE(child3->counter, 0); |
|
3860 |
QCOMPARE(child4->counter, 0); |
|
3861 |
} |
|
3862 |
||
3863 |
class CustomItem : public QGraphicsItem |
|
3864 |
{ |
|
3865 |
public: |
|
3866 |
QRectF boundingRect() const |
|
3867 |
{ return QRectF(-110, -110, 220, 220); } |
|
3868 |
||
3869 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
3870 |
{ |
|
3871 |
for (int x = -100; x <= 100; x += 25) |
|
3872 |
painter->drawLine(x, -100, x, 100); |
|
3873 |
for (int y = -100; y <= 100; y += 25) |
|
3874 |
painter->drawLine(-100, y, 100, y); |
|
3875 |
||
3876 |
QFont font = painter->font(); |
|
3877 |
font.setPointSize(4); |
|
3878 |
painter->setFont(font); |
|
3879 |
for (int x = -100; x < 100; x += 25) { |
|
3880 |
for (int y = -100; y < 100; y += 25) { |
|
3881 |
painter->drawText(QRectF(x, y, 25, 25), Qt::AlignCenter, QString("%1x%2").arg(x).arg(y)); |
|
3882 |
} |
|
3883 |
} |
|
3884 |
} |
|
3885 |
}; |
|
3886 |
||
3887 |
void tst_QGraphicsItem::ensureVisible() |
|
3888 |
{ |
|
3889 |
QGraphicsScene scene; |
|
3890 |
scene.setSceneRect(-200, -200, 400, 400); |
|
3891 |
QGraphicsItem *item = new CustomItem; |
|
3892 |
scene.addItem(item); |
|
3893 |
||
3894 |
QGraphicsView view(&scene); |
|
3895 |
view.setFixedSize(300, 300); |
|
3896 |
view.show(); |
|
3897 |
QTest::qWaitForWindowShown(&view); |
|
3898 |
||
3899 |
for (int i = 0; i < 25; ++i) { |
|
3900 |
view.scale(qreal(1.06), qreal(1.06)); |
|
3901 |
QApplication::processEvents(); |
|
3902 |
} |
|
3903 |
||
3904 |
item->ensureVisible(-100, -100, 25, 25); |
|
3905 |
QTest::qWait(25); |
|
3906 |
||
3907 |
for (int x = -100; x < 100; x += 25) { |
|
3908 |
for (int y = -100; y < 100; y += 25) { |
|
3909 |
int xmargin = rand() % 75; |
|
3910 |
int ymargin = rand() % 75; |
|
3911 |
item->ensureVisible(x, y, 25, 25, xmargin, ymargin); |
|
3912 |
QApplication::processEvents(); |
|
3913 |
||
3914 |
QPolygonF viewScenePoly; |
|
3915 |
viewScenePoly << view.mapToScene(view.rect().topLeft()) |
|
3916 |
<< view.mapToScene(view.rect().topRight()) |
|
3917 |
<< view.mapToScene(view.rect().bottomRight()) |
|
3918 |
<< view.mapToScene(view.rect().bottomLeft()); |
|
3919 |
||
3920 |
QVERIFY(scene.items(viewScenePoly).contains(item)); |
|
3921 |
||
3922 |
QPainterPath path; |
|
3923 |
path.addPolygon(viewScenePoly); |
|
3924 |
QVERIFY(path.contains(item->mapToScene(x + 12, y + 12))); |
|
3925 |
||
3926 |
QPolygonF viewScenePolyMinusMargins; |
|
3927 |
viewScenePolyMinusMargins << view.mapToScene(view.rect().topLeft() + QPoint(xmargin, ymargin)) |
|
3928 |
<< view.mapToScene(view.rect().topRight() + QPoint(-xmargin, ymargin)) |
|
3929 |
<< view.mapToScene(view.rect().bottomRight() + QPoint(-xmargin, -ymargin)) |
|
3930 |
<< view.mapToScene(view.rect().bottomLeft() + QPoint(xmargin, -ymargin)); |
|
3931 |
||
3932 |
QPainterPath path2; |
|
3933 |
path2.addPolygon(viewScenePolyMinusMargins); |
|
3934 |
QVERIFY(path2.contains(item->mapToScene(x + 12, y + 12))); |
|
3935 |
} |
|
3936 |
} |
|
3937 |
||
3938 |
item->ensureVisible(100, 100, 25, 25); |
|
3939 |
QTest::qWait(25); |
|
3940 |
} |
|
3941 |
||
3942 |
void tst_QGraphicsItem::cursor() |
|
3943 |
{ |
|
3944 |
#ifndef QT_NO_CURSOR |
|
3945 |
QGraphicsScene scene; |
|
3946 |
QGraphicsRectItem *item1 = scene.addRect(QRectF(0, 0, 50, 50)); |
|
3947 |
QGraphicsRectItem *item2 = scene.addRect(QRectF(0, 0, 50, 50)); |
|
3948 |
item1->setPos(-100, 0); |
|
3949 |
item2->setPos(50, 0); |
|
3950 |
||
3951 |
QVERIFY(!item1->hasCursor()); |
|
3952 |
QVERIFY(!item2->hasCursor()); |
|
3953 |
||
3954 |
item1->setCursor(Qt::IBeamCursor); |
|
3955 |
item2->setCursor(Qt::PointingHandCursor); |
|
3956 |
||
3957 |
QVERIFY(item1->hasCursor()); |
|
3958 |
QVERIFY(item2->hasCursor()); |
|
3959 |
||
3960 |
item1->setCursor(QCursor()); |
|
3961 |
item2->setCursor(QCursor()); |
|
3962 |
||
3963 |
QVERIFY(item1->hasCursor()); |
|
3964 |
QVERIFY(item2->hasCursor()); |
|
3965 |
||
3966 |
item1->unsetCursor(); |
|
3967 |
item2->unsetCursor(); |
|
3968 |
||
3969 |
QVERIFY(!item1->hasCursor()); |
|
3970 |
QVERIFY(!item2->hasCursor()); |
|
3971 |
||
3972 |
item1->setCursor(Qt::IBeamCursor); |
|
3973 |
item2->setCursor(Qt::PointingHandCursor); |
|
3974 |
||
3975 |
QGraphicsView view(&scene); |
|
3976 |
view.setFixedSize(200, 100); |
|
3977 |
view.show(); |
|
3978 |
QTest::mouseMove(&view, view.rect().center()); |
|
3979 |
||
3980 |
QTest::qWait(25); |
|
3981 |
||
3982 |
QCursor cursor = view.viewport()->cursor(); |
|
3983 |
||
3984 |
{ |
|
3985 |
QMouseEvent event(QEvent::MouseMove, QPoint(100, 50), Qt::NoButton, 0, 0); |
|
3986 |
QApplication::sendEvent(view.viewport(), &event); |
|
3987 |
} |
|
3988 |
||
3989 |
QTest::qWait(25); |
|
3990 |
||
3991 |
QCOMPARE(view.viewport()->cursor().shape(), cursor.shape()); |
|
3992 |
||
3993 |
{ |
|
3994 |
QTest::mouseMove(view.viewport(), view.mapFromScene(item1->sceneBoundingRect().center())); |
|
3995 |
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->sceneBoundingRect().center()), Qt::NoButton, 0, 0); |
|
3996 |
QApplication::sendEvent(view.viewport(), &event); |
|
3997 |
} |
|
3998 |
||
3999 |
#if !defined(Q_OS_WINCE) |
|
4000 |
QTest::qWait(250); |
|
4001 |
#else |
|
4002 |
// Test environment does not have any cursor, therefore no shape |
|
4003 |
return; |
|
4004 |
#endif |
|
4005 |
||
4006 |
QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); |
|
4007 |
||
4008 |
{ |
|
4009 |
QTest::mouseMove(view.viewport(), view.mapFromScene(item2->sceneBoundingRect().center())); |
|
4010 |
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item2->sceneBoundingRect().center()), Qt::NoButton, 0, 0); |
|
4011 |
QApplication::sendEvent(view.viewport(), &event); |
|
4012 |
} |
|
4013 |
||
4014 |
QTest::qWait(25); |
|
4015 |
||
4016 |
QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); |
|
4017 |
||
4018 |
{ |
|
4019 |
QTest::mouseMove(view.viewport(), view.rect().center()); |
|
4020 |
QMouseEvent event(QEvent::MouseMove, QPoint(100, 25), Qt::NoButton, 0, 0); |
|
4021 |
QApplication::sendEvent(view.viewport(), &event); |
|
4022 |
} |
|
4023 |
||
4024 |
QTest::qWait(25); |
|
4025 |
||
4026 |
QCOMPARE(view.viewport()->cursor().shape(), cursor.shape()); |
|
4027 |
#endif |
|
4028 |
} |
|
4029 |
/* |
|
4030 |
void tst_QGraphicsItem::textControlGetterSetter() |
|
4031 |
{ |
|
4032 |
QGraphicsTextItem *item = new QGraphicsTextItem; |
|
4033 |
QVERIFY(item->textControl()->parent() == item); |
|
4034 |
QPointer<QTextControl> control = item->textControl(); |
|
4035 |
delete item; |
|
4036 |
QVERIFY(!control); |
|
4037 |
||
4038 |
item = new QGraphicsTextItem; |
|
4039 |
||
4040 |
QPointer<QTextControl> oldControl = control; |
|
4041 |
control = new QTextControl; |
|
4042 |
||
4043 |
item->setTextControl(control); |
|
4044 |
QVERIFY(item->textControl() == control); |
|
4045 |
QVERIFY(!control->parent()); |
|
4046 |
QVERIFY(!oldControl); |
|
4047 |
||
4048 |
// set some text to give it a size, to test that |
|
4049 |
// setTextControl (re)connects signals |
|
4050 |
const QRectF oldBoundingRect = item->boundingRect(); |
|
4051 |
QVERIFY(oldBoundingRect.isValid()); |
|
4052 |
item->setPlainText("Some text"); |
|
4053 |
item->adjustSize(); |
|
4054 |
QVERIFY(item->boundingRect().isValid()); |
|
4055 |
QVERIFY(item->boundingRect() != oldBoundingRect); |
|
4056 |
||
4057 |
// test that on setting a control the item size |
|
4058 |
// is adjusted |
|
4059 |
oldControl = control; |
|
4060 |
control = new QTextControl; |
|
4061 |
control->setPlainText("foo!"); |
|
4062 |
item->setTextControl(control); |
|
4063 |
QCOMPARE(item->boundingRect().size(), control->document()->documentLayout()->documentSize()); |
|
4064 |
||
4065 |
QVERIFY(oldControl); |
|
4066 |
delete oldControl; |
|
4067 |
||
4068 |
delete item; |
|
4069 |
QVERIFY(control); |
|
4070 |
delete control; |
|
4071 |
} |
|
4072 |
*/ |
|
4073 |
||
4074 |
void tst_QGraphicsItem::defaultItemTest_QGraphicsLineItem() |
|
4075 |
{ |
|
4076 |
QGraphicsLineItem item; |
|
4077 |
QCOMPARE(item.line(), QLineF()); |
|
4078 |
QCOMPARE(item.pen(), QPen()); |
|
4079 |
QCOMPARE(item.shape(), QPainterPath()); |
|
4080 |
||
4081 |
item.setPen(QPen(Qt::black, 1)); |
|
4082 |
QCOMPARE(item.pen(), QPen(Qt::black, 1)); |
|
4083 |
item.setLine(QLineF(0, 0, 10, 0)); |
|
4084 |
QCOMPARE(item.line(), QLineF(0, 0, 10, 0)); |
|
4085 |
QCOMPARE(item.boundingRect(), QRectF(-0.5, -0.5, 11, 1)); |
|
4086 |
QCOMPARE(item.shape().elementCount(), 11); |
|
4087 |
||
4088 |
QPainterPath path; |
|
4089 |
path.moveTo(0, -0.5); |
|
4090 |
path.lineTo(10, -0.5); |
|
4091 |
path.lineTo(10.5, -0.5); |
|
4092 |
path.lineTo(10.5, 0.5); |
|
4093 |
path.lineTo(10, 0.5); |
|
4094 |
path.lineTo(0, 0.5); |
|
4095 |
path.lineTo(-0.5, 0.5); |
|
4096 |
path.lineTo(-0.5, -0.5); |
|
4097 |
path.lineTo(0, -0.5); |
|
4098 |
path.lineTo(0, 0); |
|
4099 |
path.lineTo(10, 0); |
|
4100 |
path.closeSubpath(); |
|
4101 |
||
4102 |
for (int i = 0; i < 11; ++i) |
|
4103 |
QCOMPARE(QPointF(item.shape().elementAt(i)), QPointF(path.elementAt(i))); |
|
4104 |
} |
|
4105 |
||
4106 |
void tst_QGraphicsItem::defaultItemTest_QGraphicsPixmapItem() |
|
4107 |
{ |
|
4108 |
QGraphicsPixmapItem item; |
|
4109 |
QVERIFY(item.pixmap().isNull()); |
|
4110 |
QCOMPARE(item.offset(), QPointF()); |
|
4111 |
QCOMPARE(item.transformationMode(), Qt::FastTransformation); |
|
4112 |
||
4113 |
QPixmap pixmap(300, 200); |
|
4114 |
pixmap.fill(Qt::red); |
|
4115 |
item.setPixmap(pixmap); |
|
4116 |
QCOMPARE(item.pixmap(), pixmap); |
|
4117 |
||
4118 |
item.setTransformationMode(Qt::FastTransformation); |
|
4119 |
QCOMPARE(item.transformationMode(), Qt::FastTransformation); |
|
4120 |
item.setTransformationMode(Qt::SmoothTransformation); |
|
4121 |
QCOMPARE(item.transformationMode(), Qt::SmoothTransformation); |
|
4122 |
||
4123 |
item.setOffset(-15, -15); |
|
4124 |
QCOMPARE(item.offset(), QPointF(-15, -15)); |
|
4125 |
item.setOffset(QPointF(-10, -10)); |
|
4126 |
QCOMPARE(item.offset(), QPointF(-10, -10)); |
|
4127 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4128 |
QCOMPARE(item.boundingRect(), QRectF(-10, -10, 300, 200)); |
0 | 4129 |
} |
4130 |
||
4131 |
void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem() |
|
4132 |
{ |
|
4133 |
QGraphicsTextItem *text = new QGraphicsTextItem; |
|
4134 |
QVERIFY(!text->openExternalLinks()); |
|
4135 |
QVERIFY(text->textCursor().isNull()); |
|
4136 |
QCOMPARE(text->defaultTextColor(), QPalette().color(QPalette::Text)); |
|
4137 |
QVERIFY(text->document() != 0); |
|
4138 |
QCOMPARE(text->font(), QApplication::font()); |
|
4139 |
QCOMPARE(text->textInteractionFlags(), Qt::TextInteractionFlags(Qt::NoTextInteraction)); |
|
4140 |
QCOMPARE(text->textWidth(), -1.0); |
|
4141 |
QCOMPARE(text->toPlainText(), QString("")); |
|
4142 |
||
4143 |
QGraphicsScene scene; |
|
4144 |
scene.addItem(text); |
|
4145 |
text->setPlainText("Hello world"); |
|
4146 |
text->setFlag(QGraphicsItem::ItemIsMovable); |
|
4147 |
||
4148 |
{ |
|
4149 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
4150 |
event.setScenePos(QPointF(1, 1)); |
|
4151 |
event.setButton(Qt::LeftButton); |
|
4152 |
event.setButtons(Qt::LeftButton); |
|
4153 |
QApplication::sendEvent(&scene, &event); |
|
4154 |
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove); |
|
4155 |
event2.setScenePos(QPointF(11, 11)); |
|
4156 |
event2.setButton(Qt::LeftButton); |
|
4157 |
event2.setButtons(Qt::LeftButton); |
|
4158 |
QApplication::sendEvent(&scene, &event2); |
|
4159 |
} |
|
4160 |
||
4161 |
QCOMPARE(text->pos(), QPointF(10, 10)); |
|
4162 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4163 |
text->setTextInteractionFlags(Qt::NoTextInteraction); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4164 |
QVERIFY(!(text->flags() & QGraphicsItem::ItemAcceptsInputMethod)); |
0 | 4165 |
text->setTextInteractionFlags(Qt::TextEditorInteraction); |
4166 |
QCOMPARE(text->textInteractionFlags(), Qt::TextInteractionFlags(Qt::TextEditorInteraction)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4167 |
QVERIFY(text->flags() & QGraphicsItem::ItemAcceptsInputMethod); |
0 | 4168 |
|
4169 |
{ |
|
4170 |
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove); |
|
4171 |
event2.setScenePos(QPointF(21, 21)); |
|
4172 |
event2.setButton(Qt::LeftButton); |
|
4173 |
event2.setButtons(Qt::LeftButton); |
|
4174 |
QApplication::sendEvent(&scene, &event2); |
|
4175 |
} |
|
4176 |
||
4177 |
QCOMPARE(text->pos(), QPointF(20, 20)); // clicked on edge, item moved |
|
4178 |
} |
|
4179 |
||
4180 |
void tst_QGraphicsItem::defaultItemTest_QGraphicsEllipseItem() |
|
4181 |
{ |
|
4182 |
QGraphicsEllipseItem item; |
|
4183 |
QVERIFY(item.rect().isNull()); |
|
4184 |
QVERIFY(item.boundingRect().isNull()); |
|
4185 |
QVERIFY(item.shape().isEmpty()); |
|
4186 |
QCOMPARE(item.spanAngle(), 360 * 16); |
|
4187 |
QCOMPARE(item.startAngle(), 0); |
|
4188 |
||
4189 |
item.setRect(0, 0, 100, 100); |
|
4190 |
QCOMPARE(item.boundingRect(), QRectF(0, 0, 100, 100)); |
|
4191 |
||
4192 |
item.setSpanAngle(90 * 16); |
|
4193 |
qFuzzyCompare(item.boundingRect().left(), qreal(50.0)); |
|
4194 |
qFuzzyCompare(item.boundingRect().top(), qreal(0.0)); |
|
4195 |
qFuzzyCompare(item.boundingRect().width(), qreal(50.0)); |
|
4196 |
qFuzzyCompare(item.boundingRect().height(), qreal(50.0)); |
|
4197 |
||
4198 |
item.setPen(QPen(Qt::black, 1)); |
|
4199 |
QCOMPARE(item.boundingRect(), QRectF(49.5, -0.5, 51, 51)); |
|
4200 |
||
4201 |
item.setSpanAngle(180 * 16); |
|
4202 |
QCOMPARE(item.boundingRect(), QRectF(-0.5, -0.5, 101, 51)); |
|
4203 |
||
4204 |
item.setSpanAngle(360 * 16); |
|
4205 |
QCOMPARE(item.boundingRect(), QRectF(-0.5, -0.5, 101, 101)); |
|
4206 |
} |
|
4207 |
||
4208 |
class ItemChangeTester : public QGraphicsRectItem |
|
4209 |
{ |
|
4210 |
public: |
|
4211 |
ItemChangeTester() |
|
4212 |
{ setFlag(ItemSendsGeometryChanges); clear(); } |
|
4213 |
ItemChangeTester(QGraphicsItem *parent) : QGraphicsRectItem(parent) |
|
4214 |
{ setFlag(ItemSendsGeometryChanges); clear(); } |
|
4215 |
||
4216 |
void clear() |
|
4217 |
{ |
|
4218 |
itemChangeReturnValue = QVariant(); |
|
4219 |
itemSceneChangeTargetScene = 0; |
|
4220 |
changes.clear(); |
|
4221 |
values.clear(); |
|
4222 |
oldValues.clear(); |
|
4223 |
} |
|
4224 |
||
4225 |
QVariant itemChangeReturnValue; |
|
4226 |
QGraphicsScene *itemSceneChangeTargetScene; |
|
4227 |
||
4228 |
QList<GraphicsItemChange> changes; |
|
4229 |
QList<QVariant> values; |
|
4230 |
QList<QVariant> oldValues; |
|
4231 |
protected: |
|
4232 |
QVariant itemChange(GraphicsItemChange change, const QVariant &value) |
|
4233 |
{ |
|
4234 |
changes << change; |
|
4235 |
values << value; |
|
4236 |
switch (change) { |
|
4237 |
case QGraphicsItem::ItemPositionChange: |
|
4238 |
oldValues << pos(); |
|
4239 |
break; |
|
4240 |
case QGraphicsItem::ItemPositionHasChanged: |
|
4241 |
break; |
|
4242 |
case QGraphicsItem::ItemMatrixChange: { |
|
4243 |
QVariant variant; |
|
4244 |
qVariantSetValue<QMatrix>(variant, matrix()); |
|
4245 |
oldValues << variant; |
|
4246 |
} |
|
4247 |
break; |
|
4248 |
case QGraphicsItem::ItemTransformChange: { |
|
4249 |
QVariant variant; |
|
4250 |
qVariantSetValue<QTransform>(variant, transform()); |
|
4251 |
oldValues << variant; |
|
4252 |
} |
|
4253 |
break; |
|
4254 |
case QGraphicsItem::ItemTransformHasChanged: |
|
4255 |
break; |
|
4256 |
case QGraphicsItem::ItemVisibleChange: |
|
4257 |
oldValues << isVisible(); |
|
4258 |
break; |
|
4259 |
case QGraphicsItem::ItemVisibleHasChanged: |
|
4260 |
break; |
|
4261 |
case QGraphicsItem::ItemEnabledChange: |
|
4262 |
oldValues << isEnabled(); |
|
4263 |
break; |
|
4264 |
case QGraphicsItem::ItemEnabledHasChanged: |
|
4265 |
break; |
|
4266 |
case QGraphicsItem::ItemSelectedChange: |
|
4267 |
oldValues << isSelected(); |
|
4268 |
break; |
|
4269 |
case QGraphicsItem::ItemSelectedHasChanged: |
|
4270 |
break; |
|
4271 |
case QGraphicsItem::ItemParentChange: |
|
4272 |
oldValues << qVariantFromValue<void *>(parentItem()); |
|
4273 |
break; |
|
4274 |
case QGraphicsItem::ItemParentHasChanged: |
|
4275 |
break; |
|
4276 |
case QGraphicsItem::ItemChildAddedChange: |
|
4277 |
oldValues << children().size(); |
|
4278 |
break; |
|
4279 |
case QGraphicsItem::ItemChildRemovedChange: |
|
4280 |
oldValues << children().size(); |
|
4281 |
break; |
|
4282 |
case QGraphicsItem::ItemSceneChange: |
|
4283 |
oldValues << qVariantFromValue<QGraphicsScene *>(scene()); |
|
4284 |
if (itemSceneChangeTargetScene |
|
4285 |
&& qVariantValue<QGraphicsScene *>(value) |
|
4286 |
&& itemSceneChangeTargetScene != qVariantValue<QGraphicsScene *>(value)) { |
|
4287 |
return qVariantFromValue<QGraphicsScene *>(itemSceneChangeTargetScene); |
|
4288 |
} |
|
4289 |
return value; |
|
4290 |
case QGraphicsItem::ItemSceneHasChanged: |
|
4291 |
break; |
|
4292 |
case QGraphicsItem::ItemCursorChange: |
|
4293 |
#ifndef QT_NO_CURSOR |
|
4294 |
oldValues << cursor(); |
|
4295 |
#endif |
|
4296 |
break; |
|
4297 |
case QGraphicsItem::ItemCursorHasChanged: |
|
4298 |
break; |
|
4299 |
case QGraphicsItem::ItemToolTipChange: |
|
4300 |
oldValues << toolTip(); |
|
4301 |
break; |
|
4302 |
case QGraphicsItem::ItemToolTipHasChanged: |
|
4303 |
break; |
|
4304 |
case QGraphicsItem::ItemFlagsChange: |
|
4305 |
oldValues << quint32(flags()); |
|
4306 |
break; |
|
4307 |
case QGraphicsItem::ItemFlagsHaveChanged: |
|
4308 |
break; |
|
4309 |
case QGraphicsItem::ItemZValueChange: |
|
4310 |
oldValues << zValue(); |
|
4311 |
break; |
|
4312 |
case QGraphicsItem::ItemZValueHasChanged: |
|
4313 |
break; |
|
4314 |
case QGraphicsItem::ItemOpacityChange: |
|
4315 |
oldValues << opacity(); |
|
4316 |
break; |
|
4317 |
case QGraphicsItem::ItemOpacityHasChanged: |
|
4318 |
break; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4319 |
case QGraphicsItem::ItemScenePositionHasChanged: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4320 |
break; |
0 | 4321 |
} |
4322 |
return itemChangeReturnValue.isValid() ? itemChangeReturnValue : value; |
|
4323 |
} |
|
4324 |
}; |
|
4325 |
||
4326 |
void tst_QGraphicsItem::itemChange() |
|
4327 |
{ |
|
4328 |
ItemChangeTester tester; |
|
4329 |
tester.itemSceneChangeTargetScene = 0; |
|
4330 |
||
4331 |
ItemChangeTester testerHelper; |
|
4332 |
QVERIFY(tester.changes.isEmpty()); |
|
4333 |
QVERIFY(tester.values.isEmpty()); |
|
4334 |
||
4335 |
int changeCount = 0; |
|
4336 |
{ |
|
4337 |
// ItemEnabledChange |
|
4338 |
tester.itemChangeReturnValue = true; |
|
4339 |
tester.setEnabled(false); |
|
4340 |
++changeCount; |
|
4341 |
++changeCount; // HasChanged |
|
4342 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4343 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemEnabledChange); |
|
4344 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemEnabledHasChanged); |
|
4345 |
QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(false)); |
|
4346 |
QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true)); |
|
4347 |
QCOMPARE(tester.oldValues.last(), QVariant(true)); |
|
4348 |
QCOMPARE(tester.isEnabled(), true); |
|
4349 |
} |
|
4350 |
{ |
|
4351 |
// ItemMatrixChange / ItemTransformHasChanged |
|
4352 |
qVariantSetValue<QMatrix>(tester.itemChangeReturnValue, QMatrix().rotate(90)); |
|
4353 |
tester.setMatrix(QMatrix().translate(50, 0), true); |
|
4354 |
++changeCount; // notification sent too |
|
4355 |
QCOMPARE(tester.changes.size(), ++changeCount); |
|
4356 |
QCOMPARE(int(tester.changes.at(tester.changes.size() - 2)), int(QGraphicsItem::ItemMatrixChange)); |
|
4357 |
QCOMPARE(int(tester.changes.last()), int(QGraphicsItem::ItemTransformHasChanged)); |
|
4358 |
QCOMPARE(qVariantValue<QMatrix>(tester.values.at(tester.values.size() - 2)), |
|
4359 |
QMatrix().translate(50, 0)); |
|
4360 |
QCOMPARE(tester.values.last(), QVariant(QTransform(QMatrix().rotate(90)))); |
|
4361 |
QVariant variant; |
|
4362 |
qVariantSetValue<QMatrix>(variant, QMatrix()); |
|
4363 |
QCOMPARE(tester.oldValues.last(), variant); |
|
4364 |
QCOMPARE(tester.matrix(), QMatrix().rotate(90)); |
|
4365 |
} |
|
4366 |
{ |
|
4367 |
tester.resetTransform(); |
|
4368 |
++changeCount; |
|
4369 |
++changeCount; // notification sent too |
|
4370 |
||
4371 |
// ItemTransformChange / ItemTransformHasChanged |
|
4372 |
qVariantSetValue<QTransform>(tester.itemChangeReturnValue, QTransform().rotate(90)); |
|
4373 |
tester.translate(50, 0); |
|
4374 |
++changeCount; // notification sent too |
|
4375 |
++changeCount; |
|
4376 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4377 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemTransformChange); |
|
4378 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemTransformHasChanged); |
|
4379 |
QCOMPARE(qVariantValue<QTransform>(tester.values.at(tester.values.size() - 2)), |
|
4380 |
QTransform().translate(50, 0)); |
|
4381 |
QCOMPARE(qVariantValue<QTransform>(tester.values.at(tester.values.size() - 1)), |
|
4382 |
QTransform().rotate(90)); |
|
4383 |
QVariant variant; |
|
4384 |
qVariantSetValue<QTransform>(variant, QTransform()); |
|
4385 |
QCOMPARE(tester.oldValues.last(), variant); |
|
4386 |
QCOMPARE(tester.transform(), QTransform().rotate(90)); |
|
4387 |
} |
|
4388 |
{ |
|
4389 |
// ItemPositionChange / ItemPositionHasChanged |
|
4390 |
tester.itemChangeReturnValue = QPointF(42, 0); |
|
4391 |
tester.setPos(0, 42); |
|
4392 |
++changeCount; // notification sent too |
|
4393 |
++changeCount; |
|
4394 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4395 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemPositionChange); |
|
4396 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemPositionHasChanged); |
|
4397 |
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(0, 42))); |
|
4398 |
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(42, 0))); |
|
4399 |
QCOMPARE(tester.oldValues.last(), QVariant(QPointF())); |
|
4400 |
QCOMPARE(tester.pos(), QPointF(42, 0)); |
|
4401 |
} |
|
4402 |
{ |
|
4403 |
// ItemZValueChange / ItemZValueHasChanged |
|
4404 |
tester.itemChangeReturnValue = qreal(2.0); |
|
4405 |
tester.setZValue(1.0); |
|
4406 |
++changeCount; // notification sent too |
|
4407 |
++changeCount; |
|
4408 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4409 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemZValueChange); |
|
4410 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemZValueHasChanged); |
|
4411 |
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.0))); |
|
4412 |
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0))); |
|
4413 |
QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0))); |
|
4414 |
QCOMPARE(tester.zValue(), qreal(2.0)); |
|
4415 |
} |
|
4416 |
{ |
|
4417 |
// ItemFlagsChange |
|
4418 |
tester.itemChangeReturnValue = QGraphicsItem::ItemIsSelectable; |
|
4419 |
tester.setFlag(QGraphicsItem::ItemIsSelectable, false); |
|
4420 |
QCOMPARE(tester.changes.size(), changeCount); // No change |
|
4421 |
tester.setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
4422 |
++changeCount; |
|
4423 |
++changeCount; // ItemFlagsHasChanged |
|
4424 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4425 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemFlagsChange); |
|
4426 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemFlagsHaveChanged); |
|
4427 |
QVariant expectedFlags = qVariantFromValue<quint32>(QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges)); |
|
4428 |
QCOMPARE(tester.values.at(tester.values.size() - 2), expectedFlags); |
|
4429 |
QCOMPARE(tester.values.at(tester.values.size() - 1), qVariantFromValue<quint32>(QGraphicsItem::ItemIsSelectable)); |
|
4430 |
} |
|
4431 |
{ |
|
4432 |
// ItemSelectedChange |
|
4433 |
tester.setSelected(false); |
|
4434 |
QCOMPARE(tester.changes.size(), changeCount); // No change :-) |
|
4435 |
tester.itemChangeReturnValue = true; |
|
4436 |
tester.setSelected(true); |
|
4437 |
++changeCount; |
|
4438 |
++changeCount; // ItemSelectedHasChanged |
|
4439 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4440 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemSelectedChange); |
|
4441 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSelectedHasChanged); |
|
4442 |
QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(true)); |
|
4443 |
QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true)); |
|
4444 |
QCOMPARE(tester.oldValues.last(), QVariant(false)); |
|
4445 |
QCOMPARE(tester.isSelected(), true); |
|
4446 |
||
4447 |
tester.itemChangeReturnValue = false; |
|
4448 |
tester.setSelected(true); |
|
4449 |
||
4450 |
// the value hasn't changed to the itemChange return value |
|
4451 |
// bacause itemChange is never called (true -> true is a noop). |
|
4452 |
QCOMPARE(tester.isSelected(), true); |
|
4453 |
} |
|
4454 |
{ |
|
4455 |
// ItemVisibleChange |
|
4456 |
tester.itemChangeReturnValue = false; |
|
4457 |
QVERIFY(tester.isVisible()); |
|
4458 |
tester.setVisible(false); |
|
4459 |
++changeCount; // ItemVisibleChange |
|
4460 |
++changeCount; // ItemSelectedChange |
|
4461 |
++changeCount; // ItemSelectedHasChanged |
|
4462 |
++changeCount; // ItemVisibleHasChanged |
|
4463 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4464 |
QCOMPARE(tester.changes.at(tester.changes.size() - 4), QGraphicsItem::ItemVisibleChange); |
|
4465 |
QCOMPARE(tester.changes.at(tester.changes.size() - 3), QGraphicsItem::ItemSelectedChange); |
|
4466 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemSelectedHasChanged); |
|
4467 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemVisibleHasChanged); |
|
4468 |
QCOMPARE(tester.values.at(tester.values.size() - 4), QVariant(false)); |
|
4469 |
QCOMPARE(tester.values.at(tester.values.size() - 3), QVariant(false)); |
|
4470 |
QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(false)); |
|
4471 |
QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(false)); |
|
4472 |
QCOMPARE(tester.isVisible(), false); |
|
4473 |
} |
|
4474 |
{ |
|
4475 |
// ItemParentChange |
|
4476 |
qVariantSetValue<QGraphicsItem *>(tester.itemChangeReturnValue, 0); |
|
4477 |
tester.setParentItem(&testerHelper); |
|
4478 |
QCOMPARE(tester.changes.size(), ++changeCount); |
|
4479 |
QCOMPARE(tester.changes.last(), QGraphicsItem::ItemParentChange); |
|
4480 |
QCOMPARE(qVariantValue<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper); |
|
4481 |
QCOMPARE(qVariantValue<QGraphicsItem *>(tester.oldValues.last()), (QGraphicsItem *)0); |
|
4482 |
QCOMPARE(tester.parentItem(), (QGraphicsItem *)0); |
|
4483 |
} |
|
4484 |
{ |
|
4485 |
// ItemOpacityChange |
|
4486 |
tester.itemChangeReturnValue = 1.0; |
|
4487 |
tester.setOpacity(0.7); |
|
4488 |
QCOMPARE(tester.changes.size(), ++changeCount); |
|
4489 |
QCOMPARE(tester.changes.last(), QGraphicsItem::ItemOpacityChange); |
|
4490 |
QVERIFY(qFuzzyCompare(qreal(tester.values.last().toDouble()), qreal(0.7))); |
|
4491 |
QCOMPARE(tester.oldValues.last().toDouble(), double(1.0)); |
|
4492 |
QCOMPARE(tester.opacity(), qreal(1.0)); |
|
4493 |
tester.itemChangeReturnValue = 0.7; |
|
4494 |
tester.setOpacity(0.7); |
|
4495 |
++changeCount; // ItemOpacityChange |
|
4496 |
++changeCount; // ItemOpacityHasChanged |
|
4497 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4498 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemOpacityChange); |
|
4499 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemOpacityHasChanged); |
|
4500 |
QCOMPARE(tester.opacity(), qreal(0.7)); |
|
4501 |
} |
|
4502 |
{ |
|
4503 |
// ItemChildAddedChange |
|
4504 |
tester.itemChangeReturnValue.clear(); |
|
4505 |
testerHelper.setParentItem(&tester); |
|
4506 |
QCOMPARE(tester.changes.size(), ++changeCount); |
|
4507 |
QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildAddedChange); |
|
4508 |
QCOMPARE(qVariantValue<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper); |
|
4509 |
} |
|
4510 |
{ |
|
4511 |
// ItemChildRemovedChange 1 |
|
4512 |
testerHelper.setParentItem(0); |
|
4513 |
QCOMPARE(tester.changes.size(), ++changeCount); |
|
4514 |
QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildRemovedChange); |
|
4515 |
QCOMPARE(qVariantValue<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper); |
|
4516 |
||
4517 |
// ItemChildRemovedChange 1 |
|
4518 |
ItemChangeTester *test = new ItemChangeTester; |
|
4519 |
test->itemSceneChangeTargetScene = 0; |
|
4520 |
int count = 0; |
|
4521 |
QGraphicsScene *scene = new QGraphicsScene; |
|
4522 |
scene->addItem(test); |
|
4523 |
count = test->changes.size(); |
|
4524 |
//We test here the fact that when a child is deleted the parent receive only one ItemChildRemovedChange |
|
4525 |
QGraphicsRectItem *child = new QGraphicsRectItem(test); |
|
4526 |
//We received ItemChildAddedChange |
|
4527 |
QCOMPARE(test->changes.size(), ++count); |
|
4528 |
QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildAddedChange); |
|
4529 |
delete child; |
|
4530 |
child = 0; |
|
4531 |
QCOMPARE(test->changes.size(), ++count); |
|
4532 |
QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange); |
|
4533 |
||
4534 |
ItemChangeTester *childTester = new ItemChangeTester(test); |
|
4535 |
//Changes contains all sceneHasChanged and so on, we don't want to test that |
|
4536 |
int childCount = childTester->changes.size(); |
|
4537 |
//We received ItemChildAddedChange |
|
4538 |
QCOMPARE(test->changes.size(), ++count); |
|
4539 |
child = new QGraphicsRectItem(childTester); |
|
4540 |
//We received ItemChildAddedChange |
|
4541 |
QCOMPARE(childTester->changes.size(), ++childCount); |
|
4542 |
QCOMPARE(childTester->changes.last(), QGraphicsItem::ItemChildAddedChange); |
|
4543 |
//Delete the child of the top level with all its children |
|
4544 |
delete childTester; |
|
4545 |
//Only one removal |
|
4546 |
QCOMPARE(test->changes.size(), ++count); |
|
4547 |
QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange); |
|
4548 |
delete scene; |
|
4549 |
} |
|
4550 |
{ |
|
4551 |
// ItemChildRemovedChange 2 |
|
4552 |
ItemChangeTester parent; |
|
4553 |
ItemChangeTester *child = new ItemChangeTester; |
|
4554 |
child->setParentItem(&parent); |
|
4555 |
QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildAddedChange); |
|
4556 |
QCOMPARE(qVariantValue<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child); |
|
4557 |
delete child; |
|
4558 |
QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildRemovedChange); |
|
4559 |
QCOMPARE(qVariantValue<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child); |
|
4560 |
} |
|
4561 |
{ |
|
4562 |
// !!! Note: If this test crashes because of double-deletion, there's |
|
4563 |
// a bug somewhere in QGraphicsScene or QGraphicsItem. |
|
4564 |
||
4565 |
// ItemSceneChange |
|
4566 |
QGraphicsScene scene; |
|
4567 |
QGraphicsScene scene2; |
|
4568 |
scene.addItem(&tester); |
|
4569 |
++changeCount; // ItemSceneChange (scene) |
|
4570 |
++changeCount; // ItemSceneHasChanged (scene) |
|
4571 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4572 |
||
4573 |
QCOMPARE(tester.scene(), &scene); |
|
4574 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemSceneChange); |
|
4575 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSceneHasChanged); |
|
4576 |
// Item's old value was 0 |
|
4577 |
// Item's current value is scene |
|
4578 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.oldValues.last()), (QGraphicsScene *)0); |
|
4579 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene); |
|
4580 |
scene2.addItem(&tester); |
|
4581 |
++changeCount; // ItemSceneChange (0) was: (scene) |
|
4582 |
++changeCount; // ItemSceneHasChanged (0) |
|
4583 |
++changeCount; // ItemSceneChange (scene2) was: (0) |
|
4584 |
++changeCount; // ItemSceneHasChanged (scene2) |
|
4585 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4586 |
||
4587 |
QCOMPARE(tester.scene(), &scene2); |
|
4588 |
QCOMPARE(tester.changes.at(tester.changes.size() - 4), QGraphicsItem::ItemSceneChange); |
|
4589 |
QCOMPARE(tester.changes.at(tester.changes.size() - 3), QGraphicsItem::ItemSceneHasChanged); |
|
4590 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemSceneChange); |
|
4591 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSceneHasChanged); |
|
4592 |
// Item's last old value was scene |
|
4593 |
// Item's last current value is 0 |
|
4594 |
||
4595 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 2)), (QGraphicsScene *)&scene); |
|
4596 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 1)), (QGraphicsScene *)0); |
|
4597 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 4)), (QGraphicsScene *)0); |
|
4598 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), (QGraphicsScene *)0); |
|
4599 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene2); |
|
4600 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene2); |
|
4601 |
// Item's last old value was 0 |
|
4602 |
// Item's last current value is scene2 |
|
4603 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.oldValues.last()), (QGraphicsScene *)0); |
|
4604 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene2); |
|
4605 |
||
4606 |
scene2.removeItem(&tester); |
|
4607 |
++changeCount; // ItemSceneChange (0) was: (scene2) |
|
4608 |
++changeCount; // ItemSceneHasChanged (0) |
|
4609 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4610 |
||
4611 |
QCOMPARE(tester.scene(), (QGraphicsScene *)0); |
|
4612 |
QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemSceneChange); |
|
4613 |
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSceneHasChanged); |
|
4614 |
// Item's last old value was scene2 |
|
4615 |
// Item's last current value is 0 |
|
4616 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.oldValues.last()), (QGraphicsScene *)&scene2); |
|
4617 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)0); |
|
4618 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)0); |
|
4619 |
||
4620 |
tester.itemSceneChangeTargetScene = &scene; |
|
4621 |
scene2.addItem(&tester); |
|
4622 |
++changeCount; // ItemSceneChange (scene2) was: (0) |
|
4623 |
++changeCount; // ItemSceneChange (scene) was: (0) |
|
4624 |
++changeCount; // ItemSceneHasChanged (scene) |
|
4625 |
QCOMPARE(tester.values.size(), changeCount); |
|
4626 |
||
4627 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), (QGraphicsScene *)&scene2); |
|
4628 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene); |
|
4629 |
QCOMPARE(qVariantValue<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene); |
|
4630 |
||
4631 |
QCOMPARE(tester.scene(), &scene); |
|
4632 |
tester.itemSceneChangeTargetScene = 0; |
|
4633 |
tester.itemChangeReturnValue = QVariant(); |
|
4634 |
scene.removeItem(&tester); |
|
4635 |
++changeCount; // ItemSceneChange |
|
4636 |
++changeCount; // ItemSceneHasChanged |
|
4637 |
QCOMPARE(tester.scene(), (QGraphicsScene *)0); |
|
4638 |
} |
|
4639 |
{ |
|
4640 |
// ItemToolTipChange/ItemToolTipHasChanged |
|
4641 |
const QString toolTip(QLatin1String("I'm soo cool")); |
|
4642 |
const QString overridenToolTip(QLatin1String("No, you are not soo cool")); |
|
4643 |
tester.itemChangeReturnValue = overridenToolTip; |
|
4644 |
tester.setToolTip(toolTip); |
|
4645 |
++changeCount; // ItemToolTipChange |
|
4646 |
++changeCount; // ItemToolTipHasChanged |
|
4647 |
QCOMPARE(tester.changes.size(), changeCount); |
|
4648 |
QCOMPARE(tester.changes.at(changeCount - 2), QGraphicsItem::ItemToolTipChange); |
|
4649 |
QCOMPARE(tester.values.at(changeCount - 2).toString(), toolTip); |
|
4650 |
QCOMPARE(tester.changes.at(changeCount - 1), QGraphicsItem::ItemToolTipHasChanged); |
|
4651 |
QCOMPARE(tester.values.at(changeCount - 1).toString(), overridenToolTip); |
|
4652 |
QCOMPARE(tester.toolTip(), overridenToolTip); |
|
4653 |
tester.itemChangeReturnValue = QVariant(); |
|
4654 |
} |
|
4655 |
} |
|
4656 |
||
4657 |
class EventFilterTesterItem : public QGraphicsLineItem |
|
4658 |
{ |
|
4659 |
public: |
|
4660 |
QList<QEvent::Type> filteredEvents; |
|
4661 |
QList<QGraphicsItem *> filteredEventReceivers; |
|
4662 |
bool handlesSceneEvents; |
|
4663 |
||
4664 |
QList<QEvent::Type> receivedEvents; |
|
4665 |
||
4666 |
EventFilterTesterItem() : handlesSceneEvents(false) {} |
|
4667 |
||
4668 |
protected: |
|
4669 |
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
4670 |
{ |
|
4671 |
filteredEvents << event->type(); |
|
4672 |
filteredEventReceivers << watched; |
|
4673 |
return handlesSceneEvents; |
|
4674 |
} |
|
4675 |
||
4676 |
bool sceneEvent(QEvent *event) |
|
4677 |
{ |
|
4678 |
return QGraphicsLineItem::sceneEvent(event); |
|
4679 |
} |
|
4680 |
}; |
|
4681 |
||
4682 |
void tst_QGraphicsItem::sceneEventFilter() |
|
4683 |
{ |
|
4684 |
QGraphicsScene scene; |
|
4685 |
||
4686 |
QGraphicsView view(&scene); |
|
4687 |
view.show(); |
|
4688 |
QApplication::setActiveWindow(&view); |
|
4689 |
QTest::qWaitForWindowShown(&view); |
|
4690 |
QTest::qWait(25); |
|
4691 |
||
4692 |
QGraphicsTextItem *text1 = scene.addText(QLatin1String("Text1")); |
|
4693 |
QGraphicsTextItem *text2 = scene.addText(QLatin1String("Text2")); |
|
4694 |
QGraphicsTextItem *text3 = scene.addText(QLatin1String("Text3")); |
|
4695 |
text1->setFlag(QGraphicsItem::ItemIsFocusable); |
|
4696 |
text2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
4697 |
text3->setFlag(QGraphicsItem::ItemIsFocusable); |
|
4698 |
||
4699 |
EventFilterTesterItem *tester = new EventFilterTesterItem; |
|
4700 |
scene.addItem(tester); |
|
4701 |
||
4702 |
QTRY_VERIFY(!text1->hasFocus()); |
|
4703 |
text1->installSceneEventFilter(tester); |
|
4704 |
text1->setFocus(); |
|
4705 |
QTRY_VERIFY(text1->hasFocus()); |
|
4706 |
||
4707 |
QCOMPARE(tester->filteredEvents.size(), 1); |
|
4708 |
QCOMPARE(tester->filteredEvents.at(0), QEvent::FocusIn); |
|
4709 |
QCOMPARE(tester->filteredEventReceivers.at(0), static_cast<QGraphicsItem *>(text1)); |
|
4710 |
||
4711 |
text2->installSceneEventFilter(tester); |
|
4712 |
text3->installSceneEventFilter(tester); |
|
4713 |
||
4714 |
text2->setFocus(); |
|
4715 |
text3->setFocus(); |
|
4716 |
||
4717 |
QCOMPARE(tester->filteredEvents.size(), 5); |
|
4718 |
QCOMPARE(tester->filteredEvents.at(1), QEvent::FocusOut); |
|
4719 |
QCOMPARE(tester->filteredEventReceivers.at(1), static_cast<QGraphicsItem *>(text1)); |
|
4720 |
QCOMPARE(tester->filteredEvents.at(2), QEvent::FocusIn); |
|
4721 |
QCOMPARE(tester->filteredEventReceivers.at(2), static_cast<QGraphicsItem *>(text2)); |
|
4722 |
QCOMPARE(tester->filteredEvents.at(3), QEvent::FocusOut); |
|
4723 |
QCOMPARE(tester->filteredEventReceivers.at(3), static_cast<QGraphicsItem *>(text2)); |
|
4724 |
QCOMPARE(tester->filteredEvents.at(4), QEvent::FocusIn); |
|
4725 |
QCOMPARE(tester->filteredEventReceivers.at(4), static_cast<QGraphicsItem *>(text3)); |
|
4726 |
||
4727 |
text1->removeSceneEventFilter(tester); |
|
4728 |
text1->setFocus(); |
|
4729 |
||
4730 |
QCOMPARE(tester->filteredEvents.size(), 6); |
|
4731 |
QCOMPARE(tester->filteredEvents.at(5), QEvent::FocusOut); |
|
4732 |
QCOMPARE(tester->filteredEventReceivers.at(5), static_cast<QGraphicsItem *>(text3)); |
|
4733 |
||
4734 |
tester->handlesSceneEvents = true; |
|
4735 |
text2->setFocus(); |
|
4736 |
||
4737 |
QCOMPARE(tester->filteredEvents.size(), 7); |
|
4738 |
QCOMPARE(tester->filteredEvents.at(6), QEvent::FocusIn); |
|
4739 |
QCOMPARE(tester->filteredEventReceivers.at(6), static_cast<QGraphicsItem *>(text2)); |
|
4740 |
||
4741 |
QVERIFY(text2->hasFocus()); |
|
4742 |
||
4743 |
//Let check if the items are correctly removed from the sceneEventFilters array |
|
4744 |
//to avoid stale pointers. |
|
4745 |
QGraphicsView gv; |
|
4746 |
QGraphicsScene *anotherScene = new QGraphicsScene; |
|
4747 |
QGraphicsTextItem *ti = anotherScene->addText("This is a test #1"); |
|
4748 |
ti->moveBy(50, 50); |
|
4749 |
QGraphicsTextItem *ti2 = anotherScene->addText("This is a test #2"); |
|
4750 |
QGraphicsTextItem *ti3 = anotherScene->addText("This is a test #3"); |
|
4751 |
gv.setScene(anotherScene); |
|
4752 |
gv.show(); |
|
4753 |
QTest::qWaitForWindowShown(&gv); |
|
4754 |
QTest::qWait(25); |
|
4755 |
ti->installSceneEventFilter(ti2); |
|
4756 |
ti3->installSceneEventFilter(ti); |
|
4757 |
delete ti2; |
|
4758 |
//we souldn't crash |
|
4759 |
QTest::mouseMove(gv.viewport(), gv.mapFromScene(ti->scenePos())); |
|
4760 |
QTest::qWait(30); |
|
4761 |
delete ti; |
|
4762 |
} |
|
4763 |
||
4764 |
class GeometryChanger : public QGraphicsItem |
|
4765 |
{ |
|
4766 |
public: |
|
4767 |
void changeGeometry() |
|
4768 |
{ prepareGeometryChange(); } |
|
4769 |
}; |
|
4770 |
||
4771 |
void tst_QGraphicsItem::prepareGeometryChange() |
|
4772 |
{ |
|
4773 |
{ |
|
4774 |
QGraphicsScene scene; |
|
4775 |
QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); |
|
4776 |
QVERIFY(scene.items(QRectF(0, 0, 100, 100)).contains(item)); |
|
4777 |
((GeometryChanger *)item)->changeGeometry(); |
|
4778 |
QVERIFY(scene.items(QRectF(0, 0, 100, 100)).contains(item)); |
|
4779 |
} |
|
4780 |
} |
|
4781 |
||
4782 |
||
4783 |
class PaintTester : public QGraphicsRectItem |
|
4784 |
{ |
|
4785 |
public: |
|
4786 |
PaintTester() : widget(NULL), painted(0) { setRect(QRectF(10, 10, 20, 20));} |
|
4787 |
||
4788 |
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *w) |
|
4789 |
{ |
|
4790 |
widget = w; |
|
4791 |
painted++; |
|
4792 |
} |
|
4793 |
||
4794 |
QWidget* widget; |
|
4795 |
int painted; |
|
4796 |
}; |
|
4797 |
||
4798 |
void tst_QGraphicsItem::paint() |
|
4799 |
{ |
|
4800 |
QGraphicsScene scene; |
|
4801 |
||
4802 |
PaintTester paintTester; |
|
4803 |
scene.addItem(&paintTester); |
|
4804 |
||
4805 |
QGraphicsView view(&scene); |
|
4806 |
||
4807 |
view.show(); |
|
4808 |
QTest::qWaitForWindowShown(&view); |
|
4809 |
QApplication::processEvents(); |
|
4810 |
#ifdef Q_OS_WIN32 |
|
4811 |
//we try to switch the desktop: if it fails, we skip the test |
|
4812 |
if (::SwitchDesktop( ::GetThreadDesktop( ::GetCurrentThreadId() ) ) == 0) { |
|
4813 |
QSKIP("The Graphics View doesn't get the paint events", SkipSingle); |
|
4814 |
} |
|
4815 |
#endif |
|
4816 |
||
4817 |
QTRY_COMPARE(paintTester.widget, view.viewport()); |
|
4818 |
||
4819 |
view.hide(); |
|
4820 |
||
4821 |
QGraphicsScene scene2; |
|
4822 |
QGraphicsView view2(&scene2); |
|
4823 |
view2.show(); |
|
4824 |
QTest::qWaitForWindowShown(&view2); |
|
4825 |
QTest::qWait(25); |
|
4826 |
||
4827 |
PaintTester tester2; |
|
4828 |
scene2.addItem(&tester2); |
|
4829 |
qApp->processEvents(); |
|
4830 |
||
4831 |
//First show one paint |
|
4832 |
QTRY_COMPARE(tester2.painted, 1); |
|
4833 |
||
4834 |
//nominal case, update call paint |
|
4835 |
tester2.update(); |
|
4836 |
qApp->processEvents(); |
|
4837 |
QTRY_VERIFY(tester2.painted == 2); |
|
4838 |
||
4839 |
//we remove the item from the scene, number of updates is still the same |
|
4840 |
tester2.update(); |
|
4841 |
scene2.removeItem(&tester2); |
|
4842 |
qApp->processEvents(); |
|
4843 |
QTRY_VERIFY(tester2.painted == 2); |
|
4844 |
||
4845 |
//We re-add the item, the number of paint should increase |
|
4846 |
scene2.addItem(&tester2); |
|
4847 |
tester2.update(); |
|
4848 |
qApp->processEvents(); |
|
4849 |
QTRY_VERIFY(tester2.painted == 3); |
|
4850 |
} |
|
4851 |
||
4852 |
class HarakiriItem : public QGraphicsRectItem |
|
4853 |
{ |
|
4854 |
public: |
|
4855 |
HarakiriItem(int harakiriPoint) |
|
4856 |
: QGraphicsRectItem(QRectF(0, 0, 100, 100)), harakiri(harakiriPoint) |
|
4857 |
{ dead = 0; } |
|
4858 |
||
4859 |
static int dead; |
|
4860 |
||
4861 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
4862 |
{ |
|
4863 |
QGraphicsRectItem::paint(painter, option, widget); |
|
4864 |
if (harakiri == 0) { |
|
4865 |
// delete unsupported since 4.5 |
|
4866 |
/* |
|
4867 |
dead = 1; |
|
4868 |
delete this; |
|
4869 |
*/ |
|
4870 |
} |
|
4871 |
} |
|
4872 |
||
4873 |
void advance(int n) |
|
4874 |
{ |
|
4875 |
if (harakiri == 1 && n == 0) { |
|
4876 |
// delete unsupported |
|
4877 |
/* |
|
4878 |
dead = 1; |
|
4879 |
delete this; |
|
4880 |
*/ |
|
4881 |
} |
|
4882 |
if (harakiri == 2 && n == 1) { |
|
4883 |
dead = 1; |
|
4884 |
delete this; |
|
4885 |
} |
|
4886 |
} |
|
4887 |
||
4888 |
protected: |
|
4889 |
void contextMenuEvent(QGraphicsSceneContextMenuEvent *) |
|
4890 |
{ |
|
4891 |
if (harakiri == 3) { |
|
4892 |
dead = 1; |
|
4893 |
delete this; |
|
4894 |
} |
|
4895 |
} |
|
4896 |
||
4897 |
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) |
|
4898 |
{ |
|
4899 |
// ?? |
|
4900 |
QGraphicsRectItem::dragEnterEvent(event); |
|
4901 |
} |
|
4902 |
||
4903 |
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) |
|
4904 |
{ |
|
4905 |
// ?? |
|
4906 |
QGraphicsRectItem::dragLeaveEvent(event); |
|
4907 |
} |
|
4908 |
||
4909 |
void dragMoveEvent(QGraphicsSceneDragDropEvent *event) |
|
4910 |
{ |
|
4911 |
// ?? |
|
4912 |
QGraphicsRectItem::dragMoveEvent(event); |
|
4913 |
} |
|
4914 |
||
4915 |
void dropEvent(QGraphicsSceneDragDropEvent *event) |
|
4916 |
{ |
|
4917 |
// ?? |
|
4918 |
QGraphicsRectItem::dropEvent(event); |
|
4919 |
} |
|
4920 |
||
4921 |
void focusInEvent(QFocusEvent *) |
|
4922 |
{ |
|
4923 |
if (harakiri == 4) { |
|
4924 |
dead = 1; |
|
4925 |
delete this; |
|
4926 |
} |
|
4927 |
} |
|
4928 |
||
4929 |
void focusOutEvent(QFocusEvent *) |
|
4930 |
{ |
|
4931 |
if (harakiri == 5) { |
|
4932 |
dead = 1; |
|
4933 |
delete this; |
|
4934 |
} |
|
4935 |
} |
|
4936 |
||
4937 |
void hoverEnterEvent(QGraphicsSceneHoverEvent *) |
|
4938 |
{ |
|
4939 |
if (harakiri == 6) { |
|
4940 |
dead = 1; |
|
4941 |
delete this; |
|
4942 |
} |
|
4943 |
} |
|
4944 |
||
4945 |
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) |
|
4946 |
{ |
|
4947 |
if (harakiri == 7) { |
|
4948 |
dead = 1; |
|
4949 |
delete this; |
|
4950 |
} |
|
4951 |
} |
|
4952 |
||
4953 |
void hoverMoveEvent(QGraphicsSceneHoverEvent *) |
|
4954 |
{ |
|
4955 |
if (harakiri == 8) { |
|
4956 |
dead = 1; |
|
4957 |
delete this; |
|
4958 |
} |
|
4959 |
} |
|
4960 |
||
4961 |
void inputMethodEvent(QInputMethodEvent *event) |
|
4962 |
{ |
|
4963 |
// ?? |
|
4964 |
QGraphicsRectItem::inputMethodEvent(event); |
|
4965 |
} |
|
4966 |
||
4967 |
QVariant inputMethodQuery(Qt::InputMethodQuery query) const |
|
4968 |
{ |
|
4969 |
// ?? |
|
4970 |
return QGraphicsRectItem::inputMethodQuery(query); |
|
4971 |
} |
|
4972 |
||
4973 |
QVariant itemChange(GraphicsItemChange change, const QVariant &value) |
|
4974 |
{ |
|
4975 |
// deletion not supported |
|
4976 |
return QGraphicsRectItem::itemChange(change, value); |
|
4977 |
} |
|
4978 |
||
4979 |
void keyPressEvent(QKeyEvent *) |
|
4980 |
{ |
|
4981 |
if (harakiri == 9) { |
|
4982 |
dead = 1; |
|
4983 |
delete this; |
|
4984 |
} |
|
4985 |
} |
|
4986 |
||
4987 |
void keyReleaseEvent(QKeyEvent *) |
|
4988 |
{ |
|
4989 |
if (harakiri == 10) { |
|
4990 |
dead = 1; |
|
4991 |
delete this; |
|
4992 |
} |
|
4993 |
} |
|
4994 |
||
4995 |
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) |
|
4996 |
{ |
|
4997 |
if (harakiri == 11) { |
|
4998 |
dead = 1; |
|
4999 |
delete this; |
|
5000 |
} |
|
5001 |
} |
|
5002 |
||
5003 |
void mouseMoveEvent(QGraphicsSceneMouseEvent *) |
|
5004 |
{ |
|
5005 |
if (harakiri == 12) { |
|
5006 |
dead = 1; |
|
5007 |
delete this; |
|
5008 |
} |
|
5009 |
} |
|
5010 |
||
5011 |
void mousePressEvent(QGraphicsSceneMouseEvent *) |
|
5012 |
{ |
|
5013 |
if (harakiri == 13) { |
|
5014 |
dead = 1; |
|
5015 |
delete this; |
|
5016 |
} |
|
5017 |
} |
|
5018 |
||
5019 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) |
|
5020 |
{ |
|
5021 |
if (harakiri == 14) { |
|
5022 |
dead = 1; |
|
5023 |
delete this; |
|
5024 |
} |
|
5025 |
} |
|
5026 |
||
5027 |
bool sceneEvent(QEvent *event) |
|
5028 |
{ |
|
5029 |
// deletion not supported |
|
5030 |
return QGraphicsRectItem::sceneEvent(event); |
|
5031 |
} |
|
5032 |
||
5033 |
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
5034 |
{ |
|
5035 |
// deletion not supported |
|
5036 |
return QGraphicsRectItem::sceneEventFilter(watched, event); |
|
5037 |
} |
|
5038 |
||
5039 |
void wheelEvent(QGraphicsSceneWheelEvent *) |
|
5040 |
{ |
|
5041 |
if (harakiri == 16) { |
|
5042 |
dead = 1; |
|
5043 |
delete this; |
|
5044 |
} |
|
5045 |
} |
|
5046 |
||
5047 |
private: |
|
5048 |
int harakiri; |
|
5049 |
}; |
|
5050 |
||
5051 |
int HarakiriItem::dead; |
|
5052 |
||
5053 |
void tst_QGraphicsItem::deleteItemInEventHandlers() |
|
5054 |
{ |
|
5055 |
for (int i = 0; i < 17; ++i) { |
|
5056 |
QGraphicsScene scene; |
|
5057 |
HarakiriItem *item = new HarakiriItem(i); |
|
5058 |
item->setAcceptsHoverEvents(true); |
|
5059 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
5060 |
||
5061 |
scene.addItem(item); |
|
5062 |
||
5063 |
item->installSceneEventFilter(item); // <- ehey! |
|
5064 |
||
5065 |
QGraphicsView view(&scene); |
|
5066 |
view.show(); |
|
5067 |
||
5068 |
qApp->processEvents(); |
|
5069 |
qApp->processEvents(); |
|
5070 |
||
5071 |
if (!item->dead) |
|
5072 |
scene.advance(); |
|
5073 |
||
5074 |
if (!item->dead) { |
|
5075 |
QContextMenuEvent event(QContextMenuEvent::Other, |
|
5076 |
view.mapFromScene(item->scenePos())); |
|
5077 |
QCoreApplication::sendEvent(view.viewport(), &event); |
|
5078 |
} |
|
5079 |
if (!item->dead) |
|
5080 |
QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos())); |
|
5081 |
if (!item->dead) |
|
5082 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); |
|
5083 |
if (!item->dead) |
|
5084 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); |
|
5085 |
if (!item->dead) |
|
5086 |
QTest::mouseClick(view.viewport(), Qt::RightButton, 0, view.mapFromScene(item->scenePos())); |
|
5087 |
if (!item->dead) |
|
5088 |
QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos() + QPointF(20, -20))); |
|
5089 |
if (!item->dead) |
|
5090 |
item->setFocus(); |
|
5091 |
if (!item->dead) |
|
5092 |
item->clearFocus(); |
|
5093 |
if (!item->dead) |
|
5094 |
item->setFocus(); |
|
5095 |
if (!item->dead) |
|
5096 |
QTest::keyPress(view.viewport(), Qt::Key_A); |
|
5097 |
if (!item->dead) |
|
5098 |
QTest::keyRelease(view.viewport(), Qt::Key_A); |
|
5099 |
if (!item->dead) |
|
5100 |
QTest::keyPress(view.viewport(), Qt::Key_A); |
|
5101 |
if (!item->dead) |
|
5102 |
QTest::keyRelease(view.viewport(), Qt::Key_A); |
|
5103 |
} |
|
5104 |
} |
|
5105 |
||
5106 |
class ItemPaintsOutsideShape : public QGraphicsItem |
|
5107 |
{ |
|
5108 |
public: |
|
5109 |
QRectF boundingRect() const |
|
5110 |
{ |
|
5111 |
return QRectF(0, 0, 100, 100); |
|
5112 |
} |
|
5113 |
||
5114 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
5115 |
{ |
|
5116 |
painter->fillRect(-50, -50, 200, 200, Qt::red); |
|
5117 |
painter->fillRect(0, 0, 100, 100, Qt::blue); |
|
5118 |
} |
|
5119 |
}; |
|
5120 |
||
5121 |
void tst_QGraphicsItem::itemClipsToShape() |
|
5122 |
{ |
|
5123 |
QGraphicsItem *clippedItem = new ItemPaintsOutsideShape; |
|
5124 |
clippedItem->setFlag(QGraphicsItem::ItemClipsToShape); |
|
5125 |
||
5126 |
QGraphicsItem *unclippedItem = new ItemPaintsOutsideShape; |
|
5127 |
unclippedItem->setPos(200, 0); |
|
5128 |
||
5129 |
QGraphicsScene scene(-50, -50, 400, 200); |
|
5130 |
scene.addItem(clippedItem); |
|
5131 |
scene.addItem(unclippedItem); |
|
5132 |
||
5133 |
QImage image(400, 200, QImage::Format_ARGB32_Premultiplied); |
|
5134 |
image.fill(0); |
|
5135 |
QPainter painter(&image); |
|
5136 |
painter.setRenderHint(QPainter::Antialiasing); |
|
5137 |
scene.render(&painter); |
|
5138 |
painter.end(); |
|
5139 |
||
5140 |
QCOMPARE(image.pixel(45, 100), QRgb(0)); |
|
5141 |
QCOMPARE(image.pixel(100, 45), QRgb(0)); |
|
5142 |
QCOMPARE(image.pixel(155, 100), QRgb(0)); |
|
5143 |
QCOMPARE(image.pixel(45, 155), QRgb(0)); |
|
5144 |
QCOMPARE(image.pixel(55, 100), QColor(Qt::blue).rgba()); |
|
5145 |
QCOMPARE(image.pixel(100, 55), QColor(Qt::blue).rgba()); |
|
5146 |
QCOMPARE(image.pixel(145, 100), QColor(Qt::blue).rgba()); |
|
5147 |
QCOMPARE(image.pixel(55, 145), QColor(Qt::blue).rgba()); |
|
5148 |
QCOMPARE(image.pixel(245, 100), QColor(Qt::red).rgba()); |
|
5149 |
QCOMPARE(image.pixel(300, 45), QColor(Qt::red).rgba()); |
|
5150 |
QCOMPARE(image.pixel(355, 100), QColor(Qt::red).rgba()); |
|
5151 |
QCOMPARE(image.pixel(245, 155), QColor(Qt::red).rgba()); |
|
5152 |
QCOMPARE(image.pixel(255, 100), QColor(Qt::blue).rgba()); |
|
5153 |
QCOMPARE(image.pixel(300, 55), QColor(Qt::blue).rgba()); |
|
5154 |
QCOMPARE(image.pixel(345, 100), QColor(Qt::blue).rgba()); |
|
5155 |
QCOMPARE(image.pixel(255, 145), QColor(Qt::blue).rgba()); |
|
5156 |
} |
|
5157 |
||
5158 |
void tst_QGraphicsItem::itemClipsChildrenToShape() |
|
5159 |
{ |
|
5160 |
QGraphicsScene scene; |
|
5161 |
QGraphicsItem *rect = scene.addRect(0, 0, 50, 50, QPen(Qt::NoPen), QBrush(Qt::yellow)); |
|
5162 |
||
5163 |
QGraphicsItem *ellipse = scene.addEllipse(0, 0, 100, 100, QPen(Qt::NoPen), QBrush(Qt::green)); |
|
5164 |
ellipse->setParentItem(rect); |
|
5165 |
||
5166 |
QGraphicsItem *clippedEllipse = scene.addEllipse(0, 0, 50, 50, QPen(Qt::NoPen), QBrush(Qt::blue)); |
|
5167 |
clippedEllipse->setParentItem(ellipse); |
|
5168 |
||
5169 |
QGraphicsItem *clippedEllipse2 = scene.addEllipse(0, 0, 25, 25, QPen(Qt::NoPen), QBrush(Qt::red)); |
|
5170 |
clippedEllipse2->setParentItem(clippedEllipse); |
|
5171 |
||
5172 |
QGraphicsItem *clippedEllipse3 = scene.addEllipse(50, 50, 25, 25, QPen(Qt::NoPen), QBrush(Qt::red)); |
|
5173 |
clippedEllipse3->setParentItem(clippedEllipse); |
|
5174 |
||
5175 |
QVERIFY(!(ellipse->flags() & QGraphicsItem::ItemClipsChildrenToShape)); |
|
5176 |
ellipse->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
5177 |
QVERIFY((ellipse->flags() & QGraphicsItem::ItemClipsChildrenToShape)); |
|
5178 |
||
5179 |
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
5180 |
image.fill(0); |
|
5181 |
QPainter painter(&image); |
|
5182 |
painter.setRenderHint(QPainter::Antialiasing); |
|
5183 |
scene.render(&painter); |
|
5184 |
painter.end(); |
|
5185 |
||
5186 |
QCOMPARE(image.pixel(16, 16), QColor(255, 0, 0).rgba()); |
|
5187 |
QCOMPARE(image.pixel(32, 32), QColor(0, 0, 255).rgba()); |
|
5188 |
QCOMPARE(image.pixel(50, 50), QColor(0, 255, 0).rgba()); |
|
5189 |
QCOMPARE(image.pixel(12, 12), QColor(255, 255, 0).rgba()); |
|
5190 |
QCOMPARE(image.pixel(60, 60), QColor(255, 0, 0).rgba()); |
|
5191 |
} |
|
5192 |
||
5193 |
void tst_QGraphicsItem::itemClipsChildrenToShape2() |
|
5194 |
{ |
|
5195 |
QGraphicsRectItem *parent = new QGraphicsRectItem(QRectF(0, 0, 10, 10)); |
|
5196 |
QGraphicsEllipseItem *child1 = new QGraphicsEllipseItem(QRectF(50, 50, 100, 100)); |
|
5197 |
QGraphicsRectItem *child2 = new QGraphicsRectItem(QRectF(15, 15, 80, 80)); |
|
5198 |
||
5199 |
child1->setParentItem(parent); |
|
5200 |
child1->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
5201 |
child2->setParentItem(child1); |
|
5202 |
||
5203 |
parent->setBrush(Qt::blue); |
|
5204 |
child1->setBrush(Qt::green); |
|
5205 |
child2->setBrush(Qt::red); |
|
5206 |
||
5207 |
QGraphicsScene scene; |
|
5208 |
scene.addItem(parent); |
|
5209 |
||
5210 |
QCOMPARE(scene.itemAt(5, 5), (QGraphicsItem *)parent); |
|
5211 |
QCOMPARE(scene.itemAt(15, 5), (QGraphicsItem *)0); |
|
5212 |
QCOMPARE(scene.itemAt(5, 15), (QGraphicsItem *)0); |
|
5213 |
QCOMPARE(scene.itemAt(60, 60), (QGraphicsItem *)0); |
|
5214 |
QCOMPARE(scene.itemAt(140, 60), (QGraphicsItem *)0); |
|
5215 |
QCOMPARE(scene.itemAt(60, 140), (QGraphicsItem *)0); |
|
5216 |
QCOMPARE(scene.itemAt(140, 140), (QGraphicsItem *)0); |
|
5217 |
QCOMPARE(scene.itemAt(75, 75), (QGraphicsItem *)child2); |
|
5218 |
QCOMPARE(scene.itemAt(75, 100), (QGraphicsItem *)child1); |
|
5219 |
QCOMPARE(scene.itemAt(100, 75), (QGraphicsItem *)child1); |
|
5220 |
||
5221 |
#if 1 |
|
5222 |
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
5223 |
image.fill(0); |
|
5224 |
QPainter painter(&image); |
|
5225 |
scene.render(&painter); |
|
5226 |
painter.end(); |
|
5227 |
||
5228 |
QCOMPARE(image.pixel(5, 5), QColor(0, 0, 255).rgba()); |
|
5229 |
QCOMPARE(image.pixel(5, 10), QRgb(0)); |
|
5230 |
QCOMPARE(image.pixel(10, 5), QRgb(0)); |
|
5231 |
QCOMPARE(image.pixel(40, 40), QRgb(0)); |
|
5232 |
QCOMPARE(image.pixel(90, 40), QRgb(0)); |
|
5233 |
QCOMPARE(image.pixel(40, 90), QRgb(0)); |
|
5234 |
QCOMPARE(image.pixel(95, 95), QRgb(0)); |
|
5235 |
QCOMPARE(image.pixel(50, 70), QColor(0, 255, 0).rgba()); |
|
5236 |
QCOMPARE(image.pixel(70, 50), QColor(0, 255, 0).rgba()); |
|
5237 |
QCOMPARE(image.pixel(50, 60), QColor(255, 0, 0).rgba()); |
|
5238 |
QCOMPARE(image.pixel(60, 50), QColor(255, 0, 0).rgba()); |
|
5239 |
#else |
|
5240 |
QGraphicsView view(&scene); |
|
5241 |
view.show(); |
|
5242 |
QTest::qWait(5000); |
|
5243 |
#endif |
|
5244 |
} |
|
5245 |
||
5246 |
void tst_QGraphicsItem::itemClipsChildrenToShape3() |
|
5247 |
{ |
|
5248 |
// Construct a scene with nested children, each 50 pixels offset from the elder. |
|
5249 |
// Set a top-level clipping flag |
|
5250 |
QGraphicsScene scene; |
|
5251 |
QGraphicsRectItem *parent = scene.addRect( 0, 0, 150, 150 ); |
|
5252 |
QGraphicsRectItem *child = scene.addRect( 0, 0, 150, 150 ); |
|
5253 |
QGraphicsRectItem *grandchild = scene.addRect( 0, 0, 150, 150 ); |
|
5254 |
child->setParentItem(parent); |
|
5255 |
grandchild->setParentItem(child); |
|
5256 |
child->setPos( 50, 50 ); |
|
5257 |
grandchild->setPos( 50, 50 ); |
|
5258 |
parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
5259 |
||
5260 |
QCOMPARE(scene.itemAt(25,25), (QGraphicsItem *)parent); |
|
5261 |
QCOMPARE(scene.itemAt(75,75), (QGraphicsItem *)child); |
|
5262 |
QCOMPARE(scene.itemAt(125,125), (QGraphicsItem *)grandchild); |
|
5263 |
QCOMPARE(scene.itemAt(175,175), (QGraphicsItem *)0); |
|
5264 |
||
5265 |
// Move child to fully overlap the parent. The grandchild should |
|
5266 |
// now occupy two-thirds of the scene |
|
5267 |
child->prepareGeometryChange(); |
|
5268 |
child->setPos( 0, 0 ); |
|
5269 |
||
5270 |
QCOMPARE(scene.itemAt(25,25), (QGraphicsItem *)child); |
|
5271 |
QCOMPARE(scene.itemAt(75,75), (QGraphicsItem *)grandchild); |
|
5272 |
QCOMPARE(scene.itemAt(125,125), (QGraphicsItem *)grandchild); |
|
5273 |
QCOMPARE(scene.itemAt(175,175), (QGraphicsItem *)0); |
|
5274 |
} |
|
5275 |
||
5276 |
class MyProxyWidget : public QGraphicsProxyWidget |
|
5277 |
{ |
|
5278 |
public: |
|
5279 |
MyProxyWidget(QGraphicsItem *parent) : QGraphicsProxyWidget(parent) |
|
5280 |
{ |
|
5281 |
painted = false; |
|
5282 |
} |
|
5283 |
||
5284 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
5285 |
{ |
|
5286 |
QGraphicsProxyWidget::paint(painter, option, widget); |
|
5287 |
painted = true; |
|
5288 |
} |
|
5289 |
bool painted; |
|
5290 |
}; |
|
5291 |
||
5292 |
void tst_QGraphicsItem::itemClipsChildrenToShape4() |
|
5293 |
{ |
|
5294 |
QGraphicsScene scene; |
|
5295 |
QGraphicsView view(&scene); |
|
5296 |
||
5297 |
QGraphicsWidget * outerWidget = new QGraphicsWidget(); |
|
5298 |
outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); |
|
5299 |
MyProxyWidget * innerWidget = new MyProxyWidget(outerWidget); |
|
5300 |
QLabel * label = new QLabel(); |
|
5301 |
label->setText("Welcome back my friends to the show that never ends..."); |
|
5302 |
innerWidget->setWidget(label); |
|
5303 |
view.resize(300, 300); |
|
5304 |
scene.addItem(outerWidget); |
|
5305 |
outerWidget->resize( 200, 100 ); |
|
5306 |
scene.addEllipse( 100, 100, 100, 50 ); // <-- this is important to trigger the right codepath* |
|
5307 |
//now the label is shown |
|
5308 |
outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false ); |
|
5309 |
QApplication::setActiveWindow(&view); |
|
5310 |
view.show(); |
|
5311 |
QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); |
|
5312 |
QTRY_COMPARE(innerWidget->painted, true); |
|
5313 |
} |
|
5314 |
||
5315 |
void tst_QGraphicsItem::itemClipsTextChildToShape() |
|
5316 |
{ |
|
5317 |
// Construct a scene with a rect that clips its children, with one text |
|
5318 |
// child that has text that exceeds the size of the rect. |
|
5319 |
QGraphicsScene scene; |
|
5320 |
QGraphicsItem *rect = scene.addRect(0, 0, 50, 50, QPen(Qt::black), Qt::black); |
|
5321 |
rect->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
5322 |
QGraphicsTextItem *text = new QGraphicsTextItem("This is a long sentence that's wider than 50 pixels."); |
|
5323 |
text->setParentItem(rect); |
|
5324 |
||
5325 |
// Render this scene to a transparent image. |
|
5326 |
QRectF sr = scene.itemsBoundingRect(); |
|
5327 |
QImage image(sr.size().toSize(), QImage::Format_ARGB32_Premultiplied); |
|
5328 |
image.fill(0); |
|
5329 |
QPainter painter(&image); |
|
5330 |
scene.render(&painter); |
|
5331 |
||
5332 |
// Erase the area immediately underneath the rect. |
|
5333 |
painter.setCompositionMode(QPainter::CompositionMode_Source); |
|
5334 |
painter.fillRect(rect->sceneBoundingRect().translated(-sr.topLeft()).adjusted(-0.5, -0.5, 0.5, 0.5), |
|
5335 |
Qt::transparent); |
|
5336 |
painter.end(); |
|
5337 |
||
5338 |
// Check that you get a truly transparent image back (i.e., the text was |
|
5339 |
// clipped away, so there should be no trails left after erasing only the |
|
5340 |
// rect's area). |
|
5341 |
QImage emptyImage(scene.itemsBoundingRect().size().toSize(), QImage::Format_ARGB32_Premultiplied); |
|
5342 |
emptyImage.fill(0); |
|
5343 |
QCOMPARE(image, emptyImage); |
|
5344 |
} |
|
5345 |
||
5346 |
void tst_QGraphicsItem::itemClippingDiscovery() |
|
5347 |
{ |
|
5348 |
// A simple scene with an ellipse parent and two rect children, one a |
|
5349 |
// child of the other. |
|
5350 |
QGraphicsScene scene; |
|
5351 |
QGraphicsEllipseItem *clipItem = scene.addEllipse(0, 0, 100, 100); |
|
5352 |
QGraphicsRectItem *leftRectItem = scene.addRect(0, 0, 50, 100); |
|
5353 |
QGraphicsRectItem *rightRectItem = scene.addRect(50, 0, 50, 100); |
|
5354 |
leftRectItem->setParentItem(clipItem); |
|
5355 |
rightRectItem->setParentItem(clipItem); |
|
5356 |
||
5357 |
// The rects item are both visible at these points. |
|
5358 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)leftRectItem); |
|
5359 |
QCOMPARE(scene.itemAt(90, 90), (QGraphicsItem *)rightRectItem); |
|
5360 |
||
5361 |
// The ellipse clips the rects now. |
|
5362 |
clipItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
5363 |
||
5364 |
// The rect items are no longer visible at these points. |
|
5365 |
QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)0); |
|
5366 |
if (sizeof(qreal) != sizeof(double)) |
|
5367 |
QSKIP("This fails due to internal rounding errors", SkipSingle); |
|
5368 |
QCOMPARE(scene.itemAt(90, 90), (QGraphicsItem *)0); |
|
5369 |
} |
|
5370 |
||
5371 |
void tst_QGraphicsItem::ancestorFlags() |
|
5372 |
{ |
|
5373 |
QGraphicsItem *level1 = new QGraphicsRectItem; |
|
5374 |
QGraphicsItem *level21 = new QGraphicsRectItem; |
|
5375 |
level21->setParentItem(level1); |
|
5376 |
QGraphicsItem *level22 = new QGraphicsRectItem; |
|
5377 |
level22->setParentItem(level1); |
|
5378 |
QGraphicsItem *level31 = new QGraphicsRectItem; |
|
5379 |
level31->setParentItem(level21); |
|
5380 |
QGraphicsItem *level32 = new QGraphicsRectItem; |
|
5381 |
level32->setParentItem(level21); |
|
5382 |
||
5383 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5384 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5385 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5386 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); |
|
5387 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 0); |
|
5388 |
||
5389 |
// HandlesChildEvents: 1) Root level sets a flag |
|
5390 |
level1->setHandlesChildEvents(true); |
|
5391 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5392 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 1); |
|
5393 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 1); |
|
5394 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5395 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5396 |
||
5397 |
// HandlesChildEvents: 2) Root level set it again |
|
5398 |
level1->setHandlesChildEvents(true); |
|
5399 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5400 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 1); |
|
5401 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 1); |
|
5402 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5403 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5404 |
||
5405 |
// HandlesChildEvents: 3) Root level unsets a flag |
|
5406 |
level1->setHandlesChildEvents(false); |
|
5407 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5408 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5409 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5410 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); |
|
5411 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 0); |
|
5412 |
||
5413 |
// HandlesChildEvents: 4) Child item sets a flag |
|
5414 |
level21->setHandlesChildEvents(true); |
|
5415 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5416 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5417 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5418 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5419 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5420 |
||
5421 |
// HandlesChildEvents: 5) Parent item sets a flag |
|
5422 |
level1->setHandlesChildEvents(true); |
|
5423 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5424 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 1); |
|
5425 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 1); |
|
5426 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5427 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5428 |
||
5429 |
// HandlesChildEvents: 6) Child item unsets a flag |
|
5430 |
level21->setHandlesChildEvents(false); |
|
5431 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5432 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 1); |
|
5433 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 1); |
|
5434 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5435 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5436 |
||
5437 |
// HandlesChildEvents: 7) Parent item unsets a flag |
|
5438 |
level21->setHandlesChildEvents(true); |
|
5439 |
level1->setHandlesChildEvents(false); |
|
5440 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5441 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5442 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5443 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5444 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5445 |
||
5446 |
// Reparent the child to root |
|
5447 |
level21->setParentItem(0); |
|
5448 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5449 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5450 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5451 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5452 |
||
5453 |
// Reparent the child to level1 again. |
|
5454 |
level1->setHandlesChildEvents(true); |
|
5455 |
level21->setParentItem(level1); |
|
5456 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5457 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 1); |
|
5458 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 1); |
|
5459 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5460 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5461 |
||
5462 |
// Reparenting level31 back to level1. |
|
5463 |
level31->setParentItem(level1); |
|
5464 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5465 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 1); |
|
5466 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 1); |
|
5467 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5468 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5469 |
||
5470 |
// Reparenting level31 back to level21. |
|
5471 |
level31->setParentItem(0); |
|
5472 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); |
|
5473 |
level31->setParentItem(level21); |
|
5474 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5475 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 1); |
|
5476 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 1); |
|
5477 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5478 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5479 |
||
5480 |
// Level1 doesn't handle child events |
|
5481 |
level1->setHandlesChildEvents(false); |
|
5482 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5483 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5484 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5485 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); |
|
5486 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); |
|
5487 |
||
5488 |
// Nobody handles child events |
|
5489 |
level21->setHandlesChildEvents(false); |
|
5490 |
||
5491 |
for (int i = 0; i < 2; ++i) { |
|
5492 |
QGraphicsItem::GraphicsItemFlag flag = !i ? QGraphicsItem::ItemClipsChildrenToShape |
|
5493 |
: QGraphicsItem::ItemIgnoresTransformations; |
|
5494 |
int ancestorFlag = !i ? QGraphicsItemPrivate::AncestorClipsChildren |
|
5495 |
: QGraphicsItemPrivate::AncestorIgnoresTransformations; |
|
5496 |
||
5497 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5498 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5499 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5500 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); |
|
5501 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 0); |
|
5502 |
||
5503 |
// HandlesChildEvents: 1) Root level sets a flag |
|
5504 |
level1->setFlag(flag, true); |
|
5505 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5506 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), ancestorFlag); |
|
5507 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), ancestorFlag); |
|
5508 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5509 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5510 |
||
5511 |
// HandlesChildEvents: 2) Root level set it again |
|
5512 |
level1->setFlag(flag, true); |
|
5513 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5514 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), ancestorFlag); |
|
5515 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), ancestorFlag); |
|
5516 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5517 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5518 |
||
5519 |
// HandlesChildEvents: 3) Root level unsets a flag |
|
5520 |
level1->setFlag(flag, false); |
|
5521 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5522 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5523 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5524 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); |
|
5525 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 0); |
|
5526 |
||
5527 |
// HandlesChildEvents: 4) Child item sets a flag |
|
5528 |
level21->setFlag(flag, true); |
|
5529 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5530 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5531 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5532 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5533 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5534 |
||
5535 |
// HandlesChildEvents: 5) Parent item sets a flag |
|
5536 |
level1->setFlag(flag, true); |
|
5537 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5538 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), ancestorFlag); |
|
5539 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), ancestorFlag); |
|
5540 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5541 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5542 |
||
5543 |
// HandlesChildEvents: 6) Child item unsets a flag |
|
5544 |
level21->setFlag(flag, false); |
|
5545 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5546 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), ancestorFlag); |
|
5547 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), ancestorFlag); |
|
5548 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5549 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5550 |
||
5551 |
// HandlesChildEvents: 7) Parent item unsets a flag |
|
5552 |
level21->setFlag(flag, true); |
|
5553 |
level1->setFlag(flag, false); |
|
5554 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5555 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5556 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5557 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5558 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5559 |
||
5560 |
// Reparent the child to root |
|
5561 |
level21->setParentItem(0); |
|
5562 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5563 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5564 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5565 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5566 |
||
5567 |
// Reparent the child to level1 again. |
|
5568 |
level1->setFlag(flag, true); |
|
5569 |
level21->setParentItem(level1); |
|
5570 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5571 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), ancestorFlag); |
|
5572 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), ancestorFlag); |
|
5573 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5574 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5575 |
||
5576 |
// Reparenting level31 back to level1. |
|
5577 |
level31->setParentItem(level1); |
|
5578 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5579 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), ancestorFlag); |
|
5580 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), ancestorFlag); |
|
5581 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5582 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5583 |
||
5584 |
// Reparenting level31 back to level21. |
|
5585 |
level31->setParentItem(0); |
|
5586 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); |
|
5587 |
level31->setParentItem(level21); |
|
5588 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5589 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), ancestorFlag); |
|
5590 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), ancestorFlag); |
|
5591 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5592 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5593 |
||
5594 |
// Level1 doesn't handle child events |
|
5595 |
level1->setFlag(flag, false); |
|
5596 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5597 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5598 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5599 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); |
|
5600 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); |
|
5601 |
||
5602 |
// Nobody handles child events |
|
5603 |
level21->setFlag(flag, false); |
|
5604 |
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); |
|
5605 |
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); |
|
5606 |
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); |
|
5607 |
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); |
|
5608 |
QCOMPARE(int(level32->d_ptr->ancestorFlags), 0); |
|
5609 |
} |
|
5610 |
||
5611 |
delete level1; |
|
5612 |
} |
|
5613 |
||
5614 |
void tst_QGraphicsItem::untransformable() |
|
5615 |
{ |
|
5616 |
QGraphicsItem *item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); |
|
5617 |
item1->setZValue(1); |
|
5618 |
item1->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
5619 |
item1->rotate(45); |
|
5620 |
((QGraphicsEllipseItem *)item1)->setBrush(Qt::red); |
|
5621 |
||
5622 |
QGraphicsItem *item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); |
|
5623 |
item2->setParentItem(item1); |
|
5624 |
item2->rotate(45); |
|
5625 |
item2->setPos(100, 0); |
|
5626 |
((QGraphicsEllipseItem *)item2)->setBrush(Qt::green); |
|
5627 |
||
5628 |
QGraphicsItem *item3 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); |
|
5629 |
item3->setParentItem(item2); |
|
5630 |
item3->setPos(100, 0); |
|
5631 |
((QGraphicsEllipseItem *)item3)->setBrush(Qt::blue); |
|
5632 |
||
5633 |
QGraphicsScene scene(-500, -500, 1000, 1000); |
|
5634 |
scene.addItem(item1); |
|
5635 |
||
5636 |
QGraphicsView view(&scene); |
|
5637 |
view.resize(300, 300); |
|
5638 |
view.show(); |
|
5639 |
view.scale(8, 8); |
|
5640 |
view.centerOn(0, 0); |
|
5641 |
||
5642 |
// Painting with the DiagCrossPattern is really slow on Mac |
|
5643 |
// when zoomed out. (The test times out). Task to fix is 155567. |
|
5644 |
#if !defined(Q_WS_MAC) || 1 |
|
5645 |
view.setBackgroundBrush(QBrush(Qt::black, Qt::DiagCrossPattern)); |
|
5646 |
#endif |
|
5647 |
||
5648 |
QTest::qWaitForWindowShown(&view); |
|
5649 |
||
5650 |
for (int i = 0; i < 10; ++i) { |
|
5651 |
QPoint center = view.viewport()->rect().center(); |
|
5652 |
QCOMPARE(view.itemAt(center), item1); |
|
5653 |
QCOMPARE(view.itemAt(center - QPoint(40, 0)), item1); |
|
5654 |
QCOMPARE(view.itemAt(center - QPoint(-40, 0)), item1); |
|
5655 |
QCOMPARE(view.itemAt(center - QPoint(0, 40)), item1); |
|
5656 |
QCOMPARE(view.itemAt(center - QPoint(0, -40)), item1); |
|
5657 |
||
5658 |
center += QPoint(70, 70); |
|
5659 |
QCOMPARE(view.itemAt(center - QPoint(40, 0)), item2); |
|
5660 |
QCOMPARE(view.itemAt(center - QPoint(-40, 0)), item2); |
|
5661 |
QCOMPARE(view.itemAt(center - QPoint(0, 40)), item2); |
|
5662 |
QCOMPARE(view.itemAt(center - QPoint(0, -40)), item2); |
|
5663 |
||
5664 |
center += QPoint(0, 100); |
|
5665 |
QCOMPARE(view.itemAt(center - QPoint(40, 0)), item3); |
|
5666 |
QCOMPARE(view.itemAt(center - QPoint(-40, 0)), item3); |
|
5667 |
QCOMPARE(view.itemAt(center - QPoint(0, 40)), item3); |
|
5668 |
QCOMPARE(view.itemAt(center - QPoint(0, -40)), item3); |
|
5669 |
||
5670 |
view.scale(0.5, 0.5); |
|
5671 |
view.rotate(13); |
|
5672 |
view.shear(qreal(0.01), qreal(0.01)); |
|
5673 |
view.translate(10, 10); |
|
5674 |
QTest::qWait(25); |
|
5675 |
} |
|
5676 |
} |
|
5677 |
||
5678 |
class ContextMenuItem : public QGraphicsRectItem |
|
5679 |
{ |
|
5680 |
public: |
|
5681 |
ContextMenuItem() |
|
5682 |
: ignoreEvent(true), gotEvent(false), eventWasAccepted(false) |
|
5683 |
{ } |
|
5684 |
bool ignoreEvent; |
|
5685 |
bool gotEvent; |
|
5686 |
bool eventWasAccepted; |
|
5687 |
protected: |
|
5688 |
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) |
|
5689 |
{ |
|
5690 |
gotEvent = true; |
|
5691 |
eventWasAccepted = event->isAccepted(); |
|
5692 |
if (ignoreEvent) |
|
5693 |
event->ignore(); |
|
5694 |
} |
|
5695 |
}; |
|
5696 |
||
5697 |
void tst_QGraphicsItem::contextMenuEventPropagation() |
|
5698 |
{ |
|
5699 |
ContextMenuItem *bottomItem = new ContextMenuItem; |
|
5700 |
bottomItem->setRect(0, 0, 100, 100); |
|
5701 |
ContextMenuItem *topItem = new ContextMenuItem; |
|
5702 |
topItem->setParentItem(bottomItem); |
|
5703 |
topItem->setRect(0, 0, 100, 100); |
|
5704 |
||
5705 |
QGraphicsScene scene; |
|
5706 |
||
5707 |
QGraphicsView view(&scene); |
|
5708 |
view.setAlignment(Qt::AlignLeft | Qt::AlignTop); |
|
5709 |
view.show(); |
|
5710 |
view.resize(200, 200); |
|
5711 |
QTest::qWaitForWindowShown(&view); |
|
5712 |
QTest::qWait(20); |
|
5713 |
||
5714 |
QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(10, 10), |
|
5715 |
view.viewport()->mapToGlobal(QPoint(10, 10))); |
|
5716 |
event.ignore(); |
|
5717 |
QApplication::sendEvent(view.viewport(), &event); |
|
5718 |
QVERIFY(!event.isAccepted()); |
|
5719 |
||
5720 |
scene.addItem(bottomItem); |
|
5721 |
topItem->ignoreEvent = true; |
|
5722 |
bottomItem->ignoreEvent = true; |
|
5723 |
||
5724 |
QApplication::sendEvent(view.viewport(), &event); |
|
5725 |
QVERIFY(!event.isAccepted()); |
|
5726 |
QCOMPARE(topItem->gotEvent, true); |
|
5727 |
QCOMPARE(topItem->eventWasAccepted, true); |
|
5728 |
QCOMPARE(bottomItem->gotEvent, true); |
|
5729 |
QCOMPARE(bottomItem->eventWasAccepted, true); |
|
5730 |
||
5731 |
topItem->ignoreEvent = false; |
|
5732 |
topItem->gotEvent = false; |
|
5733 |
bottomItem->gotEvent = false; |
|
5734 |
||
5735 |
QApplication::sendEvent(view.viewport(), &event); |
|
5736 |
QVERIFY(event.isAccepted()); |
|
5737 |
QCOMPARE(topItem->gotEvent, true); |
|
5738 |
QCOMPARE(bottomItem->gotEvent, false); |
|
5739 |
QCOMPARE(topItem->eventWasAccepted, true); |
|
5740 |
} |
|
5741 |
||
5742 |
void tst_QGraphicsItem::itemIsMovable() |
|
5743 |
{ |
|
5744 |
QGraphicsRectItem *rect = new QGraphicsRectItem(-50, -50, 100, 100); |
|
5745 |
rect->setFlag(QGraphicsItem::ItemIsMovable); |
|
5746 |
||
5747 |
QGraphicsScene scene; |
|
5748 |
scene.addItem(rect); |
|
5749 |
||
5750 |
{ |
|
5751 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
5752 |
event.setButton(Qt::LeftButton); |
|
5753 |
event.setButtons(Qt::LeftButton); |
|
5754 |
qApp->sendEvent(&scene, &event); |
|
5755 |
} |
|
5756 |
{ |
|
5757 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
5758 |
event.setButton(Qt::LeftButton); |
|
5759 |
event.setButtons(Qt::LeftButton); |
|
5760 |
qApp->sendEvent(&scene, &event); |
|
5761 |
} |
|
5762 |
QCOMPARE(rect->pos(), QPointF(0, 0)); |
|
5763 |
{ |
|
5764 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
5765 |
event.setButtons(Qt::LeftButton); |
|
5766 |
event.setScenePos(QPointF(10, 10)); |
|
5767 |
qApp->sendEvent(&scene, &event); |
|
5768 |
} |
|
5769 |
QCOMPARE(rect->pos(), QPointF(10, 10)); |
|
5770 |
{ |
|
5771 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
5772 |
event.setButtons(Qt::RightButton); |
|
5773 |
event.setScenePos(QPointF(20, 20)); |
|
5774 |
qApp->sendEvent(&scene, &event); |
|
5775 |
} |
|
5776 |
QCOMPARE(rect->pos(), QPointF(10, 10)); |
|
5777 |
{ |
|
5778 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); |
|
5779 |
event.setButtons(Qt::LeftButton); |
|
5780 |
event.setScenePos(QPointF(30, 30)); |
|
5781 |
qApp->sendEvent(&scene, &event); |
|
5782 |
} |
|
5783 |
QCOMPARE(rect->pos(), QPointF(30, 30)); |
|
5784 |
} |
|
5785 |
||
5786 |
class ItemAddScene : public QGraphicsScene |
|
5787 |
{ |
|
5788 |
Q_OBJECT |
|
5789 |
public: |
|
5790 |
ItemAddScene() |
|
5791 |
{ |
|
5792 |
QTimer::singleShot(500, this, SLOT(newTextItem())); |
|
5793 |
} |
|
5794 |
||
5795 |
public slots: |
|
5796 |
void newTextItem() |
|
5797 |
{ |
|
5798 |
// Add a text item |
|
5799 |
QGraphicsItem *item = new QGraphicsTextItem("This item will not ensure that it's visible", 0, this); |
|
5800 |
item->setPos(.0, .0); |
|
5801 |
item->show(); |
|
5802 |
} |
|
5803 |
}; |
|
5804 |
||
5805 |
void tst_QGraphicsItem::task141694_textItemEnsureVisible() |
|
5806 |
{ |
|
5807 |
ItemAddScene scene; |
|
5808 |
scene.setSceneRect(-1000, -1000, 2000, 2000); |
|
5809 |
||
5810 |
QGraphicsView view(&scene); |
|
5811 |
view.setFixedSize(200, 200); |
|
5812 |
view.show(); |
|
5813 |
QTest::qWaitForWindowShown(&view); |
|
5814 |
||
5815 |
view.ensureVisible(-1000, -1000, 5, 5); |
|
5816 |
int hscroll = view.horizontalScrollBar()->value(); |
|
5817 |
int vscroll = view.verticalScrollBar()->value(); |
|
5818 |
||
5819 |
QTest::qWait(10); |
|
5820 |
||
5821 |
// This should not cause the view to scroll |
|
5822 |
QTRY_COMPARE(view.horizontalScrollBar()->value(), hscroll); |
|
5823 |
QCOMPARE(view.verticalScrollBar()->value(), vscroll); |
|
5824 |
} |
|
5825 |
||
5826 |
void tst_QGraphicsItem::task128696_textItemEnsureMovable() |
|
5827 |
{ |
|
5828 |
QGraphicsTextItem *item = new QGraphicsTextItem; |
|
5829 |
item->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); |
|
5830 |
item->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
5831 |
item->setPlainText("abc de\nf ghi\n j k l"); |
|
5832 |
||
5833 |
QGraphicsScene scene; |
|
5834 |
scene.setSceneRect(-100, -100, 200, 200); |
|
5835 |
scene.addItem(item); |
|
5836 |
||
5837 |
QGraphicsView view(&scene); |
|
5838 |
view.setFixedSize(200, 200); |
|
5839 |
view.show(); |
|
5840 |
||
5841 |
QGraphicsSceneMouseEvent event1(QEvent::GraphicsSceneMousePress); |
|
5842 |
event1.setScenePos(QPointF(0, 0)); |
|
5843 |
event1.setButton(Qt::LeftButton); |
|
5844 |
event1.setButtons(Qt::LeftButton); |
|
5845 |
QApplication::sendEvent(&scene, &event1); |
|
5846 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); |
|
5847 |
||
5848 |
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove); |
|
5849 |
event2.setScenePos(QPointF(10, 10)); |
|
5850 |
event2.setButton(Qt::LeftButton); |
|
5851 |
event2.setButtons(Qt::LeftButton); |
|
5852 |
QApplication::sendEvent(&scene, &event2); |
|
5853 |
QCOMPARE(item->pos(), QPointF(10, 10)); |
|
5854 |
} |
|
5855 |
||
5856 |
void tst_QGraphicsItem::task177918_lineItemUndetected() |
|
5857 |
{ |
|
5858 |
QGraphicsScene scene; |
|
5859 |
QGraphicsLineItem *line = scene.addLine(10, 10, 10, 10); |
|
5860 |
QCOMPARE(line->boundingRect(), QRectF(10, 10, 0, 0)); |
|
5861 |
||
5862 |
QVERIFY(!scene.items(9, 9, 2, 2, Qt::IntersectsItemShape).isEmpty()); |
|
5863 |
QVERIFY(!scene.items(9, 9, 2, 2, Qt::ContainsItemShape).isEmpty()); |
|
5864 |
QVERIFY(!scene.items(9, 9, 2, 2, Qt::IntersectsItemBoundingRect).isEmpty()); |
|
5865 |
QVERIFY(!scene.items(9, 9, 2, 2, Qt::ContainsItemBoundingRect).isEmpty()); |
|
5866 |
} |
|
5867 |
||
5868 |
void tst_QGraphicsItem::task240400_clickOnTextItem_data() |
|
5869 |
{ |
|
5870 |
QTest::addColumn<int>("flags"); |
|
5871 |
QTest::addColumn<int>("textFlags"); |
|
5872 |
QTest::newRow("editor, noflags") << 0 << int(Qt::TextEditorInteraction); |
|
5873 |
QTest::newRow("editor, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::TextEditorInteraction); |
|
5874 |
QTest::newRow("editor, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::TextEditorInteraction); |
|
5875 |
QTest::newRow("editor, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable) |
|
5876 |
<< int(Qt::TextEditorInteraction); |
|
5877 |
QTest::newRow("noninteractive, noflags") << 0 << int(Qt::NoTextInteraction); |
|
5878 |
QTest::newRow("noninteractive, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::NoTextInteraction); |
|
5879 |
QTest::newRow("noninteractive, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::NoTextInteraction); |
|
5880 |
QTest::newRow("noninteractive, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable) |
|
5881 |
<< int(Qt::NoTextInteraction); |
|
5882 |
} |
|
5883 |
||
5884 |
void tst_QGraphicsItem::task240400_clickOnTextItem() |
|
5885 |
{ |
|
5886 |
QFETCH(int, flags); |
|
5887 |
QFETCH(int, textFlags); |
|
5888 |
||
5889 |
QGraphicsScene scene; |
|
5890 |
QEvent activate(QEvent::WindowActivate); |
|
5891 |
QApplication::sendEvent(&scene, &activate); |
|
5892 |
||
5893 |
QGraphicsTextItem *item = scene.addText("Hello"); |
|
5894 |
item->setFlags(QGraphicsItem::GraphicsItemFlags(flags)); |
|
5895 |
item->setTextInteractionFlags(Qt::TextInteractionFlags(textFlags)); |
|
5896 |
bool focusable = (item->flags() & QGraphicsItem::ItemIsFocusable); |
|
5897 |
QVERIFY(textFlags ? focusable : !focusable); |
|
5898 |
||
5899 |
int column = item->textCursor().columnNumber(); |
|
5900 |
QCOMPARE(column, 0); |
|
5901 |
||
5902 |
QVERIFY(!item->hasFocus()); |
|
5903 |
||
5904 |
// Click in the top-left corner of the item |
|
5905 |
{ |
|
5906 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
5907 |
event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1)); |
|
5908 |
event.setButton(Qt::LeftButton); |
|
5909 |
event.setButtons(Qt::LeftButton); |
|
5910 |
QApplication::sendEvent(&scene, &event); |
|
5911 |
} |
|
5912 |
if (flags || textFlags) |
|
5913 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); |
|
5914 |
else |
|
5915 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
5916 |
{ |
|
5917 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
5918 |
event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1)); |
|
5919 |
event.setButton(Qt::LeftButton); |
|
5920 |
event.setButtons(0); |
|
5921 |
QApplication::sendEvent(&scene, &event); |
|
5922 |
} |
|
5923 |
if (textFlags) |
|
5924 |
QVERIFY(item->hasFocus()); |
|
5925 |
else |
|
5926 |
QVERIFY(!item->hasFocus()); |
|
5927 |
QVERIFY(!scene.mouseGrabberItem()); |
|
5928 |
bool selectable = (flags & QGraphicsItem::ItemIsSelectable); |
|
5929 |
QVERIFY(selectable ? item->isSelected() : !item->isSelected()); |
|
5930 |
||
5931 |
// Now click in the middle and check that the cursor moved. |
|
5932 |
{ |
|
5933 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
5934 |
event.setScenePos(item->sceneBoundingRect().center()); |
|
5935 |
event.setButton(Qt::LeftButton); |
|
5936 |
event.setButtons(Qt::LeftButton); |
|
5937 |
QApplication::sendEvent(&scene, &event); |
|
5938 |
} |
|
5939 |
if (flags || textFlags) |
|
5940 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); |
|
5941 |
else |
|
5942 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
5943 |
{ |
|
5944 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
5945 |
event.setScenePos(item->sceneBoundingRect().center()); |
|
5946 |
event.setButton(Qt::LeftButton); |
|
5947 |
event.setButtons(0); |
|
5948 |
QApplication::sendEvent(&scene, &event); |
|
5949 |
} |
|
5950 |
if (textFlags) |
|
5951 |
QVERIFY(item->hasFocus()); |
|
5952 |
else |
|
5953 |
QVERIFY(!item->hasFocus()); |
|
5954 |
QVERIFY(!scene.mouseGrabberItem()); |
|
5955 |
||
5956 |
QVERIFY(selectable ? item->isSelected() : !item->isSelected()); |
|
5957 |
||
5958 |
// |
|
5959 |
if (textFlags & Qt::TextEditorInteraction) |
|
5960 |
QVERIFY(item->textCursor().columnNumber() > column); |
|
5961 |
else |
|
5962 |
QCOMPARE(item->textCursor().columnNumber(), 0); |
|
5963 |
} |
|
5964 |
||
5965 |
class TextItem : public QGraphicsSimpleTextItem |
|
5966 |
{ |
|
5967 |
public: |
|
5968 |
TextItem(const QString& text) : QGraphicsSimpleTextItem(text) |
|
5969 |
{ |
|
5970 |
updates = 0; |
|
5971 |
} |
|
5972 |
||
5973 |
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) |
|
5974 |
{ |
|
5975 |
updates++; |
|
5976 |
QGraphicsSimpleTextItem::paint(painter, option, widget); |
|
5977 |
} |
|
5978 |
||
5979 |
int updates; |
|
5980 |
}; |
|
5981 |
||
5982 |
void tst_QGraphicsItem::ensureUpdateOnTextItem() |
|
5983 |
{ |
|
5984 |
QGraphicsScene scene; |
|
5985 |
QGraphicsView view(&scene); |
|
5986 |
view.show(); |
|
5987 |
QTest::qWaitForWindowShown(&view); |
|
5988 |
QTest::qWait(25); |
|
5989 |
TextItem *text1 = new TextItem(QLatin1String("123")); |
|
5990 |
scene.addItem(text1); |
|
5991 |
qApp->processEvents(); |
|
5992 |
QTRY_COMPARE(text1->updates,1); |
|
5993 |
||
5994 |
//same bouding rect but we have to update |
|
5995 |
text1->setText(QLatin1String("321")); |
|
5996 |
qApp->processEvents(); |
|
5997 |
QTRY_COMPARE(text1->updates,2); |
|
5998 |
} |
|
5999 |
||
6000 |
void tst_QGraphicsItem::task243707_addChildBeforeParent() |
|
6001 |
{ |
|
6002 |
// Task reports that adding the child before the parent leads to an |
|
6003 |
// inconsistent internal state that can cause a crash. This test shows |
|
6004 |
// one such crash. |
|
6005 |
QGraphicsScene scene; |
|
6006 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
6007 |
QGraphicsWidget *widget2 = new QGraphicsWidget(widget); |
|
6008 |
scene.addItem(widget2); |
|
6009 |
QVERIFY(!widget2->parentItem()); |
|
6010 |
scene.addItem(widget); |
|
6011 |
QVERIFY(!widget->commonAncestorItem(widget2)); |
|
6012 |
QVERIFY(!widget2->commonAncestorItem(widget)); |
|
6013 |
} |
|
6014 |
||
6015 |
void tst_QGraphicsItem::task197802_childrenVisibility() |
|
6016 |
{ |
|
6017 |
QGraphicsScene scene; |
|
6018 |
QGraphicsRectItem item(QRectF(0,0,20,20)); |
|
6019 |
||
6020 |
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(0,0,10,10), &item); |
|
6021 |
scene.addItem(&item); |
|
6022 |
||
6023 |
//freshly created: both visible |
|
6024 |
QVERIFY(item.isVisible()); |
|
6025 |
QVERIFY(item2->isVisible()); |
|
6026 |
||
6027 |
//hide child: parent visible, child not |
|
6028 |
item2->hide(); |
|
6029 |
QVERIFY(item.isVisible()); |
|
6030 |
QVERIFY(!item2->isVisible()); |
|
6031 |
||
6032 |
//hide parent: parent and child invisible |
|
6033 |
item.hide(); |
|
6034 |
QVERIFY(!item.isVisible()); |
|
6035 |
QVERIFY(!item2->isVisible()); |
|
6036 |
||
6037 |
//ask to show the child: parent and child invisible anyways |
|
6038 |
item2->show(); |
|
6039 |
QVERIFY(!item.isVisible()); |
|
6040 |
QVERIFY(!item2->isVisible()); |
|
6041 |
||
6042 |
//show the parent: both parent and child visible |
|
6043 |
item.show(); |
|
6044 |
QVERIFY(item.isVisible()); |
|
6045 |
QVERIFY(item2->isVisible()); |
|
6046 |
||
6047 |
delete item2; |
|
6048 |
} |
|
6049 |
||
6050 |
void tst_QGraphicsItem::boundingRegion_data() |
|
6051 |
{ |
|
6052 |
QTest::addColumn<QLineF>("line"); |
|
6053 |
QTest::addColumn<qreal>("granularity"); |
|
6054 |
QTest::addColumn<QTransform>("transform"); |
|
6055 |
QTest::addColumn<QRegion>("expectedRegion"); |
|
6056 |
||
6057 |
QTest::newRow("(0, 0, 10, 10) | 0.0 | identity | {(0, 0, 10, 10)}") << QLineF(0, 0, 10, 10) << qreal(0.0) << QTransform() |
|
6058 |
<< QRegion(QRect(0, 0, 10, 10)); |
|
6059 |
{ |
|
6060 |
QRegion r; |
|
6061 |
r += QRect(0, 0, 6, 2); |
|
6062 |
r += QRect(0, 2, 8, 2); |
|
6063 |
r += QRect(0, 4, 10, 2); |
|
6064 |
r += QRect(2, 6, 8, 2); |
|
6065 |
r += QRect(4, 8, 6, 2); |
|
6066 |
QTest::newRow("(0, 0, 10, 10) | 0.5 | identity | {(0, 0, 10, 10)}") << QLineF(0, 0, 10, 10) << qreal(0.5) << QTransform() << r; |
|
6067 |
} |
|
6068 |
{ |
|
6069 |
QRegion r; |
|
6070 |
r += QRect(0, 0, 4, 1); r += QRect(0, 1, 5, 1); r += QRect(0, 2, 6, 1); |
|
6071 |
r += QRect(0, 3, 7, 1); r += QRect(1, 4, 7, 1); r += QRect(2, 5, 7, 1); |
|
6072 |
r += QRect(3, 6, 7, 1); r += QRect(4, 7, 6, 1); r += QRect(5, 8, 5, 1); |
|
6073 |
r += QRect(6, 9, 4, 1); |
|
6074 |
QTest::newRow("(0, 0, 10, 10) | 1.0 | identity | {(0, 0, 10, 10)}") << QLineF(0, 0, 10, 10) << qreal(1.0) << QTransform() << r; |
|
6075 |
} |
|
6076 |
QTest::newRow("(0, 0, 10, 0) | 0.0 | identity | {(0, 0, 10, 10)}") << QLineF(0, 0, 10, 0) << qreal(0.0) << QTransform() |
|
6077 |
<< QRegion(QRect(0, 0, 10, 1)); |
|
6078 |
QTest::newRow("(0, 0, 10, 0) | 0.5 | identity | {(0, 0, 10, 1)}") << QLineF(0, 0, 10, 0) << qreal(0.5) << QTransform() |
|
6079 |
<< QRegion(QRect(0, 0, 10, 1)); |
|
6080 |
QTest::newRow("(0, 0, 10, 0) | 1.0 | identity | {(0, 0, 10, 1)}") << QLineF(0, 0, 10, 0) << qreal(1.0) << QTransform() |
|
6081 |
<< QRegion(QRect(0, 0, 10, 1)); |
|
6082 |
QTest::newRow("(0, 0, 0, 10) | 0.0 | identity | {(0, 0, 10, 10)}") << QLineF(0, 0, 0, 10) << qreal(0.0) << QTransform() |
|
6083 |
<< QRegion(QRect(0, 0, 1, 10)); |
|
6084 |
QTest::newRow("(0, 0, 0, 10) | 0.5 | identity | {(0, 0, 1, 10)}") << QLineF(0, 0, 0, 10) << qreal(0.5) << QTransform() |
|
6085 |
<< QRegion(QRect(0, 0, 1, 10)); |
|
6086 |
QTest::newRow("(0, 0, 0, 10) | 1.0 | identity | {(0, 0, 1, 10)}") << QLineF(0, 0, 0, 10) << qreal(1.0) << QTransform() |
|
6087 |
<< QRegion(QRect(0, 0, 1, 10)); |
|
6088 |
} |
|
6089 |
||
6090 |
void tst_QGraphicsItem::boundingRegion() |
|
6091 |
{ |
|
6092 |
QFETCH(QLineF, line); |
|
6093 |
QFETCH(qreal, granularity); |
|
6094 |
QFETCH(QTransform, transform); |
|
6095 |
QFETCH(QRegion, expectedRegion); |
|
6096 |
||
6097 |
QGraphicsLineItem item(line); |
|
6098 |
QCOMPARE(item.boundingRegionGranularity(), qreal(0.0)); |
|
6099 |
item.setBoundingRegionGranularity(granularity); |
|
6100 |
QCOMPARE(item.boundingRegionGranularity(), granularity); |
|
6101 |
QCOMPARE(item.boundingRegion(transform), expectedRegion); |
|
6102 |
} |
|
6103 |
||
6104 |
void tst_QGraphicsItem::itemTransform_parentChild() |
|
6105 |
{ |
|
6106 |
QGraphicsScene scene; |
|
6107 |
QGraphicsItem *parent = scene.addRect(0, 0, 100, 100); |
|
6108 |
QGraphicsItem *child = scene.addRect(0, 0, 100, 100); |
|
6109 |
child->setParentItem(parent); |
|
6110 |
child->setPos(10, 10); |
|
6111 |
child->scale(2, 2); |
|
6112 |
child->rotate(90); |
|
6113 |
||
6114 |
QCOMPARE(child->itemTransform(parent).map(QPointF(10, 10)), QPointF(-10, 30)); |
|
6115 |
QCOMPARE(parent->itemTransform(child).map(QPointF(-10, 30)), QPointF(10, 10)); |
|
6116 |
} |
|
6117 |
||
6118 |
void tst_QGraphicsItem::itemTransform_siblings() |
|
6119 |
{ |
|
6120 |
QGraphicsScene scene; |
|
6121 |
QGraphicsItem *parent = scene.addRect(0, 0, 100, 100); |
|
6122 |
QGraphicsItem *brother = scene.addRect(0, 0, 100, 100); |
|
6123 |
QGraphicsItem *sister = scene.addRect(0, 0, 100, 100); |
|
6124 |
parent->scale(10, 5); |
|
6125 |
parent->rotate(-180); |
|
6126 |
parent->shear(2, 3); |
|
6127 |
||
6128 |
brother->setParentItem(parent); |
|
6129 |
sister->setParentItem(parent); |
|
6130 |
||
6131 |
brother->setPos(10, 10); |
|
6132 |
brother->scale(2, 2); |
|
6133 |
brother->rotate(90); |
|
6134 |
sister->setPos(10, 10); |
|
6135 |
sister->scale(2, 2); |
|
6136 |
sister->rotate(90); |
|
6137 |
||
6138 |
QCOMPARE(brother->itemTransform(sister).map(QPointF(10, 10)), QPointF(10, 10)); |
|
6139 |
QCOMPARE(sister->itemTransform(brother).map(QPointF(10, 10)), QPointF(10, 10)); |
|
6140 |
} |
|
6141 |
||
6142 |
void tst_QGraphicsItem::itemTransform_unrelated() |
|
6143 |
{ |
|
6144 |
QGraphicsScene scene; |
|
6145 |
QGraphicsItem *stranger1 = scene.addRect(0, 0, 100, 100); |
|
6146 |
QGraphicsItem *stranger2 = scene.addRect(0, 0, 100, 100); |
|
6147 |
stranger1->setPos(10, 10); |
|
6148 |
stranger1->scale(2, 2); |
|
6149 |
stranger1->rotate(90); |
|
6150 |
stranger2->setPos(10, 10); |
|
6151 |
stranger2->scale(2, 2); |
|
6152 |
stranger2->rotate(90); |
|
6153 |
||
6154 |
QCOMPARE(stranger1->itemTransform(stranger2).map(QPointF(10, 10)), QPointF(10, 10)); |
|
6155 |
QCOMPARE(stranger2->itemTransform(stranger1).map(QPointF(10, 10)), QPointF(10, 10)); |
|
6156 |
} |
|
6157 |
||
6158 |
void tst_QGraphicsItem::opacity_data() |
|
6159 |
{ |
|
6160 |
QTest::addColumn<qreal>("p_opacity"); |
|
6161 |
QTest::addColumn<int>("p_opacityFlags"); |
|
6162 |
QTest::addColumn<qreal>("c1_opacity"); |
|
6163 |
QTest::addColumn<int>("c1_opacityFlags"); |
|
6164 |
QTest::addColumn<qreal>("c2_opacity"); |
|
6165 |
QTest::addColumn<int>("c2_opacityFlags"); |
|
6166 |
QTest::addColumn<qreal>("p_effectiveOpacity"); |
|
6167 |
QTest::addColumn<qreal>("c1_effectiveOpacity"); |
|
6168 |
QTest::addColumn<qreal>("c2_effectiveOpacity"); |
|
6169 |
QTest::addColumn<qreal>("c3_effectiveOpacity"); |
|
6170 |
||
6171 |
// Modify the opacity and see how it propagates |
|
6172 |
QTest::newRow("A: 1.0 0 1.0 0 1.0 1.0 1.0 1.0 1.0") << qreal(1.0) << 0 << qreal(1.0) << 0 << qreal(1.0) << 0 |
|
6173 |
<< qreal(1.0) << qreal(1.0) << qreal(1.0) << qreal(1.0); |
|
6174 |
QTest::newRow("B: 0.5 0 1.0 0 1.0 1.0 1.0 1.0 1.0") << qreal(0.5) << 0 << qreal(1.0) << 0 << qreal(1.0) << 0 |
|
6175 |
<< qreal(0.5) << qreal(0.5) << qreal(0.5) << qreal(0.5); |
|
6176 |
QTest::newRow("C: 0.5 0 0.1 0 1.0 1.0 1.0 1.0 1.0") << qreal(0.5) << 0 << qreal(0.1) << 0 << qreal(1.0) << 0 |
|
6177 |
<< qreal(0.5) << qreal(0.05) << qreal(0.05) << qreal(0.05); |
|
6178 |
QTest::newRow("D: 0.0 0 1.0 0 1.0 1.0 1.0 1.0 1.0") << qreal(0.0) << 0 << qreal(1.0) << 0 << qreal(1.0) << 0 |
|
6179 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(0.0); |
|
6180 |
||
6181 |
// Parent doesn't propagate to children - now modify the opacity and see how it propagates |
|
6182 |
int flags = QGraphicsItem::ItemDoesntPropagateOpacityToChildren; |
|
6183 |
QTest::newRow("E: 1.0 2 1.0 0 1.0 1.0 1.0 1.0 1.0") << qreal(1.0) << flags << qreal(1.0) << 0 << qreal(1.0) << 0 |
|
6184 |
<< qreal(1.0) << qreal(1.0) << qreal(1.0) << qreal(1.0); |
|
6185 |
QTest::newRow("F: 0.5 2 1.0 0 1.0 1.0 1.0 1.0 1.0") << qreal(0.5) << flags << qreal(1.0) << 0 << qreal(1.0) << 0 |
|
6186 |
<< qreal(0.5) << qreal(1.0) << qreal(1.0) << qreal(1.0); |
|
6187 |
QTest::newRow("G: 0.5 2 0.1 0 1.0 1.0 1.0 1.0 1.0") << qreal(0.5) << flags << qreal(0.1) << 0 << qreal(1.0) << 0 |
|
6188 |
<< qreal(0.5) << qreal(0.1) << qreal(0.1) << qreal(0.1); |
|
6189 |
QTest::newRow("H: 0.0 2 1.0 0 1.0 1.0 1.0 1.0 1.0") << qreal(0.0) << flags << qreal(1.0) << 0 << qreal(1.0) << 0 |
|
6190 |
<< qreal(0.0) << qreal(1.0) << qreal(1.0) << qreal(1.0); |
|
6191 |
||
6192 |
// Child ignores parent - now modify the opacity and see how it propagates |
|
6193 |
flags = QGraphicsItem::ItemIgnoresParentOpacity; |
|
6194 |
QTest::newRow("I: 1.0 0 1.0 1 1.0 1.0 1.0 1.0 1.0") << qreal(1.0) << 0 << qreal(1.0) << flags << qreal(1.0) << 0 |
|
6195 |
<< qreal(1.0) << qreal(1.0) << qreal(1.0) << qreal(1.0); |
|
6196 |
QTest::newRow("J: 1.0 0 1.0 1 1.0 1.0 1.0 1.0 1.0") << qreal(0.5) << 0 << qreal(0.5) << flags << qreal(0.5) << 0 |
|
6197 |
<< qreal(0.5) << qreal(0.5) << qreal(0.25) << qreal(0.25); |
|
6198 |
QTest::newRow("K: 1.0 0 1.0 1 1.0 1.0 1.0 1.0 1.0") << qreal(0.2) << 0 << qreal(0.2) << flags << qreal(0.2) << 0 |
|
6199 |
<< qreal(0.2) << qreal(0.2) << qreal(0.04) << qreal(0.04); |
|
6200 |
QTest::newRow("L: 1.0 0 1.0 1 1.0 1.0 1.0 1.0 1.0") << qreal(0.0) << 0 << qreal(0.0) << flags << qreal(0.0) << 0 |
|
6201 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(0.0); |
|
6202 |
||
6203 |
// Child ignores parent and doesn't propagate - now modify the opacity and see how it propagates |
|
6204 |
flags = QGraphicsItem::ItemIgnoresParentOpacity | QGraphicsItem::ItemDoesntPropagateOpacityToChildren; |
|
6205 |
QTest::newRow("M: 1.0 0 1.0 1 1.0 1.0 1.0 1.0 1.0") << qreal(1.0) << 0 // p |
|
6206 |
<< qreal(1.0) << flags // c1 (no prop) |
|
6207 |
<< qreal(1.0) << 0 // c2 |
|
6208 |
<< qreal(1.0) << qreal(1.0) << qreal(1.0) << qreal(1.0); |
|
6209 |
QTest::newRow("M: 0.5 0 1.0 1 1.0 1.0 1.0 1.0 1.0") << qreal(0.5) << 0 // p |
|
6210 |
<< qreal(1.0) << flags // c1 (no prop) |
|
6211 |
<< qreal(1.0) << 0 // c2 |
|
6212 |
<< qreal(0.5) << qreal(1.0) << qreal(1.0) << qreal(1.0); |
|
6213 |
QTest::newRow("M: 0.5 0 0.5 1 1.0 1.0 1.0 1.0 1.0") << qreal(0.5) << 0 // p |
|
6214 |
<< qreal(0.5) << flags // c1 (no prop) |
|
6215 |
<< qreal(1.0) << 0 // c2 |
|
6216 |
<< qreal(0.5) << qreal(0.5) << qreal(1.0) << qreal(1.0); |
|
6217 |
QTest::newRow("M: 0.5 0 0.5 1 0.5 1.0 1.0 1.0 1.0") << qreal(0.5) << 0 // p |
|
6218 |
<< qreal(0.5) << flags // c1 (no prop) |
|
6219 |
<< qreal(0.5) << 0 // c2 |
|
6220 |
<< qreal(0.5) << qreal(0.5) << qreal(0.5) << qreal(0.5); |
|
6221 |
QTest::newRow("M: 1.0 0 0.5 1 0.5 1.0 1.0 1.0 1.0") << qreal(1.0) << 0 // p |
|
6222 |
<< qreal(0.5) << flags // c1 (no prop) |
|
6223 |
<< qreal(0.5) << 0 // c2 |
|
6224 |
<< qreal(1.0) << qreal(0.5) << qreal(0.5) << qreal(0.5); |
|
6225 |
} |
|
6226 |
||
6227 |
void tst_QGraphicsItem::opacity() |
|
6228 |
{ |
|
6229 |
QFETCH(qreal, p_opacity); |
|
6230 |
QFETCH(int, p_opacityFlags); |
|
6231 |
QFETCH(qreal, p_effectiveOpacity); |
|
6232 |
QFETCH(qreal, c1_opacity); |
|
6233 |
QFETCH(int, c1_opacityFlags); |
|
6234 |
QFETCH(qreal, c1_effectiveOpacity); |
|
6235 |
QFETCH(qreal, c2_opacity); |
|
6236 |
QFETCH(int, c2_opacityFlags); |
|
6237 |
QFETCH(qreal, c2_effectiveOpacity); |
|
6238 |
QFETCH(qreal, c3_effectiveOpacity); |
|
6239 |
||
6240 |
QGraphicsRectItem *p = new QGraphicsRectItem; |
|
6241 |
QGraphicsRectItem *c1 = new QGraphicsRectItem(p); |
|
6242 |
QGraphicsRectItem *c2 = new QGraphicsRectItem(c1); |
|
6243 |
QGraphicsRectItem *c3 = new QGraphicsRectItem(c2); |
|
6244 |
||
6245 |
QCOMPARE(p->opacity(), qreal(1.0)); |
|
6246 |
QCOMPARE(p->effectiveOpacity(), qreal(1.0)); |
|
6247 |
int opacityMask = QGraphicsItem::ItemIgnoresParentOpacity | QGraphicsItem::ItemDoesntPropagateOpacityToChildren; |
|
6248 |
QVERIFY(!(p->flags() & opacityMask)); |
|
6249 |
||
6250 |
p->setOpacity(p_opacity); |
|
6251 |
c1->setOpacity(c1_opacity); |
|
6252 |
c2->setOpacity(c2_opacity); |
|
6253 |
p->setFlags(QGraphicsItem::GraphicsItemFlags(p->flags() | p_opacityFlags)); |
|
6254 |
c1->setFlags(QGraphicsItem::GraphicsItemFlags(c1->flags() | c1_opacityFlags)); |
|
6255 |
c2->setFlags(QGraphicsItem::GraphicsItemFlags(c2->flags() | c2_opacityFlags)); |
|
6256 |
||
6257 |
QCOMPARE(int(p->flags() & opacityMask), p_opacityFlags); |
|
6258 |
QCOMPARE(int(c1->flags() & opacityMask), c1_opacityFlags); |
|
6259 |
QCOMPARE(int(c2->flags() & opacityMask), c2_opacityFlags); |
|
6260 |
QCOMPARE(p->opacity(), p_opacity); |
|
6261 |
QCOMPARE(p->effectiveOpacity(), p_effectiveOpacity); |
|
6262 |
QCOMPARE(c1->effectiveOpacity(), c1_effectiveOpacity); |
|
6263 |
QCOMPARE(c2->effectiveOpacity(), c2_effectiveOpacity); |
|
6264 |
QCOMPARE(c3->effectiveOpacity(), c3_effectiveOpacity); |
|
6265 |
} |
|
6266 |
||
6267 |
void tst_QGraphicsItem::opacity2() |
|
6268 |
{ |
|
6269 |
EventTester *parent = new EventTester; |
|
6270 |
EventTester *child = new EventTester(parent); |
|
6271 |
EventTester *grandChild = new EventTester(child); |
|
6272 |
||
6273 |
QGraphicsScene scene; |
|
6274 |
scene.addItem(parent); |
|
6275 |
||
6276 |
MyGraphicsView view(&scene); |
|
6277 |
view.show(); |
|
6278 |
QTest::qWaitForWindowShown(&view); |
|
6279 |
QTRY_VERIFY(view.repaints >= 1); |
|
6280 |
||
6281 |
#define RESET_REPAINT_COUNTERS \ |
|
6282 |
parent->repaints = 0; \ |
|
6283 |
child->repaints = 0; \ |
|
6284 |
grandChild->repaints = 0; \ |
|
6285 |
view.repaints = 0; |
|
6286 |
||
6287 |
RESET_REPAINT_COUNTERS |
|
6288 |
||
6289 |
child->setOpacity(0.0); |
|
6290 |
QTest::qWait(10); |
|
6291 |
QTRY_COMPARE(view.repaints, 1); |
|
6292 |
QCOMPARE(parent->repaints, 1); |
|
6293 |
QCOMPARE(child->repaints, 0); |
|
6294 |
QCOMPARE(grandChild->repaints, 0); |
|
6295 |
||
6296 |
RESET_REPAINT_COUNTERS |
|
6297 |
||
6298 |
child->setOpacity(1.0); |
|
6299 |
QTest::qWait(10); |
|
6300 |
QTRY_COMPARE(view.repaints, 1); |
|
6301 |
QCOMPARE(parent->repaints, 1); |
|
6302 |
QCOMPARE(child->repaints, 1); |
|
6303 |
QCOMPARE(grandChild->repaints, 1); |
|
6304 |
||
6305 |
RESET_REPAINT_COUNTERS |
|
6306 |
||
6307 |
parent->setOpacity(0.0); |
|
6308 |
QTest::qWait(10); |
|
6309 |
QTRY_COMPARE(view.repaints, 1); |
|
6310 |
QCOMPARE(parent->repaints, 0); |
|
6311 |
QCOMPARE(child->repaints, 0); |
|
6312 |
QCOMPARE(grandChild->repaints, 0); |
|
6313 |
||
6314 |
RESET_REPAINT_COUNTERS |
|
6315 |
||
6316 |
parent->setOpacity(1.0); |
|
6317 |
QTest::qWait(10); |
|
6318 |
QTRY_COMPARE(view.repaints, 1); |
|
6319 |
QCOMPARE(parent->repaints, 1); |
|
6320 |
QCOMPARE(child->repaints, 1); |
|
6321 |
QCOMPARE(grandChild->repaints, 1); |
|
6322 |
||
6323 |
grandChild->setFlag(QGraphicsItem::ItemIgnoresParentOpacity); |
|
6324 |
RESET_REPAINT_COUNTERS |
|
6325 |
||
6326 |
child->setOpacity(0.0); |
|
6327 |
QTest::qWait(10); |
|
6328 |
QTRY_COMPARE(view.repaints, 1); |
|
6329 |
QCOMPARE(parent->repaints, 1); |
|
6330 |
QCOMPARE(child->repaints, 0); |
|
6331 |
QCOMPARE(grandChild->repaints, 1); |
|
6332 |
||
6333 |
RESET_REPAINT_COUNTERS |
|
6334 |
||
6335 |
child->setOpacity(0.0); // Already 0.0; no change. |
|
6336 |
QTest::qWait(10); |
|
6337 |
QTRY_COMPARE(view.repaints, 0); |
|
6338 |
QCOMPARE(parent->repaints, 0); |
|
6339 |
QCOMPARE(child->repaints, 0); |
|
6340 |
QCOMPARE(grandChild->repaints, 0); |
|
6341 |
} |
|
6342 |
||
6343 |
void tst_QGraphicsItem::opacityZeroUpdates() |
|
6344 |
{ |
|
6345 |
EventTester *parent = new EventTester; |
|
6346 |
EventTester *child = new EventTester(parent); |
|
6347 |
||
6348 |
child->setPos(10, 10); |
|
6349 |
||
6350 |
QGraphicsScene scene; |
|
6351 |
scene.addItem(parent); |
|
6352 |
||
6353 |
MyGraphicsView view(&scene); |
|
6354 |
view.show(); |
|
6355 |
QTest::qWaitForWindowShown(&view); |
|
6356 |
QTRY_VERIFY(view.repaints > 0); |
|
6357 |
||
6358 |
view.reset(); |
|
6359 |
parent->setOpacity(0.0); |
|
6360 |
||
6361 |
QTest::qWait(20); |
|
6362 |
||
6363 |
// transforming items bounding rect to view coordinates |
|
6364 |
const QRect childDeviceBoundingRect = child->deviceTransform(view.viewportTransform()) |
|
6365 |
.mapRect(child->boundingRect()).toRect(); |
|
6366 |
const QRect parentDeviceBoundingRect = parent->deviceTransform(view.viewportTransform()) |
|
6367 |
.mapRect(parent->boundingRect()).toRect(); |
|
6368 |
||
6369 |
QRegion expectedRegion = parentDeviceBoundingRect.adjusted(-2, -2, 2, 2); |
|
6370 |
expectedRegion += childDeviceBoundingRect.adjusted(-2, -2, 2, 2); |
|
6371 |
||
6372 |
COMPARE_REGIONS(view.paintedRegion, expectedRegion); |
|
6373 |
} |
|
6374 |
||
6375 |
class StacksBehindParentHelper : public QGraphicsRectItem |
|
6376 |
{ |
|
6377 |
public: |
|
6378 |
StacksBehindParentHelper(QList<QGraphicsItem *> *paintedItems, const QRectF &rect, QGraphicsItem *parent = 0) |
|
6379 |
: QGraphicsRectItem(rect, parent), paintedItems(paintedItems) |
|
6380 |
{ } |
|
6381 |
||
6382 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
6383 |
{ |
|
6384 |
QGraphicsRectItem::paint(painter, option, widget); |
|
6385 |
paintedItems->append(this); |
|
6386 |
} |
|
6387 |
||
6388 |
private: |
|
6389 |
QList<QGraphicsItem *> *paintedItems; |
|
6390 |
}; |
|
6391 |
||
6392 |
void tst_QGraphicsItem::itemStacksBehindParent() |
|
6393 |
{ |
|
6394 |
StacksBehindParentHelper *parent1 = new StacksBehindParentHelper(&paintedItems, QRectF(0, 0, 100, 50)); |
|
6395 |
StacksBehindParentHelper *child11 = new StacksBehindParentHelper(&paintedItems, QRectF(-10, 10, 50, 50), parent1); |
|
6396 |
StacksBehindParentHelper *grandChild111 = new StacksBehindParentHelper(&paintedItems, QRectF(-20, 20, 50, 50), child11); |
|
6397 |
StacksBehindParentHelper *child12 = new StacksBehindParentHelper(&paintedItems, QRectF(60, 10, 50, 50), parent1); |
|
6398 |
StacksBehindParentHelper *grandChild121 = new StacksBehindParentHelper(&paintedItems, QRectF(70, 20, 50, 50), child12); |
|
6399 |
||
6400 |
StacksBehindParentHelper *parent2 = new StacksBehindParentHelper(&paintedItems, QRectF(0, 0, 100, 50)); |
|
6401 |
StacksBehindParentHelper *child21 = new StacksBehindParentHelper(&paintedItems, QRectF(-10, 10, 50, 50), parent2); |
|
6402 |
StacksBehindParentHelper *grandChild211 = new StacksBehindParentHelper(&paintedItems, QRectF(-20, 20, 50, 50), child21); |
|
6403 |
StacksBehindParentHelper *child22 = new StacksBehindParentHelper(&paintedItems, QRectF(60, 10, 50, 50), parent2); |
|
6404 |
StacksBehindParentHelper *grandChild221 = new StacksBehindParentHelper(&paintedItems, QRectF(70, 20, 50, 50), child22); |
|
6405 |
||
6406 |
parent1->setData(0, "parent1"); |
|
6407 |
child11->setData(0, "child11"); |
|
6408 |
grandChild111->setData(0, "grandChild111"); |
|
6409 |
child12->setData(0, "child12"); |
|
6410 |
grandChild121->setData(0, "grandChild121"); |
|
6411 |
parent2->setData(0, "parent2"); |
|
6412 |
child21->setData(0, "child21"); |
|
6413 |
grandChild211->setData(0, "grandChild211"); |
|
6414 |
child22->setData(0, "child22"); |
|
6415 |
grandChild221->setData(0, "grandChild221"); |
|
6416 |
||
6417 |
// Disambiguate siblings |
|
6418 |
parent1->setZValue(1); |
|
6419 |
child11->setZValue(1); |
|
6420 |
child21->setZValue(1); |
|
6421 |
||
6422 |
QGraphicsScene scene; |
|
6423 |
scene.addItem(parent1); |
|
6424 |
scene.addItem(parent2); |
|
6425 |
||
6426 |
QGraphicsView view(&scene); |
|
6427 |
view.show(); |
|
6428 |
QTest::qWaitForWindowShown(&view); |
|
6429 |
QTRY_VERIFY(!paintedItems.isEmpty()); |
|
6430 |
QTest::qWait(100); |
|
6431 |
paintedItems.clear(); |
|
6432 |
view.viewport()->update(); |
|
6433 |
QApplication::processEvents(); |
|
6434 |
QTRY_COMPARE(scene.items(0, 0, 100, 100), (QList<QGraphicsItem *>() |
|
6435 |
<< grandChild111 << child11 |
|
6436 |
<< grandChild121 << child12 << parent1 |
|
6437 |
<< grandChild211 << child21 |
|
6438 |
<< grandChild221 << child22 << parent2)); |
|
6439 |
QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>() |
|
6440 |
<< parent2 << child22 << grandChild221 |
|
6441 |
<< child21 << grandChild211 |
|
6442 |
<< parent1 << child12 << grandChild121 |
|
6443 |
<< child11 << grandChild111); |
|
6444 |
||
6445 |
child11->setFlag(QGraphicsItem::ItemStacksBehindParent); |
|
6446 |
scene.update(); |
|
6447 |
paintedItems.clear(); |
|
6448 |
QApplication::processEvents(); |
|
6449 |
||
6450 |
QTRY_COMPARE(scene.items(0, 0, 100, 100), (QList<QGraphicsItem *>() |
|
6451 |
<< grandChild121 << child12 << parent1 |
|
6452 |
<< grandChild111 << child11 |
|
6453 |
<< grandChild211 << child21 |
|
6454 |
<< grandChild221 << child22 << parent2)); |
|
6455 |
QCOMPARE(paintedItems, QList<QGraphicsItem *>() |
|
6456 |
<< parent2 << child22 << grandChild221 |
|
6457 |
<< child21 << grandChild211 |
|
6458 |
<< child11 << grandChild111 |
|
6459 |
<< parent1 << child12 << grandChild121); |
|
6460 |
||
6461 |
child12->setFlag(QGraphicsItem::ItemStacksBehindParent); |
|
6462 |
paintedItems.clear(); |
|
6463 |
scene.update(); |
|
6464 |
QApplication::processEvents(); |
|
6465 |
||
6466 |
QTRY_COMPARE(scene.items(0, 0, 100, 100), (QList<QGraphicsItem *>() |
|
6467 |
<< parent1 << grandChild111 << child11 |
|
6468 |
<< grandChild121 << child12 |
|
6469 |
<< grandChild211 << child21 |
|
6470 |
<< grandChild221 << child22 << parent2)); |
|
6471 |
QCOMPARE(paintedItems, QList<QGraphicsItem *>() |
|
6472 |
<< parent2 << child22 << grandChild221 |
|
6473 |
<< child21 << grandChild211 |
|
6474 |
<< child12 << grandChild121 |
|
6475 |
<< child11 << grandChild111 << parent1); |
|
6476 |
} |
|
6477 |
||
6478 |
class ClippingAndTransformsScene : public QGraphicsScene |
|
6479 |
{ |
|
6480 |
public: |
|
6481 |
QList<QGraphicsItem *> drawnItems; |
|
6482 |
protected: |
|
6483 |
void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], |
|
6484 |
const QStyleOptionGraphicsItem options[], QWidget *widget = 0) |
|
6485 |
{ |
|
6486 |
drawnItems.clear(); |
|
6487 |
for (int i = 0; i < numItems; ++i) |
|
6488 |
drawnItems << items[i]; |
|
6489 |
QGraphicsScene::drawItems(painter, numItems, items, options, widget); |
|
6490 |
} |
|
6491 |
}; |
|
6492 |
||
6493 |
void tst_QGraphicsItem::nestedClipping() |
|
6494 |
{ |
|
6495 |
ClippingAndTransformsScene scene; |
|
6496 |
scene.setSceneRect(-50, -50, 200, 200); |
|
6497 |
||
6498 |
QGraphicsRectItem *root = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); |
|
6499 |
root->setBrush(QColor(0, 0, 255)); |
|
6500 |
root->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
6501 |
QGraphicsRectItem *l1 = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); |
|
6502 |
l1->setParentItem(root); |
|
6503 |
l1->setPos(-50, 0); |
|
6504 |
l1->setBrush(QColor(255, 0, 0)); |
|
6505 |
l1->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
6506 |
QGraphicsEllipseItem *l2 = new QGraphicsEllipseItem(QRectF(0, 0, 100, 100)); |
|
6507 |
l2->setParentItem(l1); |
|
6508 |
l2->setPos(50, 50); |
|
6509 |
l2->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
6510 |
l2->setBrush(QColor(255, 255, 0)); |
|
6511 |
QGraphicsRectItem *l3 = new QGraphicsRectItem(QRectF(0, 0, 25, 25)); |
|
6512 |
l3->setParentItem(l2); |
|
6513 |
l3->setBrush(QColor(0, 255, 0)); |
|
6514 |
l3->setPos(50 - 12, -12); |
|
6515 |
||
6516 |
scene.addItem(root); |
|
6517 |
||
6518 |
root->setData(0, "root"); |
|
6519 |
l1->setData(0, "l1"); |
|
6520 |
l2->setData(0, "l2"); |
|
6521 |
l3->setData(0, "l3"); |
|
6522 |
||
6523 |
QGraphicsView view(&scene); |
|
6524 |
view.setOptimizationFlag(QGraphicsView::IndirectPainting); |
|
6525 |
view.show(); |
|
6526 |
QTest::qWaitForWindowShown(&view); |
|
6527 |
QTest::qWait(25); |
|
6528 |
||
6529 |
QList<QGraphicsItem *> expected; |
|
6530 |
expected << root << l1 << l2 << l3; |
|
6531 |
QTRY_COMPARE(scene.drawnItems, expected); |
|
6532 |
||
6533 |
QImage image(200, 200, QImage::Format_ARGB32_Premultiplied); |
|
6534 |
image.fill(0); |
|
6535 |
||
6536 |
QPainter painter(&image); |
|
6537 |
scene.render(&painter); |
|
6538 |
painter.end(); |
|
6539 |
||
6540 |
// Check transparent areas |
|
6541 |
QCOMPARE(image.pixel(100, 25), qRgba(0, 0, 0, 0)); |
|
6542 |
QCOMPARE(image.pixel(100, 175), qRgba(0, 0, 0, 0)); |
|
6543 |
QCOMPARE(image.pixel(25, 100), qRgba(0, 0, 0, 0)); |
|
6544 |
QCOMPARE(image.pixel(175, 100), qRgba(0, 0, 0, 0)); |
|
6545 |
QCOMPARE(image.pixel(70, 80), qRgba(255, 0, 0, 255)); |
|
6546 |
QCOMPARE(image.pixel(80, 130), qRgba(255, 255, 0, 255)); |
|
6547 |
QCOMPARE(image.pixel(92, 105), qRgba(0, 255, 0, 255)); |
|
6548 |
QCOMPARE(image.pixel(105, 105), qRgba(0, 0, 255, 255)); |
|
6549 |
#if 0 |
|
6550 |
// Enable this to compare if the test starts failing. |
|
6551 |
image.save("nestedClipping_reference.png"); |
|
6552 |
#endif |
|
6553 |
} |
|
6554 |
||
6555 |
class TransformDebugItem : public QGraphicsRectItem |
|
6556 |
{ |
|
6557 |
public: |
|
6558 |
TransformDebugItem() |
|
6559 |
: QGraphicsRectItem(QRectF(-10, -10, 20, 20)) |
|
6560 |
{ |
|
6561 |
setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); |
|
6562 |
} |
|
6563 |
||
6564 |
QTransform x; |
|
6565 |
||
6566 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
6567 |
QWidget *widget = 0) |
|
6568 |
{ |
|
6569 |
x = painter->worldTransform(); |
|
6570 |
QGraphicsRectItem::paint(painter, option, widget); |
|
6571 |
} |
|
6572 |
}; |
|
6573 |
||
6574 |
void tst_QGraphicsItem::nestedClippingTransforms() |
|
6575 |
{ |
|
6576 |
TransformDebugItem *rootClipper = new TransformDebugItem; |
|
6577 |
rootClipper->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
6578 |
TransformDebugItem *child = new TransformDebugItem; |
|
6579 |
child->setParentItem(rootClipper); |
|
6580 |
child->setPos(2, 2); |
|
6581 |
TransformDebugItem *grandChildClipper = new TransformDebugItem; |
|
6582 |
grandChildClipper->setParentItem(child); |
|
6583 |
grandChildClipper->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
6584 |
grandChildClipper->setPos(4, 4); |
|
6585 |
TransformDebugItem *greatGrandChild = new TransformDebugItem; |
|
6586 |
greatGrandChild->setPos(2, 2); |
|
6587 |
greatGrandChild->setParentItem(grandChildClipper); |
|
6588 |
TransformDebugItem *grandChildClipper2 = new TransformDebugItem; |
|
6589 |
grandChildClipper2->setParentItem(child); |
|
6590 |
grandChildClipper2->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
6591 |
grandChildClipper2->setPos(8, 8); |
|
6592 |
TransformDebugItem *greatGrandChild2 = new TransformDebugItem; |
|
6593 |
greatGrandChild2->setPos(2, 2); |
|
6594 |
greatGrandChild2->setParentItem(grandChildClipper2); |
|
6595 |
TransformDebugItem *grandChildClipper3 = new TransformDebugItem; |
|
6596 |
grandChildClipper3->setParentItem(child); |
|
6597 |
grandChildClipper3->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
6598 |
grandChildClipper3->setPos(12, 12); |
|
6599 |
TransformDebugItem *greatGrandChild3 = new TransformDebugItem; |
|
6600 |
greatGrandChild3->setPos(2, 2); |
|
6601 |
greatGrandChild3->setParentItem(grandChildClipper3); |
|
6602 |
||
6603 |
QGraphicsScene scene; |
|
6604 |
scene.addItem(rootClipper); |
|
6605 |
||
6606 |
QImage image(scene.itemsBoundingRect().size().toSize(), QImage::Format_ARGB32_Premultiplied); |
|
6607 |
image.fill(0); |
|
6608 |
QPainter p(&image); |
|
6609 |
scene.render(&p); |
|
6610 |
p.end(); |
|
6611 |
||
6612 |
QCOMPARE(rootClipper->x, QTransform(1, 0, 0, 0, 1, 0, 10, 10, 1)); |
|
6613 |
QCOMPARE(child->x, QTransform(1, 0, 0, 0, 1, 0, 12, 12, 1)); |
|
6614 |
QCOMPARE(grandChildClipper->x, QTransform(1, 0, 0, 0, 1, 0, 16, 16, 1)); |
|
6615 |
QCOMPARE(greatGrandChild->x, QTransform(1, 0, 0, 0, 1, 0, 18, 18, 1)); |
|
6616 |
QCOMPARE(grandChildClipper2->x, QTransform(1, 0, 0, 0, 1, 0, 20, 20, 1)); |
|
6617 |
QCOMPARE(greatGrandChild2->x, QTransform(1, 0, 0, 0, 1, 0, 22, 22, 1)); |
|
6618 |
QCOMPARE(grandChildClipper3->x, QTransform(1, 0, 0, 0, 1, 0, 24, 24, 1)); |
|
6619 |
QCOMPARE(greatGrandChild3->x, QTransform(1, 0, 0, 0, 1, 0, 26, 26, 1)); |
|
6620 |
} |
|
6621 |
||
6622 |
void tst_QGraphicsItem::sceneTransformCache() |
|
6623 |
{ |
|
6624 |
// Test that an item's scene transform is updated correctly when the |
|
6625 |
// parent is transformed. |
|
6626 |
QGraphicsScene scene; |
|
6627 |
QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); |
|
6628 |
QGraphicsRectItem *rect2 = scene.addRect(0, 0, 100, 100); |
|
6629 |
rect2->setParentItem(rect); |
|
6630 |
rect2->rotate(90); |
|
6631 |
rect->translate(0, 50); |
|
6632 |
QGraphicsView view(&scene); |
|
6633 |
view.show(); |
|
6634 |
#ifdef Q_WS_X11 |
|
6635 |
qt_x11_wait_for_window_manager(&view); |
|
6636 |
#endif |
|
6637 |
||
6638 |
rect->translate(0, 100); |
|
6639 |
QTransform x; |
|
6640 |
x.translate(0, 150); |
|
6641 |
x.rotate(90); |
|
6642 |
QCOMPARE(rect2->sceneTransform(), x); |
|
6643 |
||
6644 |
scene.removeItem(rect); |
|
6645 |
||
6646 |
//Crazy use case : rect4 child of rect3 so the transformation of rect4 will be cached.Good! |
|
6647 |
//We remove rect4 from the scene, then the validTransform bit flag is set to 0 and the index of the cache |
|
6648 |
//add to the freeTransformSlots. The problem was that sceneTransformIndex was not set to -1 so if a new item arrive |
|
6649 |
//with a child (rect6) that will be cached then it will take the freeSlot (ex rect4) and put it his transform. But if rect4 is |
|
6650 |
//added back to the scene then it will set the transform to his old sceneTransformIndex value that will erase the new |
|
6651 |
//value of rect6 so rect6 transform will be wrong. |
|
6652 |
QGraphicsRectItem *rect3 = scene.addRect(0, 0, 100, 100); |
|
6653 |
QGraphicsRectItem *rect4 = scene.addRect(0, 0, 100, 100); |
|
6654 |
rect3->setPos(QPointF(10,10)); |
|
6655 |
||
6656 |
rect4->setParentItem(rect3); |
|
6657 |
rect4->setPos(QPointF(10,10)); |
|
6658 |
||
6659 |
QCOMPARE(rect4->mapToScene(rect4->boundingRect().topLeft()), QPointF(20,20)); |
|
6660 |
||
6661 |
scene.removeItem(rect4); |
|
6662 |
//rect4 transform is local only |
|
6663 |
QCOMPARE(rect4->mapToScene(rect4->boundingRect().topLeft()), QPointF(10,10)); |
|
6664 |
||
6665 |
QGraphicsRectItem *rect5 = scene.addRect(0, 0, 100, 100); |
|
6666 |
QGraphicsRectItem *rect6 = scene.addRect(0, 0, 100, 100); |
|
6667 |
rect5->setPos(QPointF(20,20)); |
|
6668 |
||
6669 |
rect6->setParentItem(rect5); |
|
6670 |
rect6->setPos(QPointF(10,10)); |
|
6671 |
//test if rect6 transform is ok |
|
6672 |
QCOMPARE(rect6->mapToScene(rect6->boundingRect().topLeft()), QPointF(30,30)); |
|
6673 |
||
6674 |
scene.addItem(rect4); |
|
6675 |
||
6676 |
QCOMPARE(rect4->mapToScene(rect4->boundingRect().topLeft()), QPointF(10,10)); |
|
6677 |
//test if rect6 transform is still correct |
|
6678 |
QCOMPARE(rect6->mapToScene(rect6->boundingRect().topLeft()), QPointF(30,30)); |
|
6679 |
} |
|
6680 |
||
6681 |
void tst_QGraphicsItem::tabChangesFocus_data() |
|
6682 |
{ |
|
6683 |
QTest::addColumn<bool>("tabChangesFocus"); |
|
6684 |
QTest::newRow("tab changes focus") << true; |
|
6685 |
QTest::newRow("tab doesn't change focus") << false; |
|
6686 |
} |
|
6687 |
||
6688 |
void tst_QGraphicsItem::tabChangesFocus() |
|
6689 |
{ |
|
6690 |
QFETCH(bool, tabChangesFocus); |
|
6691 |
||
6692 |
QGraphicsScene scene; |
|
6693 |
QGraphicsTextItem *item = scene.addText("Hello"); |
|
6694 |
item->setTabChangesFocus(tabChangesFocus); |
|
6695 |
item->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
6696 |
item->setFocus(); |
|
6697 |
||
6698 |
QDial *dial1 = new QDial; |
|
6699 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
6700 |
||
6701 |
QDial *dial2 = new QDial; |
|
6702 |
QVBoxLayout *layout = new QVBoxLayout; |
|
6703 |
layout->addWidget(dial1); |
|
6704 |
layout->addWidget(view); |
|
6705 |
layout->addWidget(dial2); |
|
6706 |
||
6707 |
QWidget widget; |
|
6708 |
widget.setLayout(layout); |
|
6709 |
widget.show(); |
|
6710 |
QTest::qWaitForWindowShown(&widget); |
|
6711 |
||
6712 |
QTRY_VERIFY(scene.isActive()); |
|
6713 |
||
6714 |
dial1->setFocus(); |
|
6715 |
QTest::qWait(15); |
|
6716 |
QTRY_VERIFY(dial1->hasFocus()); |
|
6717 |
||
6718 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
6719 |
QTest::qWait(15); |
|
6720 |
QTRY_VERIFY(view->hasFocus()); |
|
6721 |
QTRY_VERIFY(item->hasFocus()); |
|
6722 |
||
6723 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
6724 |
QTest::qWait(15); |
|
6725 |
||
6726 |
if (tabChangesFocus) { |
|
6727 |
QTRY_VERIFY(!view->hasFocus()); |
|
6728 |
QTRY_VERIFY(!item->hasFocus()); |
|
6729 |
QTRY_VERIFY(dial2->hasFocus()); |
|
6730 |
} else { |
|
6731 |
QTRY_VERIFY(view->hasFocus()); |
|
6732 |
QTRY_VERIFY(item->hasFocus()); |
|
6733 |
QCOMPARE(item->toPlainText(), QString("\tHello")); |
|
6734 |
} |
|
6735 |
} |
|
6736 |
||
6737 |
void tst_QGraphicsItem::cacheMode() |
|
6738 |
{ |
|
6739 |
QGraphicsScene scene(0, 0, 100, 100); |
|
6740 |
QGraphicsView view(&scene); |
|
6741 |
view.resize(150, 150); |
|
6742 |
view.show(); |
|
6743 |
QApplication::setActiveWindow(&view); |
|
6744 |
QTest::qWaitForWindowShown(&view); |
|
6745 |
||
6746 |
// Increase the probability of window activation |
|
6747 |
// not causing another repaint of test items. |
|
6748 |
QTest::qWait(50); |
|
6749 |
||
6750 |
EventTester *tester = new EventTester; |
|
6751 |
EventTester *testerChild = new EventTester; |
|
6752 |
testerChild->setParentItem(tester); |
|
6753 |
EventTester *testerChild2 = new EventTester; |
|
6754 |
testerChild2->setParentItem(testerChild); |
|
6755 |
testerChild2->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
6756 |
||
6757 |
scene.addItem(tester); |
|
6758 |
QTest::qWait(10); |
|
6759 |
||
6760 |
for (int i = 0; i < 2; ++i) { |
|
6761 |
// No visual change. |
|
6762 |
QTRY_COMPARE(tester->repaints, 1); |
|
6763 |
QCOMPARE(testerChild->repaints, 1); |
|
6764 |
QCOMPARE(testerChild2->repaints, 1); |
|
6765 |
tester->setCacheMode(QGraphicsItem::NoCache); |
|
6766 |
testerChild->setCacheMode(QGraphicsItem::NoCache); |
|
6767 |
testerChild2->setCacheMode(QGraphicsItem::NoCache); |
|
6768 |
QTest::qWait(25); |
|
6769 |
QTRY_COMPARE(tester->repaints, 1); |
|
6770 |
QCOMPARE(testerChild->repaints, 1); |
|
6771 |
QCOMPARE(testerChild2->repaints, 1); |
|
6772 |
tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6773 |
testerChild->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6774 |
testerChild2->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6775 |
QTest::qWait(25); |
|
6776 |
} |
|
6777 |
||
6778 |
// The first move causes a repaint as the item is painted into its pixmap. |
|
6779 |
// (Only occurs if the item has previously been painted without cache). |
|
6780 |
tester->setPos(10, 10); |
|
6781 |
testerChild->setPos(10, 10); |
|
6782 |
testerChild2->setPos(10, 10); |
|
6783 |
QTest::qWait(25); |
|
6784 |
QTRY_COMPARE(tester->repaints, 2); |
|
6785 |
QCOMPARE(testerChild->repaints, 2); |
|
6786 |
QCOMPARE(testerChild2->repaints, 2); |
|
6787 |
||
6788 |
// Consecutive moves should not repaint. |
|
6789 |
tester->setPos(20, 20); |
|
6790 |
testerChild->setPos(20, 20); |
|
6791 |
testerChild2->setPos(20, 20); |
|
6792 |
QTest::qWait(250); |
|
6793 |
QCOMPARE(tester->repaints, 2); |
|
6794 |
QCOMPARE(testerChild->repaints, 2); |
|
6795 |
QCOMPARE(testerChild2->repaints, 2); |
|
6796 |
||
6797 |
// Translating does not result in a repaint. |
|
6798 |
tester->translate(10, 10); |
|
6799 |
QTest::qWait(25); |
|
6800 |
QTRY_COMPARE(tester->repaints, 2); |
|
6801 |
QCOMPARE(testerChild->repaints, 2); |
|
6802 |
QCOMPARE(testerChild2->repaints, 2); |
|
6803 |
||
6804 |
// Rotating results in a repaint. |
|
6805 |
tester->rotate(45); |
|
6806 |
QTest::qWait(25); |
|
6807 |
QTRY_COMPARE(tester->repaints, 3); |
|
6808 |
QCOMPARE(testerChild->repaints, 3); |
|
6809 |
QCOMPARE(testerChild2->repaints, 2); |
|
6810 |
||
6811 |
// Change to ItemCoordinateCache (triggers repaint). |
|
6812 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); // autosize |
|
6813 |
testerChild->setCacheMode(QGraphicsItem::ItemCoordinateCache); // autosize |
|
6814 |
testerChild2->setCacheMode(QGraphicsItem::ItemCoordinateCache); // autosize |
|
6815 |
QTest::qWait(25); |
|
6816 |
QTRY_COMPARE(tester->repaints, 4); |
|
6817 |
QCOMPARE(testerChild->repaints, 4); |
|
6818 |
QCOMPARE(testerChild2->repaints, 3); |
|
6819 |
||
6820 |
// Rotating items with ItemCoordinateCache doesn't cause a repaint. |
|
6821 |
tester->rotate(22); |
|
6822 |
testerChild->rotate(22); |
|
6823 |
testerChild2->rotate(22); |
|
6824 |
QTest::qWait(25); |
|
6825 |
QTRY_COMPARE(tester->repaints, 4); |
|
6826 |
QCOMPARE(testerChild->repaints, 4); |
|
6827 |
QCOMPARE(testerChild2->repaints, 3); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6828 |
tester->resetTransform(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6829 |
testerChild->resetTransform(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6830 |
testerChild2->resetTransform(); |
0 | 6831 |
|
6832 |
// Explicit update causes a repaint. |
|
6833 |
tester->update(0, 0, 5, 5); |
|
6834 |
QTest::qWait(25); |
|
6835 |
QTRY_COMPARE(tester->repaints, 5); |
|
6836 |
QCOMPARE(testerChild->repaints, 4); |
|
6837 |
QCOMPARE(testerChild2->repaints, 3); |
|
6838 |
||
6839 |
// Updating outside the item's bounds does not cause a repaint. |
|
6840 |
tester->update(10, 10, 5, 5); |
|
6841 |
QTest::qWait(25); |
|
6842 |
QTRY_COMPARE(tester->repaints, 5); |
|
6843 |
QCOMPARE(testerChild->repaints, 4); |
|
6844 |
QCOMPARE(testerChild2->repaints, 3); |
|
6845 |
||
6846 |
// Resizing an item should cause a repaint of that item. (because of |
|
6847 |
// autosize). |
|
6848 |
tester->setGeometry(QRectF(-15, -15, 30, 30)); |
|
6849 |
QTest::qWait(25); |
|
6850 |
QTRY_COMPARE(tester->repaints, 6); |
|
6851 |
QCOMPARE(testerChild->repaints, 4); |
|
6852 |
QCOMPARE(testerChild2->repaints, 3); |
|
6853 |
||
6854 |
// Set fixed size. |
|
6855 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(30, 30)); |
|
6856 |
testerChild->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(30, 30)); |
|
6857 |
testerChild2->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(30, 30)); |
|
6858 |
QTest::qWait(20); |
|
6859 |
QTRY_COMPARE(tester->repaints, 7); |
|
6860 |
QCOMPARE(testerChild->repaints, 5); |
|
6861 |
QCOMPARE(testerChild2->repaints, 4); |
|
6862 |
||
6863 |
// Resizing the item should cause a repaint. |
|
6864 |
testerChild->setGeometry(QRectF(-15, -15, 30, 30)); |
|
6865 |
QTest::qWait(25); |
|
6866 |
QTRY_COMPARE(tester->repaints, 7); |
|
6867 |
QCOMPARE(testerChild->repaints, 6); |
|
6868 |
QCOMPARE(testerChild2->repaints, 4); |
|
6869 |
||
6870 |
// Scaling the view does not cause a repaint. |
|
6871 |
view.scale(0.7, 0.7); |
|
6872 |
QTest::qWait(25); |
|
6873 |
QTRY_COMPARE(tester->repaints, 7); |
|
6874 |
QCOMPARE(testerChild->repaints, 6); |
|
6875 |
QCOMPARE(testerChild2->repaints, 4); |
|
6876 |
||
6877 |
// Switch to device coordinate cache. |
|
6878 |
tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6879 |
testerChild->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6880 |
testerChild2->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
|
6881 |
QTest::qWait(25); |
|
6882 |
QTRY_COMPARE(tester->repaints, 8); |
|
6883 |
QCOMPARE(testerChild->repaints, 7); |
|
6884 |
QCOMPARE(testerChild2->repaints, 5); |
|
6885 |
||
6886 |
// Scaling the view back should cause repaints for two of the items. |
|
6887 |
view.setTransform(QTransform()); |
|
6888 |
QTest::qWait(25); |
|
6889 |
QTRY_COMPARE(tester->repaints, 9); |
|
6890 |
QCOMPARE(testerChild->repaints, 8); |
|
6891 |
QCOMPARE(testerChild2->repaints, 5); |
|
6892 |
||
6893 |
// Rotating the base item (perspective) should repaint two items. |
|
6894 |
tester->setTransform(QTransform().rotate(10, Qt::XAxis)); |
|
6895 |
QTest::qWait(25); |
|
6896 |
QTRY_COMPARE(tester->repaints, 10); |
|
6897 |
QCOMPARE(testerChild->repaints, 9); |
|
6898 |
QCOMPARE(testerChild2->repaints, 5); |
|
6899 |
||
6900 |
// Moving the middle item should case a repaint even if it's a move, |
|
6901 |
// because the parent is rotated with a perspective. |
|
6902 |
testerChild->setPos(1, 1); |
|
6903 |
QTest::qWait(25); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6904 |
QTRY_COMPARE(tester->repaints, 11); |
0 | 6905 |
QCOMPARE(testerChild->repaints, 10); |
6906 |
QCOMPARE(testerChild2->repaints, 5); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6907 |
tester->resetTransform(); |
0 | 6908 |
|
6909 |
// Make a huge item |
|
6910 |
tester->setGeometry(QRectF(-4000, -4000, 8000, 8000)); |
|
6911 |
QTest::qWait(25); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6912 |
QTRY_COMPARE(tester->repaints, 12); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6913 |
QCOMPARE(testerChild->repaints, 11); |
0 | 6914 |
QCOMPARE(testerChild2->repaints, 5); |
6915 |
||
6916 |
// Move the large item - will cause a repaint as the |
|
6917 |
// cache is clipped. |
|
6918 |
tester->setPos(5, 0); |
|
6919 |
QTest::qWait(25); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6920 |
QTRY_COMPARE(tester->repaints, 13); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6921 |
QCOMPARE(testerChild->repaints, 11); |
0 | 6922 |
QCOMPARE(testerChild2->repaints, 5); |
6923 |
||
6924 |
// Hiding and showing should invalidate the cache |
|
6925 |
tester->hide(); |
|
6926 |
QTest::qWait(25); |
|
6927 |
tester->show(); |
|
6928 |
QTest::qWait(25); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6929 |
QTRY_COMPARE(tester->repaints, 14); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6930 |
QCOMPARE(testerChild->repaints, 12); |
0 | 6931 |
QCOMPARE(testerChild2->repaints, 6); |
6932 |
} |
|
6933 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6934 |
void tst_QGraphicsItem::cacheMode2() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6935 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6936 |
QGraphicsScene scene(0, 0, 100, 100); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6937 |
QGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6938 |
view.resize(150, 150); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6939 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6940 |
QApplication::setActiveWindow(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6941 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6942 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6943 |
// Increase the probability of window activation |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6944 |
// not causing another repaint of test items. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6945 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6946 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6947 |
EventTester *tester = new EventTester; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6948 |
scene.addItem(tester); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6949 |
QTest::qWait(10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6950 |
QTRY_COMPARE(tester->repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6951 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6952 |
// Switching from NoCache to NoCache (no repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6953 |
tester->setCacheMode(QGraphicsItem::NoCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6954 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6955 |
QTRY_COMPARE(tester->repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6956 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6957 |
// Switching from NoCache to DeviceCoordinateCache (no repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6958 |
tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6959 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6960 |
QTRY_COMPARE(tester->repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6961 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6962 |
// Switching from DeviceCoordinateCache to DeviceCoordinateCache (no repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6963 |
tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6964 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6965 |
QTRY_COMPARE(tester->repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6966 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6967 |
// Switching from DeviceCoordinateCache to NoCache (no repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6968 |
tester->setCacheMode(QGraphicsItem::NoCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6969 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6970 |
QTRY_COMPARE(tester->repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6971 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6972 |
// Switching from NoCache to ItemCoordinateCache (repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6973 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6974 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6975 |
QTRY_COMPARE(tester->repaints, 2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6976 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6977 |
// Switching from ItemCoordinateCache to ItemCoordinateCache (no repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6978 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6979 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6980 |
QTRY_COMPARE(tester->repaints, 2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6981 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6982 |
// Switching from ItemCoordinateCache to ItemCoordinateCache with different size (repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6983 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(100, 100)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6984 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6985 |
QTRY_COMPARE(tester->repaints, 3); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6986 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6987 |
// Switching from ItemCoordinateCache to NoCache (repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6988 |
tester->setCacheMode(QGraphicsItem::NoCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6989 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6990 |
QTRY_COMPARE(tester->repaints, 4); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6991 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6992 |
// Switching from DeviceCoordinateCache to ItemCoordinateCache (repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6993 |
tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6994 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6995 |
QTRY_COMPARE(tester->repaints, 4); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6996 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6997 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6998 |
QTRY_COMPARE(tester->repaints, 5); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
6999 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
7000 |
// Switching from ItemCoordinateCache to DeviceCoordinateCache (repaint) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
7001 |
tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
7002 |
QTest::qWait(50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
7003 |
QTRY_COMPARE(tester->repaints, 6); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
7004 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
7005 |
|
0 | 7006 |
void tst_QGraphicsItem::updateCachedItemAfterMove() |
7007 |
{ |
|
7008 |
// A simple item that uses ItemCoordinateCache |
|
7009 |
EventTester *tester = new EventTester; |
|
7010 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
|
7011 |
||
7012 |
// Add to a scene, show in a view, ensure it's painted and reset its |
|
7013 |
// repaint counter. |
|
7014 |
QGraphicsScene scene; |
|
7015 |
scene.addItem(tester); |
|
7016 |
QGraphicsView view(&scene); |
|
7017 |
view.show(); |
|
7018 |
QTest::qWaitForWindowShown(&view); |
|
7019 |
||
7020 |
QTest::qWait(12); |
|
7021 |
QTRY_VERIFY(tester->repaints > 0); |
|
7022 |
tester->repaints = 0; |
|
7023 |
||
7024 |
// Move the item, should not cause repaints |
|
7025 |
tester->setPos(10, 0); |
|
7026 |
QTest::qWait(12); |
|
7027 |
QCOMPARE(tester->repaints, 0); |
|
7028 |
||
7029 |
// Move then update, should cause one repaint |
|
7030 |
tester->setPos(20, 0); |
|
7031 |
tester->update(); |
|
7032 |
QTest::qWait(12); |
|
7033 |
QCOMPARE(tester->repaints, 1); |
|
7034 |
||
7035 |
// Hiding the item doesn't cause a repaint |
|
7036 |
tester->hide(); |
|
7037 |
QTest::qWait(12); |
|
7038 |
QCOMPARE(tester->repaints, 1); |
|
7039 |
||
7040 |
// Moving a hidden item doesn't cause a repaint |
|
7041 |
tester->setPos(30, 0); |
|
7042 |
tester->update(); |
|
7043 |
QTest::qWait(12); |
|
7044 |
QCOMPARE(tester->repaints, 1); |
|
7045 |
} |
|
7046 |
||
7047 |
class Track : public QGraphicsRectItem |
|
7048 |
{ |
|
7049 |
public: |
|
7050 |
Track(const QRectF &rect) |
|
7051 |
: QGraphicsRectItem(rect) |
|
7052 |
{ |
|
7053 |
setAcceptHoverEvents(true); |
|
7054 |
} |
|
7055 |
||
7056 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) |
|
7057 |
{ |
|
7058 |
QGraphicsRectItem::paint(painter, option, widget); |
|
7059 |
painter->drawText(boundingRect(), Qt::AlignCenter, QString("%1x%2\n%3x%4").arg(p.x()).arg(p.y()).arg(sp.x()).arg(sp.y())); |
|
7060 |
} |
|
7061 |
||
7062 |
protected: |
|
7063 |
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) |
|
7064 |
{ |
|
7065 |
p = event->pos(); |
|
7066 |
sp = event->widget()->mapFromGlobal(event->screenPos()); |
|
7067 |
update(); |
|
7068 |
} |
|
7069 |
private: |
|
7070 |
QPointF p; |
|
7071 |
QPoint sp; |
|
7072 |
}; |
|
7073 |
||
7074 |
void tst_QGraphicsItem::deviceTransform_data() |
|
7075 |
{ |
|
7076 |
QTest::addColumn<bool>("untransformable1"); |
|
7077 |
QTest::addColumn<bool>("untransformable2"); |
|
7078 |
QTest::addColumn<bool>("untransformable3"); |
|
7079 |
QTest::addColumn<qreal>("rotation1"); |
|
7080 |
QTest::addColumn<qreal>("rotation2"); |
|
7081 |
QTest::addColumn<qreal>("rotation3"); |
|
7082 |
QTest::addColumn<QTransform>("deviceX"); |
|
7083 |
QTest::addColumn<QPointF>("mapResult1"); |
|
7084 |
QTest::addColumn<QPointF>("mapResult2"); |
|
7085 |
QTest::addColumn<QPointF>("mapResult3"); |
|
7086 |
||
7087 |
QTest::newRow("nil") << false << false << false |
|
7088 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) |
|
7089 |
<< QTransform() |
|
7090 |
<< QPointF(150, 150) << QPointF(250, 250) << QPointF(350, 350); |
|
7091 |
QTest::newRow("deviceX rot 90") << false << false << false |
|
7092 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) |
|
7093 |
<< QTransform().rotate(90) |
|
7094 |
<< QPointF(-150, 150) << QPointF(-250, 250) << QPointF(-350, 350); |
|
7095 |
QTest::newRow("deviceX rot 90 100") << true << false << false |
|
7096 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) |
|
7097 |
<< QTransform().rotate(90) |
|
7098 |
<< QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350); |
|
7099 |
QTest::newRow("deviceX rot 90 010") << false << true << false |
|
7100 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) |
|
7101 |
<< QTransform().rotate(90) |
|
7102 |
<< QPointF(-150, 150) << QPointF(-150, 250) << QPointF(-50, 350); |
|
7103 |
QTest::newRow("deviceX rot 90 001") << false << false << true |
|
7104 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) |
|
7105 |
<< QTransform().rotate(90) |
|
7106 |
<< QPointF(-150, 150) << QPointF(-250, 250) << QPointF(-250, 350); |
|
7107 |
QTest::newRow("deviceX rot 90 111") << true << true << true |
|
7108 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) |
|
7109 |
<< QTransform().rotate(90) |
|
7110 |
<< QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350); |
|
7111 |
QTest::newRow("deviceX rot 90 101") << true << false << true |
|
7112 |
<< qreal(0.0) << qreal(0.0) << qreal(0.0) |
|
7113 |
<< QTransform().rotate(90) |
|
7114 |
<< QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350); |
|
7115 |
} |
|
7116 |
||
7117 |
void tst_QGraphicsItem::deviceTransform() |
|
7118 |
{ |
|
7119 |
QFETCH(bool, untransformable1); |
|
7120 |
QFETCH(bool, untransformable2); |
|
7121 |
QFETCH(bool, untransformable3); |
|
7122 |
QFETCH(qreal, rotation1); |
|
7123 |
QFETCH(qreal, rotation2); |
|
7124 |
QFETCH(qreal, rotation3); |
|
7125 |
QFETCH(QTransform, deviceX); |
|
7126 |
QFETCH(QPointF, mapResult1); |
|
7127 |
QFETCH(QPointF, mapResult2); |
|
7128 |
QFETCH(QPointF, mapResult3); |
|
7129 |
||
7130 |
QGraphicsScene scene; |
|
7131 |
Track *rect1 = new Track(QRectF(0, 0, 100, 100)); |
|
7132 |
Track *rect2 = new Track(QRectF(0, 0, 100, 100)); |
|
7133 |
Track *rect3 = new Track(QRectF(0, 0, 100, 100)); |
|
7134 |
rect2->setParentItem(rect1); |
|
7135 |
rect3->setParentItem(rect2); |
|
7136 |
rect1->setPos(100, 100); |
|
7137 |
rect2->setPos(100, 100); |
|
7138 |
rect3->setPos(100, 100); |
|
7139 |
rect1->rotate(rotation1); |
|
7140 |
rect2->rotate(rotation2); |
|
7141 |
rect3->rotate(rotation3); |
|
7142 |
rect1->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable1); |
|
7143 |
rect2->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable2); |
|
7144 |
rect3->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable3); |
|
7145 |
rect1->setBrush(Qt::red); |
|
7146 |
rect2->setBrush(Qt::green); |
|
7147 |
rect3->setBrush(Qt::blue); |
|
7148 |
scene.addItem(rect1); |
|
7149 |
||
7150 |
QCOMPARE(rect1->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult1); |
|
7151 |
QCOMPARE(rect2->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult2); |
|
7152 |
QCOMPARE(rect3->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult3); |
|
7153 |
} |
|
7154 |
||
7155 |
void tst_QGraphicsItem::update() |
|
7156 |
{ |
|
7157 |
QGraphicsScene scene; |
|
7158 |
scene.setSceneRect(-100, -100, 200, 200); |
|
7159 |
MyGraphicsView view(&scene); |
|
7160 |
||
7161 |
view.show(); |
|
7162 |
#ifdef Q_WS_X11 |
|
7163 |
qt_x11_wait_for_window_manager(&view); |
|
7164 |
#endif |
|
7165 |
QTest::qWait(100); |
|
7166 |
||
7167 |
EventTester *item = new EventTester; |
|
7168 |
scene.addItem(item); |
|
7169 |
QTest::qWait(100); // Make sure all pending updates are processed. |
|
7170 |
item->repaints = 0; |
|
7171 |
||
7172 |
item->update(); // Item marked as dirty |
|
7173 |
scene.update(); // Entire scene marked as dirty |
|
7174 |
qApp->processEvents(); |
|
7175 |
QCOMPARE(item->repaints, 1); |
|
7176 |
||
7177 |
// Make sure the dirty state from the previous update is reset so that |
|
7178 |
// the item don't think it is already dirty and discards this update. |
|
7179 |
item->update(); |
|
7180 |
qApp->processEvents(); |
|
7181 |
QCOMPARE(item->repaints, 2); |
|
7182 |
||
7183 |
// Make sure a partial update doesn't cause a full update to be discarded. |
|
7184 |
view.reset(); |
|
7185 |
item->repaints = 0; |
|
7186 |
item->update(QRectF(0, 0, 5, 5)); |
|
7187 |
item->update(); |
|
7188 |
qApp->processEvents(); |
|
7189 |
QCOMPARE(item->repaints, 1); |
|
7190 |
QCOMPARE(view.repaints, 1); |
|
7191 |
QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) |
|
7192 |
.mapRect(item->boundingRect()).toRect(); |
|
7193 |
QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); |
|
7194 |
// The entire item's bounding rect (adjusted for antialiasing) should have been painted. |
|
7195 |
QCOMPARE(view.paintedRegion, expectedRegion); |
|
7196 |
||
7197 |
// Make sure update requests outside the bounding rect are discarded. |
|
7198 |
view.reset(); |
|
7199 |
item->repaints = 0; |
|
7200 |
item->update(-15, -15, 5, 5); // Item's brect: (-10, -10, 20, 20) |
|
7201 |
qApp->processEvents(); |
|
7202 |
QCOMPARE(item->repaints, 0); |
|
7203 |
QCOMPARE(view.repaints, 0); |
|
7204 |
||
7205 |
// Make sure the area occupied by an item is repainted when hiding it. |
|
7206 |
view.reset(); |
|
7207 |
item->repaints = 0; |
|
7208 |
item->update(); // Full update; all sub-sequent update requests are discarded. |
|
7209 |
item->hide(); // visible set to 0. ignoreVisible must be set to 1; the item won't be processed otherwise. |
|
7210 |
qApp->processEvents(); |
|
7211 |
QCOMPARE(item->repaints, 0); |
|
7212 |
QCOMPARE(view.repaints, 1); |
|
7213 |
// The entire item's bounding rect (adjusted for antialiasing) should have been painted. |
|
7214 |
QCOMPARE(view.paintedRegion, expectedRegion); |
|
7215 |
||
7216 |
// Make sure item is repainted when shown (after being hidden). |
|
7217 |
view.reset(); |
|
7218 |
item->repaints = 0; |
|
7219 |
item->show(); |
|
7220 |
qApp->processEvents(); |
|
7221 |
QCOMPARE(item->repaints, 1); |
|
7222 |
QCOMPARE(view.repaints, 1); |
|
7223 |
// The entire item's bounding rect (adjusted for antialiasing) should have been painted. |
|
7224 |
QCOMPARE(view.paintedRegion, expectedRegion); |
|
7225 |
||
7226 |
item->repaints = 0; |
|
7227 |
item->hide(); |
|
7228 |
qApp->processEvents(); |
|
7229 |
view.reset(); |
|
7230 |
const QPointF originalPos = item->pos(); |
|
7231 |
item->setPos(5000, 5000); |
|
7232 |
qApp->processEvents(); |
|
7233 |
QCOMPARE(item->repaints, 0); |
|
7234 |
QCOMPARE(view.repaints, 0); |
|
7235 |
qApp->processEvents(); |
|
7236 |
||
7237 |
item->setPos(originalPos); |
|
7238 |
qApp->processEvents(); |
|
7239 |
QCOMPARE(item->repaints, 0); |
|
7240 |
QCOMPARE(view.repaints, 0); |
|
7241 |
item->show(); |
|
7242 |
qApp->processEvents(); |
|
7243 |
QCOMPARE(item->repaints, 1); |
|
7244 |
QCOMPARE(view.repaints, 1); |
|
7245 |
// The entire item's bounding rect (adjusted for antialiasing) should have been painted. |
|
7246 |
QCOMPARE(view.paintedRegion, expectedRegion); |
|
7247 |
||
7248 |
QGraphicsViewPrivate *viewPrivate = static_cast<QGraphicsViewPrivate *>(qt_widget_private(&view)); |
|
7249 |
item->setPos(originalPos + QPoint(50, 50)); |
|
7250 |
viewPrivate->updateAll(); |
|
7251 |
QVERIFY(viewPrivate->fullUpdatePending); |
|
7252 |
QTest::qWait(50); |
|
7253 |
item->repaints = 0; |
|
7254 |
view.reset(); |
|
7255 |
item->setPos(originalPos); |
|
7256 |
QTest::qWait(50); |
|
7257 |
qApp->processEvents(); |
|
7258 |
QCOMPARE(item->repaints, 1); |
|
7259 |
QCOMPARE(view.repaints, 1); |
|
7260 |
COMPARE_REGIONS(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); |
|
7261 |
||
7262 |
// Make sure moving a parent item triggers an update on the children |
|
7263 |
// (even though the parent itself is outside the viewport). |
|
7264 |
QGraphicsRectItem *parent = new QGraphicsRectItem(0, 0, 10, 10); |
|
7265 |
parent->setPos(-400, 0); |
|
7266 |
item->setParentItem(parent); |
|
7267 |
item->setPos(400, 0); |
|
7268 |
scene.addItem(parent); |
|
7269 |
QTest::qWait(50); |
|
7270 |
itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) |
|
7271 |
.mapRect(item->boundingRect()).toRect(); |
|
7272 |
expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); |
|
7273 |
view.reset(); |
|
7274 |
item->repaints = 0; |
|
7275 |
parent->translate(-400, 0); |
|
7276 |
qApp->processEvents(); |
|
7277 |
QCOMPARE(item->repaints, 0); |
|
7278 |
QCOMPARE(view.repaints, 1); |
|
7279 |
QCOMPARE(view.paintedRegion, expectedRegion); |
|
7280 |
view.reset(); |
|
7281 |
item->repaints = 0; |
|
7282 |
parent->translate(400, 0); |
|
7283 |
qApp->processEvents(); |
|
7284 |
QCOMPARE(item->repaints, 1); |
|
7285 |
QCOMPARE(view.repaints, 1); |
|
7286 |
QCOMPARE(view.paintedRegion, expectedRegion); |
|
7287 |
QCOMPARE(view.paintedRegion, expectedRegion); |
|
7288 |
} |
|
7289 |
||
7290 |
void tst_QGraphicsItem::setTransformProperties_data() |
|
7291 |
{ |
|
7292 |
QTest::addColumn<QPointF>("origin"); |
|
7293 |
QTest::addColumn<qreal>("rotation"); |
|
7294 |
QTest::addColumn<qreal>("scale"); |
|
7295 |
||
7296 |
QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(1.0); |
|
7297 |
||
7298 |
QTest::newRow("rotation") << QPointF() << qreal(42.2) << qreal(1.0); |
|
7299 |
||
7300 |
QTest::newRow("rotation dicentred") << QPointF(qreal(22.3), qreal(-56.2)) |
|
7301 |
<< qreal(-2578.2) |
|
7302 |
<< qreal(1.0); |
|
7303 |
||
7304 |
QTest::newRow("Scale") << QPointF() << qreal(0.0) |
|
7305 |
<< qreal(6); |
|
7306 |
||
7307 |
QTest::newRow("Everything dicentred") << QPointF(qreal(22.3), qreal(-56.2)) << qreal(-175) << qreal(196); |
|
7308 |
} |
|
7309 |
||
7310 |
/** |
|
7311 |
* the normal QCOMPARE doesn't work because it doesn't use qFuzzyCompare |
|
7312 |
*/ |
|
7313 |
#define QCOMPARE_TRANSFORM(X1, X2) QVERIFY(((X1)*(X2).inverted()).isIdentity()) |
|
7314 |
||
7315 |
void tst_QGraphicsItem::setTransformProperties() |
|
7316 |
{ |
|
7317 |
QFETCH(QPointF,origin); |
|
7318 |
QFETCH(qreal,rotation); |
|
7319 |
QFETCH(qreal,scale); |
|
7320 |
||
7321 |
QTransform result; |
|
7322 |
result.translate(origin.x(), origin.y()); |
|
7323 |
result.rotate(rotation, Qt::ZAxis); |
|
7324 |
result.scale(scale, scale); |
|
7325 |
result.translate(-origin.x(), -origin.y()); |
|
7326 |
||
7327 |
QGraphicsScene scene; |
|
7328 |
QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); |
|
7329 |
scene.addItem(item); |
|
7330 |
||
7331 |
item->setRotation(rotation); |
|
7332 |
item->setScale(scale); |
|
7333 |
item->setTransformOriginPoint(origin); |
|
7334 |
||
7335 |
QCOMPARE(item->rotation(), rotation); |
|
7336 |
QCOMPARE(item->scale(), scale); |
|
7337 |
QCOMPARE(item->transformOriginPoint(), origin); |
|
7338 |
||
7339 |
QCOMPARE(QTransform(), item->transform()); |
|
7340 |
QCOMPARE(result, item->sceneTransform()); |
|
7341 |
||
7342 |
//----------------------------------------------------------------- |
|
7343 |
//Change the rotation Z |
|
7344 |
item->setRotation(45); |
|
7345 |
QTransform result2; |
|
7346 |
result2.translate(origin.x(), origin.y()); |
|
7347 |
result2.rotate(45); |
|
7348 |
result2.scale(scale, scale); |
|
7349 |
result2.translate(-origin.x(), -origin.y()); |
|
7350 |
||
7351 |
QCOMPARE(item->rotation(), 45.); |
|
7352 |
QCOMPARE(item->scale(), scale); |
|
7353 |
QCOMPARE(item->transformOriginPoint(), origin); |
|
7354 |
||
7355 |
QCOMPARE(QTransform(), item->transform()); |
|
7356 |
QCOMPARE(result2, item->sceneTransform()); |
|
7357 |
||
7358 |
//----------------------------------------------------------------- |
|
7359 |
// calling setTransform() and setPos should change the sceneTransform |
|
7360 |
item->setTransform(result); |
|
7361 |
item->setPos(100, -150.5); |
|
7362 |
||
7363 |
QCOMPARE(item->rotation(), 45.); |
|
7364 |
QCOMPARE(item->scale(), scale); |
|
7365 |
QCOMPARE(item->transformOriginPoint(), origin); |
|
7366 |
QCOMPARE(result, item->transform()); |
|
7367 |
||
7368 |
QTransform result3(result); |
|
7369 |
||
7370 |
result3.translate(origin.x(), origin.y()); |
|
7371 |
result3.rotate(45); |
|
7372 |
result3.scale(scale, scale); |
|
7373 |
result3.translate(-origin.x(), -origin.y()); |
|
7374 |
||
7375 |
result3 *= QTransform::fromTranslate(100, -150.5); //the pos; |
|
7376 |
||
7377 |
QCOMPARE(result3, item->sceneTransform()); |
|
7378 |
||
7379 |
//----------------------------------------------------- |
|
7380 |
// setting the propertiees should be the same as setting a transform |
|
7381 |
{//with center origin on the matrix |
|
7382 |
QGraphicsRectItem *item1 = new QGraphicsRectItem(QRectF(50.2, -150, 230.5, 119)); |
|
7383 |
scene.addItem(item1); |
|
7384 |
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(50.2, -150, 230.5, 119)); |
|
7385 |
scene.addItem(item2); |
|
7386 |
||
7387 |
item1->setPos(12.3, -5); |
|
7388 |
item2->setPos(12.3, -5); |
|
7389 |
item1->setRotation(rotation); |
|
7390 |
item1->setScale(scale); |
|
7391 |
item1->setTransformOriginPoint(origin); |
|
7392 |
||
7393 |
item2->setTransform(result); |
|
7394 |
||
7395 |
QCOMPARE_TRANSFORM(item1->sceneTransform(), item2->sceneTransform()); |
|
7396 |
||
7397 |
QCOMPARE_TRANSFORM(item1->itemTransform(item2), QTransform()); |
|
7398 |
QCOMPARE_TRANSFORM(item2->itemTransform(item1), QTransform()); |
|
7399 |
} |
|
7400 |
} |
|
7401 |
||
7402 |
class MyStyleOptionTester : public QGraphicsRectItem |
|
7403 |
{ |
|
7404 |
public: |
|
7405 |
MyStyleOptionTester(const QRectF &rect) |
|
7406 |
: QGraphicsRectItem(rect), startTrack(false) |
|
7407 |
{} |
|
7408 |
||
7409 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) |
|
7410 |
{ |
|
7411 |
if (startTrack) { |
|
7412 |
//Doesn't use the extended style option so the exposed rect is the boundingRect |
|
7413 |
if (!(flags() & QGraphicsItem::ItemUsesExtendedStyleOption)) { |
|
7414 |
QCOMPARE(option->exposedRect, boundingRect()); |
|
7415 |
QCOMPARE(option->matrix, QMatrix()); |
|
7416 |
} else { |
|
7417 |
QVERIFY(option->exposedRect != QRect()); |
|
7418 |
QVERIFY(option->exposedRect != boundingRect()); |
|
7419 |
QCOMPARE(option->matrix, sceneTransform().toAffine()); |
|
7420 |
} |
|
7421 |
} |
|
7422 |
QGraphicsRectItem::paint(painter, option, widget); |
|
7423 |
} |
|
7424 |
bool startTrack; |
|
7425 |
}; |
|
7426 |
||
7427 |
void tst_QGraphicsItem::itemUsesExtendedStyleOption() |
|
7428 |
{ |
|
7429 |
QGraphicsScene scene(0, 0, 300, 300); |
|
7430 |
QGraphicsPixmapItem item; |
|
7431 |
item.setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); |
|
7432 |
QCOMPARE(item.flags(), QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemUsesExtendedStyleOption)); |
|
7433 |
item.setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, false); |
|
7434 |
QCOMPARE(item.flags(), 0); |
|
7435 |
||
7436 |
//We now test the content of the style option |
|
7437 |
MyStyleOptionTester *rect = new MyStyleOptionTester(QRect(0, 0, 100, 100)); |
|
7438 |
scene.addItem(rect); |
|
7439 |
rect->setPos(200, 200); |
|
7440 |
QGraphicsView view(&scene); |
|
7441 |
rect->startTrack = false; |
|
7442 |
view.show(); |
|
7443 |
QTest::qWaitForWindowShown(&view); |
|
7444 |
QTest::qWait(60); |
|
7445 |
rect->startTrack = true; |
|
7446 |
rect->update(10, 10, 10, 10); |
|
7447 |
QTest::qWait(60); |
|
7448 |
rect->startTrack = false; |
|
7449 |
rect->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); |
|
7450 |
QVERIFY((rect->flags() & QGraphicsItem::ItemUsesExtendedStyleOption)); |
|
7451 |
QTest::qWait(60); |
|
7452 |
rect->startTrack = true; |
|
7453 |
rect->update(10, 10, 10, 10); |
|
7454 |
QTest::qWait(60); |
|
7455 |
} |
|
7456 |
||
7457 |
void tst_QGraphicsItem::itemSendsGeometryChanges() |
|
7458 |
{ |
|
7459 |
ItemChangeTester item; |
|
7460 |
item.setFlags(0); |
|
7461 |
item.clear(); |
|
7462 |
||
7463 |
QTransform x = QTransform().rotate(45); |
|
7464 |
QPointF pos(10, 10); |
|
7465 |
qreal o(0.5); |
|
7466 |
item.setTransform(x); |
|
7467 |
item.setPos(pos); |
|
7468 |
QCOMPARE(item.transform(), x); |
|
7469 |
QCOMPARE(item.pos(), pos); |
|
7470 |
QCOMPARE(item.changes.size(), 0); |
|
7471 |
||
7472 |
item.setOpacity(o); |
|
7473 |
QCOMPARE(item.changes.size(), 2); // opacity |
|
7474 |
||
7475 |
item.setFlag(QGraphicsItem::ItemSendsGeometryChanges); |
|
7476 |
QCOMPARE(item.changes.size(), 4); // flags |
|
7477 |
item.setTransform(QTransform()); |
|
7478 |
item.setPos(QPointF()); |
|
7479 |
QCOMPARE(item.changes.size(), 8); // transform + pos |
|
7480 |
QCOMPARE(item.transform(), QTransform()); |
|
7481 |
QCOMPARE(item.pos(), QPointF()); |
|
7482 |
QCOMPARE(item.opacity(), o); |
|
7483 |
||
7484 |
QCOMPARE(item.changes, QList<QGraphicsItem::GraphicsItemChange>() |
|
7485 |
<< QGraphicsItem::ItemOpacityChange |
|
7486 |
<< QGraphicsItem::ItemOpacityHasChanged |
|
7487 |
<< QGraphicsItem::ItemFlagsChange |
|
7488 |
<< QGraphicsItem::ItemFlagsHaveChanged |
|
7489 |
<< QGraphicsItem::ItemTransformChange |
|
7490 |
<< QGraphicsItem::ItemTransformHasChanged |
|
7491 |
<< QGraphicsItem::ItemPositionChange |
|
7492 |
<< QGraphicsItem::ItemPositionHasChanged); |
|
7493 |
} |
|
7494 |
||
7495 |
// Make sure we update moved items correctly. |
|
7496 |
void tst_QGraphicsItem::moveItem() |
|
7497 |
{ |
|
7498 |
QGraphicsScene scene; |
|
7499 |
scene.setSceneRect(-50, -50, 200, 200); |
|
7500 |
||
7501 |
MyGraphicsView view(&scene); |
|
7502 |
view.show(); |
|
7503 |
#ifdef Q_WS_X11 |
|
7504 |
qt_x11_wait_for_window_manager(&view); |
|
7505 |
#endif |
|
7506 |
QTest::qWait(100); |
|
7507 |
||
7508 |
EventTester *parent = new EventTester; |
|
7509 |
EventTester *child = new EventTester(parent); |
|
7510 |
EventTester *grandChild = new EventTester(child); |
|
7511 |
||
7512 |
#define RESET_COUNTERS \ |
|
7513 |
parent->repaints = 0; \ |
|
7514 |
child->repaints = 0; \ |
|
7515 |
grandChild->repaints = 0; \ |
|
7516 |
view.reset(); |
|
7517 |
||
7518 |
scene.addItem(parent); |
|
7519 |
QTest::qWait(100); |
|
7520 |
||
7521 |
RESET_COUNTERS |
|
7522 |
||
7523 |
// Item's boundingRect: (-10, -10, 20, 20). |
|
7524 |
QRect parentDeviceBoundingRect = parent->deviceTransform(view.viewportTransform()) |
|
7525 |
.mapRect(parent->boundingRect()).toRect() |
|
7526 |
.adjusted(-2, -2, 2, 2); // Adjusted for antialiasing. |
|
7527 |
||
7528 |
parent->setPos(20, 20); |
|
7529 |
qApp->processEvents(); |
|
7530 |
QCOMPARE(parent->repaints, 1); |
|
7531 |
QCOMPARE(view.repaints, 1); |
|
7532 |
QRegion expectedParentRegion = parentDeviceBoundingRect; // old position |
|
7533 |
parentDeviceBoundingRect.translate(20, 20); |
|
7534 |
expectedParentRegion += parentDeviceBoundingRect; // new position |
|
7535 |
COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); |
|
7536 |
||
7537 |
RESET_COUNTERS |
|
7538 |
||
7539 |
child->setPos(20, 20); |
|
7540 |
qApp->processEvents(); |
|
7541 |
QCOMPARE(parent->repaints, 1); |
|
7542 |
QCOMPARE(child->repaints, 1); |
|
7543 |
QCOMPARE(view.repaints, 1); |
|
7544 |
const QRegion expectedChildRegion = expectedParentRegion.translated(20, 20); |
|
7545 |
COMPARE_REGIONS(view.paintedRegion, expectedChildRegion); |
|
7546 |
||
7547 |
RESET_COUNTERS |
|
7548 |
||
7549 |
grandChild->setPos(20, 20); |
|
7550 |
qApp->processEvents(); |
|
7551 |
QCOMPARE(parent->repaints, 1); |
|
7552 |
QCOMPARE(child->repaints, 1); |
|
7553 |
QCOMPARE(grandChild->repaints, 1); |
|
7554 |
QCOMPARE(view.repaints, 1); |
|
7555 |
const QRegion expectedGrandChildRegion = expectedParentRegion.translated(40, 40); |
|
7556 |
COMPARE_REGIONS(view.paintedRegion, expectedGrandChildRegion); |
|
7557 |
||
7558 |
RESET_COUNTERS |
|
7559 |
||
7560 |
parent->translate(20, 20); |
|
7561 |
qApp->processEvents(); |
|
7562 |
QCOMPARE(parent->repaints, 1); |
|
7563 |
QCOMPARE(child->repaints, 1); |
|
7564 |
QCOMPARE(grandChild->repaints, 1); |
|
7565 |
QCOMPARE(view.repaints, 1); |
|
7566 |
expectedParentRegion.translate(20, 20); |
|
7567 |
expectedParentRegion += expectedChildRegion.translated(20, 20); |
|
7568 |
expectedParentRegion += expectedGrandChildRegion.translated(20, 20); |
|
7569 |
COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); |
|
7570 |
} |
|
7571 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7572 |
void tst_QGraphicsItem::moveLineItem() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7573 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7574 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7575 |
scene.setSceneRect(0, 0, 200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7576 |
QGraphicsLineItem *item = new QGraphicsLineItem(0, 0, 100, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7577 |
item->setPos(50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7578 |
scene.addItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7579 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7580 |
MyGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7581 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7582 |
#ifdef Q_WS_X11 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7583 |
qt_x11_wait_for_window_manager(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7584 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7585 |
QTest::qWait(200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7586 |
view.reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7587 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7588 |
const QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7589 |
.mapRect(item->boundingRect()).toRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7590 |
QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); // antialiasing |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7591 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7592 |
// Make sure the calculated region is correct. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7593 |
item->update(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7594 |
QTest::qWait(10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7595 |
QTRY_COMPARE(view.paintedRegion, expectedRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7596 |
view.reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7597 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7598 |
// Old position: (50, 50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7599 |
item->setPos(50, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7600 |
expectedRegion += expectedRegion.translated(0, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7601 |
QTest::qWait(10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7602 |
QCOMPARE(view.paintedRegion, expectedRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7603 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7604 |
|
0 | 7605 |
void tst_QGraphicsItem::sorting_data() |
7606 |
{ |
|
7607 |
QTest::addColumn<int>("index"); |
|
7608 |
||
7609 |
QTest::newRow("NoIndex") << int(QGraphicsScene::NoIndex); |
|
7610 |
QTest::newRow("BspTreeIndex") << int(QGraphicsScene::BspTreeIndex); |
|
7611 |
} |
|
7612 |
||
7613 |
void tst_QGraphicsItem::sorting() |
|
7614 |
{ |
|
7615 |
_paintedItems.clear(); |
|
7616 |
||
7617 |
QGraphicsScene scene; |
|
7618 |
QGraphicsItem *grid[100][100]; |
|
7619 |
for (int x = 0; x < 100; ++x) { |
|
7620 |
for (int y = 0; y < 100; ++y) { |
|
7621 |
PainterItem *item = new PainterItem; |
|
7622 |
item->setPos(x * 25, y * 25); |
|
7623 |
item->setData(0, QString("%1x%2").arg(x).arg(y)); |
|
7624 |
grid[x][y] = item; |
|
7625 |
scene.addItem(item); |
|
7626 |
} |
|
7627 |
} |
|
7628 |
||
7629 |
PainterItem *item1 = new PainterItem; |
|
7630 |
PainterItem *item2 = new PainterItem; |
|
7631 |
item1->setData(0, "item1"); |
|
7632 |
item2->setData(0, "item2"); |
|
7633 |
scene.addItem(item1); |
|
7634 |
scene.addItem(item2); |
|
7635 |
||
7636 |
QGraphicsView view(&scene); |
|
7637 |
view.setResizeAnchor(QGraphicsView::NoAnchor); |
|
7638 |
view.setTransformationAnchor(QGraphicsView::NoAnchor); |
|
7639 |
view.resize(120, 100); |
|
7640 |
view.setFrameStyle(0); |
|
7641 |
view.show(); |
|
7642 |
#ifdef Q_WS_X11 |
|
7643 |
qt_x11_wait_for_window_manager(&view); |
|
7644 |
#endif |
|
7645 |
QTest::qWait(100); |
|
7646 |
||
7647 |
_paintedItems.clear(); |
|
7648 |
||
7649 |
view.viewport()->repaint(); |
|
7650 |
#ifdef Q_WS_MAC |
|
7651 |
// There's no difference between repaint and update on the Mac, |
|
7652 |
// so we have to process events here to make sure we get the event. |
|
7653 |
QTest::qWait(100); |
|
7654 |
#endif |
|
7655 |
||
7656 |
QCOMPARE(_paintedItems, QList<QGraphicsItem *>() |
|
7657 |
<< grid[0][0] << grid[0][1] << grid[0][2] << grid[0][3] |
|
7658 |
<< grid[1][0] << grid[1][1] << grid[1][2] << grid[1][3] |
|
7659 |
<< grid[2][0] << grid[2][1] << grid[2][2] << grid[2][3] |
|
7660 |
<< grid[3][0] << grid[3][1] << grid[3][2] << grid[3][3] |
|
7661 |
<< grid[4][0] << grid[4][1] << grid[4][2] << grid[4][3] |
|
7662 |
<< item1 << item2); |
|
7663 |
} |
|
7664 |
||
7665 |
void tst_QGraphicsItem::itemHasNoContents() |
|
7666 |
{ |
|
7667 |
PainterItem *item1 = new PainterItem; |
|
7668 |
PainterItem *item2 = new PainterItem; |
|
7669 |
item2->setParentItem(item1); |
|
7670 |
item2->setPos(50, 50); |
|
7671 |
item1->setFlag(QGraphicsItem::ItemHasNoContents); |
|
7672 |
item1->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
7673 |
||
7674 |
QGraphicsScene scene; |
|
7675 |
scene.addItem(item1); |
|
7676 |
||
7677 |
QGraphicsView view(&scene); |
|
7678 |
view.show(); |
|
7679 |
QTest::qWaitForWindowShown(&view); |
|
7680 |
QTRY_VERIFY(!_paintedItems.isEmpty()); |
|
7681 |
||
7682 |
_paintedItems.clear(); |
|
7683 |
||
7684 |
view.viewport()->repaint(); |
|
7685 |
#ifdef Q_WS_MAC |
|
7686 |
// There's no difference between update() and repaint() on the Mac, |
|
7687 |
// so we have to process events here to make sure we get the event. |
|
7688 |
QTest::qWait(10); |
|
7689 |
#endif |
|
7690 |
||
7691 |
QTRY_COMPARE(_paintedItems, QList<QGraphicsItem *>() << item2); |
|
7692 |
} |
|
7693 |
||
7694 |
void tst_QGraphicsItem::hitTestUntransformableItem() |
|
7695 |
{ |
|
7696 |
QGraphicsScene scene; |
|
7697 |
scene.setSceneRect(-100, -100, 200, 200); |
|
7698 |
||
7699 |
QGraphicsView view(&scene); |
|
7700 |
view.show(); |
|
7701 |
#ifdef Q_WS_X11 |
|
7702 |
qt_x11_wait_for_window_manager(&view); |
|
7703 |
#endif |
|
7704 |
QTest::qWait(100); |
|
7705 |
||
7706 |
// Confuse the BSP with dummy items. |
|
7707 |
QGraphicsRectItem *dummy = new QGraphicsRectItem(0, 0, 20, 20); |
|
7708 |
dummy->setPos(-100, -100); |
|
7709 |
scene.addItem(dummy); |
|
7710 |
for (int i = 0; i < 100; ++i) { |
|
7711 |
QGraphicsItem *parent = dummy; |
|
7712 |
dummy = new QGraphicsRectItem(0, 0, 20, 20); |
|
7713 |
dummy->setPos(-100 + i, -100 + i); |
|
7714 |
dummy->setParentItem(parent); |
|
7715 |
} |
|
7716 |
||
7717 |
QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, 20, 20); |
|
7718 |
item1->setPos(-200, -200); |
|
7719 |
||
7720 |
QGraphicsRectItem *item2 = new QGraphicsRectItem(0, 0, 20, 20); |
|
7721 |
item2->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
7722 |
item2->setParentItem(item1); |
|
7723 |
item2->setPos(200, 200); |
|
7724 |
||
7725 |
QGraphicsRectItem *item3 = new QGraphicsRectItem(0, 0, 20, 20); |
|
7726 |
item3->setParentItem(item2); |
|
7727 |
item3->setPos(80, 80); |
|
7728 |
||
7729 |
scene.addItem(item1); |
|
7730 |
QTest::qWait(100); |
|
7731 |
||
7732 |
QList<QGraphicsItem *> items = scene.items(QPointF(80, 80)); |
|
7733 |
QCOMPARE(items.size(), 1); |
|
7734 |
QCOMPARE(items.at(0), static_cast<QGraphicsItem*>(item3)); |
|
7735 |
||
7736 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); |
|
7737 |
QTest::qWait(100); |
|
7738 |
||
7739 |
items = scene.items(QPointF(80, 80)); |
|
7740 |
QCOMPARE(items.size(), 1); |
|
7741 |
QCOMPARE(items.at(0), static_cast<QGraphicsItem*>(item3)); |
|
7742 |
} |
|
7743 |
||
7744 |
void tst_QGraphicsItem::hitTestGraphicsEffectItem() |
|
7745 |
{ |
|
7746 |
QGraphicsScene scene; |
|
7747 |
scene.setSceneRect(-100, -100, 200, 200); |
|
7748 |
||
7749 |
QGraphicsView view(&scene); |
|
7750 |
view.show(); |
|
7751 |
#ifdef Q_WS_X11 |
|
7752 |
qt_x11_wait_for_window_manager(&view); |
|
7753 |
#endif |
|
7754 |
QTest::qWait(100); |
|
7755 |
||
7756 |
// Confuse the BSP with dummy items. |
|
7757 |
QGraphicsRectItem *dummy = new QGraphicsRectItem(0, 0, 20, 20); |
|
7758 |
dummy->setPos(-100, -100); |
|
7759 |
scene.addItem(dummy); |
|
7760 |
for (int i = 0; i < 100; ++i) { |
|
7761 |
QGraphicsItem *parent = dummy; |
|
7762 |
dummy = new QGraphicsRectItem(0, 0, 20, 20); |
|
7763 |
dummy->setPos(-100 + i, -100 + i); |
|
7764 |
dummy->setParentItem(parent); |
|
7765 |
} |
|
7766 |
||
7767 |
const QRectF itemBoundingRect(0, 0, 20, 20); |
|
7768 |
EventTester *item1 = new EventTester; |
|
7769 |
item1->br = itemBoundingRect; |
|
7770 |
item1->setPos(-200, -200); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7771 |
item1->brush = Qt::red; |
0 | 7772 |
|
7773 |
EventTester *item2 = new EventTester; |
|
7774 |
item2->br = itemBoundingRect; |
|
7775 |
item2->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
7776 |
item2->setParentItem(item1); |
|
7777 |
item2->setPos(200, 200); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7778 |
item2->brush = Qt::green; |
0 | 7779 |
|
7780 |
EventTester *item3 = new EventTester; |
|
7781 |
item3->br = itemBoundingRect; |
|
7782 |
item3->setParentItem(item2); |
|
7783 |
item3->setPos(80, 80); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7784 |
item3->brush = Qt::blue; |
0 | 7785 |
|
7786 |
scene.addItem(item1); |
|
7787 |
QTest::qWait(100); |
|
7788 |
||
7789 |
item1->repaints = 0; |
|
7790 |
item2->repaints = 0; |
|
7791 |
item3->repaints = 0; |
|
7792 |
||
7793 |
// Apply shadow effect to the entire sub-tree. |
|
7794 |
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect; |
|
7795 |
shadow->setOffset(-20, -20); |
|
7796 |
item1->setGraphicsEffect(shadow); |
|
7797 |
QTest::qWait(50); |
|
7798 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7799 |
// Make sure all visible items are repainted. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7800 |
QCOMPARE(item1->repaints, 0); |
0 | 7801 |
QCOMPARE(item2->repaints, 1); |
7802 |
QCOMPARE(item3->repaints, 1); |
|
7803 |
||
7804 |
// Make sure an item doesn't respond to a click on its shadow. |
|
7805 |
QList<QGraphicsItem *> items = scene.items(QPointF(75, 75)); |
|
7806 |
QVERIFY(items.isEmpty()); |
|
7807 |
items = scene.items(QPointF(80, 80)); |
|
7808 |
QCOMPARE(items.size(), 1); |
|
7809 |
QCOMPARE(items.at(0), static_cast<QGraphicsItem *>(item3)); |
|
7810 |
||
7811 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); |
|
7812 |
QTest::qWait(100); |
|
7813 |
||
7814 |
items = scene.items(QPointF(75, 75)); |
|
7815 |
QVERIFY(items.isEmpty()); |
|
7816 |
items = scene.items(QPointF(80, 80)); |
|
7817 |
QCOMPARE(items.size(), 1); |
|
7818 |
QCOMPARE(items.at(0), static_cast<QGraphicsItem *>(item3)); |
|
7819 |
} |
|
7820 |
||
7821 |
void tst_QGraphicsItem::focusProxy() |
|
7822 |
{ |
|
7823 |
QGraphicsScene scene; |
|
7824 |
QEvent activate(QEvent::WindowActivate); |
|
7825 |
QApplication::sendEvent(&scene, &activate); |
|
7826 |
||
7827 |
QGraphicsItem *item = scene.addRect(0, 0, 10, 10); |
|
7828 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
7829 |
QVERIFY(!item->focusProxy()); |
|
7830 |
||
7831 |
QGraphicsItem *item2 = scene.addRect(0, 0, 10, 10); |
|
7832 |
item2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
7833 |
item->setFocusProxy(item2); |
|
7834 |
QCOMPARE(item->focusProxy(), item2); |
|
7835 |
||
7836 |
item->setFocus(); |
|
7837 |
QVERIFY(item->hasFocus()); |
|
7838 |
QVERIFY(item2->hasFocus()); |
|
7839 |
||
7840 |
// Try to make a focus chain loop |
|
7841 |
QString err; |
|
7842 |
QTextStream stream(&err); |
|
7843 |
stream << "QGraphicsItem::setFocusProxy: " |
|
7844 |
<< (void*)item << " is already in the focus proxy chain" << flush; |
|
7845 |
QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); |
|
7846 |
item2->setFocusProxy(item); // fails |
|
7847 |
QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); |
|
7848 |
QCOMPARE(item2->focusProxy(), (QGraphicsItem *)0); |
|
7849 |
||
7850 |
// Try to assign self as focus proxy |
|
7851 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::setFocusProxy: cannot assign self as focus proxy"); |
|
7852 |
item->setFocusProxy(item); // fails |
|
7853 |
QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); |
|
7854 |
QCOMPARE(item2->focusProxy(), (QGraphicsItem *)0); |
|
7855 |
||
7856 |
// Reset the focus proxy |
|
7857 |
item->setFocusProxy(0); |
|
7858 |
QCOMPARE(item->focusProxy(), (QGraphicsItem *)0); |
|
7859 |
QVERIFY(!item->hasFocus()); |
|
7860 |
QVERIFY(item2->hasFocus()); |
|
7861 |
||
7862 |
// Test deletion |
|
7863 |
item->setFocusProxy(item2); |
|
7864 |
QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); |
|
7865 |
delete item2; |
|
7866 |
QCOMPARE(item->focusProxy(), (QGraphicsItem *)0); |
|
7867 |
||
7868 |
// Test event delivery |
|
7869 |
item2 = scene.addRect(0, 0, 10, 10); |
|
7870 |
item2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
7871 |
item->setFocusProxy(item2); |
|
7872 |
item->clearFocus(); |
|
7873 |
||
7874 |
EventSpy focusInSpy(&scene, item, QEvent::FocusIn); |
|
7875 |
EventSpy focusOutSpy(&scene, item, QEvent::FocusOut); |
|
7876 |
EventSpy focusInSpy2(&scene, item2, QEvent::FocusIn); |
|
7877 |
EventSpy focusOutSpy2(&scene, item2, QEvent::FocusOut); |
|
7878 |
QCOMPARE(focusInSpy.count(), 0); |
|
7879 |
QCOMPARE(focusOutSpy.count(), 0); |
|
7880 |
QCOMPARE(focusInSpy2.count(), 0); |
|
7881 |
QCOMPARE(focusOutSpy2.count(), 0); |
|
7882 |
||
7883 |
item->setFocus(); |
|
7884 |
QCOMPARE(focusInSpy.count(), 0); |
|
7885 |
QCOMPARE(focusInSpy2.count(), 1); |
|
7886 |
item->clearFocus(); |
|
7887 |
QCOMPARE(focusOutSpy.count(), 0); |
|
7888 |
QCOMPARE(focusOutSpy2.count(), 1); |
|
7889 |
||
7890 |
// Test two items proxying one item. |
|
7891 |
QGraphicsItem *item3 = scene.addRect(0, 0, 10, 10); |
|
7892 |
item3->setFlag(QGraphicsItem::ItemIsFocusable); |
|
7893 |
item3->setFocusProxy(item2); // item and item3 use item2 as proxy |
|
7894 |
||
7895 |
QCOMPARE(item->focusProxy(), item2); |
|
7896 |
QCOMPARE(item2->focusProxy(), (QGraphicsItem *)0); |
|
7897 |
QCOMPARE(item3->focusProxy(), item2); |
|
7898 |
delete item2; |
|
7899 |
QCOMPARE(item->focusProxy(), (QGraphicsItem *)0); |
|
7900 |
QCOMPARE(item3->focusProxy(), (QGraphicsItem *)0); |
|
7901 |
} |
|
7902 |
||
7903 |
void tst_QGraphicsItem::subFocus() |
|
7904 |
{ |
|
7905 |
// Construct a text item that's not part of a scene (yet) |
|
7906 |
// and has no parent. Setting focus on it will not make |
|
7907 |
// the item gain input focus; that requires a scene. But |
|
7908 |
// it does set subfocus, indicating that the item wishes |
|
7909 |
// to gain focus later. |
|
7910 |
QGraphicsTextItem *text = new QGraphicsTextItem("Hello"); |
|
7911 |
text->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
7912 |
QVERIFY(!text->hasFocus()); |
|
7913 |
text->setFocus(); |
|
7914 |
QVERIFY(!text->hasFocus()); |
|
7915 |
QCOMPARE(text->focusItem(), (QGraphicsItem *)text); |
|
7916 |
||
7917 |
// Add a sibling. |
|
7918 |
QGraphicsTextItem *text2 = new QGraphicsTextItem("Hi"); |
|
7919 |
text2->setTextInteractionFlags(Qt::TextEditorInteraction); |
|
7920 |
text2->setPos(30, 30); |
|
7921 |
||
7922 |
// Add both items to a scene and check that it's text that |
|
7923 |
// got input focus. |
|
7924 |
QGraphicsScene scene; |
|
7925 |
QEvent activate(QEvent::WindowActivate); |
|
7926 |
QApplication::sendEvent(&scene, &activate); |
|
7927 |
||
7928 |
scene.addItem(text); |
|
7929 |
scene.addItem(text2); |
|
7930 |
QVERIFY(text->hasFocus()); |
|
7931 |
||
7932 |
text->setData(0, "text"); |
|
7933 |
text2->setData(0, "text2"); |
|
7934 |
||
7935 |
// Remove text2 and set subfocus on it. Then readd. Reparent it onto the |
|
7936 |
// other item and see that it gains input focus. |
|
7937 |
scene.removeItem(text2); |
|
7938 |
text2->setFocus(); |
|
7939 |
scene.addItem(text2); |
|
7940 |
QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2); |
|
7941 |
text2->setParentItem(text); |
|
7942 |
QCOMPARE(text->focusItem(), (QGraphicsItem *)text2); |
|
7943 |
QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2); |
|
7944 |
QVERIFY(!text->hasFocus()); |
|
7945 |
QVERIFY(text2->hasFocus()); |
|
7946 |
||
7947 |
// Remove both items from the scene, restore subfocus and |
|
7948 |
// readd them. Now the subfocus should kick in and give |
|
7949 |
// text2 focus. |
|
7950 |
scene.removeItem(text); |
|
7951 |
QCOMPARE(text->focusItem(), (QGraphicsItem *)0); |
|
7952 |
QCOMPARE(text2->focusItem(), (QGraphicsItem *)0); |
|
7953 |
text2->setFocus(); |
|
7954 |
QCOMPARE(text->focusItem(), (QGraphicsItem *)text2); |
|
7955 |
QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2); |
|
7956 |
scene.addItem(text); |
|
7957 |
||
7958 |
// Hiding and showing text should pass focus to text2. |
|
7959 |
QCOMPARE(text->focusItem(), (QGraphicsItem *)text2); |
|
7960 |
QVERIFY(text2->hasFocus()); |
|
7961 |
||
7962 |
// Subfocus should repropagate to root when reparenting. |
|
7963 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
7964 |
QGraphicsRectItem *rect2 = new QGraphicsRectItem(rect); |
|
7965 |
QGraphicsRectItem *rect3 = new QGraphicsRectItem(rect2); |
|
7966 |
rect3->setFlag(QGraphicsItem::ItemIsFocusable); |
|
7967 |
||
7968 |
text->setData(0, "text"); |
|
7969 |
text2->setData(0, "text2"); |
|
7970 |
rect->setData(0, "rect"); |
|
7971 |
rect2->setData(0, "rect2"); |
|
7972 |
rect3->setData(0, "rect3"); |
|
7973 |
||
7974 |
rect3->setFocus(); |
|
7975 |
QVERIFY(!rect3->hasFocus()); |
|
7976 |
QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3); |
|
7977 |
QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3); |
|
7978 |
QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3); |
|
7979 |
rect->setParentItem(text2); |
|
7980 |
QCOMPARE(text->focusItem(), (QGraphicsItem *)rect3); |
|
7981 |
QCOMPARE(text2->focusItem(), (QGraphicsItem *)rect3); |
|
7982 |
QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3); |
|
7983 |
QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3); |
|
7984 |
QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3); |
|
7985 |
QVERIFY(!rect->hasFocus()); |
|
7986 |
QVERIFY(!rect2->hasFocus()); |
|
7987 |
QVERIFY(rect3->hasFocus()); |
|
7988 |
||
7989 |
delete rect2; |
|
7990 |
QCOMPARE(text->focusItem(), (QGraphicsItem *)0); |
|
7991 |
QCOMPARE(text2->focusItem(), (QGraphicsItem *)0); |
|
7992 |
QCOMPARE(rect->focusItem(), (QGraphicsItem *)0); |
|
7993 |
} |
|
7994 |
||
7995 |
void tst_QGraphicsItem::focusProxyDeletion() |
|
7996 |
{ |
|
7997 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
7998 |
QGraphicsRectItem *rect2 = new QGraphicsRectItem; |
|
7999 |
rect->setFocusProxy(rect2); |
|
8000 |
QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2); |
|
8001 |
||
8002 |
delete rect2; |
|
8003 |
QCOMPARE(rect->focusProxy(), (QGraphicsItem *)0); |
|
8004 |
||
8005 |
rect2 = new QGraphicsRectItem; |
|
8006 |
rect->setFocusProxy(rect2); |
|
8007 |
delete rect; // don't crash |
|
8008 |
||
8009 |
rect = new QGraphicsRectItem; |
|
8010 |
rect->setFocusProxy(rect2); |
|
8011 |
QGraphicsScene *scene = new QGraphicsScene; |
|
8012 |
scene->addItem(rect); |
|
8013 |
scene->addItem(rect2); |
|
8014 |
delete rect2; |
|
8015 |
QCOMPARE(rect->focusProxy(), (QGraphicsItem *)0); |
|
8016 |
||
8017 |
rect2 = new QGraphicsRectItem; |
|
8018 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::setFocusProxy: focus proxy must be in same scene"); |
|
8019 |
rect->setFocusProxy(rect2); |
|
8020 |
QCOMPARE(rect->focusProxy(), (QGraphicsItem *)0); |
|
8021 |
scene->addItem(rect2); |
|
8022 |
rect->setFocusProxy(rect2); |
|
8023 |
QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2); |
|
8024 |
delete rect; // don't crash |
|
8025 |
||
8026 |
rect = new QGraphicsRectItem; |
|
8027 |
rect2 = new QGraphicsRectItem; |
|
8028 |
rect->setFocusProxy(rect2); |
|
8029 |
QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2); |
|
8030 |
scene->addItem(rect); |
|
8031 |
scene->addItem(rect2); |
|
8032 |
rect->setFocusProxy(rect2); |
|
8033 |
delete scene; // don't crash |
|
8034 |
} |
|
8035 |
||
8036 |
void tst_QGraphicsItem::negativeZStacksBehindParent() |
|
8037 |
{ |
|
8038 |
QGraphicsRectItem rect; |
|
8039 |
QCOMPARE(rect.zValue(), qreal(0.0)); |
|
8040 |
QVERIFY(!(rect.flags() & QGraphicsItem::ItemNegativeZStacksBehindParent)); |
|
8041 |
QVERIFY(!(rect.flags() & QGraphicsItem::ItemStacksBehindParent)); |
|
8042 |
rect.setZValue(-1); |
|
8043 |
QCOMPARE(rect.zValue(), qreal(-1.0)); |
|
8044 |
QVERIFY(!(rect.flags() & QGraphicsItem::ItemStacksBehindParent)); |
|
8045 |
rect.setZValue(0); |
|
8046 |
rect.setFlag(QGraphicsItem::ItemNegativeZStacksBehindParent); |
|
8047 |
QVERIFY(rect.flags() & QGraphicsItem::ItemNegativeZStacksBehindParent); |
|
8048 |
QVERIFY(!(rect.flags() & QGraphicsItem::ItemStacksBehindParent)); |
|
8049 |
rect.setZValue(-1); |
|
8050 |
QVERIFY(rect.flags() & QGraphicsItem::ItemStacksBehindParent); |
|
8051 |
rect.setZValue(0); |
|
8052 |
QVERIFY(!(rect.flags() & QGraphicsItem::ItemStacksBehindParent)); |
|
8053 |
rect.setFlag(QGraphicsItem::ItemNegativeZStacksBehindParent, false); |
|
8054 |
rect.setZValue(-1); |
|
8055 |
rect.setFlag(QGraphicsItem::ItemNegativeZStacksBehindParent, true); |
|
8056 |
QVERIFY(rect.flags() & QGraphicsItem::ItemStacksBehindParent); |
|
8057 |
rect.setFlag(QGraphicsItem::ItemNegativeZStacksBehindParent, false); |
|
8058 |
QVERIFY(rect.flags() & QGraphicsItem::ItemStacksBehindParent); |
|
8059 |
} |
|
8060 |
||
8061 |
void tst_QGraphicsItem::setGraphicsEffect() |
|
8062 |
{ |
|
8063 |
// Check that we don't have any effect by default. |
|
8064 |
QGraphicsItem *item = new QGraphicsRectItem(0, 0, 10, 10); |
|
8065 |
QVERIFY(!item->graphicsEffect()); |
|
8066 |
||
8067 |
// SetGet check. |
|
8068 |
QPointer<QGraphicsEffect> blurEffect = new QGraphicsBlurEffect; |
|
8069 |
item->setGraphicsEffect(blurEffect); |
|
8070 |
QCOMPARE(item->graphicsEffect(), static_cast<QGraphicsEffect *>(blurEffect)); |
|
8071 |
||
8072 |
// Ensure the existing effect is deleted when setting a new one. |
|
8073 |
QPointer<QGraphicsEffect> shadowEffect = new QGraphicsDropShadowEffect; |
|
8074 |
item->setGraphicsEffect(shadowEffect); |
|
8075 |
QVERIFY(!blurEffect); |
|
8076 |
QCOMPARE(item->graphicsEffect(), static_cast<QGraphicsEffect *>(shadowEffect)); |
|
8077 |
blurEffect = new QGraphicsBlurEffect; |
|
8078 |
||
8079 |
// Ensure the effect is uninstalled when setting it on a new target. |
|
8080 |
QGraphicsItem *anotherItem = new QGraphicsRectItem(0, 0, 10, 10); |
|
8081 |
anotherItem->setGraphicsEffect(blurEffect); |
|
8082 |
item->setGraphicsEffect(blurEffect); |
|
8083 |
QVERIFY(!anotherItem->graphicsEffect()); |
|
8084 |
QVERIFY(!shadowEffect); |
|
8085 |
||
8086 |
// Ensure the existing effect is deleted when deleting the item. |
|
8087 |
delete item; |
|
8088 |
QVERIFY(!blurEffect); |
|
8089 |
delete anotherItem; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8090 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8091 |
// Ensure the effect is uninstalled when deleting it |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8092 |
item = new QGraphicsRectItem(0, 0, 10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8093 |
blurEffect = new QGraphicsBlurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8094 |
item->setGraphicsEffect(blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8095 |
delete blurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8096 |
QVERIFY(!item->graphicsEffect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8097 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8098 |
// Ensure the existing effect is uninstalled and deleted when setting a null effect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8099 |
blurEffect = new QGraphicsBlurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8100 |
item->setGraphicsEffect(blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8101 |
item->setGraphicsEffect(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8102 |
QVERIFY(!item->graphicsEffect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8103 |
QVERIFY(!blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8104 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8105 |
delete item; |
0 | 8106 |
} |
8107 |
||
8108 |
void tst_QGraphicsItem::panel() |
|
8109 |
{ |
|
8110 |
QGraphicsScene scene; |
|
8111 |
||
8112 |
QGraphicsRectItem *panel1 = new QGraphicsRectItem; |
|
8113 |
QGraphicsRectItem *panel2 = new QGraphicsRectItem; |
|
8114 |
QGraphicsRectItem *panel3 = new QGraphicsRectItem; |
|
8115 |
QGraphicsRectItem *panel4 = new QGraphicsRectItem; |
|
8116 |
QGraphicsRectItem *notPanel1 = new QGraphicsRectItem; |
|
8117 |
QGraphicsRectItem *notPanel2 = new QGraphicsRectItem; |
|
8118 |
panel1->setFlag(QGraphicsItem::ItemIsPanel); |
|
8119 |
panel2->setFlag(QGraphicsItem::ItemIsPanel); |
|
8120 |
panel3->setFlag(QGraphicsItem::ItemIsPanel); |
|
8121 |
panel4->setFlag(QGraphicsItem::ItemIsPanel); |
|
8122 |
scene.addItem(panel1); |
|
8123 |
scene.addItem(panel2); |
|
8124 |
scene.addItem(panel3); |
|
8125 |
scene.addItem(panel4); |
|
8126 |
scene.addItem(notPanel1); |
|
8127 |
scene.addItem(notPanel2); |
|
8128 |
||
8129 |
EventSpy spy_activate_panel1(&scene, panel1, QEvent::WindowActivate); |
|
8130 |
EventSpy spy_deactivate_panel1(&scene, panel1, QEvent::WindowDeactivate); |
|
8131 |
EventSpy spy_activate_panel2(&scene, panel2, QEvent::WindowActivate); |
|
8132 |
EventSpy spy_deactivate_panel2(&scene, panel2, QEvent::WindowDeactivate); |
|
8133 |
EventSpy spy_activate_panel3(&scene, panel3, QEvent::WindowActivate); |
|
8134 |
EventSpy spy_deactivate_panel3(&scene, panel3, QEvent::WindowDeactivate); |
|
8135 |
EventSpy spy_activate_panel4(&scene, panel4, QEvent::WindowActivate); |
|
8136 |
EventSpy spy_deactivate_panel4(&scene, panel4, QEvent::WindowDeactivate); |
|
8137 |
EventSpy spy_activate_notPanel1(&scene, notPanel1, QEvent::WindowActivate); |
|
8138 |
EventSpy spy_deactivate_notPanel1(&scene, notPanel1, QEvent::WindowDeactivate); |
|
8139 |
EventSpy spy_activate_notPanel2(&scene, notPanel1, QEvent::WindowActivate); |
|
8140 |
EventSpy spy_deactivate_notPanel2(&scene, notPanel1, QEvent::WindowDeactivate); |
|
8141 |
||
8142 |
QCOMPARE(spy_activate_panel1.count(), 0); |
|
8143 |
QCOMPARE(spy_deactivate_panel1.count(), 0); |
|
8144 |
QCOMPARE(spy_activate_panel2.count(), 0); |
|
8145 |
QCOMPARE(spy_deactivate_panel2.count(), 0); |
|
8146 |
QCOMPARE(spy_activate_panel3.count(), 0); |
|
8147 |
QCOMPARE(spy_deactivate_panel3.count(), 0); |
|
8148 |
QCOMPARE(spy_activate_panel4.count(), 0); |
|
8149 |
QCOMPARE(spy_deactivate_panel4.count(), 0); |
|
8150 |
QCOMPARE(spy_activate_notPanel1.count(), 0); |
|
8151 |
QCOMPARE(spy_deactivate_notPanel1.count(), 0); |
|
8152 |
QCOMPARE(spy_activate_notPanel2.count(), 0); |
|
8153 |
QCOMPARE(spy_deactivate_notPanel2.count(), 0); |
|
8154 |
||
8155 |
QVERIFY(!scene.activePanel()); |
|
8156 |
QVERIFY(!scene.isActive()); |
|
8157 |
||
8158 |
QEvent activate(QEvent::WindowActivate); |
|
8159 |
QEvent deactivate(QEvent::WindowDeactivate); |
|
8160 |
||
8161 |
QApplication::sendEvent(&scene, &activate); |
|
8162 |
||
8163 |
// No previous activation, so the scene is active. |
|
8164 |
QVERIFY(scene.isActive()); |
|
8165 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)panel1); |
|
8166 |
QVERIFY(panel1->isActive()); |
|
8167 |
QVERIFY(!panel2->isActive()); |
|
8168 |
QVERIFY(!panel3->isActive()); |
|
8169 |
QVERIFY(!panel4->isActive()); |
|
8170 |
QVERIFY(!notPanel1->isActive()); |
|
8171 |
QVERIFY(!notPanel2->isActive()); |
|
8172 |
QCOMPARE(spy_deactivate_notPanel1.count(), 0); |
|
8173 |
QCOMPARE(spy_deactivate_notPanel2.count(), 0); |
|
8174 |
QCOMPARE(spy_activate_panel1.count(), 1); |
|
8175 |
QCOMPARE(spy_activate_panel2.count(), 0); |
|
8176 |
QCOMPARE(spy_activate_panel3.count(), 0); |
|
8177 |
QCOMPARE(spy_activate_panel4.count(), 0); |
|
8178 |
||
8179 |
// Switch back to scene. |
|
8180 |
scene.setActivePanel(0); |
|
8181 |
QVERIFY(!scene.activePanel()); |
|
8182 |
QVERIFY(!panel1->isActive()); |
|
8183 |
QVERIFY(!panel2->isActive()); |
|
8184 |
QVERIFY(!panel3->isActive()); |
|
8185 |
QVERIFY(!panel4->isActive()); |
|
8186 |
QVERIFY(notPanel1->isActive()); |
|
8187 |
QVERIFY(notPanel2->isActive()); |
|
8188 |
QCOMPARE(spy_activate_notPanel1.count(), 1); |
|
8189 |
QCOMPARE(spy_activate_notPanel2.count(), 1); |
|
8190 |
||
8191 |
// Deactivate the scene |
|
8192 |
QApplication::sendEvent(&scene, &deactivate); |
|
8193 |
QVERIFY(!scene.activePanel()); |
|
8194 |
QVERIFY(!panel1->isActive()); |
|
8195 |
QVERIFY(!panel2->isActive()); |
|
8196 |
QVERIFY(!panel3->isActive()); |
|
8197 |
QVERIFY(!panel4->isActive()); |
|
8198 |
QVERIFY(!notPanel1->isActive()); |
|
8199 |
QVERIFY(!notPanel2->isActive()); |
|
8200 |
QCOMPARE(spy_deactivate_notPanel1.count(), 1); |
|
8201 |
QCOMPARE(spy_deactivate_notPanel2.count(), 1); |
|
8202 |
||
8203 |
// Reactivate the scene |
|
8204 |
QApplication::sendEvent(&scene, &activate); |
|
8205 |
QVERIFY(!scene.activePanel()); |
|
8206 |
QVERIFY(!panel1->isActive()); |
|
8207 |
QVERIFY(!panel2->isActive()); |
|
8208 |
QVERIFY(!panel3->isActive()); |
|
8209 |
QVERIFY(!panel4->isActive()); |
|
8210 |
QVERIFY(notPanel1->isActive()); |
|
8211 |
QVERIFY(notPanel2->isActive()); |
|
8212 |
QCOMPARE(spy_activate_notPanel1.count(), 2); |
|
8213 |
QCOMPARE(spy_activate_notPanel2.count(), 2); |
|
8214 |
||
8215 |
// Switch to panel1 |
|
8216 |
scene.setActivePanel(panel1); |
|
8217 |
QVERIFY(panel1->isActive()); |
|
8218 |
QCOMPARE(spy_deactivate_notPanel1.count(), 2); |
|
8219 |
QCOMPARE(spy_deactivate_notPanel2.count(), 2); |
|
8220 |
QCOMPARE(spy_activate_panel1.count(), 2); |
|
8221 |
||
8222 |
// Deactivate the scene |
|
8223 |
QApplication::sendEvent(&scene, &deactivate); |
|
8224 |
QVERIFY(!panel1->isActive()); |
|
8225 |
QCOMPARE(spy_deactivate_panel1.count(), 2); |
|
8226 |
||
8227 |
// Reactivate the scene |
|
8228 |
QApplication::sendEvent(&scene, &activate); |
|
8229 |
QVERIFY(panel1->isActive()); |
|
8230 |
QCOMPARE(spy_activate_panel1.count(), 3); |
|
8231 |
||
8232 |
// Deactivate the scene |
|
8233 |
QApplication::sendEvent(&scene, &deactivate); |
|
8234 |
QVERIFY(!panel1->isActive()); |
|
8235 |
QVERIFY(!scene.activePanel()); |
|
8236 |
scene.setActivePanel(0); |
|
8237 |
||
8238 |
// Reactivate the scene |
|
8239 |
QApplication::sendEvent(&scene, &activate); |
|
8240 |
QVERIFY(!panel1->isActive()); |
|
8241 |
} |
|
8242 |
||
8243 |
void tst_QGraphicsItem::addPanelToActiveScene() |
|
8244 |
{ |
|
8245 |
QGraphicsScene scene; |
|
8246 |
QVERIFY(!scene.isActive()); |
|
8247 |
||
8248 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
8249 |
scene.addItem(rect); |
|
8250 |
QVERIFY(!rect->isActive()); |
|
8251 |
scene.removeItem(rect); |
|
8252 |
||
8253 |
QEvent activate(QEvent::WindowActivate); |
|
8254 |
QEvent deactivate(QEvent::WindowDeactivate); |
|
8255 |
||
8256 |
QApplication::sendEvent(&scene, &activate); |
|
8257 |
QVERIFY(scene.isActive()); |
|
8258 |
scene.addItem(rect); |
|
8259 |
QVERIFY(rect->isActive()); |
|
8260 |
scene.removeItem(rect); |
|
8261 |
||
8262 |
rect->setFlag(QGraphicsItem::ItemIsPanel); |
|
8263 |
scene.addItem(rect); |
|
8264 |
QVERIFY(rect->isActive()); |
|
8265 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect); |
|
8266 |
||
8267 |
QGraphicsRectItem *rect2 = new QGraphicsRectItem; |
|
8268 |
scene.addItem(rect2); |
|
8269 |
QVERIFY(rect->isActive()); |
|
8270 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect); |
|
8271 |
} |
|
8272 |
||
8273 |
void tst_QGraphicsItem::activate() |
|
8274 |
{ |
|
8275 |
QGraphicsScene scene; |
|
8276 |
QGraphicsRectItem *rect = scene.addRect(-10, -10, 20, 20); |
|
8277 |
QVERIFY(!rect->isActive()); |
|
8278 |
||
8279 |
QEvent activate(QEvent::WindowActivate); |
|
8280 |
QEvent deactivate(QEvent::WindowDeactivate); |
|
8281 |
||
8282 |
QApplication::sendEvent(&scene, &activate); |
|
8283 |
||
8284 |
// Non-panel item (active when scene is active). |
|
8285 |
QVERIFY(rect->isActive()); |
|
8286 |
||
8287 |
QGraphicsRectItem *rect2 = new QGraphicsRectItem; |
|
8288 |
rect2->setFlag(QGraphicsItem::ItemIsPanel); |
|
8289 |
QGraphicsRectItem *rect3 = new QGraphicsRectItem; |
|
8290 |
rect3->setFlag(QGraphicsItem::ItemIsPanel); |
|
8291 |
||
8292 |
// Test normal activation. |
|
8293 |
QVERIFY(!rect2->isActive()); |
|
8294 |
scene.addItem(rect2); |
|
8295 |
QVERIFY(rect2->isActive()); // first panel item is activated |
|
8296 |
scene.addItem(rect3); |
|
8297 |
QVERIFY(!rect3->isActive()); // second panel item is _not_ activated |
|
8298 |
rect3->setActive(true); |
|
8299 |
QVERIFY(rect3->isActive()); |
|
8300 |
scene.removeItem(rect3); |
|
8301 |
QVERIFY(!rect3->isActive()); // no panel is active anymore |
|
8302 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)0); |
|
8303 |
scene.addItem(rect3); |
|
8304 |
QVERIFY(rect3->isActive()); // second panel item is activated |
|
8305 |
||
8306 |
// Test pending activation. |
|
8307 |
scene.removeItem(rect3); |
|
8308 |
rect2->setActive(true); |
|
8309 |
QVERIFY(rect2->isActive()); // first panel item is activated |
|
8310 |
rect3->setActive(true); |
|
8311 |
QVERIFY(!rect3->isActive()); // not active (yet) |
|
8312 |
scene.addItem(rect3); |
|
8313 |
QVERIFY(rect3->isActive()); // now becomes active |
|
8314 |
||
8315 |
// Test pending deactivation. |
|
8316 |
scene.removeItem(rect3); |
|
8317 |
rect3->setActive(false); |
|
8318 |
scene.addItem(rect3); |
|
8319 |
QVERIFY(!rect3->isActive()); // doesn't become active |
|
8320 |
||
8321 |
// Child of panel activation. |
|
8322 |
rect3->setActive(true); |
|
8323 |
QGraphicsRectItem *rect4 = new QGraphicsRectItem; |
|
8324 |
rect4->setFlag(QGraphicsItem::ItemIsPanel); |
|
8325 |
QGraphicsRectItem *rect5 = new QGraphicsRectItem(rect4); |
|
8326 |
QGraphicsRectItem *rect6 = new QGraphicsRectItem(rect5); |
|
8327 |
scene.addItem(rect4); |
|
8328 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect3); |
|
8329 |
scene.removeItem(rect4); |
|
8330 |
rect6->setActive(true); |
|
8331 |
scene.addItem(rect4); |
|
8332 |
QVERIFY(rect4->isActive()); |
|
8333 |
QVERIFY(rect5->isActive()); |
|
8334 |
QVERIFY(rect6->isActive()); |
|
8335 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect4); |
|
8336 |
scene.removeItem(rect4); // no active panel |
|
8337 |
rect6->setActive(false); |
|
8338 |
scene.addItem(rect4); |
|
8339 |
QVERIFY(!rect4->isActive()); |
|
8340 |
QVERIFY(!rect5->isActive()); |
|
8341 |
QVERIFY(!rect6->isActive()); |
|
8342 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)0); |
|
8343 |
||
8344 |
// Controlling auto-activation when the scene changes activation. |
|
8345 |
rect4->setActive(true); |
|
8346 |
QApplication::sendEvent(&scene, &deactivate); |
|
8347 |
QVERIFY(!scene.isActive()); |
|
8348 |
QVERIFY(!rect4->isActive()); |
|
8349 |
rect4->setActive(false); |
|
8350 |
QApplication::sendEvent(&scene, &activate); |
|
8351 |
QVERIFY(scene.isActive()); |
|
8352 |
QVERIFY(!scene.activePanel()); |
|
8353 |
QVERIFY(!rect4->isActive()); |
|
8354 |
} |
|
8355 |
||
8356 |
void tst_QGraphicsItem::setActivePanelOnInactiveScene() |
|
8357 |
{ |
|
8358 |
QGraphicsScene scene; |
|
8359 |
QGraphicsRectItem *item = scene.addRect(QRectF()); |
|
8360 |
QGraphicsRectItem *panel = scene.addRect(QRectF()); |
|
8361 |
panel->setFlag(QGraphicsItem::ItemIsPanel); |
|
8362 |
||
8363 |
EventSpy itemActivateSpy(&scene, item, QEvent::WindowActivate); |
|
8364 |
EventSpy itemDeactivateSpy(&scene, item, QEvent::WindowDeactivate); |
|
8365 |
EventSpy panelActivateSpy(&scene, panel, QEvent::WindowActivate); |
|
8366 |
EventSpy panelDeactivateSpy(&scene, panel, QEvent::WindowDeactivate); |
|
8367 |
EventSpy sceneActivationChangeSpy(&scene, QEvent::ActivationChange); |
|
8368 |
||
8369 |
scene.setActivePanel(panel); |
|
8370 |
QCOMPARE(scene.activePanel(), (QGraphicsItem *)0); |
|
8371 |
QCOMPARE(itemActivateSpy.count(), 0); |
|
8372 |
QCOMPARE(itemDeactivateSpy.count(), 0); |
|
8373 |
QCOMPARE(panelActivateSpy.count(), 0); |
|
8374 |
QCOMPARE(panelDeactivateSpy.count(), 0); |
|
8375 |
QCOMPARE(sceneActivationChangeSpy.count(), 0); |
|
8376 |
} |
|
8377 |
||
8378 |
void tst_QGraphicsItem::activationOnShowHide() |
|
8379 |
{ |
|
8380 |
QGraphicsScene scene; |
|
8381 |
QEvent activate(QEvent::WindowActivate); |
|
8382 |
QApplication::sendEvent(&scene, &activate); |
|
8383 |
||
8384 |
QGraphicsRectItem *rootPanel = scene.addRect(QRectF()); |
|
8385 |
rootPanel->setFlag(QGraphicsItem::ItemIsPanel); |
|
8386 |
rootPanel->setActive(true); |
|
8387 |
||
8388 |
QGraphicsRectItem *subPanel = new QGraphicsRectItem; |
|
8389 |
subPanel->setFlag(QGraphicsItem::ItemIsPanel); |
|
8390 |
||
8391 |
// Reparenting onto an active panel auto-activates the child panel. |
|
8392 |
subPanel->setParentItem(rootPanel); |
|
8393 |
QVERIFY(subPanel->isActive()); |
|
8394 |
QVERIFY(!rootPanel->isActive()); |
|
8395 |
||
8396 |
// Hiding an active child panel will reactivate the parent panel. |
|
8397 |
subPanel->hide(); |
|
8398 |
QVERIFY(rootPanel->isActive()); |
|
8399 |
||
8400 |
// Showing a child panel will auto-activate it. |
|
8401 |
subPanel->show(); |
|
8402 |
QVERIFY(subPanel->isActive()); |
|
8403 |
QVERIFY(!rootPanel->isActive()); |
|
8404 |
||
8405 |
// Adding an unrelated panel doesn't affect activation. |
|
8406 |
QGraphicsRectItem *otherPanel = new QGraphicsRectItem; |
|
8407 |
otherPanel->setFlag(QGraphicsItem::ItemIsPanel); |
|
8408 |
scene.addItem(otherPanel); |
|
8409 |
QVERIFY(subPanel->isActive()); |
|
8410 |
||
8411 |
// Showing an unrelated panel doesn't affect activation. |
|
8412 |
otherPanel->hide(); |
|
8413 |
otherPanel->show(); |
|
8414 |
QVERIFY(subPanel->isActive()); |
|
8415 |
||
8416 |
// Add a non-panel item. |
|
8417 |
QGraphicsRectItem *otherItem = new QGraphicsRectItem; |
|
8418 |
scene.addItem(otherItem); |
|
8419 |
otherItem->setActive(true); |
|
8420 |
QVERIFY(otherItem->isActive()); |
|
8421 |
||
8422 |
// Reparent a panel onto an active non-panel item. |
|
8423 |
subPanel->setParentItem(otherItem); |
|
8424 |
QVERIFY(subPanel->isActive()); |
|
8425 |
||
8426 |
// Showing a child panel of a non-panel item will activate it. |
|
8427 |
subPanel->hide(); |
|
8428 |
QVERIFY(!subPanel->isActive()); |
|
8429 |
QVERIFY(otherItem->isActive()); |
|
8430 |
subPanel->show(); |
|
8431 |
QVERIFY(subPanel->isActive()); |
|
8432 |
||
8433 |
// Hiding a toplevel active panel will pass activation back |
|
8434 |
// to the non-panel items. |
|
8435 |
rootPanel->setActive(true); |
|
8436 |
rootPanel->hide(); |
|
8437 |
QVERIFY(!rootPanel->isActive()); |
|
8438 |
QVERIFY(otherItem->isActive()); |
|
8439 |
} |
|
8440 |
||
8441 |
class MoveWhileDying : public QGraphicsRectItem |
|
8442 |
{ |
|
8443 |
public: |
|
8444 |
MoveWhileDying(QGraphicsItem *parent = 0) |
|
8445 |
: QGraphicsRectItem(parent) |
|
8446 |
{ } |
|
8447 |
~MoveWhileDying() |
|
8448 |
{ |
|
8449 |
foreach (QGraphicsItem *c, childItems()) { |
|
8450 |
foreach (QGraphicsItem *cc, c->childItems()) { |
|
8451 |
cc->moveBy(10, 10); |
|
8452 |
} |
|
8453 |
c->moveBy(10, 10); |
|
8454 |
} |
|
8455 |
if (QGraphicsItem *p = parentItem()) { p->moveBy(10, 10); } |
|
8456 |
} |
|
8457 |
}; |
|
8458 |
||
8459 |
void tst_QGraphicsItem::moveWhileDeleting() |
|
8460 |
{ |
|
8461 |
QGraphicsScene scene; |
|
8462 |
QGraphicsRectItem *rect = new QGraphicsRectItem; |
|
8463 |
MoveWhileDying *silly = new MoveWhileDying(rect); |
|
8464 |
QGraphicsRectItem *child = new QGraphicsRectItem(silly); |
|
8465 |
scene.addItem(rect); |
|
8466 |
delete rect; // don't crash! |
|
8467 |
||
8468 |
rect = new QGraphicsRectItem; |
|
8469 |
silly = new MoveWhileDying(rect); |
|
8470 |
child = new QGraphicsRectItem(silly); |
|
8471 |
||
8472 |
QGraphicsView view(&scene); |
|
8473 |
view.show(); |
|
8474 |
#ifdef Q_WS_X11 |
|
8475 |
qt_x11_wait_for_window_manager(&view); |
|
8476 |
#endif |
|
8477 |
QTest::qWait(125); |
|
8478 |
||
8479 |
delete rect; |
|
8480 |
||
8481 |
rect = new QGraphicsRectItem; |
|
8482 |
rect->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
8483 |
silly = new MoveWhileDying(rect); |
|
8484 |
child = new QGraphicsRectItem(silly); |
|
8485 |
||
8486 |
QTest::qWait(125); |
|
8487 |
||
8488 |
delete rect; |
|
8489 |
||
8490 |
rect = new MoveWhileDying; |
|
8491 |
rect->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
8492 |
child = new QGraphicsRectItem(rect); |
|
8493 |
silly = new MoveWhileDying(child); |
|
8494 |
||
8495 |
QTest::qWait(125); |
|
8496 |
||
8497 |
delete rect; |
|
8498 |
} |
|
8499 |
||
8500 |
class MyRectItem : public QGraphicsWidget |
|
8501 |
{ |
|
8502 |
Q_OBJECT |
|
8503 |
public: |
|
8504 |
MyRectItem(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) |
|
8505 |
{ |
|
8506 |
||
8507 |
} |
|
8508 |
||
8509 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
8510 |
{ |
|
8511 |
painter->setBrush(brush); |
|
8512 |
painter->drawRect(boundingRect()); |
|
8513 |
} |
|
8514 |
void move() |
|
8515 |
{ |
|
8516 |
setPos(-100,-100); |
|
8517 |
topLevel->collidingItems(Qt::IntersectsItemBoundingRect); |
|
8518 |
} |
|
8519 |
public: |
|
8520 |
QGraphicsItem *topLevel; |
|
8521 |
QBrush brush; |
|
8522 |
}; |
|
8523 |
||
8524 |
||
8525 |
void tst_QGraphicsItem::ensureDirtySceneTransform() |
|
8526 |
{ |
|
8527 |
QGraphicsScene scene; |
|
8528 |
||
8529 |
MyRectItem *topLevel = new MyRectItem; |
|
8530 |
topLevel->setGeometry(0, 0, 100, 100); |
|
8531 |
topLevel->setPos(-50, -50); |
|
8532 |
topLevel->brush = QBrush(QColor(Qt::black)); |
|
8533 |
scene.addItem(topLevel); |
|
8534 |
||
8535 |
MyRectItem *parent = new MyRectItem; |
|
8536 |
parent->topLevel = topLevel; |
|
8537 |
parent->setGeometry(0, 0, 100, 100); |
|
8538 |
parent->setPos(0, 0); |
|
8539 |
parent->brush = QBrush(QColor(Qt::magenta)); |
|
8540 |
parent->setObjectName("parent"); |
|
8541 |
scene.addItem(parent); |
|
8542 |
||
8543 |
MyRectItem *child = new MyRectItem(parent); |
|
8544 |
child->setGeometry(0, 0, 80, 80); |
|
8545 |
child->setPos(10, 10); |
|
8546 |
child->setObjectName("child"); |
|
8547 |
child->brush = QBrush(QColor(Qt::blue)); |
|
8548 |
||
8549 |
MyRectItem *child2 = new MyRectItem(parent); |
|
8550 |
child2->setGeometry(0, 0, 80, 80); |
|
8551 |
child2->setPos(15, 15); |
|
8552 |
child2->setObjectName("child2"); |
|
8553 |
child2->brush = QBrush(QColor(Qt::green)); |
|
8554 |
||
8555 |
MyRectItem *child3 = new MyRectItem(parent); |
|
8556 |
child3->setGeometry(0, 0, 80, 80); |
|
8557 |
child3->setPos(20, 20); |
|
8558 |
child3->setObjectName("child3"); |
|
8559 |
child3->brush = QBrush(QColor(Qt::gray)); |
|
8560 |
||
8561 |
QGraphicsView view(&scene); |
|
8562 |
view.show(); |
|
8563 |
QTest::qWaitForWindowShown(&view); |
|
8564 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
8565 |
||
8566 |
//We move the parent |
|
8567 |
parent->move(); |
|
8568 |
QApplication::processEvents(); |
|
8569 |
||
8570 |
//We check if all items moved |
|
8571 |
QCOMPARE(child->pos(), QPointF(10, 10)); |
|
8572 |
QCOMPARE(child2->pos(), QPointF(15, 15)); |
|
8573 |
QCOMPARE(child3->pos(), QPointF(20, 20)); |
|
8574 |
||
8575 |
QCOMPARE(child->sceneBoundingRect(), QRectF(-90, -90, 80, 80)); |
|
8576 |
QCOMPARE(child2->sceneBoundingRect(), QRectF(-85, -85, 80, 80)); |
|
8577 |
QCOMPARE(child3->sceneBoundingRect(), QRectF(-80, -80, 80, 80)); |
|
8578 |
||
8579 |
QCOMPARE(child->sceneTransform(), QTransform::fromTranslate(-90, -90)); |
|
8580 |
QCOMPARE(child2->sceneTransform(), QTransform::fromTranslate(-85, -85)); |
|
8581 |
QCOMPARE(child3->sceneTransform(), QTransform::fromTranslate(-80, -80)); |
|
8582 |
} |
|
8583 |
||
8584 |
void tst_QGraphicsItem::focusScope() |
|
8585 |
{ |
|
8586 |
// ItemIsFocusScope is an internal feature (for now). |
|
8587 |
QGraphicsScene scene; |
|
8588 |
||
8589 |
QGraphicsRectItem *scope3 = new QGraphicsRectItem; |
|
8590 |
scope3->setData(0, "scope3"); |
|
8591 |
scope3->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
|
8592 |
scope3->setFocus(); |
|
8593 |
QVERIFY(!scope3->focusScopeItem()); |
|
8594 |
QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3); |
|
8595 |
||
8596 |
QGraphicsRectItem *scope2 = new QGraphicsRectItem; |
|
8597 |
scope2->setData(0, "scope2"); |
|
8598 |
scope2->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
|
8599 |
scope2->setFocus(); |
|
8600 |
QVERIFY(!scope2->focusScopeItem()); |
|
8601 |
scope3->setParentItem(scope2); |
|
8602 |
QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8603 |
QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3); |
0 | 8604 |
|
8605 |
QGraphicsRectItem *scope1 = new QGraphicsRectItem; |
|
8606 |
scope1->setData(0, "scope1"); |
|
8607 |
scope1->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
|
8608 |
scope1->setFocus(); |
|
8609 |
QVERIFY(!scope1->focusScopeItem()); |
|
8610 |
scope2->setParentItem(scope1); |
|
8611 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8612 |
QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8613 |
QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8614 |
QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3); |
0 | 8615 |
QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2); |
8616 |
QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3); |
|
8617 |
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)0); |
|
8618 |
||
8619 |
scene.addItem(scope1); |
|
8620 |
||
8621 |
QEvent windowActivate(QEvent::WindowActivate); |
|
8622 |
qApp->sendEvent(&scene, &windowActivate); |
|
8623 |
scene.setFocus(); |
|
8624 |
||
8625 |
QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3); |
|
8626 |
QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3); |
|
8627 |
QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3); |
|
8628 |
QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2); |
|
8629 |
QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3); |
|
8630 |
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)0); |
|
8631 |
||
8632 |
QVERIFY(scope3->hasFocus()); |
|
8633 |
||
8634 |
scope3->hide(); |
|
8635 |
QVERIFY(scope2->hasFocus()); |
|
8636 |
scope2->hide(); |
|
8637 |
QVERIFY(scope1->hasFocus()); |
|
8638 |
scope2->show(); |
|
8639 |
QVERIFY(scope2->hasFocus()); |
|
8640 |
scope3->show(); |
|
8641 |
QVERIFY(scope3->hasFocus()); |
|
8642 |
scope1->hide(); |
|
8643 |
QVERIFY(!scope3->hasFocus()); |
|
8644 |
scope1->show(); |
|
8645 |
QVERIFY(scope3->hasFocus()); |
|
8646 |
scope3->clearFocus(); |
|
8647 |
QVERIFY(scope2->hasFocus()); |
|
8648 |
scope2->clearFocus(); |
|
8649 |
QVERIFY(scope1->hasFocus()); |
|
8650 |
scope2->hide(); |
|
8651 |
scope2->show(); |
|
8652 |
QVERIFY(!scope2->hasFocus()); |
|
8653 |
QVERIFY(scope3->hasFocus()); |
|
8654 |
||
8655 |
QGraphicsRectItem *rect4 = new QGraphicsRectItem; |
|
8656 |
rect4->setData(0, "rect4"); |
|
8657 |
rect4->setParentItem(scope3); |
|
8658 |
||
8659 |
QGraphicsRectItem *rect5 = new QGraphicsRectItem; |
|
8660 |
rect5->setData(0, "rect5"); |
|
8661 |
rect5->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
|
8662 |
rect5->setFocus(); |
|
8663 |
rect5->setParentItem(rect4); |
|
8664 |
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)rect5); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8665 |
QVERIFY(rect5->hasFocus()); |
0 | 8666 |
|
8667 |
rect4->setParentItem(0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8668 |
QVERIFY(rect5->hasFocus()); |
0 | 8669 |
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8670 |
QCOMPARE(scope3->focusItem(), (QGraphicsItem *)0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8671 |
QVERIFY(!scope3->hasFocus()); |
0 | 8672 |
|
8673 |
QGraphicsRectItem *rectA = new QGraphicsRectItem; |
|
8674 |
QGraphicsRectItem *scopeA = new QGraphicsRectItem(rectA); |
|
8675 |
scopeA->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
|
8676 |
scopeA->setFocus(); |
|
8677 |
QGraphicsRectItem *scopeB = new QGraphicsRectItem(scopeA); |
|
8678 |
scopeB->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
|
8679 |
scopeB->setFocus(); |
|
8680 |
||
8681 |
scene.addItem(rectA); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8682 |
QVERIFY(rect5->hasFocus()); |
0 | 8683 |
QVERIFY(!scopeB->hasFocus()); |
8684 |
||
8685 |
scopeA->setFocus(); |
|
8686 |
QVERIFY(scopeB->hasFocus()); |
|
8687 |
QCOMPARE(scopeB->focusItem(), (QGraphicsItem *)scopeB); |
|
8688 |
} |
|
8689 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8690 |
void tst_QGraphicsItem::focusScope2() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8691 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8692 |
QGraphicsRectItem *child1 = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8693 |
child1->setFlags(QGraphicsItem::ItemIsFocusable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8694 |
child1->setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8695 |
QCOMPARE(child1->focusItem(), (QGraphicsItem *)child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8696 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8697 |
QGraphicsRectItem *child2 = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8698 |
child2->setFlags(QGraphicsItem::ItemIsFocusable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8699 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8700 |
QGraphicsRectItem *rootFocusScope = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8701 |
rootFocusScope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8702 |
rootFocusScope->setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8703 |
QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)rootFocusScope); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8704 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8705 |
child1->setParentItem(rootFocusScope); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8706 |
child2->setParentItem(rootFocusScope); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8707 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8708 |
QCOMPARE(rootFocusScope->focusScopeItem(), (QGraphicsItem *)child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8709 |
QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8710 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8711 |
QGraphicsRectItem *siblingChild1 = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8712 |
siblingChild1->setFlags(QGraphicsItem::ItemIsFocusable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8713 |
siblingChild1->setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8714 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8715 |
QGraphicsRectItem *siblingChild2 = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8716 |
siblingChild2->setFlags(QGraphicsItem::ItemIsFocusable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8717 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8718 |
QGraphicsRectItem *siblingFocusScope = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8719 |
siblingFocusScope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8720 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8721 |
siblingChild1->setParentItem(siblingFocusScope); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8722 |
siblingChild2->setParentItem(siblingFocusScope); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8723 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8724 |
QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8725 |
QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8726 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8727 |
QGraphicsItem *root = new QGraphicsRectItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8728 |
rootFocusScope->setParentItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8729 |
siblingFocusScope->setParentItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8730 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8731 |
QCOMPARE(root->focusItem(), (QGraphicsItem *)child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8732 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8733 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8734 |
scene.addItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8735 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8736 |
QEvent activate(QEvent::WindowActivate); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8737 |
qApp->sendEvent(&scene, &activate); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8738 |
scene.setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8739 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8740 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *)child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8741 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8742 |
// You cannot set focus on a descendant of a focus scope directly; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8743 |
// this will only change the scope's focus scope item pointer. If |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8744 |
// you want to give true input focus, you must set it directly on |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8745 |
// the scope itself |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8746 |
siblingChild2->setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8747 |
QVERIFY(!siblingChild2->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8748 |
QVERIFY(!siblingChild2->focusItem()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8749 |
QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8750 |
QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8751 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8752 |
// Set focus on the scope; focus is forwarded to the focus scope item. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8753 |
siblingFocusScope->setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8754 |
QVERIFY(siblingChild2->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8755 |
QVERIFY(siblingChild2->focusItem()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8756 |
QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8757 |
QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)siblingChild2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8758 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8759 |
|
0 | 8760 |
void tst_QGraphicsItem::stackBefore() |
8761 |
{ |
|
8762 |
QGraphicsRectItem parent; |
|
8763 |
QGraphicsRectItem *child1 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent); |
|
8764 |
QGraphicsRectItem *child2 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent); |
|
8765 |
QGraphicsRectItem *child3 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent); |
|
8766 |
QGraphicsRectItem *child4 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent); |
|
8767 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); |
|
8768 |
child1->setData(0, "child1"); |
|
8769 |
child2->setData(0, "child2"); |
|
8770 |
child3->setData(0, "child3"); |
|
8771 |
child4->setData(0, "child4"); |
|
8772 |
||
8773 |
// Remove and append |
|
8774 |
child2->setParentItem(0); |
|
8775 |
child2->setParentItem(&parent); |
|
8776 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2)); |
|
8777 |
||
8778 |
// Move child2 before child1 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8779 |
child2->stackBefore(child1); // 2134 |
0 | 8780 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8781 |
child2->stackBefore(child2); // 2134 |
0 | 8782 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8783 |
child1->setZValue(1); // 2341 |
0 | 8784 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8785 |
child1->stackBefore(child2); // 2341 |
0 | 8786 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8787 |
child1->setZValue(0); // 1234 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8788 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8789 |
child4->stackBefore(child1); // 4123 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8790 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8791 |
child4->setZValue(1); // 1234 (4123) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8792 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8793 |
child3->stackBefore(child1); // 3124 (4312) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8794 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8795 |
child4->setZValue(0); // 4312 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8796 |
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2)); |
0 | 8797 |
|
8798 |
// Make them all toplevels |
|
8799 |
child1->setParentItem(0); |
|
8800 |
child2->setParentItem(0); |
|
8801 |
child3->setParentItem(0); |
|
8802 |
child4->setParentItem(0); |
|
8803 |
||
8804 |
QGraphicsScene scene; |
|
8805 |
scene.addItem(child1); |
|
8806 |
scene.addItem(child2); |
|
8807 |
scene.addItem(child3); |
|
8808 |
scene.addItem(child4); |
|
8809 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), |
|
8810 |
(QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); |
|
8811 |
||
8812 |
// Remove and append |
|
8813 |
scene.removeItem(child2); |
|
8814 |
scene.addItem(child2); |
|
8815 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2)); |
|
8816 |
||
8817 |
// Move child2 before child1 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8818 |
child2->stackBefore(child1); // 2134 |
0 | 8819 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8820 |
child2->stackBefore(child2); // 2134 |
0 | 8821 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8822 |
child1->setZValue(1); // 2341 |
0 | 8823 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8824 |
child1->stackBefore(child2); // 2341 |
0 | 8825 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8826 |
child1->setZValue(0); // 1234 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8827 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8828 |
child4->stackBefore(child1); // 4123 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8829 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8830 |
child4->setZValue(1); // 1234 (4123) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8831 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8832 |
child3->stackBefore(child1); // 3124 (4312) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8833 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8834 |
child4->setZValue(0); // 4312 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8835 |
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2)); |
0 | 8836 |
} |
8837 |
||
8838 |
void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect() |
|
8839 |
{ |
|
8840 |
EventTester *tester = new EventTester; |
|
8841 |
tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
|
8842 |
||
8843 |
QGraphicsScene scene; |
|
8844 |
scene.addItem(tester); |
|
8845 |
scene.setSceneRect(-100, -100, 200, 200); // contains the tester item |
|
8846 |
||
8847 |
QGraphicsView view(&scene); |
|
8848 |
view.show(); |
|
8849 |
QTest::qWaitForWindowShown(&view); |
|
8850 |
QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); |
|
8851 |
||
8852 |
QTRY_COMPARE(tester->repaints, 1); |
|
8853 |
||
8854 |
scene.update(); // triggers "updateAll" optimization |
|
8855 |
qApp->processEvents(); |
|
8856 |
qApp->processEvents(); // in 4.6 only one processEvents is necessary |
|
8857 |
||
8858 |
QCOMPARE(tester->repaints, 1); |
|
8859 |
||
8860 |
scene.update(); // triggers "updateAll" optimization |
|
8861 |
tester->update(); |
|
8862 |
qApp->processEvents(); |
|
8863 |
qApp->processEvents(); // in 4.6 only one processEvents is necessary |
|
8864 |
||
8865 |
QCOMPARE(tester->repaints, 2); |
|
8866 |
} |
|
8867 |
||
8868 |
void tst_QGraphicsItem::sceneModality() |
|
8869 |
{ |
|
8870 |
// 1) Test mouse events (delivery/propagation/redirection) |
|
8871 |
// 2) Test hover events (incl. leave on block, enter on unblock) |
|
8872 |
// 3) Test cursor stuff (incl. unset on block, set on unblock) |
|
8873 |
// 4) Test clickfocus |
|
8874 |
// 5) Test grab/ungrab events (possibly ungrab on block, regrab on unblock) |
|
8875 |
// 6) ### modality for non-panels is unsupported for now |
|
8876 |
QGraphicsScene scene; |
|
8877 |
||
8878 |
QGraphicsRectItem *bottomItem = scene.addRect(-150, -100, 300, 200); |
|
8879 |
bottomItem->setFlag(QGraphicsItem::ItemIsFocusable); |
|
8880 |
bottomItem->setBrush(Qt::yellow); |
|
8881 |
||
8882 |
QGraphicsRectItem *leftParent = scene.addRect(-50, -50, 100, 100); |
|
8883 |
leftParent->setFlag(QGraphicsItem::ItemIsPanel); |
|
8884 |
leftParent->setBrush(Qt::blue); |
|
8885 |
||
8886 |
QGraphicsRectItem *leftChild = scene.addRect(-25, -25, 50, 50); |
|
8887 |
leftChild->setFlag(QGraphicsItem::ItemIsPanel); |
|
8888 |
leftChild->setBrush(Qt::green); |
|
8889 |
leftChild->setParentItem(leftParent); |
|
8890 |
||
8891 |
QGraphicsRectItem *rightParent = scene.addRect(-50, -50, 100, 100); |
|
8892 |
rightParent->setFlag(QGraphicsItem::ItemIsPanel); |
|
8893 |
rightParent->setBrush(Qt::red); |
|
8894 |
QGraphicsRectItem *rightChild = scene.addRect(-25, -25, 50, 50); |
|
8895 |
rightChild->setFlag(QGraphicsItem::ItemIsPanel); |
|
8896 |
rightChild->setBrush(Qt::gray); |
|
8897 |
rightChild->setParentItem(rightParent); |
|
8898 |
||
8899 |
leftParent->setPos(-75, 0); |
|
8900 |
rightParent->setPos(75, 0); |
|
8901 |
||
8902 |
bottomItem->setData(0, "bottomItem"); |
|
8903 |
leftParent->setData(0, "leftParent"); |
|
8904 |
leftChild->setData(0, "leftChild"); |
|
8905 |
rightParent->setData(0, "rightParent"); |
|
8906 |
rightChild->setData(0, "rightChild"); |
|
8907 |
||
8908 |
scene.setSceneRect(scene.itemsBoundingRect().adjusted(-50, -50, 50, 50)); |
|
8909 |
||
8910 |
EventSpy2 leftParentSpy(&scene, leftParent); |
|
8911 |
EventSpy2 leftChildSpy(&scene, leftChild); |
|
8912 |
EventSpy2 rightParentSpy(&scene, rightParent); |
|
8913 |
EventSpy2 rightChildSpy(&scene, rightChild); |
|
8914 |
EventSpy2 bottomItemSpy(&scene, bottomItem); |
|
8915 |
||
8916 |
// Scene modality, also test multiple scene modal items |
|
8917 |
leftChild->setPanelModality(QGraphicsItem::SceneModal); |
|
8918 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
8919 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
8920 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
8921 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1); |
|
8922 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); // not a panel |
|
8923 |
||
8924 |
// Click inside left child |
|
8925 |
sendMouseClick(&scene, leftChild->scenePos(), Qt::LeftButton); |
|
8926 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
8927 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab |
|
8928 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8929 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8930 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8931 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8932 |
||
8933 |
// Click on left parent, event goes to modal child |
|
8934 |
sendMouseClick(&scene, leftParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton); |
|
8935 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 2); |
|
8936 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab |
|
8937 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8938 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8939 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8940 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8941 |
||
8942 |
// Click on all other items and outside the items |
|
8943 |
sendMouseClick(&scene, rightParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton); |
|
8944 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 3); |
|
8945 |
sendMouseClick(&scene, rightChild->scenePos(), Qt::LeftButton); |
|
8946 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 4); |
|
8947 |
sendMouseClick(&scene, bottomItem->scenePos(), Qt::LeftButton); |
|
8948 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 5); |
|
8949 |
sendMouseClick(&scene, QPointF(10000, 10000), Qt::LeftButton); |
|
8950 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 6); |
|
8951 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab |
|
8952 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8953 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8954 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8955 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8956 |
||
8957 |
leftChildSpy.counts.clear(); |
|
8958 |
rightChildSpy.counts.clear(); |
|
8959 |
leftParentSpy.counts.clear(); |
|
8960 |
rightParentSpy.counts.clear(); |
|
8961 |
bottomItemSpy.counts.clear(); |
|
8962 |
||
8963 |
leftChild->setPanelModality(QGraphicsItem::NonModal); |
|
8964 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
8965 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1); |
|
8966 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 1); |
|
8967 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 1); |
|
8968 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowUnblocked], 0); |
|
8969 |
||
8970 |
// Left parent enters scene modality. |
|
8971 |
leftParent->setPanelModality(QGraphicsItem::SceneModal); |
|
8972 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
8973 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1); |
|
8974 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0); |
|
8975 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
8976 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); |
|
8977 |
||
8978 |
// Click inside left child. |
|
8979 |
sendMouseClick(&scene, leftChild->scenePos(), Qt::LeftButton); |
|
8980 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
8981 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
8982 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // panel stops propagation |
|
8983 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); |
|
8984 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8985 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
8986 |
||
8987 |
// Click on left parent. |
|
8988 |
sendMouseClick(&scene, leftParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton); |
|
8989 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
8990 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
8991 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
8992 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); |
|
8993 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); |
|
8994 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); |
|
8995 |
||
8996 |
// Click on all other items and outside the items |
|
8997 |
sendMouseClick(&scene, rightParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton); |
|
8998 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 2); |
|
8999 |
sendMouseClick(&scene, rightChild->scenePos(), Qt::LeftButton); |
|
9000 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 3); |
|
9001 |
sendMouseClick(&scene, bottomItem->scenePos(), Qt::LeftButton); |
|
9002 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 4); |
|
9003 |
sendMouseClick(&scene, QPointF(10000, 10000), Qt::LeftButton); |
|
9004 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 5); |
|
9005 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9006 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9007 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); |
|
9008 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); |
|
9009 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); |
|
9010 |
||
9011 |
leftChildSpy.counts.clear(); |
|
9012 |
rightChildSpy.counts.clear(); |
|
9013 |
leftParentSpy.counts.clear(); |
|
9014 |
rightParentSpy.counts.clear(); |
|
9015 |
bottomItemSpy.counts.clear(); |
|
9016 |
||
9017 |
// Now both left parent and child are scene modal. Left parent is blocked. |
|
9018 |
leftChild->setPanelModality(QGraphicsItem::SceneModal); |
|
9019 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9020 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9021 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9022 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9023 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); |
|
9024 |
||
9025 |
// Click inside left child |
|
9026 |
sendMouseClick(&scene, leftChild->scenePos(), Qt::LeftButton); |
|
9027 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9028 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab |
|
9029 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9030 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9031 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9032 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9033 |
||
9034 |
// Click on left parent, event goes to modal child |
|
9035 |
sendMouseClick(&scene, leftParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton); |
|
9036 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 2); |
|
9037 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab |
|
9038 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9039 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9040 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9041 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9042 |
||
9043 |
// Click on all other items and outside the items |
|
9044 |
sendMouseClick(&scene, rightParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton); |
|
9045 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 3); |
|
9046 |
sendMouseClick(&scene, rightChild->scenePos(), Qt::LeftButton); |
|
9047 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 4); |
|
9048 |
sendMouseClick(&scene, bottomItem->scenePos(), Qt::LeftButton); |
|
9049 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 5); |
|
9050 |
sendMouseClick(&scene, QPointF(10000, 10000), Qt::LeftButton); |
|
9051 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 6); |
|
9052 |
QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab |
|
9053 |
QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9054 |
QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9055 |
QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9056 |
QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked |
|
9057 |
||
9058 |
leftChildSpy.counts.clear(); |
|
9059 |
rightChildSpy.counts.clear(); |
|
9060 |
leftParentSpy.counts.clear(); |
|
9061 |
rightParentSpy.counts.clear(); |
|
9062 |
bottomItemSpy.counts.clear(); |
|
9063 |
||
9064 |
// Right child enters scene modality, only left child is blocked. |
|
9065 |
rightChild->setPanelModality(QGraphicsItem::SceneModal); |
|
9066 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9067 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9068 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9069 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9070 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); |
|
9071 |
} |
|
9072 |
||
9073 |
void tst_QGraphicsItem::panelModality() |
|
9074 |
{ |
|
9075 |
// 1) Test mouse events (delivery/propagation/redirection) |
|
9076 |
// 2) Test hover events (incl. leave on block, enter on unblock) |
|
9077 |
// 3) Test cursor stuff (incl. unset on block, set on unblock) |
|
9078 |
// 4) Test clickfocus |
|
9079 |
// 5) Test grab/ungrab events (possibly ungrab on block, regrab on unblock) |
|
9080 |
// 6) ### modality for non-panels is unsupported for now |
|
9081 |
QGraphicsScene scene; |
|
9082 |
||
9083 |
QGraphicsRectItem *bottomItem = scene.addRect(-150, -100, 300, 200); |
|
9084 |
bottomItem->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9085 |
bottomItem->setBrush(Qt::yellow); |
|
9086 |
||
9087 |
QGraphicsRectItem *leftParent = scene.addRect(-50, -50, 100, 100); |
|
9088 |
leftParent->setFlag(QGraphicsItem::ItemIsPanel); |
|
9089 |
leftParent->setBrush(Qt::blue); |
|
9090 |
||
9091 |
QGraphicsRectItem *leftChild = scene.addRect(-25, -25, 50, 50); |
|
9092 |
leftChild->setFlag(QGraphicsItem::ItemIsPanel); |
|
9093 |
leftChild->setBrush(Qt::green); |
|
9094 |
leftChild->setParentItem(leftParent); |
|
9095 |
||
9096 |
QGraphicsRectItem *rightParent = scene.addRect(-50, -50, 100, 100); |
|
9097 |
rightParent->setFlag(QGraphicsItem::ItemIsPanel); |
|
9098 |
rightParent->setBrush(Qt::red); |
|
9099 |
QGraphicsRectItem *rightChild = scene.addRect(-25, -25, 50, 50); |
|
9100 |
rightChild->setFlag(QGraphicsItem::ItemIsPanel); |
|
9101 |
rightChild->setBrush(Qt::gray); |
|
9102 |
rightChild->setParentItem(rightParent); |
|
9103 |
||
9104 |
leftParent->setPos(-75, 0); |
|
9105 |
rightParent->setPos(75, 0); |
|
9106 |
||
9107 |
bottomItem->setData(0, "bottomItem"); |
|
9108 |
leftParent->setData(0, "leftParent"); |
|
9109 |
leftChild->setData(0, "leftChild"); |
|
9110 |
rightParent->setData(0, "rightParent"); |
|
9111 |
rightChild->setData(0, "rightChild"); |
|
9112 |
||
9113 |
scene.setSceneRect(scene.itemsBoundingRect().adjusted(-50, -50, 50, 50)); |
|
9114 |
||
9115 |
EventSpy2 leftParentSpy(&scene, leftParent); |
|
9116 |
EventSpy2 leftChildSpy(&scene, leftChild); |
|
9117 |
EventSpy2 rightParentSpy(&scene, rightParent); |
|
9118 |
EventSpy2 rightChildSpy(&scene, rightChild); |
|
9119 |
EventSpy2 bottomItemSpy(&scene, bottomItem); |
|
9120 |
||
9121 |
// Left Child enters panel modality, only left parent is blocked. |
|
9122 |
leftChild->setPanelModality(QGraphicsItem::PanelModal); |
|
9123 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9124 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9125 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9126 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9127 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); |
|
9128 |
||
9129 |
leftChild->setPanelModality(QGraphicsItem::NonModal); |
|
9130 |
leftChildSpy.counts.clear(); |
|
9131 |
rightChildSpy.counts.clear(); |
|
9132 |
leftParentSpy.counts.clear(); |
|
9133 |
rightParentSpy.counts.clear(); |
|
9134 |
bottomItemSpy.counts.clear(); |
|
9135 |
||
9136 |
// Left parent enter panel modality, nothing is blocked. |
|
9137 |
leftParent->setPanelModality(QGraphicsItem::PanelModal); |
|
9138 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9139 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9140 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9141 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9142 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); |
|
9143 |
||
9144 |
// Left child enters panel modality, left parent is blocked again. |
|
9145 |
leftChild->setPanelModality(QGraphicsItem::PanelModal); |
|
9146 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9147 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9148 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9149 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9150 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); |
|
9151 |
||
9152 |
leftChildSpy.counts.clear(); |
|
9153 |
rightChildSpy.counts.clear(); |
|
9154 |
leftParentSpy.counts.clear(); |
|
9155 |
rightParentSpy.counts.clear(); |
|
9156 |
bottomItemSpy.counts.clear(); |
|
9157 |
||
9158 |
leftChild->setPanelModality(QGraphicsItem::NonModal); |
|
9159 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 1); |
|
9160 |
leftParent->setPanelModality(QGraphicsItem::NonModal); |
|
9161 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9162 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9163 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 1); |
|
9164 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9165 |
QCOMPARE(bottomItemSpy.counts[QEvent::WindowUnblocked], 0); |
|
9166 |
||
9167 |
leftChildSpy.counts.clear(); |
|
9168 |
rightChildSpy.counts.clear(); |
|
9169 |
leftParentSpy.counts.clear(); |
|
9170 |
rightParentSpy.counts.clear(); |
|
9171 |
bottomItemSpy.counts.clear(); |
|
9172 |
||
9173 |
// Left and right child enter panel modality, both parents are blocked. |
|
9174 |
rightChild->setPanelModality(QGraphicsItem::PanelModal); |
|
9175 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9176 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9177 |
leftChild->setPanelModality(QGraphicsItem::PanelModal); |
|
9178 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9179 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9180 |
} |
|
9181 |
||
9182 |
void tst_QGraphicsItem::mixedModality() |
|
9183 |
{ |
|
9184 |
// 1) Test mouse events (delivery/propagation/redirection) |
|
9185 |
// 2) Test hover events (incl. leave on block, enter on unblock) |
|
9186 |
// 3) Test cursor stuff (incl. unset on block, set on unblock) |
|
9187 |
// 4) Test clickfocus |
|
9188 |
// 5) Test grab/ungrab events (possibly ungrab on block, regrab on unblock) |
|
9189 |
// 6) ### modality for non-panels is unsupported for now |
|
9190 |
QGraphicsScene scene; |
|
9191 |
||
9192 |
QGraphicsRectItem *bottomItem = scene.addRect(-150, -100, 300, 200); |
|
9193 |
bottomItem->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9194 |
bottomItem->setBrush(Qt::yellow); |
|
9195 |
||
9196 |
QGraphicsRectItem *leftParent = scene.addRect(-50, -50, 100, 100); |
|
9197 |
leftParent->setFlag(QGraphicsItem::ItemIsPanel); |
|
9198 |
leftParent->setBrush(Qt::blue); |
|
9199 |
||
9200 |
QGraphicsRectItem *leftChild = scene.addRect(-25, -25, 50, 50); |
|
9201 |
leftChild->setFlag(QGraphicsItem::ItemIsPanel); |
|
9202 |
leftChild->setBrush(Qt::green); |
|
9203 |
leftChild->setParentItem(leftParent); |
|
9204 |
||
9205 |
QGraphicsRectItem *rightParent = scene.addRect(-50, -50, 100, 100); |
|
9206 |
rightParent->setFlag(QGraphicsItem::ItemIsPanel); |
|
9207 |
rightParent->setBrush(Qt::red); |
|
9208 |
QGraphicsRectItem *rightChild = scene.addRect(-25, -25, 50, 50); |
|
9209 |
rightChild->setFlag(QGraphicsItem::ItemIsPanel); |
|
9210 |
rightChild->setBrush(Qt::gray); |
|
9211 |
rightChild->setParentItem(rightParent); |
|
9212 |
||
9213 |
leftParent->setPos(-75, 0); |
|
9214 |
rightParent->setPos(75, 0); |
|
9215 |
||
9216 |
bottomItem->setData(0, "bottomItem"); |
|
9217 |
leftParent->setData(0, "leftParent"); |
|
9218 |
leftChild->setData(0, "leftChild"); |
|
9219 |
rightParent->setData(0, "rightParent"); |
|
9220 |
rightChild->setData(0, "rightChild"); |
|
9221 |
||
9222 |
scene.setSceneRect(scene.itemsBoundingRect().adjusted(-50, -50, 50, 50)); |
|
9223 |
||
9224 |
EventSpy2 leftParentSpy(&scene, leftParent); |
|
9225 |
EventSpy2 leftChildSpy(&scene, leftChild); |
|
9226 |
EventSpy2 rightParentSpy(&scene, rightParent); |
|
9227 |
EventSpy2 rightChildSpy(&scene, rightChild); |
|
9228 |
EventSpy2 bottomItemSpy(&scene, bottomItem); |
|
9229 |
||
9230 |
// Left Child enters panel modality, only left parent is blocked. |
|
9231 |
leftChild->setPanelModality(QGraphicsItem::PanelModal); |
|
9232 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9233 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9234 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9235 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0); |
|
9236 |
||
9237 |
// Left parent enters scene modality, which blocks everything except the child. |
|
9238 |
leftParent->setPanelModality(QGraphicsItem::SceneModal); |
|
9239 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9240 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9241 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9242 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9243 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9244 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9245 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9246 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9247 |
||
9248 |
// Right child enters panel modality (changes nothing). |
|
9249 |
rightChild->setPanelModality(QGraphicsItem::PanelModal); |
|
9250 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9251 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9252 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9253 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9254 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9255 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9256 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9257 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9258 |
||
9259 |
// Left parent leaves modality. Right child is unblocked. |
|
9260 |
leftParent->setPanelModality(QGraphicsItem::NonModal); |
|
9261 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0); |
|
9262 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9263 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9264 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1); |
|
9265 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9266 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9267 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9268 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9269 |
||
9270 |
// Right child "upgrades" its modality to scene modal. Left child is blocked. |
|
9271 |
// Right parent is unaffected. |
|
9272 |
rightChild->setPanelModality(QGraphicsItem::SceneModal); |
|
9273 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9274 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0); |
|
9275 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9276 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1); |
|
9277 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9278 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9279 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9280 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9281 |
||
9282 |
// "downgrade" right child back to panel modal, left child is unblocked |
|
9283 |
rightChild->setPanelModality(QGraphicsItem::PanelModal); |
|
9284 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9285 |
QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 1); |
|
9286 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1); |
|
9287 |
QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1); |
|
9288 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9289 |
QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9290 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1); |
|
9291 |
QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0); |
|
9292 |
} |
|
9293 |
||
9294 |
void tst_QGraphicsItem::modality_hover() |
|
9295 |
{ |
|
9296 |
QGraphicsScene scene; |
|
9297 |
QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100); |
|
9298 |
rect1->setFlag(QGraphicsItem::ItemIsPanel); |
|
9299 |
rect1->setAcceptHoverEvents(true); |
|
9300 |
rect1->setData(0, "rect1"); |
|
9301 |
||
9302 |
QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100); |
|
9303 |
rect2->setParentItem(rect1); |
|
9304 |
rect2->setFlag(QGraphicsItem::ItemIsPanel); |
|
9305 |
rect2->setAcceptHoverEvents(true); |
|
9306 |
rect2->setPos(50, 50); |
|
9307 |
rect2->setPanelModality(QGraphicsItem::SceneModal); |
|
9308 |
rect2->setData(0, "rect2"); |
|
9309 |
||
9310 |
EventSpy2 rect1Spy(&scene, rect1); |
|
9311 |
EventSpy2 rect2Spy(&scene, rect2); |
|
9312 |
||
9313 |
sendMouseMove(&scene, QPointF(-25, -25)); |
|
9314 |
||
9315 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 0); |
|
9316 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 0); |
|
9317 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 0); |
|
9318 |
||
9319 |
sendMouseMove(&scene, QPointF(75, 75)); |
|
9320 |
||
9321 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 0); |
|
9322 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 0); |
|
9323 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 0); |
|
9324 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 1); |
|
9325 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 1); |
|
9326 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 0); |
|
9327 |
||
9328 |
sendMouseMove(&scene, QPointF(-25, -25)); |
|
9329 |
||
9330 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 1); |
|
9331 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 0); |
|
9332 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 0); |
|
9333 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 0); |
|
9334 |
||
9335 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9336 |
||
9337 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 1); |
|
9338 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 1); |
|
9339 |
||
9340 |
sendMouseMove(&scene, QPointF(75, 75)); |
|
9341 |
||
9342 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2); |
|
9343 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 2); |
|
9344 |
||
9345 |
rect2->setPanelModality(QGraphicsItem::SceneModal); |
|
9346 |
||
9347 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 1); |
|
9348 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2); |
|
9349 |
// changing modality causes a spurious GraphicsSceneHoveMove, even though the mouse didn't |
|
9350 |
// actually move |
|
9351 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 3); |
|
9352 |
||
9353 |
sendMouseMove(&scene, QPointF(-25, -25)); |
|
9354 |
||
9355 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 2); |
|
9356 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 1); |
|
9357 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 1); |
|
9358 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 1); |
|
9359 |
||
9360 |
rect2->setPanelModality(QGraphicsItem::PanelModal); |
|
9361 |
||
9362 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 1); |
|
9363 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 1); |
|
9364 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 1); |
|
9365 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2); |
|
9366 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 3); |
|
9367 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 2); |
|
9368 |
||
9369 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9370 |
||
9371 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 2); |
|
9372 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 2); |
|
9373 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2); |
|
9374 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 3); |
|
9375 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 2); |
|
9376 |
} |
|
9377 |
||
9378 |
void tst_QGraphicsItem::modality_mouseGrabber() |
|
9379 |
{ |
|
9380 |
QGraphicsScene scene; |
|
9381 |
QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100); |
|
9382 |
rect1->setFlag(QGraphicsItem::ItemIsPanel); |
|
9383 |
rect1->setFlag(QGraphicsItem::ItemIsMovable); |
|
9384 |
rect1->setData(0, "rect1"); |
|
9385 |
||
9386 |
QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100); |
|
9387 |
rect2->setParentItem(rect1); |
|
9388 |
rect2->setFlag(QGraphicsItem::ItemIsPanel); |
|
9389 |
rect2->setFlag(QGraphicsItem::ItemIsMovable); |
|
9390 |
rect2->setPos(50, 50); |
|
9391 |
rect2->setData(0, "rect2"); |
|
9392 |
||
9393 |
EventSpy2 rect1Spy(&scene, rect1); |
|
9394 |
EventSpy2 rect2Spy(&scene, rect2); |
|
9395 |
||
9396 |
{ |
|
9397 |
// pressing mouse on rect1 starts implicit grab |
|
9398 |
sendMousePress(&scene, QPoint(-25, -25)); |
|
9399 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9400 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9401 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9402 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9403 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9404 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); |
|
9405 |
||
9406 |
// grab lost when rect1 is modally shadowed |
|
9407 |
rect2->setPanelModality(QGraphicsItem::SceneModal); |
|
9408 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9409 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9410 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9411 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9412 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9413 |
||
9414 |
// releasing goes nowhere |
|
9415 |
sendMouseRelease(&scene, QPoint(-25, -25)); |
|
9416 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9417 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9418 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9419 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9420 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9421 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9422 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9423 |
||
9424 |
// pressing mouse on rect1 starts implicit grab on rect2 (since it is modal) |
|
9425 |
sendMouseClick(&scene, QPoint(-25, -25)); |
|
9426 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9427 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9428 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9429 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9430 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9431 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9432 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 1); |
|
9433 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9434 |
||
9435 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9436 |
||
9437 |
// pressing mouse on rect1 starts implicit grab |
|
9438 |
sendMousePress(&scene, QPoint(-25, -25)); |
|
9439 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9440 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 2); |
|
9441 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9442 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9443 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9444 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); |
|
9445 |
||
9446 |
// grab lost to rect2 when rect1 is modally shadowed |
|
9447 |
rect2->setPanelModality(QGraphicsItem::SceneModal); |
|
9448 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9449 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2); |
|
9450 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9451 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9452 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9453 |
||
9454 |
// rect1 does *not* re-grab when rect2 is no longer modal |
|
9455 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9456 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9457 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2); |
|
9458 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9459 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9460 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9461 |
||
9462 |
// release goes nowhere |
|
9463 |
sendMouseRelease(&scene, QPoint(-25, -25)); |
|
9464 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9465 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9466 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2); |
|
9467 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9468 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9469 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9470 |
} |
|
9471 |
{ |
|
9472 |
// repeat the test using PanelModal |
|
9473 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9474 |
rect1Spy.counts.clear(); |
|
9475 |
rect2Spy.counts.clear(); |
|
9476 |
||
9477 |
// pressing mouse on rect1 starts implicit grab |
|
9478 |
sendMousePress(&scene, QPoint(-25, -25)); |
|
9479 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9480 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9481 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9482 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9483 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9484 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); |
|
9485 |
||
9486 |
// grab lost when rect1 is modally shadowed |
|
9487 |
rect2->setPanelModality(QGraphicsItem::PanelModal); |
|
9488 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9489 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9490 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9491 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9492 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9493 |
||
9494 |
// releasing goes nowhere |
|
9495 |
sendMouseRelease(&scene, QPoint(-25, -25)); |
|
9496 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9497 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9498 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9499 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9500 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9501 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9502 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9503 |
||
9504 |
// pressing mouse on rect1 starts implicit grab on rect2 (since it is modal) |
|
9505 |
sendMouseClick(&scene, QPoint(-25, -25)); |
|
9506 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1); |
|
9507 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9508 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9509 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9510 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9511 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9512 |
QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 1); |
|
9513 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9514 |
||
9515 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9516 |
||
9517 |
// pressing mouse on rect1 starts implicit grab |
|
9518 |
sendMousePress(&scene, QPoint(-25, -25)); |
|
9519 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9520 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 2); |
|
9521 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); |
|
9522 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9523 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9524 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); |
|
9525 |
||
9526 |
// grab lost to rect2 when rect1 is modally shadowed |
|
9527 |
rect2->setPanelModality(QGraphicsItem::PanelModal); |
|
9528 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9529 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2); |
|
9530 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9531 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9532 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9533 |
||
9534 |
// rect1 does *not* re-grab when rect2 is no longer modal |
|
9535 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9536 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9537 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2); |
|
9538 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9539 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9540 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9541 |
||
9542 |
// release goes nowhere |
|
9543 |
sendMouseRelease(&scene, QPoint(-25, -25)); |
|
9544 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2); |
|
9545 |
QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0); |
|
9546 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2); |
|
9547 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); |
|
9548 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); |
|
9549 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9550 |
} |
|
9551 |
||
9552 |
{ |
|
9553 |
// repeat the PanelModal tests, but this time the mouse events will be on a non-modal item, |
|
9554 |
// meaning normal grabbing should work |
|
9555 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9556 |
rect1Spy.counts.clear(); |
|
9557 |
rect2Spy.counts.clear(); |
|
9558 |
||
9559 |
QGraphicsRectItem *rect3 = scene.addRect(-50, -50, 100, 100); |
|
9560 |
rect3->setFlag(QGraphicsItem::ItemIsPanel); |
|
9561 |
rect3->setFlag(QGraphicsItem::ItemIsMovable); |
|
9562 |
rect3->setPos(150, 50); |
|
9563 |
rect3->setData(0, "rect3"); |
|
9564 |
||
9565 |
EventSpy2 rect3Spy(&scene, rect3); |
|
9566 |
||
9567 |
// pressing mouse on rect3 starts implicit grab |
|
9568 |
sendMousePress(&scene, QPoint(150, 50)); |
|
9569 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0); |
|
9570 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9571 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9572 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9573 |
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1); |
|
9574 |
QCOMPARE(rect3Spy.counts[QEvent::GraphicsSceneMousePress], 1); |
|
9575 |
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0); |
|
9576 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); |
|
9577 |
||
9578 |
// grab is *not* lost when rect1 is modally shadowed by rect2 |
|
9579 |
rect2->setPanelModality(QGraphicsItem::PanelModal); |
|
9580 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0); |
|
9581 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9582 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9583 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9584 |
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1); |
|
9585 |
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0); |
|
9586 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); |
|
9587 |
||
9588 |
// releasing goes to rect3 |
|
9589 |
sendMouseRelease(&scene, QPoint(150, 50)); |
|
9590 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0); |
|
9591 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9592 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9593 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9594 |
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1); |
|
9595 |
QCOMPARE(rect3Spy.counts[QEvent::GraphicsSceneMouseRelease], 1); |
|
9596 |
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1); |
|
9597 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9598 |
||
9599 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9600 |
||
9601 |
// pressing mouse on rect3 starts implicit grab |
|
9602 |
sendMousePress(&scene, QPoint(150, 50)); |
|
9603 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0); |
|
9604 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9605 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9606 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9607 |
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2); |
|
9608 |
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1); |
|
9609 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); |
|
9610 |
||
9611 |
// grab is not lost |
|
9612 |
rect2->setPanelModality(QGraphicsItem::PanelModal); |
|
9613 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0); |
|
9614 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9615 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9616 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9617 |
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2); |
|
9618 |
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1); |
|
9619 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); |
|
9620 |
||
9621 |
// grab stays on rect3 |
|
9622 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9623 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0); |
|
9624 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9625 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9626 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9627 |
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2); |
|
9628 |
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1); |
|
9629 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); |
|
9630 |
||
9631 |
// release goes to rect3 |
|
9632 |
sendMouseRelease(&scene, QPoint(150, 50)); |
|
9633 |
QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0); |
|
9634 |
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); |
|
9635 |
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); |
|
9636 |
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); |
|
9637 |
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2); |
|
9638 |
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 2); |
|
9639 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0); |
|
9640 |
} |
|
9641 |
} |
|
9642 |
||
9643 |
void tst_QGraphicsItem::modality_clickFocus() |
|
9644 |
{ |
|
9645 |
QGraphicsScene scene; |
|
9646 |
QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100); |
|
9647 |
rect1->setFlag(QGraphicsItem::ItemIsPanel); |
|
9648 |
rect1->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9649 |
rect1->setData(0, "rect1"); |
|
9650 |
||
9651 |
QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100); |
|
9652 |
rect2->setParentItem(rect1); |
|
9653 |
rect2->setFlag(QGraphicsItem::ItemIsPanel); |
|
9654 |
rect2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9655 |
rect2->setPos(50, 50); |
|
9656 |
rect2->setData(0, "rect2"); |
|
9657 |
||
9658 |
QEvent windowActivateEvent(QEvent::WindowActivate); |
|
9659 |
QApplication::sendEvent(&scene, &windowActivateEvent); |
|
9660 |
||
9661 |
EventSpy2 rect1Spy(&scene, rect1); |
|
9662 |
EventSpy2 rect2Spy(&scene, rect2); |
|
9663 |
||
9664 |
// activate rect1, it should not get focus |
|
9665 |
rect1->setActive(true); |
|
9666 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); |
|
9667 |
||
9668 |
// focus stays unset when rect2 becomes modal |
|
9669 |
rect2->setPanelModality(QGraphicsItem::SceneModal); |
|
9670 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); |
|
9671 |
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); |
|
9672 |
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); |
|
9673 |
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0); |
|
9674 |
QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); |
|
9675 |
||
9676 |
// clicking on rect1 should not set it's focus item |
|
9677 |
sendMouseClick(&scene, QPointF(-25, -25)); |
|
9678 |
QCOMPARE(rect1->focusItem(), (QGraphicsItem *) 0); |
|
9679 |
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); |
|
9680 |
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); |
|
9681 |
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0); |
|
9682 |
QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); |
|
9683 |
||
9684 |
// clicking on rect2 gives it focus |
|
9685 |
rect2->setActive(true); |
|
9686 |
sendMouseClick(&scene, QPointF(75, 75)); |
|
9687 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect2); |
|
9688 |
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); |
|
9689 |
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); |
|
9690 |
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); |
|
9691 |
QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); |
|
9692 |
||
9693 |
// clicking on rect1 does *not* give it focus |
|
9694 |
rect1->setActive(true); |
|
9695 |
sendMouseClick(&scene, QPointF(-25, -25)); |
|
9696 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); |
|
9697 |
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); |
|
9698 |
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); |
|
9699 |
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); |
|
9700 |
QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); |
|
9701 |
||
9702 |
// focus doesn't change when leaving modality either |
|
9703 |
rect2->setPanelModality(QGraphicsItem::NonModal); |
|
9704 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); |
|
9705 |
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); |
|
9706 |
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); |
|
9707 |
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); |
|
9708 |
QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); |
|
9709 |
||
9710 |
// click on rect1, it should get focus now |
|
9711 |
sendMouseClick(&scene, QPointF(-25, -25)); |
|
9712 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); |
|
9713 |
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); |
|
9714 |
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); |
|
9715 |
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); |
|
9716 |
QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); |
|
9717 |
} |
|
9718 |
||
9719 |
void tst_QGraphicsItem::modality_keyEvents() |
|
9720 |
{ |
|
9721 |
QGraphicsScene scene; |
|
9722 |
QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100); |
|
9723 |
rect1->setFlag(QGraphicsItem::ItemIsPanel); |
|
9724 |
rect1->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9725 |
rect1->setData(0, "rect1"); |
|
9726 |
||
9727 |
QGraphicsRectItem *rect1child = scene.addRect(-10, -10, 20, 20); |
|
9728 |
rect1child->setParentItem(rect1); |
|
9729 |
rect1child->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9730 |
rect1child->setData(0, "rect1child1"); |
|
9731 |
||
9732 |
QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100); |
|
9733 |
rect2->setParentItem(rect1); |
|
9734 |
rect2->setFlag(QGraphicsItem::ItemIsPanel); |
|
9735 |
rect2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9736 |
rect2->setPos(50, 50); |
|
9737 |
rect2->setData(0, "rect2"); |
|
9738 |
||
9739 |
QGraphicsRectItem *rect2child = scene.addRect(-10, -10, 20, 20); |
|
9740 |
rect2child->setParentItem(rect2); |
|
9741 |
rect2child->setFlag(QGraphicsItem::ItemIsFocusable); |
|
9742 |
rect2child->setData(0, "rect2child1"); |
|
9743 |
||
9744 |
QEvent windowActivateEvent(QEvent::WindowActivate); |
|
9745 |
QApplication::sendEvent(&scene, &windowActivateEvent); |
|
9746 |
||
9747 |
EventSpy2 rect1Spy(&scene, rect1); |
|
9748 |
EventSpy2 rect1childSpy(&scene, rect1child); |
|
9749 |
EventSpy2 rect2Spy(&scene, rect2); |
|
9750 |
EventSpy2 rect2childSpy(&scene, rect2child); |
|
9751 |
||
9752 |
// activate rect1 and give it rect1child focus |
|
9753 |
rect1->setActive(true); |
|
9754 |
rect1child->setFocus(); |
|
9755 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child); |
|
9756 |
||
9757 |
// focus stays on rect1child when rect2 becomes modal |
|
9758 |
rect2->setPanelModality(QGraphicsItem::SceneModal); |
|
9759 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child); |
|
9760 |
||
9761 |
// but key events to rect1child should be neither delivered nor propagated |
|
9762 |
sendKeyClick(&scene, Qt::Key_A); |
|
9763 |
sendKeyClick(&scene, Qt::Key_S); |
|
9764 |
sendKeyClick(&scene, Qt::Key_D); |
|
9765 |
sendKeyClick(&scene, Qt::Key_F); |
|
9766 |
QCOMPARE(rect1childSpy.counts[QEvent::KeyPress], 0); |
|
9767 |
QCOMPARE(rect1childSpy.counts[QEvent::KeyRelease], 0); |
|
9768 |
QCOMPARE(rect1Spy.counts[QEvent::KeyPress], 0); |
|
9769 |
QCOMPARE(rect1Spy.counts[QEvent::KeyRelease], 0); |
|
9770 |
||
9771 |
// change to panel modality, rect1child1 keeps focus |
|
9772 |
rect2->setPanelModality(QGraphicsItem::PanelModal); |
|
9773 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child); |
|
9774 |
||
9775 |
// still no key events |
|
9776 |
sendKeyClick(&scene, Qt::Key_J); |
|
9777 |
sendKeyClick(&scene, Qt::Key_K); |
|
9778 |
sendKeyClick(&scene, Qt::Key_L); |
|
9779 |
sendKeyClick(&scene, Qt::Key_Semicolon); |
|
9780 |
QCOMPARE(rect1childSpy.counts[QEvent::KeyPress], 0); |
|
9781 |
QCOMPARE(rect1childSpy.counts[QEvent::KeyRelease], 0); |
|
9782 |
QCOMPARE(rect1Spy.counts[QEvent::KeyPress], 0); |
|
9783 |
QCOMPARE(rect1Spy.counts[QEvent::KeyRelease], 0); |
|
9784 |
} |
|
9785 |
||
9786 |
void tst_QGraphicsItem::itemIsInFront() |
|
9787 |
{ |
|
9788 |
QGraphicsScene scene; |
|
9789 |
QGraphicsRectItem *rect1 = new QGraphicsRectItem; |
|
9790 |
rect1->setData(0, "rect1"); |
|
9791 |
scene.addItem(rect1); |
|
9792 |
||
9793 |
QGraphicsRectItem *rect1child1 = new QGraphicsRectItem(rect1); |
|
9794 |
rect1child1->setZValue(1); |
|
9795 |
rect1child1->setData(0, "rect1child1"); |
|
9796 |
||
9797 |
QGraphicsRectItem *rect1child2 = new QGraphicsRectItem(rect1); |
|
9798 |
rect1child2->setParentItem(rect1); |
|
9799 |
rect1child2->setData(0, "rect1child2"); |
|
9800 |
||
9801 |
QGraphicsRectItem *rect1child1_1 = new QGraphicsRectItem(rect1child1); |
|
9802 |
rect1child1_1->setData(0, "rect1child1_1"); |
|
9803 |
||
9804 |
QGraphicsRectItem *rect1child1_2 = new QGraphicsRectItem(rect1child1); |
|
9805 |
rect1child1_2->setFlag(QGraphicsItem::ItemStacksBehindParent); |
|
9806 |
rect1child1_2->setData(0, "rect1child1_2"); |
|
9807 |
||
9808 |
QGraphicsRectItem *rect2 = new QGraphicsRectItem; |
|
9809 |
rect2->setData(0, "rect2"); |
|
9810 |
scene.addItem(rect2); |
|
9811 |
||
9812 |
QGraphicsRectItem *rect2child1 = new QGraphicsRectItem(rect2); |
|
9813 |
rect2child1->setData(0, "rect2child1"); |
|
9814 |
||
9815 |
QCOMPARE(qt_closestItemFirst(rect1, rect1), false); |
|
9816 |
QCOMPARE(qt_closestItemFirst(rect1, rect2), false); |
|
9817 |
QCOMPARE(qt_closestItemFirst(rect1child1, rect2child1), false); |
|
9818 |
QCOMPARE(qt_closestItemFirst(rect1child1, rect1child2), true); |
|
9819 |
QCOMPARE(qt_closestItemFirst(rect1child1_1, rect1child2), true); |
|
9820 |
QCOMPARE(qt_closestItemFirst(rect1child1_1, rect1child1), true); |
|
9821 |
QCOMPARE(qt_closestItemFirst(rect1child1_2, rect1child2), true); |
|
9822 |
QCOMPARE(qt_closestItemFirst(rect1child1_2, rect1child1), false); |
|
9823 |
QCOMPARE(qt_closestItemFirst(rect1child1_2, rect1), true); |
|
9824 |
QCOMPARE(qt_closestItemFirst(rect1child1_2, rect2), false); |
|
9825 |
QCOMPARE(qt_closestItemFirst(rect1child1_2, rect2child1), false); |
|
9826 |
} |
|
9827 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9828 |
class ScenePosChangeTester : public ItemChangeTester |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9829 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9830 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9831 |
ScenePosChangeTester() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9832 |
{ } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9833 |
ScenePosChangeTester(QGraphicsItem *parent) : ItemChangeTester(parent) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9834 |
{ } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9835 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9836 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9837 |
void tst_QGraphicsItem::scenePosChange() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9838 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9839 |
ScenePosChangeTester* root = new ScenePosChangeTester; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9840 |
ScenePosChangeTester* child1 = new ScenePosChangeTester(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9841 |
ScenePosChangeTester* grandChild1 = new ScenePosChangeTester(child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9842 |
ScenePosChangeTester* child2 = new ScenePosChangeTester(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9843 |
ScenePosChangeTester* grandChild2 = new ScenePosChangeTester(child2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9844 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9845 |
child1->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9846 |
grandChild2->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9847 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9848 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9849 |
scene.addItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9850 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9851 |
// ignore uninteresting changes |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9852 |
child1->clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9853 |
child2->clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9854 |
grandChild1->clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9855 |
grandChild2->clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9856 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9857 |
// move whole tree |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9858 |
root->moveBy(1.0, 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9859 |
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9860 |
QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9861 |
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9862 |
QCOMPARE(grandChild2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9863 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9864 |
// move subtree |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9865 |
child2->moveBy(1.0, 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9866 |
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9867 |
QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9868 |
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9869 |
QCOMPARE(grandChild2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9870 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9871 |
// reparent |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9872 |
grandChild2->setParentItem(child1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9873 |
child1->moveBy(1.0, 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9874 |
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9875 |
QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9876 |
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9877 |
QCOMPARE(grandChild2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9878 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9879 |
// change flags |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9880 |
grandChild1->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9881 |
grandChild2->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9882 |
QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9883 |
child1->moveBy(1.0, 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9884 |
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9885 |
QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9886 |
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9887 |
QCOMPARE(grandChild2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9888 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9889 |
// remove |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9890 |
scene.removeItem(grandChild1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9891 |
delete grandChild2; grandChild2 = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9892 |
QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9893 |
root->moveBy(1.0, 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9894 |
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9895 |
QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9896 |
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9897 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9898 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9899 |
void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9900 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9901 |
struct Item : public QGraphicsTextItem |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9902 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9903 |
int painted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9904 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9905 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9906 |
painted++; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9907 |
QGraphicsTextItem::paint(painter, opt, wid); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9908 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9909 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9910 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9911 |
Item *i = new Item; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9912 |
i->painted = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9913 |
i->setPlainText("I AM A TROLL"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9914 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9915 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9916 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9917 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9918 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9919 |
scene.addItem(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9920 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9921 |
QTRY_VERIFY(i->painted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9922 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9923 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9924 |
i->painted = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9925 |
QColor col(Qt::red); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9926 |
i->setDefaultTextColor(col); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9927 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9928 |
QTRY_COMPARE(i->painted, 1); //check that changing the color force an update |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9929 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9930 |
i->painted = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9931 |
QImage image(400, 200, QImage::Format_RGB32); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9932 |
image.fill(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9933 |
QPainter painter(&image); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9934 |
scene.render(&painter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9935 |
painter.end(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9936 |
QCOMPARE(i->painted, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9937 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9938 |
int numRedPixel = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9939 |
QRgb rgb = col.rgb(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9940 |
for (int y = 0; y < image.height(); ++y) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9941 |
for (int x = 0; x < image.width(); ++x) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9942 |
// Because of antialiasing we allow a certain range of errors here. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9943 |
QRgb pixel = image.pixel(x, y); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9944 |
if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) + |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9945 |
qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) + |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9946 |
qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9947 |
if (++numRedPixel >= 10) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9948 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9949 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9950 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9951 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9952 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9953 |
QCOMPARE(numRedPixel, -1); //color not found, FAIL! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9954 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9955 |
i->painted = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9956 |
i->setDefaultTextColor(col); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9957 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9958 |
QCOMPARE(i->painted, 0); //same color as before should not trigger an update (QTBUG-6242) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9959 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9960 |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9961 |
void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9962 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9963 |
// In all 3 test cases below the reparented item should disappear |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9964 |
EventTester *parent = new EventTester; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9965 |
EventTester *child = new EventTester(parent); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9966 |
EventTester *child2 = new EventTester(parent); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9967 |
EventTester *child3 = new EventTester(parent); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9968 |
EventTester *child4 = new EventTester(parent); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9969 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9970 |
child->setPos(10, 10); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9971 |
child2->setPos(20, 20); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9972 |
child3->setPos(30, 30); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9973 |
child4->setPos(40, 40); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9974 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9975 |
QGraphicsScene scene; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9976 |
scene.addItem(parent); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9977 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9978 |
MyGraphicsView view(&scene); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9979 |
view.show(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9980 |
QTest::qWaitForWindowShown(&view); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9981 |
QTRY_VERIFY(view.repaints > 0); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9982 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9983 |
// test case #1 |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9984 |
view.reset(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9985 |
child2->setVisible(false); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9986 |
child2->setParentItem(child); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9987 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9988 |
QTRY_VERIFY(view.repaints == 1); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9989 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9990 |
// test case #2 |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9991 |
view.reset(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9992 |
child3->setOpacity(0.0); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9993 |
child3->setParentItem(child); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9994 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9995 |
QTRY_VERIFY(view.repaints == 1); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9996 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9997 |
// test case #3 |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9998 |
view.reset(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
9999 |
child4->setParentItem(child); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
10000 |
child4->setVisible(false); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
10001 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
10002 |
QTRY_VERIFY(view.repaints == 1); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
10003 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
10004 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10005 |
void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10006 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10007 |
QGraphicsScene scene(0, 0, 200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10008 |
MyGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10009 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10010 |
EventTester *parentGreen = new EventTester(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10011 |
parentGreen->setGeometry(QRectF(20, 20, 100, 100)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10012 |
parentGreen->brush = Qt::green; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10013 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10014 |
EventTester *childYellow = new EventTester(parentGreen); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10015 |
childYellow->setGeometry(QRectF(10, 10, 50, 50)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10016 |
childYellow->brush = Qt::yellow; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10017 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10018 |
scene.addItem(parentGreen); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10019 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10020 |
childYellow->setOpacity(0.0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10021 |
parentGreen->setOpacity(0.0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10022 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10023 |
// set any of the flags below to trigger a fullUpdate to reproduce the bug: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10024 |
// ItemIgnoresTransformations, ItemClipsChildrenToShape, ItemIsSelectable |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10025 |
parentGreen->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10026 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10027 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10028 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10029 |
view.reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10030 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10031 |
parentGreen->setOpacity(1.0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10032 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10033 |
QTRY_COMPARE(view.repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10034 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10035 |
view.reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10036 |
childYellow->repaints = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10037 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10038 |
childYellow->setOpacity(1.0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10039 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10040 |
QTRY_COMPARE(view.repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10041 |
QTRY_COMPARE(childYellow->repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10042 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10043 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10044 |
void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10045 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10046 |
QGraphicsScene scene(0, 0, 200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10047 |
MyGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10048 |
MyGraphicsView origView(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10049 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10050 |
EventTester *parentGreen = new EventTester(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10051 |
parentGreen->setGeometry(QRectF(20, 20, 100, 100)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10052 |
parentGreen->brush = Qt::green; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10053 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10054 |
EventTester *childYellow = new EventTester(parentGreen); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10055 |
childYellow->setGeometry(QRectF(10, 10, 50, 50)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10056 |
childYellow->brush = Qt::yellow; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10057 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10058 |
scene.addItem(parentGreen); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10059 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10060 |
origView.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10061 |
QTest::qWaitForWindowShown(&origView); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10062 |
origView.setGeometry(origView.width() + 20, 20, |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10063 |
origView.width(), origView.height()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10064 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10065 |
parentGreen->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10066 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10067 |
origView.reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10068 |
childYellow->setOpacity(0.0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10069 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10070 |
QTRY_COMPARE(origView.repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10071 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10072 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10073 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10074 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10075 |
view.reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10076 |
origView.reset(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10077 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10078 |
childYellow->setOpacity(1.0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10079 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10080 |
QTRY_COMPARE(origView.repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10081 |
QTRY_COMPARE(view.repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10082 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10083 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10084 |
void tst_QGraphicsItem::QT_2649_focusScope() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10085 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10086 |
QGraphicsScene *scene = new QGraphicsScene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10087 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10088 |
QGraphicsRectItem *subFocusItem = new QGraphicsRectItem; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10089 |
subFocusItem->setFlags(QGraphicsItem::ItemIsFocusable); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10090 |
subFocusItem->setFocus(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10091 |
QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10092 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10093 |
QGraphicsRectItem *scope = new QGraphicsRectItem; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10094 |
scope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10095 |
scope->setFocus(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10096 |
subFocusItem->setParentItem(scope); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10097 |
QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10098 |
QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10099 |
QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10100 |
QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10101 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10102 |
QGraphicsRectItem *rootItem = new QGraphicsRectItem; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10103 |
rootItem->setFlags(QGraphicsItem::ItemIsFocusable); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10104 |
scope->setParentItem(rootItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10105 |
QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10106 |
QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10107 |
QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10108 |
QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10109 |
QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10110 |
QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10111 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10112 |
scene->addItem(rootItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10113 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10114 |
QEvent windowActivate(QEvent::WindowActivate); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10115 |
qApp->sendEvent(scene, &windowActivate); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10116 |
scene->setFocus(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10117 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10118 |
QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10119 |
QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10120 |
QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10121 |
QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10122 |
QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10123 |
QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10124 |
QVERIFY(subFocusItem->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10125 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10126 |
scope->hide(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10127 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10128 |
QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10129 |
QCOMPARE(scope->focusItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10130 |
QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10131 |
QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10132 |
QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10133 |
QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10134 |
QVERIFY(!subFocusItem->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10135 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10136 |
scope->show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10137 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10138 |
QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10139 |
QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10140 |
QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10141 |
QCOMPARE(rootItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10142 |
QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10143 |
QCOMPARE(subFocusItem->focusScopeItem(), (QGraphicsItem *)0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10144 |
QVERIFY(subFocusItem->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10145 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10146 |
// This should not crash |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10147 |
scope->hide(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10148 |
delete scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10149 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10150 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10151 |
class MyGraphicsItemWithItemChange : public QGraphicsWidget |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10152 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10153 |
public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10154 |
MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10155 |
{} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10156 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10157 |
QVariant itemChange(GraphicsItemChange change, const QVariant &value) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10158 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10159 |
if (change == QGraphicsItem::ItemSceneHasChanged) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10160 |
foreach (QGraphicsView *view, scene()->views()) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10161 |
//We trigger a sort of unindexed items in the BSP |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10162 |
view->sceneRect(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10163 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10164 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10165 |
return QGraphicsWidget::itemChange(change, value); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10166 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10167 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10168 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10169 |
void tst_QGraphicsItem::sortItemsWhileAdding() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10170 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10171 |
QGraphicsScene scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10172 |
QGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10173 |
QGraphicsWidget grandGrandParent; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10174 |
grandGrandParent.resize(200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10175 |
scene.addItem(&grandGrandParent); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10176 |
QGraphicsWidget grandParent; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10177 |
grandParent.resize(200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10178 |
QGraphicsWidget parent(&grandParent); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10179 |
parent.resize(200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10180 |
MyGraphicsItemWithItemChange item(&parent); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10181 |
grandParent.setParentItem(&grandGrandParent); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10182 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10183 |
|
0 | 10184 |
QTEST_MAIN(tst_QGraphicsItem) |
10185 |
#include "tst_qgraphicsitem.moc" |