author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the 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 <qgraphicsitem.h> |
|
46 |
#include <qgraphicsscene.h> |
|
47 |
#include <qgraphicssceneevent.h> |
|
48 |
#include <qgraphicsview.h> |
|
49 |
#include <qgraphicswidget.h> |
|
50 |
#include <qgraphicsproxywidget.h> |
|
51 |
||
52 |
#include <math.h> |
|
53 |
||
54 |
#include <QtGui/QLabel> |
|
55 |
#if !defined(QT_NO_STYLE_MOTIF) |
|
56 |
#include <QtGui/QMotifStyle> |
|
57 |
#endif |
|
58 |
#if !defined(QT_NO_STYLE_WINDOWS) |
|
59 |
#include <QtGui/QWindowsStyle> |
|
60 |
#endif |
|
61 |
#if !defined(QT_NO_STYLE_PLASTIQUE) |
|
62 |
#include <QtGui/QPlastiqueStyle> |
|
63 |
#endif |
|
64 |
#include <QtGui/QPainterPath> |
|
65 |
#include <QtGui/QRubberBand> |
|
66 |
#include <QtGui/QScrollBar> |
|
67 |
#include <QtGui/QStyleOption> |
|
68 |
#include <QtGui/QBoxLayout> |
|
69 |
#include <QtGui/QStyle> |
|
70 |
#include <QtGui/QPushButton> |
|
71 |
#include <QtGui/QInputContext> |
|
72 |
#include <private/qgraphicsview_p.h> |
|
73 |
#include "../../shared/util.h" |
|
74 |
||
75 |
//TESTED_CLASS= |
|
76 |
//TESTED_FILES= |
|
77 |
||
78 |
Q_DECLARE_METATYPE(QList<int>) |
|
79 |
Q_DECLARE_METATYPE(QList<QRectF>) |
|
80 |
Q_DECLARE_METATYPE(QMatrix) |
|
81 |
Q_DECLARE_METATYPE(QPainterPath) |
|
82 |
Q_DECLARE_METATYPE(QPointF) |
|
83 |
Q_DECLARE_METATYPE(QPolygonF) |
|
84 |
Q_DECLARE_METATYPE(QRectF) |
|
85 |
Q_DECLARE_METATYPE(Qt::ScrollBarPolicy) |
|
86 |
||
87 |
#ifdef Q_WS_MAC |
|
88 |
//On mac we get full update. So check that the expected region is contained inside the actual |
|
89 |
#define COMPARE_REGIONS(ACTUAL, EXPECTED) QVERIFY((EXPECTED).subtracted(ACTUAL).isEmpty()) |
|
90 |
#else |
|
91 |
#define COMPARE_REGIONS QCOMPARE |
|
92 |
#endif |
|
93 |
||
94 |
static void sendMousePress(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) |
|
95 |
{ |
|
96 |
QMouseEvent event(QEvent::MouseButtonPress, point, widget->mapToGlobal(point), button, 0, 0); |
|
97 |
QApplication::sendEvent(widget, &event); |
|
98 |
} |
|
99 |
||
100 |
static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = 0) |
|
101 |
{ |
|
102 |
QTest::mouseMove(widget, point); |
|
103 |
QMouseEvent event(QEvent::MouseMove, point, button, buttons, 0); |
|
104 |
QApplication::sendEvent(widget, &event); |
|
105 |
} |
|
106 |
||
107 |
static void sendMouseRelease(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) |
|
108 |
{ |
|
109 |
QMouseEvent event(QEvent::MouseButtonRelease, point, widget->mapToGlobal(point), button, 0, 0); |
|
110 |
QApplication::sendEvent(widget, &event); |
|
111 |
} |
|
112 |
||
113 |
class EventSpy : public QObject |
|
114 |
{ |
|
115 |
Q_OBJECT |
|
116 |
public: |
|
117 |
EventSpy(QObject *watched, QEvent::Type type) |
|
118 |
: _count(0), spied(type) |
|
119 |
{ |
|
120 |
watched->installEventFilter(this); |
|
121 |
} |
|
122 |
||
123 |
int count() const { return _count; } |
|
124 |
void reset() { _count = 0; } |
|
125 |
||
126 |
protected: |
|
127 |
bool eventFilter(QObject *watched, QEvent *event) |
|
128 |
{ |
|
129 |
Q_UNUSED(watched); |
|
130 |
if (event->type() == spied) |
|
131 |
++_count; |
|
132 |
return false; |
|
133 |
} |
|
134 |
||
135 |
int _count; |
|
136 |
QEvent::Type spied; |
|
137 |
}; |
|
138 |
||
139 |
class tst_QGraphicsView : public QObject |
|
140 |
{ |
|
141 |
Q_OBJECT |
|
142 |
||
143 |
private slots: |
|
144 |
void initTestCase(); |
|
145 |
void construction(); |
|
146 |
void renderHints(); |
|
147 |
void alignment(); |
|
148 |
void interactive(); |
|
149 |
void scene(); |
|
150 |
void setScene(); |
|
151 |
void deleteScene(); |
|
152 |
void sceneRect(); |
|
153 |
void sceneRect_growing(); |
|
154 |
void setSceneRect(); |
|
155 |
void viewport(); |
|
156 |
void dragMode_scrollHand(); |
|
157 |
void dragMode_rubberBand(); |
|
158 |
void rubberBandSelectionMode(); |
|
159 |
void backgroundBrush(); |
|
160 |
void foregroundBrush(); |
|
161 |
void matrix(); |
|
162 |
void matrix_convenience(); |
|
163 |
void matrix_combine(); |
|
164 |
void centerOnPoint(); |
|
165 |
void centerOnItem(); |
|
166 |
void ensureVisibleRect(); |
|
167 |
void fitInView(); |
|
168 |
void itemsAtPoint(); |
|
169 |
void itemsInRect(); |
|
170 |
void itemsInRect_cosmeticAdjust_data(); |
|
171 |
void itemsInRect_cosmeticAdjust(); |
|
172 |
void itemsInPoly(); |
|
173 |
void itemsInPath(); |
|
174 |
void itemAt(); |
|
175 |
void itemAt2(); |
|
176 |
void mapToScene(); |
|
177 |
void mapToScenePoint(); |
|
178 |
void mapToSceneRect_data(); |
|
179 |
void mapToSceneRect(); |
|
180 |
void mapToScenePoly(); |
|
181 |
void mapToScenePath(); |
|
182 |
void mapFromScenePoint(); |
|
183 |
void mapFromSceneRect(); |
|
184 |
void mapFromScenePoly(); |
|
185 |
void mapFromScenePath(); |
|
186 |
void sendEvent(); |
|
187 |
void wheelEvent(); |
|
188 |
void cursor(); |
|
189 |
void cursor2(); |
|
190 |
void transformationAnchor(); |
|
191 |
void resizeAnchor(); |
|
192 |
void viewportUpdateMode(); |
|
193 |
void viewportUpdateMode2(); |
|
194 |
void acceptDrops(); |
|
195 |
void optimizationFlags(); |
|
196 |
void optimizationFlags_dontSavePainterState(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
void optimizationFlags_dontSavePainterState2_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
void optimizationFlags_dontSavePainterState2(); |
0 | 199 |
void levelOfDetail_data(); |
200 |
void levelOfDetail(); |
|
201 |
void scrollBarRanges_data(); |
|
202 |
void scrollBarRanges(); |
|
203 |
void acceptMousePressEvent(); |
|
204 |
void replayMouseMove(); |
|
205 |
void itemsUnderMouse(); |
|
206 |
void embeddedViews(); |
|
207 |
void scrollAfterResize_data(); |
|
208 |
void scrollAfterResize(); |
|
209 |
void moveItemWhileScrolling_data(); |
|
210 |
void moveItemWhileScrolling(); |
|
211 |
void centerOnDirtyItem(); |
|
212 |
void mouseTracking(); |
|
213 |
void mouseTracking2(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
void mouseTracking3(); |
0 | 215 |
void render(); |
216 |
void exposeRegion(); |
|
217 |
void update_data(); |
|
218 |
void update(); |
|
219 |
void inputMethodSensitivity(); |
|
220 |
void inputContextReset(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
221 |
void indirectPainting(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
222 |
void compositionModeInDrawBackground(); |
0 | 223 |
|
224 |
// task specific tests below me |
|
225 |
void task172231_untransformableItems(); |
|
226 |
void task180429_mouseReleaseDragMode(); |
|
227 |
void task187791_setSceneCausesUpdate(); |
|
228 |
void task186827_deleteReplayedItem(); |
|
229 |
void task207546_focusCrash(); |
|
230 |
void task210599_unsetDragWhileDragging(); |
|
231 |
void task236394_sendShortcutOverrideEvent(); |
|
232 |
void task239729_noViewUpdate_data(); |
|
233 |
void task239729_noViewUpdate(); |
|
234 |
void task239047_fitInViewSmallViewport(); |
|
235 |
void task245469_itemsAtPointWithClip(); |
|
236 |
void task253415_reconnectUpdateSceneOnSceneChanged(); |
|
237 |
void task255529_transformationAnchorMouseAndViewportMargins(); |
|
238 |
void task259503_scrollingArtifacts(); |
|
239 |
void QTBUG_4151_clipAndIgnore_data(); |
|
240 |
void QTBUG_4151_clipAndIgnore(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
void QTBUG_5859_exposedRect(); |
0 | 242 |
}; |
243 |
||
244 |
void tst_QGraphicsView::initTestCase() |
|
245 |
{ |
|
246 |
#ifdef Q_OS_WINCE_WM |
|
247 |
qApp->setAutoMaximizeThreshold(-1); |
|
248 |
#endif |
|
249 |
} |
|
250 |
||
251 |
void tst_QGraphicsView::construction() |
|
252 |
{ |
|
253 |
QGraphicsView view; |
|
254 |
QCOMPARE(view.renderHints(), QPainter::TextAntialiasing); |
|
255 |
QCOMPARE(view.dragMode(), QGraphicsView::NoDrag); |
|
256 |
QVERIFY(view.isInteractive()); |
|
257 |
QVERIFY(!view.scene()); |
|
258 |
QCOMPARE(view.sceneRect(), QRectF()); |
|
259 |
QVERIFY(view.viewport()); |
|
260 |
QCOMPARE(view.viewport()->metaObject()->className(), "QWidget"); |
|
261 |
QCOMPARE(view.matrix(), QMatrix()); |
|
262 |
QVERIFY(view.items().isEmpty()); |
|
263 |
QVERIFY(view.items(QPoint()).isEmpty()); |
|
264 |
QVERIFY(view.items(QRect()).isEmpty()); |
|
265 |
QVERIFY(view.items(QPolygon()).isEmpty()); |
|
266 |
QVERIFY(view.items(QPainterPath()).isEmpty()); |
|
267 |
QVERIFY(!view.itemAt(QPoint())); |
|
268 |
QCOMPARE(view.mapToScene(QPoint()), QPointF()); |
|
269 |
QCOMPARE(view.mapToScene(QRect()), QPolygonF()); |
|
270 |
QCOMPARE(view.mapToScene(QPolygon()), QPolygonF()); |
|
271 |
QCOMPARE(view.mapFromScene(QPointF()), QPoint()); |
|
272 |
QPolygon poly; |
|
273 |
poly << QPoint() << QPoint() << QPoint() << QPoint(); |
|
274 |
QCOMPARE(view.mapFromScene(QRectF()), poly); |
|
275 |
QCOMPARE(view.mapFromScene(QPolygonF()), QPolygon()); |
|
276 |
QCOMPARE(view.transformationAnchor(), QGraphicsView::AnchorViewCenter); |
|
277 |
QCOMPARE(view.resizeAnchor(), QGraphicsView::NoAnchor); |
|
278 |
view.show(); |
|
279 |
QTest::qWaitForWindowShown(&view); |
|
280 |
} |
|
281 |
||
282 |
class TestItem : public QGraphicsItem |
|
283 |
{ |
|
284 |
public: |
|
285 |
QRectF boundingRect() const |
|
286 |
{ return QRectF(-10, -10, 20, 20); } |
|
287 |
||
288 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
289 |
{ hints = painter->renderHints(); painter->drawRect(boundingRect()); } |
|
290 |
||
291 |
bool sceneEvent(QEvent *event) |
|
292 |
{ |
|
293 |
events << event->type(); |
|
294 |
return QGraphicsItem::sceneEvent(event); |
|
295 |
} |
|
296 |
||
297 |
QList<QEvent::Type> events; |
|
298 |
QPainter::RenderHints hints; |
|
299 |
}; |
|
300 |
||
301 |
void tst_QGraphicsView::renderHints() |
|
302 |
{ |
|
303 |
QGraphicsView view; |
|
304 |
QCOMPARE(view.renderHints(), QPainter::TextAntialiasing); |
|
305 |
view.setRenderHint(QPainter::TextAntialiasing, false); |
|
306 |
QCOMPARE(view.renderHints(), 0); |
|
307 |
view.setRenderHint(QPainter::Antialiasing, false); |
|
308 |
QCOMPARE(view.renderHints(), 0); |
|
309 |
view.setRenderHint(QPainter::TextAntialiasing, true); |
|
310 |
QCOMPARE(view.renderHints(), QPainter::TextAntialiasing); |
|
311 |
view.setRenderHint(QPainter::Antialiasing); |
|
312 |
QCOMPARE(view.renderHints(), QPainter::TextAntialiasing | QPainter::Antialiasing); |
|
313 |
view.setRenderHints(0); |
|
314 |
QCOMPARE(view.renderHints(), 0); |
|
315 |
||
316 |
TestItem *item = new TestItem; |
|
317 |
QGraphicsScene scene; |
|
318 |
scene.addItem(item); |
|
319 |
||
320 |
view.setScene(&scene); |
|
321 |
||
322 |
view.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); |
|
323 |
QCOMPARE(view.renderHints(), QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); |
|
324 |
||
325 |
QCOMPARE(item->hints, 0); |
|
326 |
view.show(); |
|
327 |
QTest::qWaitForWindowShown(&view); |
|
328 |
view.repaint(); |
|
329 |
QTRY_COMPARE(item->hints, view.renderHints()); |
|
330 |
||
331 |
view.setRenderHints(QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); |
|
332 |
QCOMPARE(view.renderHints(), QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); |
|
333 |
||
334 |
view.repaint(); |
|
335 |
QTRY_COMPARE(item->hints, view.renderHints()); |
|
336 |
} |
|
337 |
||
338 |
void tst_QGraphicsView::alignment() |
|
339 |
{ |
|
340 |
QGraphicsScene scene; |
|
341 |
scene.addRect(QRectF(-10, -10, 20, 20)); |
|
342 |
||
343 |
QGraphicsView view(&scene); |
|
344 |
view.show(); |
|
345 |
QTest::qWaitForWindowShown(&view); |
|
346 |
||
347 |
for (int i = 0; i < 3; ++i) { |
|
348 |
for (int j = 0; j < 3; ++j) { |
|
349 |
Qt::Alignment alignment = 0; |
|
350 |
switch (i) { |
|
351 |
case 0: |
|
352 |
alignment |= Qt::AlignLeft; |
|
353 |
break; |
|
354 |
case 1: |
|
355 |
alignment |= Qt::AlignHCenter; |
|
356 |
break; |
|
357 |
case 2: |
|
358 |
default: |
|
359 |
alignment |= Qt::AlignRight; |
|
360 |
break; |
|
361 |
} |
|
362 |
switch (j) { |
|
363 |
case 0: |
|
364 |
alignment |= Qt::AlignTop; |
|
365 |
break; |
|
366 |
case 1: |
|
367 |
alignment |= Qt::AlignVCenter; |
|
368 |
break; |
|
369 |
case 2: |
|
370 |
default: |
|
371 |
alignment |= Qt::AlignBottom; |
|
372 |
break; |
|
373 |
} |
|
374 |
view.setAlignment(alignment); |
|
375 |
QCOMPARE(view.alignment(), alignment); |
|
376 |
||
377 |
for (int k = 0; k < 3; ++k) { |
|
378 |
view.resize(100 + k * 25, 100 + k * 25); |
|
379 |
QApplication::processEvents(); |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
void tst_QGraphicsView::interactive() |
|
386 |
{ |
|
387 |
TestItem *item = new TestItem; |
|
388 |
item->setFlags(QGraphicsItem::ItemIsMovable); |
|
389 |
QCOMPARE(item->events.size(), 0); |
|
390 |
||
391 |
QGraphicsScene scene(-200, -200, 400, 400); |
|
392 |
scene.addItem(item); |
|
393 |
||
394 |
QGraphicsView view(&scene); |
|
395 |
view.setFixedSize(300, 300); |
|
396 |
QCOMPARE(item->events.size(), 0); |
|
397 |
view.show(); |
|
398 |
QTest::qWaitForWindowShown(&view); |
|
399 |
||
400 |
QApplication::processEvents(); |
|
401 |
QTRY_COMPARE(item->events.size(), 1); // activate |
|
402 |
||
403 |
QPoint itemPoint = view.mapFromScene(item->scenePos()); |
|
404 |
||
405 |
QVERIFY(view.itemAt(itemPoint)); |
|
406 |
||
407 |
for (int i = 0; i < 100; ++i) { |
|
408 |
sendMousePress(view.viewport(), itemPoint); |
|
409 |
QCOMPARE(item->events.size(), i * 5 + 3); |
|
410 |
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GrabMouse); |
|
411 |
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::GraphicsSceneMousePress); |
|
412 |
sendMouseRelease(view.viewport(), itemPoint); |
|
413 |
QCOMPARE(item->events.size(), i * 5 + 5); |
|
414 |
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GraphicsSceneMouseRelease); |
|
415 |
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::UngrabMouse); |
|
416 |
QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint)); |
|
417 |
QApplication::sendEvent(view.viewport(), &contextEvent); |
|
418 |
QCOMPARE(item->events.size(), i * 5 + 6); |
|
419 |
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu); |
|
420 |
} |
|
421 |
||
422 |
view.setInteractive(false); |
|
423 |
||
424 |
for (int i = 0; i < 100; ++i) { |
|
425 |
sendMousePress(view.viewport(), itemPoint); |
|
426 |
QCOMPARE(item->events.size(), 501); |
|
427 |
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu); |
|
428 |
sendMouseRelease(view.viewport(), itemPoint); |
|
429 |
QCOMPARE(item->events.size(), 501); |
|
430 |
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu); |
|
431 |
QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint)); |
|
432 |
QApplication::sendEvent(view.viewport(), &contextEvent); |
|
433 |
QCOMPARE(item->events.size(), 501); |
|
434 |
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu); |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
void tst_QGraphicsView::scene() |
|
439 |
{ |
|
440 |
QGraphicsView view; |
|
441 |
QVERIFY(!view.scene()); |
|
442 |
view.setScene(0); |
|
443 |
QVERIFY(!view.scene()); |
|
444 |
||
445 |
{ |
|
446 |
QGraphicsScene scene; |
|
447 |
view.setScene(&scene); |
|
448 |
QCOMPARE(view.scene(), &scene); |
|
449 |
} |
|
450 |
||
451 |
QCOMPARE(view.scene(), (QGraphicsScene *)0); |
|
452 |
} |
|
453 |
||
454 |
void tst_QGraphicsView::setScene() |
|
455 |
{ |
|
456 |
QGraphicsScene scene(-1000, -1000, 2000, 2000); |
|
457 |
||
458 |
QGraphicsView view(&scene); |
|
459 |
view.show(); |
|
460 |
QTest::qWaitForWindowShown(&view); |
|
461 |
||
462 |
QCOMPARE(view.sceneRect(), scene.sceneRect()); |
|
463 |
||
464 |
QVERIFY(view.horizontalScrollBar()->isVisible()); |
|
465 |
QVERIFY(view.verticalScrollBar()->isVisible()); |
|
466 |
QVERIFY(!view.horizontalScrollBar()->isHidden()); |
|
467 |
QVERIFY(!view.verticalScrollBar()->isHidden()); |
|
468 |
||
469 |
view.setScene(0); |
|
470 |
||
471 |
QTest::qWait(25); |
|
472 |
||
473 |
QVERIFY(!view.horizontalScrollBar()->isVisible()); |
|
474 |
QVERIFY(!view.verticalScrollBar()->isVisible()); |
|
475 |
QVERIFY(!view.horizontalScrollBar()->isHidden()); |
|
476 |
QVERIFY(!view.verticalScrollBar()->isHidden()); |
|
477 |
||
478 |
QCOMPARE(view.sceneRect(), QRectF()); |
|
479 |
} |
|
480 |
||
481 |
void tst_QGraphicsView::deleteScene() |
|
482 |
{ |
|
483 |
QGraphicsScene *scene = new QGraphicsScene; |
|
484 |
QGraphicsView view1(scene); |
|
485 |
view1.show(); |
|
486 |
QGraphicsView view2(scene); |
|
487 |
view2.show(); |
|
488 |
QGraphicsView view3(scene); |
|
489 |
view3.show(); |
|
490 |
delete scene; |
|
491 |
QCOMPARE(view1.scene(), (QGraphicsScene *)0); |
|
492 |
QCOMPARE(view2.scene(), (QGraphicsScene *)0); |
|
493 |
QCOMPARE(view3.scene(), (QGraphicsScene *)0); |
|
494 |
} |
|
495 |
||
496 |
void tst_QGraphicsView::sceneRect() |
|
497 |
{ |
|
498 |
QGraphicsView view; |
|
499 |
QCOMPARE(view.sceneRect(), QRectF()); |
|
500 |
||
501 |
view.setSceneRect(QRectF(-100, -100, 200, 200)); |
|
502 |
QCOMPARE(view.sceneRect(), QRectF(-100, -100, 200, 200)); |
|
503 |
view.setSceneRect(-100, -100, 200, 200); |
|
504 |
QCOMPARE(view.sceneRect(), QRectF(-100, -100, 200, 200)); |
|
505 |
||
506 |
view.setSceneRect(QRectF()); |
|
507 |
QCOMPARE(view.sceneRect(), QRectF()); |
|
508 |
QGraphicsScene scene; |
|
509 |
QGraphicsRectItem *item = scene.addRect(QRectF(-100, -100, 100, 100)); |
|
510 |
||
511 |
view.setScene(&scene); |
|
512 |
||
513 |
QCOMPARE(view.sceneRect(), QRectF(-100, -100, 100, 100)); |
|
514 |
item->moveBy(-100, -100); |
|
515 |
QCOMPARE(view.sceneRect(), QRectF(-200, -200, 200, 200)); |
|
516 |
item->moveBy(100, 100); |
|
517 |
QCOMPARE(view.sceneRect(), QRectF(-200, -200, 200, 200)); |
|
518 |
||
519 |
view.setScene(0); |
|
520 |
view.setSceneRect(QRectF()); |
|
521 |
QCOMPARE(view.sceneRect(), QRectF()); |
|
522 |
} |
|
523 |
||
524 |
void tst_QGraphicsView::sceneRect_growing() |
|
525 |
{ |
|
526 |
QGraphicsScene scene; |
|
527 |
for (int i = 0; i < 100; ++i) |
|
528 |
scene.addText(QString("(0, %1)").arg((i - 50) * 20))->setPos(0, (i - 50) * 20); |
|
529 |
||
530 |
QGraphicsView view(&scene); |
|
531 |
view.setFixedSize(200, 200); |
|
532 |
view.show(); |
|
533 |
||
534 |
int size = 200; |
|
535 |
scene.setSceneRect(-size, -size, size * 2, size * 2); |
|
536 |
QCOMPARE(view.sceneRect(), scene.sceneRect()); |
|
537 |
||
538 |
QTest::qWait(25); |
|
539 |
||
540 |
QPointF topLeft = view.mapToScene(0, 0); |
|
541 |
||
542 |
for (int i = 0; i < 5; ++i) { |
|
543 |
size *= 2; |
|
544 |
scene.setSceneRect(-size, -size, size * 2, size * 2); |
|
545 |
||
546 |
QApplication::processEvents(); |
|
547 |
||
548 |
QCOMPARE(view.sceneRect(), scene.sceneRect()); |
|
549 |
QCOMPARE(view.mapToScene(0, 0), topLeft); |
|
550 |
view.setSceneRect(-size, -size, size * 2, size * 2); |
|
551 |
QCOMPARE(view.mapToScene(0, 0), topLeft); |
|
552 |
view.setSceneRect(QRectF()); |
|
553 |
} |
|
554 |
} |
|
555 |
||
556 |
void tst_QGraphicsView::setSceneRect() |
|
557 |
{ |
|
558 |
QRectF rect1(-100, -100, 200, 200); |
|
559 |
QRectF rect2(-300, -300, 150, 150); |
|
560 |
||
561 |
QGraphicsScene scene; |
|
562 |
QGraphicsView view(&scene); |
|
563 |
||
564 |
scene.setSceneRect(rect1); |
|
565 |
QCOMPARE(scene.sceneRect(), rect1); |
|
566 |
QCOMPARE(view.sceneRect(), rect1); |
|
567 |
||
568 |
scene.setSceneRect(rect2); |
|
569 |
QCOMPARE(scene.sceneRect(), rect2); |
|
570 |
QCOMPARE(view.sceneRect(), rect2); |
|
571 |
||
572 |
view.setSceneRect(rect1); |
|
573 |
QCOMPARE(scene.sceneRect(), rect2); |
|
574 |
QCOMPARE(view.sceneRect(), rect1); |
|
575 |
||
576 |
view.setSceneRect(rect2); |
|
577 |
QCOMPARE(scene.sceneRect(), rect2); |
|
578 |
QCOMPARE(view.sceneRect(), rect2); |
|
579 |
||
580 |
scene.setSceneRect(rect1); |
|
581 |
QCOMPARE(scene.sceneRect(), rect1); |
|
582 |
QCOMPARE(view.sceneRect(), rect2); |
|
583 |
||
584 |
// extreme transformations will max out the scrollbars' ranges. |
|
585 |
view.setSceneRect(-2000000, -2000000, 4000000, 4000000); |
|
586 |
view.scale(9000, 9000); |
|
587 |
QCOMPARE(view.horizontalScrollBar()->minimum(), INT_MIN); |
|
588 |
QCOMPARE(view.horizontalScrollBar()->maximum(), INT_MAX); |
|
589 |
QCOMPARE(view.verticalScrollBar()->minimum(), INT_MIN); |
|
590 |
QCOMPARE(view.verticalScrollBar()->maximum(), INT_MAX); |
|
591 |
} |
|
592 |
||
593 |
void tst_QGraphicsView::viewport() |
|
594 |
{ |
|
595 |
QGraphicsScene scene; |
|
596 |
scene.addText("GraphicsView"); |
|
597 |
||
598 |
QGraphicsView view(&scene); |
|
599 |
QVERIFY(view.viewport() != 0); |
|
600 |
||
601 |
view.show(); |
|
602 |
QTest::qWait(25); |
|
603 |
||
604 |
QPointer<QWidget> widget = new QWidget; |
|
605 |
view.setViewport(widget); |
|
606 |
QCOMPARE(view.viewport(), (QWidget *)widget); |
|
607 |
||
608 |
view.show(); |
|
609 |
QTest::qWait(25); |
|
610 |
||
611 |
view.setViewport(0); |
|
612 |
QVERIFY(widget.isNull()); |
|
613 |
QVERIFY(view.viewport() != 0); |
|
614 |
QVERIFY(view.viewport() != widget); |
|
615 |
||
616 |
view.show(); |
|
617 |
QTest::qWait(25); |
|
618 |
} |
|
619 |
||
620 |
void tst_QGraphicsView::dragMode_scrollHand() |
|
621 |
{ |
|
622 |
for (int j = 0; j < 2; ++j) { |
|
623 |
QGraphicsView view; |
|
624 |
QCOMPARE(view.dragMode(), QGraphicsView::NoDrag); |
|
625 |
||
626 |
view.setSceneRect(-1000, -1000, 2000, 2000); |
|
627 |
view.setFixedSize(100, 100); |
|
628 |
view.show(); |
|
629 |
||
630 |
QTest::qWaitForWindowShown(&view); |
|
631 |
QApplication::processEvents(); |
|
632 |
||
633 |
view.setInteractive(j ? false : true); |
|
634 |
||
635 |
QGraphicsScene scene; |
|
636 |
scene.addRect(QRectF(-100, -100, 5, 5)); |
|
637 |
scene.addRect(QRectF(95, -100, 5, 5)); |
|
638 |
scene.addRect(QRectF(95, 95, 5, 5)); |
|
639 |
QGraphicsItem *item = scene.addRect(QRectF(-100, 95, 5, 5)); |
|
640 |
item->setFlag(QGraphicsItem::ItemIsSelectable); |
|
641 |
item->setSelected(true); |
|
642 |
QVERIFY(item->isSelected()); |
|
643 |
QVERIFY(!view.scene()); |
|
644 |
||
645 |
view.setDragMode(QGraphicsView::ScrollHandDrag); |
|
646 |
||
647 |
for (int i = 0; i < 2; ++i) { |
|
648 |
// ScrollHandDrag |
|
649 |
#ifndef QT_NO_CURSOR |
|
650 |
Qt::CursorShape cursorShape = view.viewport()->cursor().shape(); |
|
651 |
#endif |
|
652 |
int horizontalScrollBarValue = view.horizontalScrollBar()->value(); |
|
653 |
int verticalScrollBarValue = view.verticalScrollBar()->value(); |
|
654 |
{ |
|
655 |
// Press |
|
656 |
QMouseEvent event(QEvent::MouseButtonPress, |
|
657 |
view.viewport()->rect().center(), |
|
658 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
659 |
event.setAccepted(true); |
|
660 |
QApplication::sendEvent(view.viewport(), &event); |
|
661 |
QVERIFY(event.isAccepted()); |
|
662 |
} |
|
663 |
QApplication::processEvents(); |
|
664 |
||
665 |
QTRY_VERIFY(item->isSelected()); |
|
666 |
||
667 |
for (int k = 0; k < 4; ++k) { |
|
668 |
#ifndef QT_NO_CURSOR |
|
669 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::ClosedHandCursor); |
|
670 |
#endif |
|
671 |
{ |
|
672 |
// Move |
|
673 |
QMouseEvent event(QEvent::MouseMove, |
|
674 |
view.viewport()->rect().center() + QPoint(10, 0), |
|
675 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
676 |
event.setAccepted(true); |
|
677 |
QApplication::sendEvent(view.viewport(), &event); |
|
678 |
QVERIFY(event.isAccepted()); |
|
679 |
} |
|
680 |
QVERIFY(item->isSelected()); |
|
681 |
QCOMPARE(view.horizontalScrollBar()->value(), horizontalScrollBarValue - 10); |
|
682 |
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue); |
|
683 |
{ |
|
684 |
// Move |
|
685 |
QMouseEvent event(QEvent::MouseMove, |
|
686 |
view.viewport()->rect().center() + QPoint(10, 10), |
|
687 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
688 |
event.setAccepted(true); |
|
689 |
QApplication::sendEvent(view.viewport(), &event); |
|
690 |
QVERIFY(event.isAccepted()); |
|
691 |
} |
|
692 |
QVERIFY(item->isSelected()); |
|
693 |
QCOMPARE(view.horizontalScrollBar()->value(), horizontalScrollBarValue - 10); |
|
694 |
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue - 10); |
|
695 |
} |
|
696 |
||
697 |
{ |
|
698 |
// Release |
|
699 |
QMouseEvent event(QEvent::MouseButtonRelease, |
|
700 |
view.viewport()->rect().center() + QPoint(10, 10), |
|
701 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
702 |
event.setAccepted(true); |
|
703 |
QApplication::sendEvent(view.viewport(), &event); |
|
704 |
QVERIFY(event.isAccepted()); |
|
705 |
} |
|
706 |
QApplication::processEvents(); |
|
707 |
||
708 |
QTRY_VERIFY(item->isSelected()); |
|
709 |
QCOMPARE(view.horizontalScrollBar()->value(), horizontalScrollBarValue - 10); |
|
710 |
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue - 10); |
|
711 |
#ifndef QT_NO_CURSOR |
|
712 |
QCOMPARE(view.viewport()->cursor().shape(), cursorShape); |
|
713 |
#endif |
|
714 |
||
715 |
// Check that items are not unselected because of a scroll hand drag. |
|
716 |
QVERIFY(item->isSelected()); |
|
717 |
||
718 |
// Check that a click will still unselect the item. |
|
719 |
{ |
|
720 |
// Press |
|
721 |
QMouseEvent event(QEvent::MouseButtonPress, |
|
722 |
view.viewport()->rect().center() + QPoint(10, 10), |
|
723 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
724 |
QApplication::sendEvent(view.viewport(), &event); |
|
725 |
} |
|
726 |
{ |
|
727 |
// Release |
|
728 |
QMouseEvent event(QEvent::MouseButtonRelease, |
|
729 |
view.viewport()->rect().center() + QPoint(10, 10), |
|
730 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
731 |
QApplication::sendEvent(view.viewport(), &event); |
|
732 |
} |
|
733 |
||
734 |
if (view.isInteractive()) { |
|
735 |
if (view.scene()) { |
|
736 |
QVERIFY(!item->isSelected()); |
|
737 |
item->setSelected(true); |
|
738 |
} else { |
|
739 |
QVERIFY(item->isSelected()); |
|
740 |
} |
|
741 |
} else { |
|
742 |
QVERIFY(item->isSelected()); |
|
743 |
} |
|
744 |
||
745 |
view.setScene(&scene); |
|
746 |
} |
|
747 |
} |
|
748 |
} |
|
749 |
||
750 |
void tst_QGraphicsView::dragMode_rubberBand() |
|
751 |
{ |
|
752 |
QGraphicsView view; |
|
753 |
QCOMPARE(view.dragMode(), QGraphicsView::NoDrag); |
|
754 |
||
755 |
view.setSceneRect(-1000, -1000, 2000, 2000); |
|
756 |
view.show(); |
|
757 |
||
758 |
QGraphicsScene scene; |
|
759 |
scene.addRect(QRectF(-100, -100, 25, 25))->setFlag(QGraphicsItem::ItemIsSelectable); |
|
760 |
scene.addRect(QRectF(75, -100, 25, 25))->setFlag(QGraphicsItem::ItemIsSelectable); |
|
761 |
scene.addRect(QRectF(75, 75, 25, 25))->setFlag(QGraphicsItem::ItemIsSelectable); |
|
762 |
scene.addRect(QRectF(-100, 75, 25, 25))->setFlag(QGraphicsItem::ItemIsSelectable); |
|
763 |
||
764 |
view.setDragMode(QGraphicsView::RubberBandDrag); |
|
765 |
||
766 |
QTest::qWaitForWindowShown(&view); |
|
767 |
QApplication::processEvents(); |
|
768 |
||
769 |
for (int i = 0; i < 2; ++i) { |
|
770 |
// RubberBandDrag |
|
771 |
#ifndef QT_NO_CURSOR |
|
772 |
Qt::CursorShape cursorShape = view.viewport()->cursor().shape(); |
|
773 |
#endif |
|
774 |
int horizontalScrollBarValue = view.horizontalScrollBar()->value(); |
|
775 |
int verticalScrollBarValue = view.verticalScrollBar()->value(); |
|
776 |
{ |
|
777 |
// Press |
|
778 |
QMouseEvent event(QEvent::MouseButtonPress, |
|
779 |
view.viewport()->rect().center(), |
|
780 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
781 |
event.setAccepted(true); |
|
782 |
QApplication::sendEvent(view.viewport(), &event); |
|
783 |
QVERIFY(event.isAccepted()); |
|
784 |
} |
|
785 |
#ifndef QT_NO_CURSOR |
|
786 |
QCOMPARE(view.viewport()->cursor().shape(), cursorShape); |
|
787 |
#endif |
|
788 |
||
789 |
QApplication::processEvents(); |
|
790 |
||
791 |
{ |
|
792 |
// Move |
|
793 |
QMouseEvent event(QEvent::MouseMove, |
|
794 |
view.viewport()->rect().center() + QPoint(100, 0), |
|
795 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
796 |
event.setAccepted(true); |
|
797 |
QApplication::sendEvent(view.viewport(), &event); |
|
798 |
QVERIFY(event.isAccepted()); |
|
799 |
} |
|
800 |
QCOMPARE(view.horizontalScrollBar()->value(), horizontalScrollBarValue); |
|
801 |
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue); |
|
802 |
||
803 |
// We don't use QRubberBand as of 4.3; the band is drawn internally. |
|
804 |
QVERIFY(!qFindChild<QRubberBand *>(&view)); |
|
805 |
||
806 |
QTest::qWait(25); |
|
807 |
||
808 |
{ |
|
809 |
// Move |
|
810 |
QMouseEvent event(QEvent::MouseMove, |
|
811 |
view.viewport()->rect().center() + QPoint(100, 100), |
|
812 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
813 |
event.setAccepted(true); |
|
814 |
QApplication::sendEvent(view.viewport(), &event); |
|
815 |
QVERIFY(event.isAccepted()); |
|
816 |
} |
|
817 |
QCOMPARE(view.horizontalScrollBar()->value(), horizontalScrollBarValue); |
|
818 |
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue); |
|
819 |
||
820 |
QTest::qWait(25); |
|
821 |
||
822 |
{ |
|
823 |
// Release |
|
824 |
QMouseEvent event(QEvent::MouseButtonRelease, |
|
825 |
view.viewport()->rect().center() + QPoint(100, 100), |
|
826 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
827 |
event.setAccepted(true); |
|
828 |
QApplication::sendEvent(view.viewport(), &event); |
|
829 |
QVERIFY(event.isAccepted()); |
|
830 |
} |
|
831 |
QCOMPARE(view.horizontalScrollBar()->value(), horizontalScrollBarValue); |
|
832 |
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue); |
|
833 |
#ifndef QT_NO_CURSOR |
|
834 |
QCOMPARE(view.viewport()->cursor().shape(), cursorShape); |
|
835 |
#endif |
|
836 |
||
837 |
QTest::qWait(25); |
|
838 |
||
839 |
if (view.scene()) |
|
840 |
QCOMPARE(scene.selectedItems().size(), 1); |
|
841 |
||
842 |
view.setScene(&scene); |
|
843 |
view.centerOn(0, 0); |
|
844 |
} |
|
845 |
} |
|
846 |
||
847 |
void tst_QGraphicsView::rubberBandSelectionMode() |
|
848 |
{ |
|
849 |
QGraphicsScene scene; |
|
850 |
QGraphicsRectItem *rect = scene.addRect(QRectF(10, 10, 80, 80)); |
|
851 |
rect->setFlag(QGraphicsItem::ItemIsSelectable); |
|
852 |
||
853 |
QGraphicsView view(&scene); |
|
854 |
QCOMPARE(view.rubberBandSelectionMode(), Qt::IntersectsItemShape); |
|
855 |
view.setDragMode(QGraphicsView::RubberBandDrag); |
|
856 |
view.resize(120, 120); |
|
857 |
view.show(); |
|
858 |
||
859 |
// Disable mouse tracking to prevent the window system from sending mouse |
|
860 |
// move events to the viewport while we are synthesizing events. If |
|
861 |
// QGraphicsView gets a mouse move event with no buttons down, it'll |
|
862 |
// terminate the rubber band. |
|
863 |
view.viewport()->setMouseTracking(false); |
|
864 |
||
865 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>()); |
|
866 |
sendMousePress(view.viewport(), QPoint(), Qt::LeftButton); |
|
867 |
sendMouseMove(view.viewport(), view.viewport()->rect().center(), |
|
868 |
Qt::LeftButton, Qt::LeftButton); |
|
869 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << rect); |
|
870 |
sendMouseRelease(view.viewport(), QPoint(), Qt::LeftButton); |
|
871 |
||
872 |
view.setRubberBandSelectionMode(Qt::ContainsItemShape); |
|
873 |
QCOMPARE(view.rubberBandSelectionMode(), Qt::ContainsItemShape); |
|
874 |
sendMousePress(view.viewport(), QPoint(), Qt::LeftButton); |
|
875 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>()); |
|
876 |
sendMouseMove(view.viewport(), view.viewport()->rect().center(), |
|
877 |
Qt::LeftButton, Qt::LeftButton); |
|
878 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>()); |
|
879 |
sendMouseMove(view.viewport(), view.viewport()->rect().bottomRight(), |
|
880 |
Qt::LeftButton, Qt::LeftButton); |
|
881 |
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << rect); |
|
882 |
} |
|
883 |
||
884 |
void tst_QGraphicsView::backgroundBrush() |
|
885 |
{ |
|
886 |
QGraphicsScene scene; |
|
887 |
QGraphicsView view(&scene); |
|
888 |
scene.setBackgroundBrush(Qt::blue); |
|
889 |
QCOMPARE(scene.backgroundBrush(), QBrush(Qt::blue)); |
|
890 |
||
891 |
view.show(); |
|
892 |
QTest::qWait(25); |
|
893 |
||
894 |
scene.setBackgroundBrush(QBrush()); |
|
895 |
QCOMPARE(scene.backgroundBrush(), QBrush()); |
|
896 |
QTest::qWait(25); |
|
897 |
||
898 |
QRadialGradient gradient(0, 0, 10); |
|
899 |
gradient.setSpread(QGradient::RepeatSpread); |
|
900 |
scene.setBackgroundBrush(gradient); |
|
901 |
||
902 |
QCOMPARE(scene.backgroundBrush(), QBrush(gradient)); |
|
903 |
QTest::qWait(25); |
|
904 |
} |
|
905 |
||
906 |
void tst_QGraphicsView::foregroundBrush() |
|
907 |
{ |
|
908 |
QGraphicsScene scene; |
|
909 |
QGraphicsView view(&scene); |
|
910 |
scene.setForegroundBrush(Qt::blue); |
|
911 |
QCOMPARE(scene.foregroundBrush(), QBrush(Qt::blue)); |
|
912 |
||
913 |
view.show(); |
|
914 |
QTest::qWait(25); |
|
915 |
||
916 |
scene.setForegroundBrush(QBrush()); |
|
917 |
QCOMPARE(scene.foregroundBrush(), QBrush()); |
|
918 |
QTest::qWait(25); |
|
919 |
||
920 |
QRadialGradient gradient(0, 0, 10); |
|
921 |
gradient.setSpread(QGradient::RepeatSpread); |
|
922 |
scene.setForegroundBrush(gradient); |
|
923 |
||
924 |
QCOMPARE(scene.foregroundBrush(), QBrush(gradient)); |
|
925 |
QTest::qWait(25); |
|
926 |
||
927 |
for (int i = 0; i < 50; ++i) { |
|
928 |
QRadialGradient gradient(view.rect().center() + QPoint(int(sin(i / 2.0) * 10), int(cos(i / 2.0) * 10)), 10); |
|
929 |
gradient.setColorAt(0, Qt::transparent); |
|
930 |
gradient.setColorAt(0.5, Qt::black); |
|
931 |
gradient.setColorAt(1, Qt::transparent); |
|
932 |
gradient.setSpread(QGradient::RepeatSpread); |
|
933 |
scene.setForegroundBrush(gradient); |
|
934 |
||
935 |
QRadialGradient gradient2(view.rect().center() + QPoint(int(sin(i / 1.7) * 10), int(cos(i / 1.7) * 10)), 10); |
|
936 |
gradient2.setColorAt(0, Qt::transparent); |
|
937 |
gradient2.setColorAt(0.5, Qt::black); |
|
938 |
gradient2.setColorAt(1, Qt::transparent); |
|
939 |
gradient2.setSpread(QGradient::RepeatSpread); |
|
940 |
scene.setBackgroundBrush(gradient2); |
|
941 |
||
942 |
QRadialGradient gradient3(view.rect().center() + QPoint(int(sin(i / 1.85) * 10), int(cos(i / 1.85) * 10)), 10); |
|
943 |
gradient3.setColorAt(0, Qt::transparent); |
|
944 |
gradient3.setColorAt(0.5, Qt::black); |
|
945 |
gradient3.setColorAt(1, Qt::transparent); |
|
946 |
gradient3.setSpread(QGradient::RepeatSpread); |
|
947 |
scene.setBackgroundBrush(gradient3); |
|
948 |
||
949 |
QApplication::processEvents(); |
|
950 |
} |
|
951 |
||
952 |
view.setSceneRect(-1000, -1000, 2000, 2000); |
|
953 |
for (int i = -500; i < 500; i += 10) { |
|
954 |
view.centerOn(i, 0); |
|
955 |
QApplication::processEvents(); |
|
956 |
QApplication::processEvents(); |
|
957 |
} |
|
958 |
for (int i = -500; i < 500; i += 10) { |
|
959 |
view.centerOn(0, i); |
|
960 |
QApplication::processEvents(); |
|
961 |
QApplication::processEvents(); |
|
962 |
} |
|
963 |
} |
|
964 |
||
965 |
void tst_QGraphicsView::matrix() |
|
966 |
{ |
|
967 |
{ |
|
968 |
QGraphicsScene scene; |
|
969 |
QGraphicsView view(&scene); |
|
970 |
view.show(); |
|
971 |
||
972 |
// Show rendering of background with no scene |
|
973 |
for (int i = 0; i < 50; ++i) { |
|
974 |
view.rotate(5); |
|
975 |
QRadialGradient gradient(view.rect().center() + QPoint(int(sin(i / 2.0) * 10), int(cos(i / 2.0) * 10)), 10); |
|
976 |
gradient.setColorAt(0, Qt::transparent); |
|
977 |
gradient.setColorAt(0.5, Qt::black); |
|
978 |
gradient.setColorAt(1, Qt::transparent); |
|
979 |
gradient.setSpread(QGradient::RepeatSpread); |
|
980 |
scene.setForegroundBrush(gradient); |
|
981 |
QRadialGradient gradient2(view.rect().center() + QPoint(int(sin(i / 1.7) * 10), int(cos(i / 1.7) * 10)), 10); |
|
982 |
gradient2.setColorAt(0, Qt::transparent); |
|
983 |
gradient2.setColorAt(0.5, Qt::black); |
|
984 |
gradient2.setColorAt(1, Qt::transparent); |
|
985 |
gradient2.setSpread(QGradient::RepeatSpread); |
|
986 |
scene.setBackgroundBrush(gradient2); |
|
987 |
QApplication::processEvents(); |
|
988 |
QApplication::processEvents(); |
|
989 |
} |
|
990 |
} |
|
991 |
||
992 |
// Test transformation extremes, see if they cause crashes |
|
993 |
{ |
|
994 |
QGraphicsScene scene; |
|
995 |
scene.addText("GraphicsView rotated clockwise"); |
|
996 |
||
997 |
QGraphicsView view(&scene); |
|
998 |
view.show(); |
|
999 |
for (int i = 0; i < 160; ++i) { |
|
1000 |
view.rotate(18); |
|
1001 |
QApplication::processEvents(); |
|
1002 |
QApplication::processEvents(); |
|
1003 |
} |
|
1004 |
/* |
|
1005 |
// These cause a crash |
|
1006 |
for (int i = 0; i < 40; ++i) { |
|
1007 |
view.shear(1.2, 1.2); |
|
1008 |
QTest::qWait(20); |
|
1009 |
} |
|
1010 |
for (int i = 0; i < 40; ++i) { |
|
1011 |
view.shear(-1.2, -1.2); |
|
1012 |
QTest::qWait(20); |
|
1013 |
} |
|
1014 |
*/ |
|
1015 |
for (int i = 0; i < 20; ++i) { |
|
1016 |
view.scale(1.2, 1.2); |
|
1017 |
QApplication::processEvents(); |
|
1018 |
QApplication::processEvents(); |
|
1019 |
} |
|
1020 |
for (int i = 0; i < 20; ++i) { |
|
1021 |
view.scale(0.6, 0.6); |
|
1022 |
QApplication::processEvents(); |
|
1023 |
QApplication::processEvents(); |
|
1024 |
} |
|
1025 |
} |
|
1026 |
} |
|
1027 |
||
1028 |
void tst_QGraphicsView::matrix_convenience() |
|
1029 |
{ |
|
1030 |
QGraphicsView view; |
|
1031 |
QCOMPARE(view.matrix(), QMatrix()); |
|
1032 |
||
1033 |
// Check the convenience functions |
|
1034 |
view.rotate(90); |
|
1035 |
QCOMPARE(view.matrix(), QMatrix().rotate(90)); |
|
1036 |
view.scale(2, 2); |
|
1037 |
QCOMPARE(view.matrix(), QMatrix().scale(2, 2) * QMatrix().rotate(90)); |
|
1038 |
view.shear(1.2, 1.2); |
|
1039 |
QCOMPARE(view.matrix(), QMatrix().shear(1.2, 1.2) * QMatrix().scale(2, 2) * QMatrix().rotate(90)); |
|
1040 |
view.translate(1, 1); |
|
1041 |
QCOMPARE(view.matrix(), QMatrix().translate(1, 1) * QMatrix().shear(1.2, 1.2) * QMatrix().scale(2, 2) * QMatrix().rotate(90)); |
|
1042 |
} |
|
1043 |
||
1044 |
void tst_QGraphicsView::matrix_combine() |
|
1045 |
{ |
|
1046 |
// Check matrix combining |
|
1047 |
QGraphicsView view; |
|
1048 |
QCOMPARE(view.matrix(), QMatrix()); |
|
1049 |
view.setMatrix(QMatrix().rotate(90), true); |
|
1050 |
view.setMatrix(QMatrix().rotate(90), true); |
|
1051 |
view.setMatrix(QMatrix().rotate(90), true); |
|
1052 |
view.setMatrix(QMatrix().rotate(90), true); |
|
1053 |
QCOMPARE(view.matrix(), QMatrix()); |
|
1054 |
||
1055 |
view.resetMatrix(); |
|
1056 |
QCOMPARE(view.matrix(), QMatrix()); |
|
1057 |
view.setMatrix(QMatrix().rotate(90), false); |
|
1058 |
view.setMatrix(QMatrix().rotate(90), false); |
|
1059 |
view.setMatrix(QMatrix().rotate(90), false); |
|
1060 |
view.setMatrix(QMatrix().rotate(90), false); |
|
1061 |
QCOMPARE(view.matrix(), QMatrix().rotate(90)); |
|
1062 |
} |
|
1063 |
||
1064 |
void tst_QGraphicsView::centerOnPoint() |
|
1065 |
{ |
|
1066 |
QGraphicsScene scene; |
|
1067 |
scene.addEllipse(QRectF(-100, -100, 50, 50)); |
|
1068 |
scene.addEllipse(QRectF(50, -100, 50, 50)); |
|
1069 |
scene.addEllipse(QRectF(-100, 50, 50, 50)); |
|
1070 |
scene.addEllipse(QRectF(50, 50, 50, 50)); |
|
1071 |
||
1072 |
QGraphicsView view(&scene); |
|
1073 |
view.setSceneRect(-400, -400, 800, 800); |
|
1074 |
view.setFixedSize(100, 100); |
|
1075 |
view.show(); |
|
1076 |
||
1077 |
int tolerance = 5; |
|
1078 |
||
1079 |
for (int i = 0; i < 3; ++i) { |
|
1080 |
for (int y = -100; y < 100; y += 23) { |
|
1081 |
for (int x = -100; x < 100; x += 23) { |
|
1082 |
view.centerOn(x, y); |
|
1083 |
QPoint viewCenter = view.mapToScene(view.viewport()->rect().center()).toPoint(); |
|
1084 |
||
1085 |
// Fuzzy compare |
|
1086 |
if (viewCenter.x() < x - tolerance || viewCenter.x() > x + tolerance |
|
1087 |
|| viewCenter.y() < y - tolerance || viewCenter.y() > y + tolerance) { |
|
1088 |
QString error = QString("Compared values are not the same\n\tActual: (%1, %2)\n\tExpected: (%3, %4)") |
|
1089 |
.arg(viewCenter.x()).arg(viewCenter.y()).arg(x).arg(y); |
|
1090 |
QFAIL(qPrintable(error)); |
|
1091 |
} |
|
1092 |
||
1093 |
QApplication::processEvents(); |
|
1094 |
} |
|
1095 |
} |
|
1096 |
||
1097 |
view.rotate(13); |
|
1098 |
view.scale(1.5, 1.5); |
|
1099 |
view.shear(1.25, 1.25); |
|
1100 |
} |
|
1101 |
} |
|
1102 |
||
1103 |
void tst_QGraphicsView::centerOnItem() |
|
1104 |
{ |
|
1105 |
QGraphicsScene scene; |
|
1106 |
QGraphicsItem *items[4]; |
|
1107 |
items[0] = scene.addEllipse(QRectF(-25, -25, 50, 50)); |
|
1108 |
items[1] = scene.addEllipse(QRectF(-25, -25, 50, 50)); |
|
1109 |
items[2] = scene.addEllipse(QRectF(-25, -25, 50, 50)); |
|
1110 |
items[3] = scene.addEllipse(QRectF(-25, -25, 50, 50)); |
|
1111 |
items[0]->setPos(-100, -100); |
|
1112 |
items[1]->setPos(100, -100); |
|
1113 |
items[2]->setPos(-100, 100); |
|
1114 |
items[3]->setPos(100, 100); |
|
1115 |
||
1116 |
QGraphicsView view(&scene); |
|
1117 |
view.setSceneRect(-1000, -1000, 2000, 2000); |
|
1118 |
view.show(); |
|
1119 |
QTest::qWaitForWindowShown(&view); |
|
1120 |
int tolerance = 7; |
|
1121 |
||
1122 |
for (int x = 0; x < 3; ++x) { |
|
1123 |
for (int i = 0; i < 4; ++i) { |
|
1124 |
QApplication::processEvents(); |
|
1125 |
view.centerOn(items[i]); |
|
1126 |
||
1127 |
QPoint viewCenter = view.mapToScene(view.viewport()->rect().center()).toPoint(); |
|
1128 |
qreal x = items[i]->pos().x(); |
|
1129 |
qreal y = items[i]->pos().y(); |
|
1130 |
||
1131 |
// Fuzzy compare |
|
1132 |
if (viewCenter.x() < x - tolerance || viewCenter.x() > x + tolerance |
|
1133 |
|| viewCenter.y() < y - tolerance || viewCenter.y() > y + tolerance) { |
|
1134 |
QString error = QString("Compared values are not the same\n\tActual: (%1, %2)\n\tExpected: (%3, %4)") |
|
1135 |
.arg(viewCenter.x()).arg(viewCenter.y()).arg(x).arg(y); |
|
1136 |
QFAIL(qPrintable(error)); |
|
1137 |
} |
|
1138 |
||
1139 |
QApplication::processEvents(); |
|
1140 |
} |
|
1141 |
||
1142 |
view.rotate(13); |
|
1143 |
view.scale(1.5, 1.5); |
|
1144 |
view.shear(1.25, 1.25); |
|
1145 |
} |
|
1146 |
} |
|
1147 |
||
1148 |
void tst_QGraphicsView::ensureVisibleRect() |
|
1149 |
{ |
|
1150 |
QGraphicsScene scene; |
|
1151 |
QGraphicsItem *items[4]; |
|
1152 |
items[0] = scene.addEllipse(QRectF(-25, -25, 50, 50), QPen(Qt::black), QBrush(Qt::green)); |
|
1153 |
items[1] = scene.addEllipse(QRectF(-25, -25, 50, 50), QPen(Qt::black), QBrush(Qt::red)); |
|
1154 |
items[2] = scene.addEllipse(QRectF(-25, -25, 50, 50), QPen(Qt::black), QBrush(Qt::blue)); |
|
1155 |
items[3] = scene.addEllipse(QRectF(-25, -25, 50, 50), QPen(Qt::black), QBrush(Qt::yellow)); |
|
1156 |
scene.addLine(QLineF(0, -100, 0, 100), QPen(Qt::blue, 2)); |
|
1157 |
scene.addLine(QLineF(-100, 0, 100, 0), QPen(Qt::blue, 2)); |
|
1158 |
items[0]->setPos(-100, -100); |
|
1159 |
items[1]->setPos(100, -100); |
|
1160 |
items[2]->setPos(-100, 100); |
|
1161 |
items[3]->setPos(100, 100); |
|
1162 |
||
1163 |
QGraphicsItem *icon = scene.addEllipse(QRectF(-10, -10, 20, 20), QPen(Qt::black), QBrush(Qt::gray)); |
|
1164 |
||
1165 |
QGraphicsView view(&scene); |
|
1166 |
view.setSceneRect(-500, -500, 1000, 1000); |
|
1167 |
view.setFixedSize(250, 250); |
|
1168 |
view.show(); |
|
1169 |
QTest::qWaitForWindowShown(&view); |
|
1170 |
||
1171 |
for (int y = -100; y < 100; y += 25) { |
|
1172 |
for (int x = -100; x < 100; x += 13) { |
|
1173 |
||
1174 |
icon->setPos(x, y); |
|
1175 |
||
1176 |
switch (x & 3) { |
|
1177 |
case 0: |
|
1178 |
view.centerOn(-500, -500); |
|
1179 |
break; |
|
1180 |
case 1: |
|
1181 |
view.centerOn(500, -500); |
|
1182 |
break; |
|
1183 |
case 2: |
|
1184 |
view.centerOn(-500, 500); |
|
1185 |
break; |
|
1186 |
case 3: |
|
1187 |
default: |
|
1188 |
view.centerOn(500, 500); |
|
1189 |
break; |
|
1190 |
} |
|
1191 |
||
1192 |
QVERIFY(!view.viewport()->rect().contains(view.mapFromScene(x, y))); |
|
1193 |
||
1194 |
for (int margin = 10; margin < 60; margin += 15) { |
|
1195 |
view.ensureVisible(x, y, 0, 0, margin, margin); |
|
1196 |
||
1197 |
QRect viewRect = view.viewport()->rect(); |
|
1198 |
QPoint viewPoint = view.mapFromScene(x, y); |
|
1199 |
||
1200 |
QVERIFY(viewRect.contains(viewPoint)); |
|
1201 |
QVERIFY(qAbs(viewPoint.x() - viewRect.left()) >= margin -1); |
|
1202 |
QVERIFY(qAbs(viewPoint.x() - viewRect.right()) >= margin -1); |
|
1203 |
QVERIFY(qAbs(viewPoint.y() - viewRect.top()) >= margin -1); |
|
1204 |
QVERIFY(qAbs(viewPoint.y() - viewRect.bottom()) >= margin -1); |
|
1205 |
||
1206 |
QApplication::processEvents(); |
|
1207 |
} |
|
1208 |
} |
|
1209 |
view.rotate(5); |
|
1210 |
view.scale(1.05, 1.05); |
|
1211 |
view.translate(30, -30); |
|
1212 |
} |
|
1213 |
} |
|
1214 |
||
1215 |
void tst_QGraphicsView::fitInView() |
|
1216 |
{ |
|
1217 |
QGraphicsScene scene; |
|
1218 |
QGraphicsItem *items[4]; |
|
1219 |
items[0] = scene.addEllipse(QRectF(-25, -25, 100, 20), QPen(Qt::black), QBrush(Qt::green)); |
|
1220 |
items[1] = scene.addEllipse(QRectF(-25, -25, 20, 100), QPen(Qt::black), QBrush(Qt::red)); |
|
1221 |
items[2] = scene.addEllipse(QRectF(-25, -25, 50, 50), QPen(Qt::black), QBrush(Qt::blue)); |
|
1222 |
items[3] = scene.addEllipse(QRectF(-25, -25, 50, 50), QPen(Qt::black), QBrush(Qt::yellow)); |
|
1223 |
scene.addLine(QLineF(0, -100, 0, 100), QPen(Qt::blue, 2)); |
|
1224 |
scene.addLine(QLineF(-100, 0, 100, 0), QPen(Qt::blue, 2)); |
|
1225 |
items[0]->setPos(-100, -100); |
|
1226 |
items[1]->setPos(100, -100); |
|
1227 |
items[2]->setPos(-100, 100); |
|
1228 |
items[3]->setPos(100, 100); |
|
1229 |
||
1230 |
items[0]->rotate(30); |
|
1231 |
items[1]->rotate(-30); |
|
1232 |
||
1233 |
#if defined(Q_OS_WINCE) |
|
1234 |
//Is the standard scrollbar size |
|
1235 |
int scrollbarSize = qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent) - 13; |
|
1236 |
#endif |
|
1237 |
||
1238 |
QGraphicsView view(&scene); |
|
1239 |
view.setSceneRect(-400, -400, 800, 800); |
|
1240 |
||
1241 |
#if defined(Q_OS_WINCE) |
|
1242 |
//We need to take in account the scrollbar size for the WindowsMobilStyle |
|
1243 |
view.setFixedSize(400 + scrollbarSize, 200 + scrollbarSize); |
|
1244 |
#else |
|
1245 |
view.setFixedSize(400, 200); |
|
1246 |
#endif |
|
1247 |
||
1248 |
view.show(); |
|
1249 |
view.fitInView(scene.itemsBoundingRect(), Qt::IgnoreAspectRatio); |
|
1250 |
qApp->processEvents(); |
|
1251 |
||
1252 |
// Sampled coordinates. |
|
1253 |
QVERIFY(!view.itemAt(45, 41)); |
|
1254 |
QVERIFY(!view.itemAt(297, 44)); |
|
1255 |
QVERIFY(!view.itemAt(359, 143)); |
|
1256 |
QCOMPARE(view.itemAt(79, 22), items[0]); |
|
1257 |
QCOMPARE(view.itemAt(329, 41), items[1]); |
|
1258 |
QCOMPARE(view.itemAt(38, 158), items[2]); |
|
1259 |
QCOMPARE(view.itemAt(332, 160), items[3]); |
|
1260 |
||
1261 |
view.fitInView(items[0], Qt::IgnoreAspectRatio); |
|
1262 |
qApp->processEvents(); |
|
1263 |
||
1264 |
QCOMPARE(view.itemAt(19, 13), items[0]); |
|
1265 |
QCOMPARE(view.itemAt(91, 47), items[0]); |
|
1266 |
QCOMPARE(view.itemAt(202, 94), items[0]); |
|
1267 |
QCOMPARE(view.itemAt(344, 161), items[0]); |
|
1268 |
QVERIFY(!view.itemAt(236, 54)); |
|
1269 |
QVERIFY(!view.itemAt(144, 11)); |
|
1270 |
QVERIFY(!view.itemAt(29, 69)); |
|
1271 |
QVERIFY(!view.itemAt(251, 167)); |
|
1272 |
||
1273 |
view.fitInView(items[0], Qt::KeepAspectRatio); |
|
1274 |
qApp->processEvents(); |
|
1275 |
||
1276 |
QCOMPARE(view.itemAt(325, 170), items[0]); |
|
1277 |
QCOMPARE(view.itemAt(206, 74), items[0]); |
|
1278 |
QCOMPARE(view.itemAt(190, 115), items[0]); |
|
1279 |
QCOMPARE(view.itemAt(55, 14), items[0]); |
|
1280 |
QVERIFY(!view.itemAt(109, 4)); |
|
1281 |
QVERIFY(!view.itemAt(244, 68)); |
|
1282 |
QVERIFY(!view.itemAt(310, 125)); |
|
1283 |
QVERIFY(!view.itemAt(261, 168)); |
|
1284 |
||
1285 |
view.fitInView(items[0], Qt::KeepAspectRatioByExpanding); |
|
1286 |
qApp->processEvents(); |
|
1287 |
||
1288 |
QCOMPARE(view.itemAt(18, 10), items[0]); |
|
1289 |
QCOMPARE(view.itemAt(95, 4), items[0]); |
|
1290 |
QCOMPARE(view.itemAt(279, 175), items[0]); |
|
1291 |
QCOMPARE(view.itemAt(359, 170), items[0]); |
|
1292 |
QVERIFY(!view.itemAt(370, 166)); |
|
1293 |
QVERIFY(!view.itemAt(136, 7)); |
|
1294 |
QVERIFY(!view.itemAt(31, 44)); |
|
1295 |
QVERIFY(!view.itemAt(203, 153)); |
|
1296 |
} |
|
1297 |
||
1298 |
void tst_QGraphicsView::itemsAtPoint() |
|
1299 |
{ |
|
1300 |
QGraphicsScene scene; |
|
1301 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(1); |
|
1302 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(0); |
|
1303 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(2); |
|
1304 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(-1); |
|
1305 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(3); |
|
1306 |
||
1307 |
QGraphicsView view; |
|
1308 |
QVERIFY(view.items(0, 0).isEmpty()); |
|
1309 |
||
1310 |
view.setScene(&scene); |
|
1311 |
view.setSceneRect(-10000, -10000, 20000, 20000); |
|
1312 |
view.show(); |
|
1313 |
||
1314 |
QList<QGraphicsItem *> items = view.items(view.viewport()->rect().center()); |
|
1315 |
QCOMPARE(items.size(), 5); |
|
1316 |
QCOMPARE(items.takeFirst()->zValue(), qreal(3)); |
|
1317 |
QCOMPARE(items.takeFirst()->zValue(), qreal(2)); |
|
1318 |
QCOMPARE(items.takeFirst()->zValue(), qreal(1)); |
|
1319 |
QCOMPARE(items.takeFirst()->zValue(), qreal(0)); |
|
1320 |
QCOMPARE(items.takeFirst()->zValue(), qreal(-1)); |
|
1321 |
} |
|
1322 |
||
1323 |
void tst_QGraphicsView::itemsInRect() |
|
1324 |
{ |
|
1325 |
QGraphicsScene scene; |
|
1326 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(1); |
|
1327 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(0); |
|
1328 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(2); |
|
1329 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(-1); |
|
1330 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(3); |
|
1331 |
||
1332 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(5); |
|
1333 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(4); |
|
1334 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(6); |
|
1335 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(3); |
|
1336 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(7); |
|
1337 |
||
1338 |
QGraphicsView view; |
|
1339 |
QVERIFY(view.items(QRect(-100, -100, 200, 200)).isEmpty()); |
|
1340 |
view.setScene(&scene); |
|
1341 |
view.setSceneRect(-10000, -10000, 20000, 20000); |
|
1342 |
view.show(); |
|
1343 |
||
1344 |
QPoint centerPoint = view.viewport()->rect().center(); |
|
1345 |
QRect leftRect = view.mapFromScene(-30, -10, 20, 20).boundingRect(); |
|
1346 |
QRect rightRect = view.mapFromScene(30, -10, 20, 20).boundingRect(); |
|
1347 |
||
1348 |
QList<QGraphicsItem *> items = view.items(leftRect); |
|
1349 |
QCOMPARE(items.size(), 5); |
|
1350 |
QCOMPARE(items.takeFirst()->zValue(), qreal(3)); |
|
1351 |
QCOMPARE(items.takeFirst()->zValue(), qreal(2)); |
|
1352 |
QCOMPARE(items.takeFirst()->zValue(), qreal(1)); |
|
1353 |
QCOMPARE(items.takeFirst()->zValue(), qreal(0)); |
|
1354 |
QCOMPARE(items.takeFirst()->zValue(), qreal(-1)); |
|
1355 |
||
1356 |
items = view.items(rightRect); |
|
1357 |
QCOMPARE(items.size(), 5); |
|
1358 |
QCOMPARE(items.takeFirst()->zValue(), qreal(7)); |
|
1359 |
QCOMPARE(items.takeFirst()->zValue(), qreal(6)); |
|
1360 |
QCOMPARE(items.takeFirst()->zValue(), qreal(5)); |
|
1361 |
QCOMPARE(items.takeFirst()->zValue(), qreal(4)); |
|
1362 |
QCOMPARE(items.takeFirst()->zValue(), qreal(3)); |
|
1363 |
} |
|
1364 |
||
1365 |
class CountPaintItem : public QGraphicsRectItem |
|
1366 |
{ |
|
1367 |
public: |
|
1368 |
int numPaints; |
|
1369 |
||
1370 |
CountPaintItem(const QRectF &rect) |
|
1371 |
: QGraphicsRectItem(rect), numPaints(0) |
|
1372 |
{ } |
|
1373 |
||
1374 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) |
|
1375 |
{ |
|
1376 |
++numPaints; |
|
1377 |
QGraphicsRectItem::paint(painter, option, widget); |
|
1378 |
} |
|
1379 |
}; |
|
1380 |
||
1381 |
void tst_QGraphicsView::itemsInRect_cosmeticAdjust_data() |
|
1382 |
{ |
|
1383 |
QTest::addColumn<QRect>("updateRect"); |
|
1384 |
QTest::addColumn<int>("numPaints"); |
|
1385 |
||
1386 |
QTest::newRow("nil") << QRect() << 1; |
|
1387 |
QTest::newRow("0, 0, 300, 100") << QRect(0, 0, 300, 100) << 1; |
|
1388 |
QTest::newRow("0, 0, 100, 300") << QRect(0, 0, 100, 300) << 1; |
|
1389 |
QTest::newRow("200, 0, 100, 300") << QRect(200, 0, 100, 300) << 1; |
|
1390 |
QTest::newRow("0, 200, 300, 100") << QRect(0, 200, 300, 100) << 1; |
|
1391 |
QTest::newRow("0, 0, 300, 99") << QRect(0, 0, 300, 99) << 0; |
|
1392 |
QTest::newRow("0, 0, 99, 300") << QRect(0, 0, 99, 300) << 0; |
|
1393 |
QTest::newRow("201, 0, 99, 300") << QRect(201, 0, 99, 300) << 0; |
|
1394 |
QTest::newRow("0, 201, 300, 99") << QRect(0, 201, 300, 99) << 0; |
|
1395 |
} |
|
1396 |
||
1397 |
void tst_QGraphicsView::itemsInRect_cosmeticAdjust() |
|
1398 |
{ |
|
1399 |
QFETCH(QRect, updateRect); |
|
1400 |
QFETCH(int, numPaints); |
|
1401 |
||
1402 |
QGraphicsScene scene(-100, -100, 200, 200); |
|
1403 |
CountPaintItem *rect = new CountPaintItem(QRectF(-50, -50, 100, 100)); |
|
1404 |
scene.addItem(rect); |
|
1405 |
||
1406 |
QGraphicsView view(&scene); |
|
1407 |
view.setFrameStyle(0); |
|
1408 |
view.resize(300, 300); |
|
1409 |
view.show(); |
|
1410 |
QTest::qWaitForWindowShown(&view) ; |
|
1411 |
QTRY_VERIFY(rect->numPaints > 0); |
|
1412 |
||
1413 |
rect->numPaints = 0; |
|
1414 |
if (updateRect.isNull()) |
|
1415 |
view.viewport()->update(); |
|
1416 |
else |
|
1417 |
view.viewport()->update(updateRect); |
|
1418 |
qApp->processEvents(); |
|
1419 |
QTRY_COMPARE(rect->numPaints, numPaints); |
|
1420 |
} |
|
1421 |
||
1422 |
void tst_QGraphicsView::itemsInPoly() |
|
1423 |
{ |
|
1424 |
QGraphicsScene scene; |
|
1425 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(1); |
|
1426 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(0); |
|
1427 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(2); |
|
1428 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(-1); |
|
1429 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(3); |
|
1430 |
||
1431 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(5); |
|
1432 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(4); |
|
1433 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(6); |
|
1434 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(3); |
|
1435 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(7); |
|
1436 |
||
1437 |
QGraphicsView view; |
|
1438 |
QVERIFY(view.items(QPolygon()).isEmpty()); |
|
1439 |
view.setScene(&scene); |
|
1440 |
view.setSceneRect(-10000, -10000, 20000, 20000); |
|
1441 |
view.show(); |
|
1442 |
||
1443 |
QPoint centerPoint = view.viewport()->rect().center(); |
|
1444 |
QPolygon leftPoly = view.mapFromScene(QRectF(-30, -10, 20, 20)); |
|
1445 |
QPolygon rightPoly = view.mapFromScene(QRectF(30, -10, 20, 20)); |
|
1446 |
||
1447 |
QList<QGraphicsItem *> items = view.items(leftPoly); |
|
1448 |
QCOMPARE(items.size(), 5); |
|
1449 |
QCOMPARE(items.takeFirst()->zValue(), qreal(3)); |
|
1450 |
QCOMPARE(items.takeFirst()->zValue(), qreal(2)); |
|
1451 |
QCOMPARE(items.takeFirst()->zValue(), qreal(1)); |
|
1452 |
QCOMPARE(items.takeFirst()->zValue(), qreal(0)); |
|
1453 |
QCOMPARE(items.takeFirst()->zValue(), qreal(-1)); |
|
1454 |
||
1455 |
items = view.items(rightPoly); |
|
1456 |
QCOMPARE(items.size(), 5); |
|
1457 |
QCOMPARE(items.takeFirst()->zValue(), qreal(7)); |
|
1458 |
QCOMPARE(items.takeFirst()->zValue(), qreal(6)); |
|
1459 |
QCOMPARE(items.takeFirst()->zValue(), qreal(5)); |
|
1460 |
QCOMPARE(items.takeFirst()->zValue(), qreal(4)); |
|
1461 |
QCOMPARE(items.takeFirst()->zValue(), qreal(3)); |
|
1462 |
} |
|
1463 |
||
1464 |
void tst_QGraphicsView::itemsInPath() |
|
1465 |
{ |
|
1466 |
QGraphicsScene scene; |
|
1467 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(1); |
|
1468 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(0); |
|
1469 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(2); |
|
1470 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(-1); |
|
1471 |
scene.addRect(QRectF(-30, -10, 20, 20))->setZValue(3); |
|
1472 |
||
1473 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(5); |
|
1474 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(4); |
|
1475 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(6); |
|
1476 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(3); |
|
1477 |
scene.addRect(QRectF(30, -10, 20, 20))->setZValue(7); |
|
1478 |
||
1479 |
QGraphicsView view; |
|
1480 |
QVERIFY(view.items(QPainterPath()).isEmpty()); |
|
1481 |
view.setScene(&scene); |
|
1482 |
view.translate(100, 400); |
|
1483 |
view.rotate(22.3); |
|
1484 |
view.setSceneRect(-10000, -10000, 20000, 20000); |
|
1485 |
view.show(); |
|
1486 |
||
1487 |
QPoint centerPoint = view.viewport()->rect().center(); |
|
1488 |
QPainterPath leftPath; |
|
1489 |
leftPath.addEllipse(QRect(view.mapFromScene(-30, -10), QSize(20, 20))); |
|
1490 |
||
1491 |
QPainterPath rightPath; |
|
1492 |
rightPath.addEllipse(QRect(view.mapFromScene(30, -10), QSize(20, 20))); |
|
1493 |
||
1494 |
QList<QGraphicsItem *> items = view.items(leftPath); |
|
1495 |
||
1496 |
QCOMPARE(items.size(), 5); |
|
1497 |
QCOMPARE(items.takeFirst()->zValue(), qreal(3)); |
|
1498 |
QCOMPARE(items.takeFirst()->zValue(), qreal(2)); |
|
1499 |
QCOMPARE(items.takeFirst()->zValue(), qreal(1)); |
|
1500 |
QCOMPARE(items.takeFirst()->zValue(), qreal(0)); |
|
1501 |
QCOMPARE(items.takeFirst()->zValue(), qreal(-1)); |
|
1502 |
||
1503 |
items = view.items(rightPath); |
|
1504 |
QCOMPARE(items.size(), 5); |
|
1505 |
QCOMPARE(items.takeFirst()->zValue(), qreal(7)); |
|
1506 |
QCOMPARE(items.takeFirst()->zValue(), qreal(6)); |
|
1507 |
QCOMPARE(items.takeFirst()->zValue(), qreal(5)); |
|
1508 |
QCOMPARE(items.takeFirst()->zValue(), qreal(4)); |
|
1509 |
QCOMPARE(items.takeFirst()->zValue(), qreal(3)); |
|
1510 |
} |
|
1511 |
||
1512 |
void tst_QGraphicsView::itemAt() |
|
1513 |
{ |
|
1514 |
QGraphicsScene scene; |
|
1515 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(1); |
|
1516 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(0); |
|
1517 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(2); |
|
1518 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(-1); |
|
1519 |
scene.addRect(QRectF(-10, -10, 20, 20))->setZValue(3); |
|
1520 |
||
1521 |
QGraphicsView view; |
|
1522 |
QCOMPARE(view.itemAt(0, 0), (QGraphicsItem *)0); |
|
1523 |
||
1524 |
view.setScene(&scene); |
|
1525 |
view.setSceneRect(-10000, -10000, 20000, 20000); |
|
1526 |
view.show(); |
|
1527 |
||
1528 |
QCOMPARE(view.itemAt(0, 0), (QGraphicsItem *)0); |
|
1529 |
QGraphicsItem* item = view.itemAt(view.viewport()->rect().center()); |
|
1530 |
QVERIFY(item); |
|
1531 |
QCOMPARE(item->zValue(), qreal(3)); |
|
1532 |
} |
|
1533 |
||
1534 |
void tst_QGraphicsView::itemAt2() |
|
1535 |
{ |
|
1536 |
// test precision of the itemAt() function with items that are smaller |
|
1537 |
// than 1 pixel. |
|
1538 |
QGraphicsScene scene(0, 0, 100, 100); |
|
1539 |
||
1540 |
// Add a 0.5x0.5 item at position 0 on the scene, top-left corner at -0.25, -0.25. |
|
1541 |
QGraphicsItem *item = scene.addRect(QRectF(-0.25, -0.25, 0.5, 0.5), QPen(Qt::black, 0.1)); |
|
1542 |
||
1543 |
QGraphicsView view(&scene); |
|
1544 |
view.setFixedSize(200, 200); |
|
1545 |
view.setTransformationAnchor(QGraphicsView::NoAnchor); |
|
1546 |
view.setRenderHint(QPainter::Antialiasing); |
|
1547 |
view.show(); |
|
1548 |
QTest::qWaitForWindowShown(&view); |
|
1549 |
QApplication::processEvents(); |
|
1550 |
||
1551 |
QPoint itemViewPoint = view.mapFromScene(item->scenePos()); |
|
1552 |
||
1553 |
for (int i = 0; i < 3; ++i) { |
|
1554 |
QVERIFY(view.itemAt(itemViewPoint)); |
|
1555 |
QVERIFY(!view.items(itemViewPoint).isEmpty()); |
|
1556 |
QVERIFY(view.itemAt(itemViewPoint + QPoint(-1, 0))); |
|
1557 |
QVERIFY(!view.items(itemViewPoint + QPoint(-1, 0)).isEmpty()); |
|
1558 |
QVERIFY(view.itemAt(itemViewPoint + QPoint(-1, -1))); |
|
1559 |
QVERIFY(!view.items(itemViewPoint + QPoint(-1, -1)).isEmpty()); |
|
1560 |
QVERIFY(view.itemAt(itemViewPoint + QPoint(0, -1))); |
|
1561 |
QVERIFY(!view.items(itemViewPoint + QPoint(0, -1)).isEmpty()); |
|
1562 |
item->moveBy(0.1, 0); |
|
1563 |
} |
|
1564 |
||
1565 |
// Here |
|
1566 |
QVERIFY(view.itemAt(itemViewPoint)); |
|
1567 |
QVERIFY(!view.items(itemViewPoint).isEmpty()); |
|
1568 |
QVERIFY(view.itemAt(itemViewPoint + QPoint(0, -1))); |
|
1569 |
QVERIFY(!view.items(itemViewPoint + QPoint(0, -1)).isEmpty()); |
|
1570 |
||
1571 |
if (sizeof(qreal) != sizeof(double)) { |
|
1572 |
QSKIP("Skipped due to rounding errors", SkipAll); |
|
1573 |
} |
|
1574 |
// Not here |
|
1575 |
QVERIFY(!view.itemAt(itemViewPoint + QPoint(-1, 0))); |
|
1576 |
QVERIFY(view.items(itemViewPoint + QPoint(-1, 0)).isEmpty()); |
|
1577 |
QVERIFY(!view.itemAt(itemViewPoint + QPoint(-1, -1))); |
|
1578 |
QVERIFY(view.items(itemViewPoint + QPoint(-1, -1)).isEmpty()); |
|
1579 |
} |
|
1580 |
||
1581 |
void tst_QGraphicsView::mapToScene() |
|
1582 |
{ |
|
1583 |
// Uncomment the commented-out code to see what's going on. It doesn't |
|
1584 |
// affect the test; it just slows it down. |
|
1585 |
||
1586 |
QGraphicsScene scene; |
|
1587 |
scene.addPixmap(QPixmap("3D-Qt-1-2.png")); |
|
1588 |
||
1589 |
QGraphicsView view; |
|
1590 |
view.setScene(&scene); |
|
1591 |
view.setSceneRect(-500, -500, 1000, 1000); |
|
1592 |
#if defined(Q_OS_WINCE) |
|
1593 |
QSize viewSize(200,200); |
|
1594 |
#else |
|
1595 |
QSize viewSize(300,300); |
|
1596 |
#endif |
|
1597 |
||
1598 |
view.setFixedSize(viewSize); |
|
1599 |
view.show(); |
|
1600 |
QApplication::processEvents(); |
|
1601 |
QVERIFY(view.isVisible()); |
|
1602 |
QCOMPARE(view.size(), viewSize); |
|
1603 |
||
1604 |
// First once without setting the scene rect |
|
1605 |
#ifdef QT_ARCH_ARM |
|
1606 |
const int step = 20; |
|
1607 |
#else |
|
1608 |
const int step = 1; |
|
1609 |
#endif |
|
1610 |
||
1611 |
for (int x = 0; x < view.width(); x += step) { |
|
1612 |
for (int y = 0; y < view.height(); y += step) { |
|
1613 |
QCOMPARE(view.mapToScene(QPoint(x, y)), |
|
1614 |
QPointF(view.horizontalScrollBar()->value() + x, |
|
1615 |
view.verticalScrollBar()->value() + y)); |
|
1616 |
} |
|
1617 |
} |
|
1618 |
||
1619 |
for (int sceneRectHeight = 250; sceneRectHeight < 1000; sceneRectHeight += 250) { |
|
1620 |
for (int sceneRectWidth = 250; sceneRectWidth < 1000; sceneRectWidth += 250) { |
|
1621 |
view.setSceneRect(QRectF(-int(sceneRectWidth / 2), -int(sceneRectHeight / 2), |
|
1622 |
sceneRectWidth, sceneRectHeight)); |
|
1623 |
QApplication::processEvents(); |
|
1624 |
||
1625 |
int hmin = view.horizontalScrollBar()->minimum(); |
|
1626 |
int hmax = view.horizontalScrollBar()->maximum(); |
|
1627 |
int hstep = (hmax - hmin) / 3; |
|
1628 |
int vmin = view.verticalScrollBar()->minimum(); |
|
1629 |
int vmax = view.verticalScrollBar()->maximum(); |
|
1630 |
int vstep = (vmax - vmin) / 3; |
|
1631 |
||
1632 |
for (int hscrollValue = hmin; hscrollValue < hmax; hscrollValue += hstep) { |
|
1633 |
for (int vscrollValue = vmin; vscrollValue < vmax; vscrollValue += vstep) { |
|
1634 |
||
1635 |
view.horizontalScrollBar()->setValue(hscrollValue); |
|
1636 |
view.verticalScrollBar()->setValue(vscrollValue); |
|
1637 |
QApplication::processEvents(); |
|
1638 |
||
1639 |
int h = view.horizontalScrollBar()->value(); |
|
1640 |
int v = view.verticalScrollBar()->value(); |
|
1641 |
||
1642 |
for (int x = 0; x < view.width(); x += step) { |
|
1643 |
for (int y = 0; y < view.height(); y += step) { |
|
1644 |
QCOMPARE(view.mapToScene(QPoint(x, y)), QPointF(h + x, v + y)); |
|
1645 |
QCOMPARE(view.mapFromScene(QPointF(h + x, v + y)), QPoint(x, y)); |
|
1646 |
} |
|
1647 |
} |
|
1648 |
} |
|
1649 |
} |
|
1650 |
} |
|
1651 |
} |
|
1652 |
} |
|
1653 |
||
1654 |
void tst_QGraphicsView::mapToScenePoint() |
|
1655 |
{ |
|
1656 |
QGraphicsScene scene; |
|
1657 |
QGraphicsView view(&scene); |
|
1658 |
view.rotate(90); |
|
1659 |
view.setFixedSize(117, 117); |
|
1660 |
view.show(); |
|
1661 |
QPoint center = view.viewport()->rect().center(); |
|
1662 |
QCOMPARE(view.mapToScene(center + QPoint(10, 0)), |
|
1663 |
view.mapToScene(center) + QPointF(0, -10)); |
|
1664 |
} |
|
1665 |
||
1666 |
void tst_QGraphicsView::mapToSceneRect_data() |
|
1667 |
{ |
|
1668 |
QTest::addColumn<QRect>("viewRect"); |
|
1669 |
QTest::addColumn<QPolygonF>("scenePoly"); |
|
1670 |
QTest::addColumn<qreal>("rotation"); |
|
1671 |
||
1672 |
QTest::newRow("nil") << QRect() << QPolygonF() << qreal(0); |
|
1673 |
QTest::newRow("0, 0, 1, 1") << QRect(0, 0, 1, 1) << QPolygonF(QRectF(0, 0, 1, 1)) << qreal(0); |
|
1674 |
QTest::newRow("0, 0, 10, 10") << QRect(0, 0, 10, 10) << QPolygonF(QRectF(0, 0, 10, 10)) << qreal(0); |
|
1675 |
QTest::newRow("nil") << QRect() << QPolygonF() << qreal(90); |
|
1676 |
QPolygonF p; |
|
1677 |
p << QPointF(0, 0) << QPointF(0, -1) << QPointF(1, -1) << QPointF(1, 0) << QPointF(0, 0); |
|
1678 |
QTest::newRow("0, 0, 1, 1") << QRect(0, 0, 1, 1) |
|
1679 |
<< p |
|
1680 |
<< qreal(90); |
|
1681 |
p.clear(); |
|
1682 |
p << QPointF(0, 0) << QPointF(0, -10) << QPointF(10, -10) << QPointF(10, 0) << QPointF(0, 0); |
|
1683 |
QTest::newRow("0, 0, 10, 10") << QRect(0, 0, 10, 10) |
|
1684 |
<< p |
|
1685 |
<< qreal(90); |
|
1686 |
} |
|
1687 |
||
1688 |
void tst_QGraphicsView::mapToSceneRect() |
|
1689 |
{ |
|
1690 |
QFETCH(QRect, viewRect); |
|
1691 |
QFETCH(QPolygonF, scenePoly); |
|
1692 |
QFETCH(qreal, rotation); |
|
1693 |
||
1694 |
QGraphicsScene scene(-1000, -1000, 2000, 2000); |
|
1695 |
scene.addRect(25, -25, 50, 50); |
|
1696 |
QGraphicsView view(&scene); |
|
1697 |
view.setFrameStyle(0); |
|
1698 |
view.setAlignment(Qt::AlignTop | Qt::AlignLeft); |
|
1699 |
view.setFixedSize(200, 200); |
|
1700 |
view.setTransformationAnchor(QGraphicsView::NoAnchor); |
|
1701 |
view.setResizeAnchor(QGraphicsView::NoAnchor); |
|
1702 |
view.show(); |
|
1703 |
||
1704 |
view.rotate(rotation); |
|
1705 |
||
1706 |
QPolygonF poly = view.mapToScene(viewRect); |
|
1707 |
if (!poly.isEmpty()) |
|
1708 |
poly << poly[0]; |
|
1709 |
||
1710 |
QCOMPARE(poly, scenePoly); |
|
1711 |
} |
|
1712 |
||
1713 |
void tst_QGraphicsView::mapToScenePoly() |
|
1714 |
{ |
|
1715 |
QGraphicsScene scene; |
|
1716 |
QGraphicsView view(&scene); |
|
1717 |
view.translate(100, 100); |
|
1718 |
view.setFixedSize(117, 117); |
|
1719 |
view.show(); |
|
1720 |
QPoint center = view.viewport()->rect().center(); |
|
1721 |
QRect rect(center + QPoint(10, 0), QSize(10, 10)); |
|
1722 |
||
1723 |
QPolygon poly; |
|
1724 |
poly << rect.topLeft(); |
|
1725 |
poly << rect.topRight(); |
|
1726 |
poly << rect.bottomRight(); |
|
1727 |
poly << rect.bottomLeft(); |
|
1728 |
||
1729 |
QPolygonF poly2; |
|
1730 |
poly2 << view.mapToScene(rect.topLeft()); |
|
1731 |
poly2 << view.mapToScene(rect.topRight()); |
|
1732 |
poly2 << view.mapToScene(rect.bottomRight()); |
|
1733 |
poly2 << view.mapToScene(rect.bottomLeft()); |
|
1734 |
||
1735 |
QCOMPARE(view.mapToScene(poly), poly2); |
|
1736 |
} |
|
1737 |
||
1738 |
void tst_QGraphicsView::mapToScenePath() |
|
1739 |
{ |
|
1740 |
QGraphicsScene scene; |
|
1741 |
QGraphicsView view(&scene); |
|
1742 |
view.setSceneRect(-300, -300, 600, 600); |
|
1743 |
view.translate(10, 10); |
|
1744 |
view.setFixedSize(300, 300); |
|
1745 |
view.show(); |
|
1746 |
QPoint center = view.viewport()->rect().center(); |
|
1747 |
QRect rect(QPoint(10, 0), QSize(10, 10)); |
|
1748 |
||
1749 |
QPainterPath path; |
|
1750 |
path.addRect(rect); |
|
1751 |
||
1752 |
QPainterPath path2; |
|
1753 |
path2.addRect(rect.translated(view.horizontalScrollBar()->value() - 10, |
|
1754 |
view.verticalScrollBar()->value() - 10)); |
|
1755 |
QCOMPARE(view.mapToScene(path), path2); |
|
1756 |
} |
|
1757 |
||
1758 |
void tst_QGraphicsView::mapFromScenePoint() |
|
1759 |
{ |
|
1760 |
{ |
|
1761 |
QGraphicsScene scene; |
|
1762 |
QGraphicsView view(&scene); |
|
1763 |
view.rotate(90); |
|
1764 |
view.scale(10, 10); |
|
1765 |
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1766 |
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1767 |
view.show(); |
|
1768 |
||
1769 |
QPoint mapped = view.mapFromScene(0, 0); |
|
1770 |
QPoint center = view.viewport()->rect().center(); |
|
1771 |
if (qAbs(mapped.x() - center.x()) >= 2 |
|
1772 |
|| qAbs(mapped.y() - center.y()) >= 2) { |
|
1773 |
QString error = QString("Compared values are not the same\n\tActual: (%1, %2)\n\tExpected: (%3, %4)") |
|
1774 |
.arg(mapped.x()).arg(mapped.y()).arg(center.x()).arg(center.y()); |
|
1775 |
QFAIL(qPrintable(error)); |
|
1776 |
} |
|
1777 |
} |
|
1778 |
{ |
|
1779 |
QGraphicsScene scene(0, 0, 200, 200); |
|
1780 |
scene.addRect(QRectF(0, 0, 200, 200), QPen(Qt::black, 1)); |
|
1781 |
QGraphicsView view(&scene); |
|
1782 |
view.resize(view.sizeHint()); |
|
1783 |
view.show(); |
|
1784 |
||
1785 |
QCOMPARE(view.mapFromScene(0, 0), QPoint(0, 0)); |
|
1786 |
QCOMPARE(view.mapFromScene(0.4, 0.4), QPoint(0, 0)); |
|
1787 |
QCOMPARE(view.mapFromScene(0.5, 0.5), QPoint(1, 1)); |
|
1788 |
QCOMPARE(view.mapFromScene(0.9, 0.9), QPoint(1, 1)); |
|
1789 |
QCOMPARE(view.mapFromScene(1.0, 1.0), QPoint(1, 1)); |
|
1790 |
QCOMPARE(view.mapFromScene(100, 100), QPoint(100, 100)); |
|
1791 |
QCOMPARE(view.mapFromScene(100.5, 100.5), QPoint(101, 101)); |
|
1792 |
QCOMPARE(view.mapToScene(0, 0), QPointF(0, 0)); |
|
1793 |
QCOMPARE(view.mapToScene(1, 1), QPointF(1, 1)); |
|
1794 |
QCOMPARE(view.mapToScene(100, 100), QPointF(100, 100)); |
|
1795 |
} |
|
1796 |
} |
|
1797 |
||
1798 |
void tst_QGraphicsView::mapFromSceneRect() |
|
1799 |
{ |
|
1800 |
QGraphicsScene scene; |
|
1801 |
QGraphicsView view(&scene); |
|
1802 |
view.rotate(90); |
|
1803 |
view.setFixedSize(200, 200); |
|
1804 |
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1805 |
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1806 |
view.show(); |
|
1807 |
QTest::qWait(25); |
|
1808 |
||
1809 |
QPolygon polygon; |
|
1810 |
polygon << QPoint(98, 98); |
|
1811 |
polygon << QPoint(98, 108); |
|
1812 |
polygon << QPoint(88, 108); |
|
1813 |
polygon << QPoint(88, 98); |
|
1814 |
||
1815 |
||
1816 |
QPolygon viewPolygon = view.mapFromScene(0, 0, 10, 10); |
|
1817 |
for (int i = 0; i < 4; ++i) { |
|
1818 |
QVERIFY(qAbs(viewPolygon[i].x() - polygon[i].x()) < 3); |
|
1819 |
QVERIFY(qAbs(viewPolygon[i].y() - polygon[i].y()) < 3); |
|
1820 |
} |
|
1821 |
||
1822 |
QPoint pt = view.mapFromScene(QPointF()); |
|
1823 |
QPolygon p; |
|
1824 |
p << pt << pt << pt << pt; |
|
1825 |
QCOMPARE(view.mapFromScene(QRectF()), p); |
|
1826 |
} |
|
1827 |
||
1828 |
void tst_QGraphicsView::mapFromScenePoly() |
|
1829 |
{ |
|
1830 |
QGraphicsScene scene; |
|
1831 |
QGraphicsView view(&scene); |
|
1832 |
view.rotate(90); |
|
1833 |
view.setFixedSize(200, 200); |
|
1834 |
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1835 |
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1836 |
view.show(); |
|
1837 |
||
1838 |
QPolygonF polygon; |
|
1839 |
polygon << QPoint(0, 0); |
|
1840 |
polygon << QPoint(10, 0); |
|
1841 |
polygon << QPoint(10, 10); |
|
1842 |
polygon << QPoint(0, 10); |
|
1843 |
||
1844 |
QPolygon polygon2; |
|
1845 |
polygon2 << QPoint(98, 98); |
|
1846 |
polygon2 << QPoint(98, 108); |
|
1847 |
polygon2 << QPoint(88, 108); |
|
1848 |
polygon2 << QPoint(88, 98); |
|
1849 |
||
1850 |
QPolygon viewPolygon = view.mapFromScene(polygon); |
|
1851 |
for (int i = 0; i < 4; ++i) { |
|
1852 |
QVERIFY(qAbs(viewPolygon[i].x() - polygon2[i].x()) < 3); |
|
1853 |
QVERIFY(qAbs(viewPolygon[i].y() - polygon2[i].y()) < 3); |
|
1854 |
} |
|
1855 |
} |
|
1856 |
||
1857 |
void tst_QGraphicsView::mapFromScenePath() |
|
1858 |
{ |
|
1859 |
QGraphicsScene scene; |
|
1860 |
QGraphicsView view(&scene); |
|
1861 |
view.rotate(90); |
|
1862 |
view.setFixedSize(200, 200); |
|
1863 |
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1864 |
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
1865 |
view.show(); |
|
1866 |
||
1867 |
QPolygonF polygon; |
|
1868 |
polygon << QPoint(0, 0); |
|
1869 |
polygon << QPoint(10, 0); |
|
1870 |
polygon << QPoint(10, 10); |
|
1871 |
polygon << QPoint(0, 10); |
|
1872 |
QPainterPath path; |
|
1873 |
path.addPolygon(polygon); |
|
1874 |
||
1875 |
QPolygon polygon2; |
|
1876 |
polygon2 << QPoint(98, 98); |
|
1877 |
polygon2 << QPoint(98, 108); |
|
1878 |
polygon2 << QPoint(88, 108); |
|
1879 |
polygon2 << QPoint(88, 98); |
|
1880 |
QPainterPath path2; |
|
1881 |
path2.addPolygon(polygon2); |
|
1882 |
||
1883 |
QPolygonF pathPoly = view.mapFromScene(path).toFillPolygon(); |
|
1884 |
QPolygonF path2Poly = path2.toFillPolygon(); |
|
1885 |
||
1886 |
for (int i = 0; i < pathPoly.size(); ++i) { |
|
1887 |
QVERIFY(qAbs(pathPoly[i].x() - path2Poly[i].x()) < 3); |
|
1888 |
QVERIFY(qAbs(pathPoly[i].y() - path2Poly[i].y()) < 3); |
|
1889 |
} |
|
1890 |
} |
|
1891 |
||
1892 |
void tst_QGraphicsView::sendEvent() |
|
1893 |
{ |
|
1894 |
QGraphicsScene scene; |
|
1895 |
||
1896 |
TestItem *item = new TestItem; |
|
1897 |
scene.addItem(item); |
|
1898 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
1899 |
item->setFlag(QGraphicsItem::ItemIsMovable); |
|
1900 |
||
1901 |
QGraphicsView view(&scene); |
|
1902 |
view.show(); |
|
1903 |
QTest::qWaitForWindowShown(&view); |
|
1904 |
QApplication::setActiveWindow(&view); |
|
1905 |
QTest::qWait(20); |
|
1906 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
1907 |
||
1908 |
item->setFocus(); |
|
1909 |
||
1910 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *)item); |
|
1911 |
QCOMPARE(item->events.size(), 2); |
|
1912 |
QCOMPARE(item->events.last(), QEvent::FocusIn); |
|
1913 |
||
1914 |
QPoint itemPoint = view.mapFromScene(item->scenePos()); |
|
1915 |
sendMousePress(view.viewport(), itemPoint); |
|
1916 |
QCOMPARE(item->events.size(), 4); |
|
1917 |
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GrabMouse); |
|
1918 |
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::GraphicsSceneMousePress); |
|
1919 |
||
1920 |
QMouseEvent mouseMoveEvent(QEvent::MouseMove, itemPoint, view.viewport()->mapToGlobal(itemPoint), |
|
1921 |
Qt::LeftButton, Qt::LeftButton, 0); |
|
1922 |
QApplication::sendEvent(view.viewport(), &mouseMoveEvent); |
|
1923 |
QCOMPARE(item->events.size(), 5); |
|
1924 |
QCOMPARE(item->events.last(), QEvent::GraphicsSceneMouseMove); |
|
1925 |
||
1926 |
QMouseEvent mouseReleaseEvent(QEvent::MouseButtonRelease, itemPoint, |
|
1927 |
view.viewport()->mapToGlobal(itemPoint), |
|
1928 |
Qt::LeftButton, 0, 0); |
|
1929 |
QApplication::sendEvent(view.viewport(), &mouseReleaseEvent); |
|
1930 |
QCOMPARE(item->events.size(), 7); |
|
1931 |
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GraphicsSceneMouseRelease); |
|
1932 |
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::UngrabMouse); |
|
1933 |
||
1934 |
QKeyEvent keyPress(QEvent::KeyPress, Qt::Key_Space, 0); |
|
1935 |
QApplication::sendEvent(view.viewport(), &keyPress); |
|
1936 |
QCOMPARE(item->events.size(), 9); |
|
1937 |
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::ShortcutOverride); |
|
1938 |
QCOMPARE(item->events.last(), QEvent::KeyPress); |
|
1939 |
} |
|
1940 |
||
1941 |
class MouseWheelScene : public QGraphicsScene |
|
1942 |
{ |
|
1943 |
public: |
|
1944 |
Qt::Orientation orientation; |
|
1945 |
||
1946 |
void wheelEvent(QGraphicsSceneWheelEvent *event) |
|
1947 |
{ |
|
1948 |
orientation = event->orientation(); |
|
1949 |
QGraphicsScene::wheelEvent(event); |
|
1950 |
} |
|
1951 |
}; |
|
1952 |
||
1953 |
void tst_QGraphicsView::wheelEvent() |
|
1954 |
{ |
|
1955 |
// Create a scene with an invalid orientation. |
|
1956 |
MouseWheelScene scene; |
|
1957 |
scene.orientation = Qt::Orientation(-1); |
|
1958 |
||
1959 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
1960 |
widget->setGeometry(0, 0, 400, 400); |
|
1961 |
widget->setFocusPolicy(Qt::WheelFocus); |
|
1962 |
||
1963 |
EventSpy spy(widget, QEvent::GraphicsSceneWheel); |
|
1964 |
QCOMPARE(spy.count(), 0); |
|
1965 |
||
1966 |
scene.addItem(widget); |
|
1967 |
||
1968 |
// Assign a view. |
|
1969 |
QGraphicsView view(&scene); |
|
1970 |
view.show(); |
|
1971 |
QTest::qWaitForWindowShown(&view); |
|
1972 |
QApplication::setActiveWindow(&view); |
|
1973 |
QTest::qWait(20); |
|
1974 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
1975 |
||
1976 |
||
1977 |
// Send a wheel event with horizontal orientation. |
|
1978 |
{ |
|
1979 |
QWheelEvent event(view.mapFromScene(widget->boundingRect().center()), |
|
1980 |
view.mapToGlobal(view.mapFromScene(widget->boundingRect().center())), |
|
1981 |
120, 0, 0, Qt::Horizontal); |
|
1982 |
QApplication::sendEvent(view.viewport(), &event); |
|
1983 |
QCOMPARE(scene.orientation, Qt::Horizontal); |
|
1984 |
} |
|
1985 |
||
1986 |
// Send a wheel event with vertical orientation. |
|
1987 |
{ |
|
1988 |
QWheelEvent event(view.mapFromScene(widget->boundingRect().center()), |
|
1989 |
view.mapToGlobal(view.mapFromScene(widget->boundingRect().center())), |
|
1990 |
120, 0, 0, Qt::Vertical); |
|
1991 |
QApplication::sendEvent(view.viewport(), &event); |
|
1992 |
QCOMPARE(scene.orientation, Qt::Vertical); |
|
1993 |
} |
|
1994 |
||
1995 |
QCOMPARE(spy.count(), 2); |
|
1996 |
QVERIFY(widget->hasFocus()); |
|
1997 |
} |
|
1998 |
||
1999 |
void tst_QGraphicsView::cursor() |
|
2000 |
{ |
|
2001 |
#ifndef QT_NO_CURSOR |
|
2002 |
#if defined(Q_OS_WINCE) |
|
2003 |
QSKIP("Qt/CE does not have regular cursor support", SkipAll); |
|
2004 |
#endif |
|
2005 |
QGraphicsScene scene; |
|
2006 |
QGraphicsItem *item = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
2007 |
item->setCursor(Qt::IBeamCursor); |
|
2008 |
||
2009 |
QGraphicsView view(&scene); |
|
2010 |
view.setFixedSize(400, 400); |
|
2011 |
view.show(); |
|
2012 |
QTest::qWaitForWindowShown(&view); |
|
2013 |
||
2014 |
QCOMPARE(view.viewport()->cursor().shape(), QCursor().shape()); |
|
2015 |
view.viewport()->setCursor(Qt::PointingHandCursor); |
|
2016 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2017 |
||
2018 |
sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); |
|
2019 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
|
2020 |
||
2021 |
sendMouseMove(view.viewport(), QPoint(5, 5)); |
|
2022 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2023 |
#endif |
|
2024 |
} |
|
2025 |
||
2026 |
void tst_QGraphicsView::cursor2() |
|
2027 |
{ |
|
2028 |
#ifndef QT_NO_CURSOR |
|
2029 |
#if defined(Q_OS_WINCE) |
|
2030 |
QSKIP("Qt/CE does not have regular cursor support", SkipAll); |
|
2031 |
#endif |
|
2032 |
QGraphicsScene scene; |
|
2033 |
QGraphicsItem *item = scene.addRect(QRectF(-10, -10, 20, 20)); |
|
2034 |
item->setCursor(Qt::IBeamCursor); |
|
2035 |
item->setZValue(1); |
|
2036 |
||
2037 |
QGraphicsItem *item2 = scene.addRect(QRectF(-20, -20, 40, 40)); |
|
2038 |
item2->setZValue(0); |
|
2039 |
||
2040 |
QGraphicsView view(&scene); |
|
2041 |
view.viewport()->setCursor(Qt::PointingHandCursor); |
|
2042 |
view.setFixedSize(400, 400); |
|
2043 |
view.show(); |
|
2044 |
QTest::qWaitForWindowShown(&view); |
|
2045 |
||
2046 |
sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); |
|
2047 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2048 |
sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); |
|
2049 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
|
2050 |
sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); |
|
2051 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2052 |
sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); |
|
2053 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
|
2054 |
sendMouseMove(view.viewport(), view.mapFromScene(-15, 0)); |
|
2055 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2056 |
||
2057 |
view.setDragMode(QGraphicsView::ScrollHandDrag); |
|
2058 |
||
2059 |
sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); |
|
2060 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); |
|
2061 |
sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); |
|
2062 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
|
2063 |
sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); |
|
2064 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); |
|
2065 |
||
2066 |
view.setDragMode(QGraphicsView::NoDrag); |
|
2067 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); |
|
2068 |
view.viewport()->setCursor(Qt::PointingHandCursor); |
|
2069 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2070 |
||
2071 |
item2->setCursor(Qt::SizeAllCursor); |
|
2072 |
||
2073 |
sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); |
|
2074 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2075 |
sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); |
|
2076 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); |
|
2077 |
sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); |
|
2078 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
|
2079 |
sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); |
|
2080 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); |
|
2081 |
sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); |
|
2082 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
|
2083 |
sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); |
|
2084 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); |
|
2085 |
||
2086 |
view.setDragMode(QGraphicsView::ScrollHandDrag); |
|
2087 |
||
2088 |
sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); |
|
2089 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); |
|
2090 |
sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); |
|
2091 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
|
2092 |
sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); |
|
2093 |
QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); |
|
2094 |
#endif |
|
2095 |
} |
|
2096 |
||
2097 |
void tst_QGraphicsView::transformationAnchor() |
|
2098 |
{ |
|
2099 |
QGraphicsScene scene(-1000, -1000, 2000, 2000); |
|
2100 |
scene.addRect(QRectF(-50, -50, 100, 100), QPen(Qt::black), QBrush(Qt::blue)); |
|
2101 |
||
2102 |
QGraphicsView view(&scene); |
|
2103 |
||
2104 |
for (int i = 0; i < 2; ++i) { |
|
2105 |
view.resize(100, 100); |
|
2106 |
view.show(); |
|
2107 |
||
2108 |
if (i == 0) { |
|
2109 |
QCOMPARE(view.transformationAnchor(), QGraphicsView::AnchorViewCenter); |
|
2110 |
} else { |
|
2111 |
view.setTransformationAnchor(QGraphicsView::NoAnchor); |
|
2112 |
} |
|
2113 |
view.centerOn(0, 0); |
|
2114 |
view.horizontalScrollBar()->setValue(100); |
|
2115 |
QApplication::processEvents(); |
|
2116 |
||
2117 |
QPointF center = view.mapToScene(view.viewport()->rect().center()); |
|
2118 |
||
2119 |
view.scale(10, 10); |
|
2120 |
||
2121 |
QPointF newCenter = view.mapToScene(view.viewport()->rect().center()); |
|
2122 |
||
2123 |
if (i == 0) { |
|
2124 |
qreal slack = 3; |
|
2125 |
QVERIFY(qAbs(newCenter.x() - center.x()) < slack); |
|
2126 |
QVERIFY(qAbs(newCenter.y() - center.y()) < slack); |
|
2127 |
} else { |
|
2128 |
qreal slack = qreal(0.3); |
|
2129 |
QVERIFY(qAbs(newCenter.x() - center.x() / 10) < slack); |
|
2130 |
QVERIFY(qAbs(newCenter.y() - center.y() / 10) < slack); |
|
2131 |
} |
|
2132 |
} |
|
2133 |
} |
|
2134 |
||
2135 |
void tst_QGraphicsView::resizeAnchor() |
|
2136 |
{ |
|
2137 |
QGraphicsScene scene(-1000, -1000, 2000, 2000); |
|
2138 |
scene.addRect(QRectF(-50, -50, 100, 100), QPen(Qt::black), QBrush(Qt::blue)); |
|
2139 |
||
2140 |
QGraphicsView view(&scene); |
|
2141 |
||
2142 |
for (int i = 0; i < 2; ++i) { |
|
2143 |
view.resize(100, 100); |
|
2144 |
view.show(); |
|
2145 |
QTest::qWaitForWindowShown(&view); |
|
2146 |
QApplication::processEvents(); |
|
2147 |
||
2148 |
if (i == 0) { |
|
2149 |
QCOMPARE(view.resizeAnchor(), QGraphicsView::NoAnchor); |
|
2150 |
} else { |
|
2151 |
view.setResizeAnchor(QGraphicsView::AnchorViewCenter); |
|
2152 |
} |
|
2153 |
view.centerOn(0, 0); |
|
2154 |
QTest::qWait(25); |
|
2155 |
||
2156 |
QPointF f = view.mapToScene(50, 50); |
|
2157 |
QPointF center = view.mapToScene(view.viewport()->rect().center()); |
|
2158 |
||
2159 |
QApplication::processEvents(); |
|
2160 |
||
2161 |
for (int size = 200; size <= 400; size += 25) { |
|
2162 |
view.resize(size, size); |
|
2163 |
if (i == 0) { |
|
2164 |
QTRY_COMPARE(view.mapToScene(50, 50), f); |
|
2165 |
QTRY_VERIFY(view.mapToScene(view.viewport()->rect().center()) != center); |
|
2166 |
} else { |
|
2167 |
QTRY_VERIFY(view.mapToScene(50, 50) != f); |
|
2168 |
||
2169 |
QPointF newCenter = view.mapToScene(view.viewport()->rect().center()); |
|
2170 |
int slack = 3; |
|
2171 |
QVERIFY(qAbs(newCenter.x() - center.x()) < slack); |
|
2172 |
QVERIFY(qAbs(newCenter.y() - center.y()) < slack); |
|
2173 |
} |
|
2174 |
QApplication::processEvents(); |
|
2175 |
} |
|
2176 |
} |
|
2177 |
} |
|
2178 |
||
2179 |
class CustomView : public QGraphicsView |
|
2180 |
{ |
|
2181 |
Q_OBJECT |
|
2182 |
public: |
|
2183 |
CustomView(QGraphicsScene *s = 0) : QGraphicsView(s) {} |
|
2184 |
QList<QRegion> lastUpdateRegions; |
|
2185 |
bool painted; |
|
2186 |
||
2187 |
protected: |
|
2188 |
void paintEvent(QPaintEvent *event) |
|
2189 |
{ |
|
2190 |
lastUpdateRegions << event->region(); |
|
2191 |
painted = true; |
|
2192 |
QGraphicsView::paintEvent(event); |
|
2193 |
} |
|
2194 |
}; |
|
2195 |
||
2196 |
void tst_QGraphicsView::viewportUpdateMode() |
|
2197 |
{ |
|
2198 |
QGraphicsScene scene(0, 0, 100, 100); |
|
2199 |
scene.setBackgroundBrush(Qt::red); |
|
2200 |
||
2201 |
CustomView view; |
|
2202 |
view.setFixedSize(500, 500); |
|
2203 |
view.setScene(&scene); |
|
2204 |
QCOMPARE(view.viewportUpdateMode(), QGraphicsView::MinimalViewportUpdate); |
|
2205 |
||
2206 |
// Show the view, and initialize our test. |
|
2207 |
view.show(); |
|
2208 |
QTest::qWaitForWindowShown(&view); |
|
2209 |
QTRY_VERIFY(!view.lastUpdateRegions.isEmpty()); |
|
2210 |
view.lastUpdateRegions.clear(); |
|
2211 |
||
2212 |
// Issue two scene updates. |
|
2213 |
scene.update(QRectF(0, 0, 10, 10)); |
|
2214 |
scene.update(QRectF(20, 0, 10, 10)); |
|
2215 |
QTest::qWait(50); |
|
2216 |
||
2217 |
// The view gets two updates for the update scene updates. |
|
2218 |
QTRY_VERIFY(!view.lastUpdateRegions.isEmpty()); |
|
2219 |
#ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions |
|
2220 |
QCOMPARE(view.lastUpdateRegions.last().rects().size(), 2); |
|
2221 |
QCOMPARE(view.lastUpdateRegions.last().rects().at(0).size(), QSize(15, 15)); |
|
2222 |
QCOMPARE(view.lastUpdateRegions.last().rects().at(1).size(), QSize(15, 15)); |
|
2223 |
#endif |
|
2224 |
||
2225 |
// Set full update mode. |
|
2226 |
view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); |
|
2227 |
QCOMPARE(view.viewportUpdateMode(), QGraphicsView::FullViewportUpdate); |
|
2228 |
view.lastUpdateRegions.clear(); |
|
2229 |
||
2230 |
// Issue two scene updates. |
|
2231 |
scene.update(QRectF(0, 0, 10, 10)); |
|
2232 |
scene.update(QRectF(20, 0, 10, 10)); |
|
2233 |
qApp->processEvents(); |
|
2234 |
qApp->processEvents(); |
|
2235 |
||
2236 |
// The view gets one full viewport update for the update scene updates. |
|
2237 |
QCOMPARE(view.lastUpdateRegions.last().rects().size(), 1); |
|
2238 |
QCOMPARE(view.lastUpdateRegions.last().rects().at(0).size(), view.viewport()->size()); |
|
2239 |
view.lastUpdateRegions.clear(); |
|
2240 |
||
2241 |
// Set smart update mode |
|
2242 |
view.setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); |
|
2243 |
QCOMPARE(view.viewportUpdateMode(), QGraphicsView::SmartViewportUpdate); |
|
2244 |
||
2245 |
// Issue 100 mini-updates |
|
2246 |
for (int i = 0; i < 10; ++i) { |
|
2247 |
for (int j = 0; j < 10; ++j) { |
|
2248 |
scene.update(QRectF(i * 3, j * 3, 1, 1)); |
|
2249 |
} |
|
2250 |
} |
|
2251 |
qApp->processEvents(); |
|
2252 |
qApp->processEvents(); |
|
2253 |
||
2254 |
// The view gets one bounding rect update. |
|
2255 |
QCOMPARE(view.lastUpdateRegions.last().rects().size(), 1); |
|
2256 |
QCOMPARE(view.lastUpdateRegions.last().rects().at(0).size(), QSize(33, 33)); |
|
2257 |
||
2258 |
// Set no update mode |
|
2259 |
view.setViewportUpdateMode(QGraphicsView::NoViewportUpdate); |
|
2260 |
QCOMPARE(view.viewportUpdateMode(), QGraphicsView::NoViewportUpdate); |
|
2261 |
||
2262 |
// Issue two scene updates. |
|
2263 |
view.lastUpdateRegions.clear(); |
|
2264 |
TestItem item; |
|
2265 |
scene.addItem(&item); |
|
2266 |
item.moveBy(10, 10); |
|
2267 |
scene.update(QRectF(0, 0, 10, 10)); |
|
2268 |
scene.update(QRectF(20, 0, 10, 10)); |
|
2269 |
qApp->processEvents(); |
|
2270 |
qApp->processEvents(); |
|
2271 |
||
2272 |
// The view should not get any painting calls from the scene updates |
|
2273 |
QCOMPARE(view.lastUpdateRegions.size(), 0); |
|
2274 |
} |
|
2275 |
||
2276 |
void tst_QGraphicsView::viewportUpdateMode2() |
|
2277 |
{ |
|
2278 |
// Create a view with viewport rect equal to QRect(0, 0, 200, 200). |
|
2279 |
QGraphicsScene dummyScene; |
|
2280 |
CustomView view; |
|
2281 |
view.painted = false; |
|
2282 |
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); |
|
2283 |
view.setScene(&dummyScene); |
|
2284 |
int left, top, right, bottom; |
|
2285 |
view.getContentsMargins(&left, &top, &right, &bottom); |
|
2286 |
view.resize(200 + left + right, 200 + top + bottom); |
|
2287 |
view.show(); |
|
2288 |
QTest::qWaitForWindowShown(&view); |
|
2289 |
QTest::qWait(50); |
|
2290 |
QTRY_VERIFY(view.painted); |
|
2291 |
const QRect viewportRect = view.viewport()->rect(); |
|
2292 |
QCOMPARE(viewportRect, QRect(0, 0, 200, 200)); |
|
2293 |
||
2294 |
#if defined QT_BUILD_INTERNAL |
|
2295 |
QGraphicsViewPrivate *viewPrivate = static_cast<QGraphicsViewPrivate *>(qt_widget_private(&view)); |
|
2296 |
||
2297 |
QRect boundingRect; |
|
2298 |
const QRect rect1(0, 0, 10, 10); |
|
2299 |
QVERIFY(viewPrivate->updateRect(rect1)); |
|
2300 |
QVERIFY(!viewPrivate->fullUpdatePending); |
|
2301 |
boundingRect |= rect1; |
|
2302 |
QCOMPARE(viewPrivate->dirtyBoundingRect, boundingRect); |
|
2303 |
||
2304 |
const QRect rect2(50, 50, 10, 10); |
|
2305 |
QVERIFY(viewPrivate->updateRect(rect2)); |
|
2306 |
QVERIFY(!viewPrivate->fullUpdatePending); |
|
2307 |
boundingRect |= rect2; |
|
2308 |
QCOMPARE(viewPrivate->dirtyBoundingRect, boundingRect); |
|
2309 |
||
2310 |
const QRect rect3(190, 190, 10, 10); |
|
2311 |
QVERIFY(viewPrivate->updateRect(rect3)); |
|
2312 |
QVERIFY(viewPrivate->fullUpdatePending); |
|
2313 |
boundingRect |= rect3; |
|
2314 |
QCOMPARE(viewPrivate->dirtyBoundingRect, boundingRect); |
|
2315 |
||
2316 |
view.lastUpdateRegions.clear(); |
|
2317 |
viewPrivate->processPendingUpdates(); |
|
2318 |
QTest::qWait(50); |
|
2319 |
QCOMPARE(view.lastUpdateRegions.size(), 1); |
|
2320 |
// Note that we adjust by 2 for antialiasing. |
|
2321 |
QCOMPARE(view.lastUpdateRegions.at(0), QRegion(boundingRect.adjusted(-2, -2, 2, 2) & viewportRect)); |
|
2322 |
#endif |
|
2323 |
} |
|
2324 |
||
2325 |
void tst_QGraphicsView::acceptDrops() |
|
2326 |
{ |
|
2327 |
#ifdef QT_NO_DRAGANDDROP |
|
2328 |
QSKIP("Drag'n drop disabled in this build", SkipAll); |
|
2329 |
#else |
|
2330 |
QGraphicsView view; |
|
2331 |
||
2332 |
// Excepted default behavior. |
|
2333 |
QVERIFY(view.acceptDrops()); |
|
2334 |
QVERIFY(view.viewport()->acceptDrops()); |
|
2335 |
||
2336 |
// Excepted behavior with no drops. |
|
2337 |
view.setAcceptDrops(false); |
|
2338 |
QVERIFY(!view.acceptDrops()); |
|
2339 |
QVERIFY(!view.viewport()->acceptDrops()); |
|
2340 |
||
2341 |
// Setting a widget with drops on a QGraphicsView without drops. |
|
2342 |
QWidget *widget = new QWidget; |
|
2343 |
widget->setAcceptDrops(true); |
|
2344 |
view.setViewport(widget); |
|
2345 |
QVERIFY(!view.acceptDrops()); |
|
2346 |
QVERIFY(!view.viewport()->acceptDrops()); |
|
2347 |
||
2348 |
// Switching the view to accept drops. |
|
2349 |
view.setAcceptDrops(true); |
|
2350 |
QVERIFY(view.acceptDrops()); |
|
2351 |
QVERIFY(view.viewport()->acceptDrops()); |
|
2352 |
||
2353 |
// Setting a widget with no drops on a QGraphicsView with drops. |
|
2354 |
widget = new QWidget; |
|
2355 |
widget->setAcceptDrops(false); |
|
2356 |
view.setViewport(widget); |
|
2357 |
QVERIFY(view.viewport()->acceptDrops()); |
|
2358 |
QVERIFY(view.acceptDrops()); |
|
2359 |
||
2360 |
// Switching the view to not accept drops. |
|
2361 |
view.setAcceptDrops(false); |
|
2362 |
QVERIFY(!view.viewport()->acceptDrops()); |
|
2363 |
#endif |
|
2364 |
} |
|
2365 |
||
2366 |
void tst_QGraphicsView::optimizationFlags() |
|
2367 |
{ |
|
2368 |
QGraphicsView view; |
|
2369 |
QVERIFY(!view.optimizationFlags()); |
|
2370 |
||
2371 |
view.setOptimizationFlag(QGraphicsView::DontClipPainter); |
|
2372 |
QVERIFY(view.optimizationFlags() & QGraphicsView::DontClipPainter); |
|
2373 |
view.setOptimizationFlag(QGraphicsView::DontClipPainter, false); |
|
2374 |
QVERIFY(!view.optimizationFlags()); |
|
2375 |
||
2376 |
view.setOptimizationFlag(QGraphicsView::DontSavePainterState); |
|
2377 |
QVERIFY(view.optimizationFlags() & QGraphicsView::DontSavePainterState); |
|
2378 |
view.setOptimizationFlag(QGraphicsView::DontSavePainterState, false); |
|
2379 |
QVERIFY(!view.optimizationFlags()); |
|
2380 |
||
2381 |
view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing); |
|
2382 |
QVERIFY(view.optimizationFlags() & QGraphicsView::DontAdjustForAntialiasing); |
|
2383 |
view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, false); |
|
2384 |
QVERIFY(!view.optimizationFlags()); |
|
2385 |
||
2386 |
view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing |
|
2387 |
| QGraphicsView::DontClipPainter); |
|
2388 |
QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing |
|
2389 |
| QGraphicsView::DontClipPainter)); |
|
2390 |
} |
|
2391 |
||
2392 |
class MessUpPainterItem : public QGraphicsRectItem |
|
2393 |
{ |
|
2394 |
public: |
|
2395 |
MessUpPainterItem(const QRectF &rect) : QGraphicsRectItem(rect), dirtyPainter(false) |
|
2396 |
{ } |
|
2397 |
||
2398 |
bool dirtyPainter; |
|
2399 |
||
2400 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
2401 |
{ |
|
2402 |
dirtyPainter = (painter->pen().width() != 0); |
|
2403 |
painter->setPen(QPen(Qt::black, 1.0)); |
|
2404 |
} |
|
2405 |
}; |
|
2406 |
||
2407 |
class MyGraphicsView : public QGraphicsView |
|
2408 |
{ |
|
2409 |
public: |
|
2410 |
MyGraphicsView(QGraphicsScene * scene) : QGraphicsView(scene) |
|
2411 |
{ } |
|
2412 |
||
2413 |
void drawBackground(QPainter * painter, const QRectF & rect) { |
|
2414 |
painter->setCompositionMode(QPainter::CompositionMode_Source); |
|
2415 |
painter->drawRect(rect); |
|
2416 |
} |
|
2417 |
||
2418 |
void drawItems (QPainter * painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[]) { |
|
2419 |
if (!(optimizationFlags() & QGraphicsView::DontSavePainterState)) |
|
2420 |
QCOMPARE(painter->compositionMode(),QPainter::CompositionMode_SourceOver); |
|
2421 |
else |
|
2422 |
QCOMPARE(painter->compositionMode(),QPainter::CompositionMode_Source); |
|
2423 |
QGraphicsView::drawItems(painter,numItems,items,options); |
|
2424 |
} |
|
2425 |
}; |
|
2426 |
||
2427 |
void tst_QGraphicsView::optimizationFlags_dontSavePainterState() |
|
2428 |
{ |
|
2429 |
MessUpPainterItem *parent = new MessUpPainterItem(QRectF(0, 0, 100, 100)); |
|
2430 |
MessUpPainterItem *child = new MessUpPainterItem(QRectF(0, 0, 100, 100)); |
|
2431 |
child->setParentItem(parent); |
|
2432 |
||
2433 |
QGraphicsScene scene; |
|
2434 |
scene.addItem(parent); |
|
2435 |
||
2436 |
QGraphicsView view(&scene); |
|
2437 |
view.show(); |
|
2438 |
QTest::qWaitForWindowShown(&view); |
|
2439 |
view.viewport()->repaint(); |
|
2440 |
||
2441 |
QVERIFY(!parent->dirtyPainter); |
|
2442 |
QVERIFY(!child->dirtyPainter); |
|
2443 |
||
2444 |
view.setOptimizationFlags(QGraphicsView::DontSavePainterState); |
|
2445 |
view.viewport()->repaint(); |
|
2446 |
||
2447 |
#ifdef Q_WS_MAC |
|
2448 |
// Repaint on Mac OS X actually does require spinning the event loop. |
|
2449 |
QTest::qWait(100); |
|
2450 |
#endif |
|
2451 |
QVERIFY(!parent->dirtyPainter); |
|
2452 |
QVERIFY(child->dirtyPainter); |
|
2453 |
||
2454 |
MyGraphicsView painter(&scene); |
|
2455 |
painter.show(); |
|
2456 |
QTest::qWaitForWindowShown(&painter); |
|
2457 |
||
2458 |
MyGraphicsView painter2(&scene); |
|
2459 |
painter2.setOptimizationFlag(QGraphicsView::DontSavePainterState,true); |
|
2460 |
painter2.show(); |
|
2461 |
QTest::qWaitForWindowShown(&painter2); |
|
2462 |
} |
|
2463 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2464 |
void tst_QGraphicsView::optimizationFlags_dontSavePainterState2_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2465 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2466 |
QTest::addColumn<bool>("savePainter"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2467 |
QTest::newRow("With painter state protection") << true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2468 |
QTest::newRow("Without painter state protection") << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2469 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2470 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2471 |
void tst_QGraphicsView::optimizationFlags_dontSavePainterState2() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2472 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2473 |
QFETCH(bool, savePainter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2474 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2475 |
class MyScene : public QGraphicsScene |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2476 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2477 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2478 |
void drawBackground(QPainter *p, const QRectF &) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2479 |
{ transformInDrawBackground = p->worldTransform(); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2480 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2481 |
void drawForeground(QPainter *p, const QRectF &) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2482 |
{ transformInDrawForeground = p->worldTransform(); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2483 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2484 |
QTransform transformInDrawBackground; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2485 |
QTransform transformInDrawForeground; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2486 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2487 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2488 |
MyScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2489 |
// Add transformed dummy items to make sure the painter's worldTransform() is changed in drawItems. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2490 |
scene.addRect(0, 0, 20, 20)->setTransform(QTransform::fromScale(2, 2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2491 |
scene.addRect(50, 50, 20, 20)->setTransform(QTransform::fromTranslate(200, 200)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2492 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2493 |
CustomView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2494 |
if (!savePainter) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2495 |
view.setOptimizationFlag(QGraphicsView::DontSavePainterState); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2496 |
view.rotate(45); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2497 |
view.scale(1.5, 1.5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2498 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2499 |
#ifdef Q_WS_X11 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2500 |
qt_x11_wait_for_window_manager(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2501 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2502 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2503 |
// Make sure the view is repainted; otherwise the tests below will fail. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2504 |
view.viewport()->repaint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2505 |
QTest::qWait(200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2506 |
QVERIFY(view.painted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2507 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2508 |
// Make sure the painter's world transform is preserved after drawItems. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2509 |
const QTransform expectedTransform = view.viewportTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2510 |
QVERIFY(!expectedTransform.isIdentity()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2511 |
QCOMPARE(scene.transformInDrawForeground, expectedTransform); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2512 |
QCOMPARE(scene.transformInDrawBackground, expectedTransform); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2513 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2514 |
|
0 | 2515 |
class LodItem : public QGraphicsRectItem |
2516 |
{ |
|
2517 |
public: |
|
2518 |
LodItem(const QRectF &rect) : QGraphicsRectItem(rect), lastLod(-42) |
|
2519 |
{ } |
|
2520 |
||
2521 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *viewport) |
|
2522 |
{ |
|
2523 |
lastLod = option->levelOfDetailFromTransform(painter->worldTransform()); |
|
2524 |
QGraphicsRectItem::paint(painter, option, viewport); |
|
2525 |
} |
|
2526 |
||
2527 |
qreal lastLod; |
|
2528 |
}; |
|
2529 |
||
2530 |
void tst_QGraphicsView::levelOfDetail_data() |
|
2531 |
{ |
|
2532 |
QTest::addColumn<QTransform>("transform"); |
|
2533 |
QTest::addColumn<qreal>("lod"); |
|
2534 |
||
2535 |
QTest::newRow("1:4, 1:4") << QTransform().scale(0.25, 0.25) << qreal(0.25); |
|
2536 |
QTest::newRow("1:2, 1:4") << QTransform().scale(0.5, 0.25) << qreal(::sqrt(0.125)); |
|
2537 |
QTest::newRow("4:1, 1:2") << QTransform().scale(0.25, 0.5) << qreal(::sqrt(0.125)); |
|
2538 |
||
2539 |
QTest::newRow("1:2, 1:2") << QTransform().scale(0.5, 0.5) << qreal(0.5); |
|
2540 |
QTest::newRow("1:1, 1:2") << QTransform().scale(1, 0.5) << qreal(::sqrt(0.5)); |
|
2541 |
QTest::newRow("2:1, 1:1") << QTransform().scale(0.5, 1) << qreal(::sqrt(0.5)); |
|
2542 |
||
2543 |
QTest::newRow("1:1, 1:1") << QTransform().scale(1, 1) << qreal(1.0); |
|
2544 |
QTest::newRow("2:1, 1:1") << QTransform().scale(2, 1) << qreal(::sqrt(2.0)); |
|
2545 |
QTest::newRow("1:1, 2:1") << QTransform().scale(2, 1) << qreal(::sqrt(2.0)); |
|
2546 |
QTest::newRow("2:1, 2:1") << QTransform().scale(2, 2) << qreal(2.0); |
|
2547 |
QTest::newRow("2:1, 4:1") << QTransform().scale(2, 4) << qreal(::sqrt(8.0)); |
|
2548 |
QTest::newRow("4:1, 2:1") << QTransform().scale(4, 2) << qreal(::sqrt(8.0)); |
|
2549 |
QTest::newRow("4:1, 4:1") << QTransform().scale(4, 4) << qreal(4.0); |
|
2550 |
} |
|
2551 |
||
2552 |
void tst_QGraphicsView::levelOfDetail() |
|
2553 |
{ |
|
2554 |
QFETCH(QTransform, transform); |
|
2555 |
QFETCH(qreal, lod); |
|
2556 |
||
2557 |
LodItem *item = new LodItem(QRectF(0, 0, 100, 100)); |
|
2558 |
||
2559 |
QGraphicsScene scene; |
|
2560 |
scene.addItem(item); |
|
2561 |
||
2562 |
QGraphicsView view(&scene); |
|
2563 |
view.show(); |
|
2564 |
QTest::qWaitForWindowShown(&view); |
|
2565 |
||
2566 |
QTRY_COMPARE(item->lastLod, qreal(1)); |
|
2567 |
||
2568 |
view.setTransform(transform); |
|
2569 |
||
2570 |
QTRY_COMPARE(item->lastLod, lod); |
|
2571 |
} |
|
2572 |
||
2573 |
// Moved to tst_qgraphicsview_2.cpp |
|
2574 |
extern void _scrollBarRanges_data(); |
|
2575 |
||
2576 |
void tst_QGraphicsView::scrollBarRanges_data() |
|
2577 |
{ |
|
2578 |
_scrollBarRanges_data(); |
|
2579 |
} |
|
2580 |
||
2581 |
void tst_QGraphicsView::scrollBarRanges() |
|
2582 |
{ |
|
2583 |
QFETCH(QSize, viewportSize); |
|
2584 |
QFETCH(QRectF, sceneRect); |
|
2585 |
QFETCH(QTransform, transform); |
|
2586 |
QFETCH(Qt::ScrollBarPolicy, hbarpolicy); |
|
2587 |
QFETCH(Qt::ScrollBarPolicy, vbarpolicy); |
|
2588 |
QFETCH(int, hmin); |
|
2589 |
QFETCH(int, hmax); |
|
2590 |
QFETCH(int, vmin); |
|
2591 |
QFETCH(int, vmax); |
|
2592 |
QFETCH(bool, useMotif); |
|
2593 |
QFETCH(bool, useStyledPanel); |
|
2594 |
||
2595 |
QGraphicsScene scene(sceneRect); |
|
2596 |
scene.addRect(sceneRect, QPen(Qt::blue), QBrush(QColor(Qt::green))); |
|
2597 |
QGraphicsView view(&scene); |
|
2598 |
view.setRenderHint(QPainter::Antialiasing); |
|
2599 |
view.setTransform(transform); |
|
2600 |
view.setFrameStyle(useStyledPanel ? QFrame::StyledPanel : QFrame::NoFrame); |
|
2601 |
||
2602 |
if (useMotif) { |
|
2603 |
#if !defined(QT_NO_STYLE_MOTIF) |
|
2604 |
view.setStyle(new QMotifStyle); |
|
2605 |
#else |
|
2606 |
QSKIP("No Motif style compiled.", SkipSingle); |
|
2607 |
#endif |
|
2608 |
} else { |
|
2609 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
2610 |
view.setStyle(new QWindowsStyle); |
|
2611 |
#elif !defined(QT_NO_STYLE_PLASTIQUE) |
|
2612 |
view.setStyle(new QPlastiqueStyle); |
|
2613 |
#endif |
|
2614 |
} |
|
2615 |
view.setStyleSheet(" "); // enables style propagation ;-) |
|
2616 |
||
2617 |
int adjust = 0; |
|
2618 |
if (useStyledPanel) |
|
2619 |
adjust = view.style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2; |
|
2620 |
view.resize(viewportSize + QSize(adjust, adjust)); |
|
2621 |
||
2622 |
view.setHorizontalScrollBarPolicy(hbarpolicy); |
|
2623 |
view.setVerticalScrollBarPolicy(vbarpolicy); |
|
2624 |
||
2625 |
view.show(); |
|
2626 |
||
2627 |
QCOMPARE(view.horizontalScrollBar()->minimum(), hmin); |
|
2628 |
QCOMPARE(view.verticalScrollBar()->minimum(), vmin); |
|
2629 |
QCOMPARE(view.horizontalScrollBar()->maximum(), hmax); |
|
2630 |
QCOMPARE(view.verticalScrollBar()->maximum(), vmax); |
|
2631 |
} |
|
2632 |
||
2633 |
class TestView : public QGraphicsView |
|
2634 |
{ |
|
2635 |
public: |
|
2636 |
TestView(QGraphicsScene *scene) |
|
2637 |
: QGraphicsView(scene), accepted(false) |
|
2638 |
{ } |
|
2639 |
||
2640 |
bool accepted; |
|
2641 |
||
2642 |
protected: |
|
2643 |
void mousePressEvent(QMouseEvent *event) |
|
2644 |
{ |
|
2645 |
QGraphicsView::mousePressEvent(event); |
|
2646 |
accepted = event->isAccepted(); |
|
2647 |
} |
|
2648 |
}; |
|
2649 |
||
2650 |
void tst_QGraphicsView::acceptMousePressEvent() |
|
2651 |
{ |
|
2652 |
QGraphicsScene scene; |
|
2653 |
||
2654 |
TestView view(&scene); |
|
2655 |
view.show(); |
|
2656 |
QTest::qWaitForWindowShown(&view); |
|
2657 |
||
2658 |
QMouseEvent event(QEvent::MouseButtonPress, |
|
2659 |
view.viewport()->rect().center(), |
|
2660 |
view.viewport()->mapToGlobal(view.viewport()->rect().center()), |
|
2661 |
Qt::LeftButton, 0, 0); |
|
2662 |
event.setAccepted(false); |
|
2663 |
QApplication::sendEvent(view.viewport(), &event); |
|
2664 |
QVERIFY(!view.accepted); |
|
2665 |
||
2666 |
scene.addRect(0, 0, 2000, 2000)->setFlag(QGraphicsItem::ItemIsMovable); |
|
2667 |
||
2668 |
qApp->processEvents(); // ensure scene rect is updated |
|
2669 |
||
2670 |
QApplication::sendEvent(view.viewport(), &event); |
|
2671 |
QVERIFY(view.accepted); |
|
2672 |
} |
|
2673 |
||
2674 |
void tst_QGraphicsView::replayMouseMove() |
|
2675 |
{ |
|
2676 |
// An empty scene in a view. The view will send the events to the scene in |
|
2677 |
// any case. Note that the view doesn't have to be shown - the mouse event |
|
2678 |
// sending functions below send the events directly to the viewport. |
|
2679 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
2680 |
QGraphicsView view(&scene); |
|
2681 |
||
2682 |
EventSpy sceneSpy(&scene, QEvent::GraphicsSceneMouseMove); |
|
2683 |
EventSpy viewSpy(view.viewport(), QEvent::MouseMove); |
|
2684 |
||
2685 |
sendMousePress(view.viewport(), view.viewport()->rect().center()); |
|
2686 |
||
2687 |
// One mouse event should be translated into one scene event. |
|
2688 |
for (int i = 0; i < 3; ++i) { |
|
2689 |
sendMouseMove(view.viewport(), view.viewport()->rect().center(), |
|
2690 |
Qt::LeftButton, Qt::MouseButtons(Qt::LeftButton)); |
|
2691 |
QCOMPARE(viewSpy.count(), i + 1); |
|
2692 |
QCOMPARE(sceneSpy.count(), i + 1); |
|
2693 |
} |
|
2694 |
||
2695 |
// When the view is transformed, the view should get no more events. But |
|
2696 |
// the scene should get replays. |
|
2697 |
for (int i = 0; i < 3; ++i) { |
|
2698 |
view.rotate(10); |
|
2699 |
QCOMPARE(viewSpy.count(), 3); |
|
2700 |
QCOMPARE(sceneSpy.count(), 3 + i + 1); |
|
2701 |
} |
|
2702 |
||
2703 |
// When the view is scrolled, the view should get no more events. But the |
|
2704 |
// scene should get replays. |
|
2705 |
for (int i = 0; i < 3; ++i) { |
|
2706 |
view.horizontalScrollBar()->setValue((i + 1) * 10); |
|
2707 |
QCOMPARE(viewSpy.count(), 3); |
|
2708 |
QCOMPARE(sceneSpy.count(), 6 + i + 1); |
|
2709 |
} |
|
2710 |
} |
|
2711 |
||
2712 |
void tst_QGraphicsView::itemsUnderMouse() |
|
2713 |
{ |
|
2714 |
QGraphicsScene scene; |
|
2715 |
QGraphicsProxyWidget w; |
|
2716 |
w.setWidget(new QPushButton("W")); |
|
2717 |
w.resize(50,50); |
|
2718 |
QGraphicsProxyWidget w2(&w); |
|
2719 |
w2.setWidget(new QPushButton("W2")); |
|
2720 |
w2.resize(50,50); |
|
2721 |
QGraphicsProxyWidget w3(&w2); |
|
2722 |
w3.setWidget(new QPushButton("W3")); |
|
2723 |
w3.resize(50,50); |
|
2724 |
w.setZValue(150); |
|
2725 |
w2.setZValue(50); |
|
2726 |
w3.setZValue(0); |
|
2727 |
scene.addItem(&w); |
|
2728 |
||
2729 |
QGraphicsView view(&scene); |
|
2730 |
view.show(); |
|
2731 |
QTest::qWaitForWindowShown(&view); |
|
2732 |
||
2733 |
QCOMPARE(view.items(view.mapFromScene(w3.boundingRect().center())).first(), |
|
2734 |
static_cast<QGraphicsItem *>(&w3)); |
|
2735 |
w2.setFlag(QGraphicsItem::ItemIgnoresTransformations, true); |
|
2736 |
QCOMPARE(view.items(view.mapFromScene(w3.boundingRect().center())).first(), |
|
2737 |
static_cast<QGraphicsItem *>(&w3)); |
|
2738 |
} |
|
2739 |
||
2740 |
class QGraphicsTextItem_task172231 : public QGraphicsTextItem |
|
2741 |
{ |
|
2742 |
public: |
|
2743 |
QGraphicsTextItem_task172231(const QString & text, QGraphicsItem * parent = 0) |
|
2744 |
: QGraphicsTextItem(text, parent) {} |
|
2745 |
QRectF exposedRect; |
|
2746 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
2747 |
{ |
|
2748 |
exposedRect = option->exposedRect; |
|
2749 |
QGraphicsTextItem::paint(painter, option, widget); |
|
2750 |
} |
|
2751 |
}; |
|
2752 |
||
2753 |
void tst_QGraphicsView::task172231_untransformableItems() |
|
2754 |
{ |
|
2755 |
// check fix in QGraphicsView::paintEvent() |
|
2756 |
||
2757 |
QGraphicsScene scene; |
|
2758 |
||
2759 |
QGraphicsTextItem_task172231 *text = |
|
2760 |
new QGraphicsTextItem_task172231("abcdefghijklmnopqrstuvwxyz"); |
|
2761 |
text->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
2762 |
scene.addItem(text); |
|
2763 |
||
2764 |
QGraphicsView view(&scene); |
|
2765 |
||
2766 |
view.scale(2, 1); |
|
2767 |
view.show(); |
|
2768 |
QTest::qWaitForWindowShown(&view); |
|
2769 |
QApplication::setActiveWindow(&view); |
|
2770 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
2771 |
||
2772 |
QRectF origExposedRect = text->exposedRect; |
|
2773 |
||
2774 |
view.resize(int(0.75 * view.width()), view.height()); |
|
2775 |
qApp->processEvents(); |
|
2776 |
||
2777 |
QCOMPARE(text->exposedRect, origExposedRect); |
|
2778 |
||
2779 |
// notice that the fix also goes into QGraphicsView::render() |
|
2780 |
// and QGraphicsScene::render(), but in duplicated code that |
|
2781 |
// is pending a refactoring, so for now we omit autotesting |
|
2782 |
// these functions separately |
|
2783 |
} |
|
2784 |
||
2785 |
class MousePressReleaseScene : public QGraphicsScene |
|
2786 |
{ |
|
2787 |
public: |
|
2788 |
MousePressReleaseScene() |
|
2789 |
: presses(0), releases(0) |
|
2790 |
{ } |
|
2791 |
int presses; |
|
2792 |
int releases; |
|
2793 |
||
2794 |
protected: |
|
2795 |
void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
2796 |
{ ++presses; QGraphicsScene::mousePressEvent(event); } |
|
2797 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
2798 |
{ ++releases; QGraphicsScene::mouseReleaseEvent(event); } |
|
2799 |
}; |
|
2800 |
||
2801 |
void tst_QGraphicsView::task180429_mouseReleaseDragMode() |
|
2802 |
{ |
|
2803 |
MousePressReleaseScene scene; |
|
2804 |
||
2805 |
QGraphicsView view(&scene); |
|
2806 |
view.show(); |
|
2807 |
||
2808 |
sendMousePress(view.viewport(), view.viewport()->rect().center()); |
|
2809 |
QCOMPARE(scene.presses, 1); |
|
2810 |
QCOMPARE(scene.releases, 0); |
|
2811 |
sendMouseRelease(view.viewport(), view.viewport()->rect().center()); |
|
2812 |
QCOMPARE(scene.presses, 1); |
|
2813 |
QCOMPARE(scene.releases, 1); |
|
2814 |
||
2815 |
view.setDragMode(QGraphicsView::RubberBandDrag); |
|
2816 |
sendMousePress(view.viewport(), view.viewport()->rect().center()); |
|
2817 |
QCOMPARE(scene.presses, 2); |
|
2818 |
QCOMPARE(scene.releases, 1); |
|
2819 |
sendMouseRelease(view.viewport(), view.viewport()->rect().center()); |
|
2820 |
QCOMPARE(scene.presses, 2); |
|
2821 |
QCOMPARE(scene.releases, 2); |
|
2822 |
} |
|
2823 |
||
2824 |
void tst_QGraphicsView::task187791_setSceneCausesUpdate() |
|
2825 |
{ |
|
2826 |
QGraphicsScene scene(0, 0, 200, 200); |
|
2827 |
QGraphicsView view(&scene); |
|
2828 |
view.show(); |
|
2829 |
QTest::qWaitForWindowShown(&view); |
|
2830 |
||
2831 |
EventSpy updateSpy(view.viewport(), QEvent::Paint); |
|
2832 |
QCOMPARE(updateSpy.count(), 0); |
|
2833 |
||
2834 |
view.setScene(0); |
|
2835 |
QApplication::processEvents(); |
|
2836 |
QTRY_COMPARE(updateSpy.count(), 1); |
|
2837 |
view.setScene(&scene); |
|
2838 |
QApplication::processEvents(); |
|
2839 |
QTRY_COMPARE(updateSpy.count(), 2); |
|
2840 |
} |
|
2841 |
||
2842 |
class MouseMoveCounter : public QGraphicsView |
|
2843 |
{ |
|
2844 |
public: |
|
2845 |
MouseMoveCounter() : mouseMoves(0) |
|
2846 |
{ } |
|
2847 |
int mouseMoves; |
|
2848 |
protected: |
|
2849 |
void mouseMoveEvent(QMouseEvent *event) |
|
2850 |
{ |
|
2851 |
++mouseMoves; |
|
2852 |
QGraphicsView::mouseMoveEvent(event); |
|
2853 |
foreach (QGraphicsItem *item, scene()->items()) { |
|
2854 |
scene()->removeItem(item); |
|
2855 |
delete item; |
|
2856 |
} |
|
2857 |
scene()->addRect(0, 0, 50, 50); |
|
2858 |
scene()->addRect(0, 0, 100, 100); |
|
2859 |
} |
|
2860 |
}; |
|
2861 |
||
2862 |
void tst_QGraphicsView::task186827_deleteReplayedItem() |
|
2863 |
{ |
|
2864 |
// make sure the mouse is not over the window, causing spontaneous mouse moves |
|
2865 |
QCursor::setPos(0, 0); |
|
2866 |
||
2867 |
QGraphicsScene scene; |
|
2868 |
scene.addRect(0, 0, 50, 50); |
|
2869 |
scene.addRect(0, 0, 100, 100); |
|
2870 |
||
2871 |
MouseMoveCounter view; |
|
2872 |
view.setScene(&scene); |
|
2873 |
view.show(); |
|
2874 |
QTest::qWaitForWindowShown(&view); |
|
2875 |
view.viewport()->setMouseTracking(true); |
|
2876 |
||
2877 |
QCOMPARE(view.mouseMoves, 0); |
|
2878 |
{ |
|
2879 |
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, 0, 0); |
|
2880 |
QApplication::sendEvent(view.viewport(), &event); |
|
2881 |
} |
|
2882 |
QCOMPARE(view.mouseMoves, 1); |
|
2883 |
QTest::qWait(25); |
|
2884 |
QTRY_COMPARE(view.mouseMoves, 1); |
|
2885 |
QTest::qWait(25); |
|
2886 |
{ |
|
2887 |
QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, 0, 0); |
|
2888 |
QApplication::sendEvent(view.viewport(), &event); |
|
2889 |
} |
|
2890 |
QCOMPARE(view.mouseMoves, 2); |
|
2891 |
QTest::qWait(15); |
|
2892 |
} |
|
2893 |
||
2894 |
void tst_QGraphicsView::task207546_focusCrash() |
|
2895 |
{ |
|
2896 |
class _Widget : public QWidget |
|
2897 |
{ |
|
2898 |
public: |
|
2899 |
bool focusNextPrevChild(bool next) { return QWidget::focusNextPrevChild(next); } |
|
2900 |
} widget; |
|
2901 |
||
2902 |
widget.setLayout(new QVBoxLayout()); |
|
2903 |
QGraphicsView *gr1 = new QGraphicsView(&widget); |
|
2904 |
QGraphicsView *gr2 = new QGraphicsView(&widget); |
|
2905 |
widget.layout()->addWidget(gr1); |
|
2906 |
widget.layout()->addWidget(gr2); |
|
2907 |
widget.show(); |
|
2908 |
QTest::qWaitForWindowShown(&widget); |
|
2909 |
widget.activateWindow(); |
|
2910 |
QApplication::setActiveWindow(&widget); |
|
2911 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&widget)); |
|
2912 |
widget.focusNextPrevChild(true); |
|
2913 |
QCOMPARE(static_cast<QWidget *>(gr2), widget.focusWidget()); |
|
2914 |
} |
|
2915 |
||
2916 |
void tst_QGraphicsView::task210599_unsetDragWhileDragging() |
|
2917 |
{ |
|
2918 |
QGraphicsScene scene(0, 0, 400, 400); |
|
2919 |
QGraphicsView view(&scene); |
|
2920 |
view.setGeometry(0, 0, 200, 200); |
|
2921 |
view.show(); |
|
2922 |
||
2923 |
QPoint origPos = QPoint(100, 100); |
|
2924 |
QPoint step1Pos = QPoint(100, 110); |
|
2925 |
QPoint step2Pos = QPoint(100, 120); |
|
2926 |
||
2927 |
// Enable and do a drag |
|
2928 |
{ |
|
2929 |
view.setDragMode(QGraphicsView::ScrollHandDrag); |
|
2930 |
QMouseEvent press(QEvent::MouseButtonPress, origPos, Qt::LeftButton, 0, 0); |
|
2931 |
QMouseEvent move(QEvent::MouseMove, step1Pos, Qt::LeftButton, 0, 0); |
|
2932 |
QApplication::sendEvent(view.viewport(), &press); |
|
2933 |
QApplication::sendEvent(view.viewport(), &move); |
|
2934 |
} |
|
2935 |
||
2936 |
// unset drag and release mouse, inverse order |
|
2937 |
{ |
|
2938 |
view.setDragMode(QGraphicsView::NoDrag); |
|
2939 |
QMouseEvent release(QEvent::MouseButtonRelease, step1Pos, Qt::LeftButton, 0, 0); |
|
2940 |
QApplication::sendEvent(view.viewport(), &release); |
|
2941 |
} |
|
2942 |
||
2943 |
QPoint basePos = view.mapFromScene(0, 0); |
|
2944 |
||
2945 |
// reset drag, and move mouse without holding button down. |
|
2946 |
{ |
|
2947 |
view.setDragMode(QGraphicsView::ScrollHandDrag); |
|
2948 |
QMouseEvent move(QEvent::MouseMove, step2Pos, Qt::LeftButton, 0, 0); |
|
2949 |
QApplication::sendEvent(view.viewport(), &move); |
|
2950 |
} |
|
2951 |
||
2952 |
// Check that no draggin has occured... |
|
2953 |
QCOMPARE(basePos, view.mapFromScene(0, 0)); |
|
2954 |
} |
|
2955 |
||
2956 |
void tst_QGraphicsView::task236394_sendShortcutOverrideEvent() |
|
2957 |
{ |
|
2958 |
QGraphicsView view; |
|
2959 |
view.show(); |
|
2960 |
QKeyEvent event(QEvent::ShortcutOverride, Qt::Key_A, 0, QString("A")); |
|
2961 |
QApplication::sendEvent(&view, &event); |
|
2962 |
} |
|
2963 |
||
2964 |
class ChangedListener : public QObject |
|
2965 |
{ |
|
2966 |
Q_OBJECT |
|
2967 |
public: |
|
2968 |
QList<QList<QRectF> > changes; |
|
2969 |
||
2970 |
public slots: |
|
2971 |
void changed(const QList<QRectF> &dirty) |
|
2972 |
{ |
|
2973 |
changes << dirty; |
|
2974 |
} |
|
2975 |
}; |
|
2976 |
||
2977 |
void tst_QGraphicsView::task239729_noViewUpdate_data() |
|
2978 |
{ |
|
2979 |
QTest::addColumn<bool>("a"); |
|
2980 |
||
2981 |
QTest::newRow("a") << false; |
|
2982 |
QTest::newRow("b") << true; |
|
2983 |
} |
|
2984 |
||
2985 |
void tst_QGraphicsView::task239729_noViewUpdate() |
|
2986 |
{ |
|
2987 |
QFETCH(bool, a); |
|
2988 |
// The scene's changed signal is connected to something that isn't a view. |
|
2989 |
QGraphicsScene scene; |
|
2990 |
ChangedListener cl; |
|
2991 |
QGraphicsView *view = 0; |
|
2992 |
||
2993 |
if (a) { |
|
2994 |
view = new QGraphicsView(&scene); |
|
2995 |
connect(&scene, SIGNAL(changed(const QList<QRectF> &)), &cl, SLOT(changed(const QList<QRectF> &))); |
|
2996 |
} else { |
|
2997 |
connect(&scene, SIGNAL(changed(const QList<QRectF> &)), &cl, SLOT(changed(const QList<QRectF> &))); |
|
2998 |
view = new QGraphicsView(&scene); |
|
2999 |
} |
|
3000 |
||
3001 |
EventSpy spy(view->viewport(), QEvent::Paint); |
|
3002 |
QCOMPARE(spy.count(), 0); |
|
3003 |
||
3004 |
view->show(); |
|
3005 |
QTest::qWaitForWindowShown(view); |
|
3006 |
||
3007 |
QTRY_VERIFY(spy.count() >= 1); |
|
3008 |
spy.reset(); |
|
3009 |
scene.update(); |
|
3010 |
QApplication::processEvents(); |
|
3011 |
QTRY_COMPARE(spy.count(), 1); |
|
3012 |
||
3013 |
delete view; |
|
3014 |
} |
|
3015 |
||
3016 |
void tst_QGraphicsView::task239047_fitInViewSmallViewport() |
|
3017 |
{ |
|
3018 |
// Ensure that with a small viewport, fitInView doesn't mirror the |
|
3019 |
// scene. |
|
3020 |
QWidget widget; |
|
3021 |
QGraphicsScene scene; |
|
3022 |
QGraphicsView *view = new QGraphicsView(&scene, &widget); |
|
3023 |
view->resize(3, 3); |
|
3024 |
QCOMPARE(view->size(), QSize(3, 3)); |
|
3025 |
widget.show(); |
|
3026 |
view->fitInView(0, 0, 100, 100); |
|
3027 |
QPointF topLeft = view->mapToScene(0, 0); |
|
3028 |
QPointF bottomRight = view->mapToScene(100, 100); |
|
3029 |
QVERIFY(bottomRight.x() > topLeft.x()); |
|
3030 |
QVERIFY(bottomRight.y() > topLeft.y()); |
|
3031 |
||
3032 |
view->fitInView(0, 0, 0, 100); |
|
3033 |
||
3034 |
// Don't crash |
|
3035 |
view->scale(0, 0); |
|
3036 |
view->fitInView(0, 0, 100, 100); |
|
3037 |
} |
|
3038 |
||
3039 |
void tst_QGraphicsView::task245469_itemsAtPointWithClip() |
|
3040 |
{ |
|
3041 |
QGraphicsScene scene; |
|
3042 |
QGraphicsItem *parent = scene.addRect(0, 0, 100, 100); |
|
3043 |
QGraphicsItem *child = new QGraphicsRectItem(40, 40, 20, 20, parent); |
|
3044 |
parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
3045 |
||
3046 |
QGraphicsView view(&scene); |
|
3047 |
view.resize(150,150); |
|
3048 |
view.rotate(90); |
|
3049 |
view.show(); |
|
3050 |
QTest::qWaitForWindowShown(&view); |
|
3051 |
||
3052 |
QList<QGraphicsItem *> itemsAtCenter = view.items(view.viewport()->rect().center()); |
|
3053 |
QCOMPARE(itemsAtCenter, (QList<QGraphicsItem *>() << child << parent)); |
|
3054 |
||
3055 |
QPolygonF p = view.mapToScene(QRect(view.viewport()->rect().center(), QSize(1, 1))); |
|
3056 |
QList<QGraphicsItem *> itemsAtCenter2 = scene.items(p); |
|
3057 |
QCOMPARE(itemsAtCenter2, itemsAtCenter); |
|
3058 |
} |
|
3059 |
||
3060 |
static QGraphicsView *createSimpleViewAndScene() |
|
3061 |
{ |
|
3062 |
QGraphicsView *view = new QGraphicsView; |
|
3063 |
QGraphicsScene *scene = new QGraphicsScene; |
|
3064 |
view->setScene(scene); |
|
3065 |
||
3066 |
view->setBackgroundBrush(Qt::blue); |
|
3067 |
||
3068 |
QGraphicsRectItem *rect = scene->addRect(0, 0, 10, 10); |
|
3069 |
rect->setBrush(Qt::red); |
|
3070 |
rect->setPen(Qt::NoPen); |
|
3071 |
return view; |
|
3072 |
} |
|
3073 |
||
3074 |
class SpyItem : public QGraphicsRectItem |
|
3075 |
{ |
|
3076 |
public: |
|
3077 |
SpyItem() |
|
3078 |
: QGraphicsRectItem(QRectF(0, 0, 100, 100)) |
|
3079 |
{ |
|
3080 |
} |
|
3081 |
||
3082 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
3083 |
{ |
|
3084 |
transform = painter->transform(); |
|
3085 |
} |
|
3086 |
||
3087 |
QTransform transform; |
|
3088 |
}; |
|
3089 |
||
3090 |
void tst_QGraphicsView::embeddedViews() |
|
3091 |
{ |
|
3092 |
QGraphicsView *v1 = createSimpleViewAndScene(); |
|
3093 |
QGraphicsView *v2 = createSimpleViewAndScene(); |
|
3094 |
||
3095 |
QGraphicsProxyWidget *proxy = v1->scene()->addWidget(v2); |
|
3096 |
||
3097 |
SpyItem *item = new SpyItem; |
|
3098 |
v2->scene()->addItem(item); |
|
3099 |
||
3100 |
proxy->translate(5, 5); |
|
3101 |
||
3102 |
QImage actual(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
3103 |
actual.fill(0); |
|
3104 |
v1->QWidget::render(&actual); |
|
3105 |
QTransform a = item->transform; |
|
3106 |
||
3107 |
v2->QWidget::render(&actual); |
|
3108 |
QTransform b = item->transform; |
|
3109 |
||
3110 |
QVERIFY(a == b); |
|
3111 |
delete v1; |
|
3112 |
} |
|
3113 |
||
3114 |
void tst_QGraphicsView::scrollAfterResize_data() |
|
3115 |
{ |
|
3116 |
QTest::addColumn<bool>("reverse"); |
|
3117 |
QTest::addColumn<QTransform>("x1"); |
|
3118 |
QTest::addColumn<QTransform>("x2"); |
|
3119 |
QTest::addColumn<QTransform>("x3"); |
|
3120 |
||
3121 |
#if !defined(QT_NO_STYLE_PLASTIQUE) |
|
3122 |
QPlastiqueStyle style; |
|
3123 |
#elif !defined(QT_NO_STYLE_WINDOWS) |
|
3124 |
QWindowsStyle style; |
|
3125 |
#else |
|
3126 |
QCommonStyle style; |
|
3127 |
#endif |
|
3128 |
||
3129 |
int frameWidth = style.pixelMetric(QStyle::PM_DefaultFrameWidth); |
|
3130 |
int extent = style.pixelMetric(QStyle::PM_ScrollBarExtent); |
|
3131 |
int inside = style.styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents); |
|
3132 |
int viewportWidth = 300; |
|
3133 |
int scrollBarIndent = viewportWidth - extent - (inside ? 4 : 2)*frameWidth; |
|
3134 |
||
3135 |
QTest::newRow("normal") << false |
|
3136 |
<< QTransform() |
|
3137 |
<< QTransform() |
|
3138 |
<< QTransform().translate(-10, 0); |
|
3139 |
QTest::newRow("reverse") << true |
|
3140 |
<< QTransform().translate(scrollBarIndent, 0) |
|
3141 |
<< QTransform().translate(scrollBarIndent + 100, 0) |
|
3142 |
<< QTransform().translate(scrollBarIndent + 110, 0); |
|
3143 |
} |
|
3144 |
||
3145 |
void tst_QGraphicsView::scrollAfterResize() |
|
3146 |
{ |
|
3147 |
QFETCH(bool, reverse); |
|
3148 |
QFETCH(QTransform, x1); |
|
3149 |
QFETCH(QTransform, x2); |
|
3150 |
QFETCH(QTransform, x3); |
|
3151 |
||
3152 |
#if !defined(QT_NO_STYLE_PLASTIQUE) |
|
3153 |
QPlastiqueStyle style; |
|
3154 |
#elif !defined(QT_NO_STYLE_WINDOWS) |
|
3155 |
QWindowsStyle style; |
|
3156 |
#else |
|
3157 |
QCommonStyle style; |
|
3158 |
#endif |
|
3159 |
QGraphicsView view; |
|
3160 |
view.setStyle(&style); |
|
3161 |
if (reverse) |
|
3162 |
view.setLayoutDirection(Qt::RightToLeft); |
|
3163 |
||
3164 |
view.setSceneRect(-1000, -1000, 2000, 2000); |
|
3165 |
view.resize(300, 300); |
|
3166 |
view.show(); |
|
3167 |
QTest::qWaitForWindowShown(&view); |
|
3168 |
view.horizontalScrollBar()->setValue(0); |
|
3169 |
view.verticalScrollBar()->setValue(0); |
|
3170 |
QCOMPARE(view.viewportTransform(), x1); |
|
3171 |
view.resize(400, 300); |
|
3172 |
QCOMPARE(view.viewportTransform(), x2); |
|
3173 |
view.horizontalScrollBar()->setValue(10); |
|
3174 |
QCOMPARE(view.viewportTransform(), x3); |
|
3175 |
} |
|
3176 |
||
3177 |
void tst_QGraphicsView::moveItemWhileScrolling_data() |
|
3178 |
{ |
|
3179 |
QTest::addColumn<bool>("adjustForAntialiasing"); |
|
3180 |
||
3181 |
QTest::newRow("no adjust") << false; |
|
3182 |
QTest::newRow("adjust") << true; |
|
3183 |
} |
|
3184 |
||
3185 |
void tst_QGraphicsView::moveItemWhileScrolling() |
|
3186 |
{ |
|
3187 |
QFETCH(bool, adjustForAntialiasing); |
|
3188 |
||
3189 |
class MoveItemScrollView : public QGraphicsView |
|
3190 |
{ |
|
3191 |
public: |
|
3192 |
MoveItemScrollView() |
|
3193 |
{ |
|
3194 |
setWindowFlags(Qt::X11BypassWindowManagerHint); |
|
3195 |
setScene(new QGraphicsScene(0, 0, 1000, 1000)); |
|
3196 |
rect = scene()->addRect(0, 0, 10, 10); |
|
3197 |
rect->setPos(50, 50); |
|
3198 |
painted = false; |
|
3199 |
} |
|
3200 |
QRegion lastPaintedRegion; |
|
3201 |
QGraphicsItem *rect; |
|
3202 |
bool painted; |
|
3203 |
void waitForPaintEvent() |
|
3204 |
{ |
|
3205 |
QTimer::singleShot(2000, &eventLoop, SLOT(quit())); |
|
3206 |
eventLoop.exec(); |
|
3207 |
} |
|
3208 |
protected: |
|
3209 |
QEventLoop eventLoop; |
|
3210 |
void paintEvent(QPaintEvent *event) |
|
3211 |
{ |
|
3212 |
painted = true; |
|
3213 |
lastPaintedRegion = event->region(); |
|
3214 |
QGraphicsView::paintEvent(event); |
|
3215 |
if (eventLoop.isRunning()) |
|
3216 |
eventLoop.quit(); |
|
3217 |
} |
|
3218 |
}; |
|
3219 |
||
3220 |
MoveItemScrollView view; |
|
3221 |
view.setFrameStyle(0); |
|
3222 |
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
3223 |
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
3224 |
view.setResizeAnchor(QGraphicsView::NoAnchor); |
|
3225 |
view.setTransformationAnchor(QGraphicsView::NoAnchor); |
|
3226 |
if (!adjustForAntialiasing) |
|
3227 |
view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing); |
|
3228 |
view.resize(200, 200); |
|
3229 |
view.painted = false; |
|
3230 |
view.show(); |
|
3231 |
QTest::qWaitForWindowShown(&view); |
|
3232 |
QApplication::processEvents(); |
|
3233 |
QTRY_VERIFY(view.painted); |
|
3234 |
view.painted = false; |
|
3235 |
view.lastPaintedRegion = QRegion(); |
|
3236 |
view.horizontalScrollBar()->setValue(view.horizontalScrollBar()->value() + 10); |
|
3237 |
view.rect->moveBy(0, 10); |
|
3238 |
view.waitForPaintEvent(); |
|
3239 |
QTRY_VERIFY(view.painted); |
|
3240 |
||
3241 |
QRegion expectedRegion; |
|
3242 |
expectedRegion += QRect(0, 0, 200, 200); |
|
3243 |
expectedRegion -= QRect(0, 0, 190, 200); |
|
3244 |
int a = adjustForAntialiasing ? 2 : 1; |
|
3245 |
expectedRegion += QRect(40, 50, 10, 10).adjusted(-a, -a, a, a); |
|
3246 |
expectedRegion += QRect(40, 60, 10, 10).adjusted(-a, -a, a, a); |
|
3247 |
COMPARE_REGIONS(view.lastPaintedRegion, expectedRegion); |
|
3248 |
} |
|
3249 |
||
3250 |
void tst_QGraphicsView::centerOnDirtyItem() |
|
3251 |
{ |
|
3252 |
QGraphicsView view; |
|
3253 |
view.setWindowFlags(view.windowFlags() | Qt::WindowStaysOnTopHint); |
|
3254 |
view.resize(200, 200); |
|
3255 |
||
3256 |
QGraphicsScene *scene = new QGraphicsScene; |
|
3257 |
view.setScene(scene); |
|
3258 |
view.setSceneRect(-1000, -1000, 2000, 2000); |
|
3259 |
||
3260 |
QGraphicsRectItem *item = new QGraphicsRectItem(0, 0, 10, 10); |
|
3261 |
item->setBrush(Qt::red); |
|
3262 |
scene->addItem(item); |
|
3263 |
view.centerOn(item); |
|
3264 |
||
3265 |
view.show(); |
|
3266 |
QTest::qWaitForWindowShown(&view); |
|
3267 |
||
3268 |
QImage before(view.viewport()->size(), QImage::Format_ARGB32); |
|
3269 |
view.viewport()->render(&before); |
|
3270 |
||
3271 |
item->setPos(20, 0); |
|
3272 |
view.centerOn(item); |
|
3273 |
||
3274 |
QTest::qWait(50); |
|
3275 |
||
3276 |
QImage after(view.viewport()->size(), QImage::Format_ARGB32); |
|
3277 |
view.viewport()->render(&after); |
|
3278 |
||
3279 |
QCOMPARE(before, after); |
|
3280 |
} |
|
3281 |
||
3282 |
void tst_QGraphicsView::mouseTracking() |
|
3283 |
{ |
|
3284 |
// Mouse tracking should only be automatically enabled if items either accept hover events |
|
3285 |
// or have a cursor set. We never disable mouse tracking if it is already enabled. |
|
3286 |
||
3287 |
{ // Make sure mouse tracking is disabled by default. |
|
3288 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3289 |
QGraphicsView view(&scene); |
|
3290 |
QVERIFY(!view.viewport()->hasMouseTracking()); |
|
3291 |
} |
|
3292 |
||
3293 |
{ // Make sure we don't disable mouse tracking in setupViewport/setScene. |
|
3294 |
QGraphicsView view; |
|
3295 |
QWidget *viewport = new QWidget; |
|
3296 |
viewport->setMouseTracking(true); |
|
3297 |
view.setViewport(viewport); |
|
3298 |
QVERIFY(viewport->hasMouseTracking()); |
|
3299 |
||
3300 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3301 |
view.setScene(&scene); |
|
3302 |
QVERIFY(viewport->hasMouseTracking()); |
|
3303 |
} |
|
3304 |
||
3305 |
// Make sure we enable mouse tracking when having items that accept hover events. |
|
3306 |
{ |
|
3307 |
// Adding an item to the scene after the scene is set on the view. |
|
3308 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3309 |
QGraphicsView view(&scene); |
|
3310 |
||
3311 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
|
3312 |
item->setAcceptHoverEvents(true); |
|
3313 |
scene.addItem(item); |
|
3314 |
QVERIFY(view.viewport()->hasMouseTracking()); |
|
3315 |
} |
|
3316 |
{ |
|
3317 |
// Adding an item to the scene before the scene is set on the view. |
|
3318 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3319 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
|
3320 |
item->setAcceptHoverEvents(true); |
|
3321 |
scene.addItem(item); |
|
3322 |
||
3323 |
QGraphicsView view(&scene); |
|
3324 |
QVERIFY(view.viewport()->hasMouseTracking()); |
|
3325 |
} |
|
3326 |
{ |
|
3327 |
// QGraphicsWidget implicitly accepts hover if it has window decoration. |
|
3328 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3329 |
QGraphicsView view(&scene); |
|
3330 |
||
3331 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
3332 |
scene.addItem(widget); |
|
3333 |
QVERIFY(!view.viewport()->hasMouseTracking()); |
|
3334 |
// Enable window decoraton. |
|
3335 |
widget->setWindowFlags(Qt::Window | Qt::WindowTitleHint); |
|
3336 |
QVERIFY(view.viewport()->hasMouseTracking()); |
|
3337 |
} |
|
3338 |
||
3339 |
// Make sure we enable mouse tracking when having items with a cursor set. |
|
3340 |
{ |
|
3341 |
// Adding an item to the scene after the scene is set on the view. |
|
3342 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3343 |
QGraphicsView view(&scene); |
|
3344 |
||
3345 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
|
3346 |
#ifndef QT_NO_CURSOR |
|
3347 |
item->setCursor(Qt::CrossCursor); |
|
3348 |
#endif |
|
3349 |
scene.addItem(item); |
|
3350 |
QVERIFY(view.viewport()->hasMouseTracking()); |
|
3351 |
} |
|
3352 |
{ |
|
3353 |
// Adding an item to the scene before the scene is set on the view. |
|
3354 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3355 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
|
3356 |
#ifndef QT_NO_CURSOR |
|
3357 |
item->setCursor(Qt::CrossCursor); |
|
3358 |
#endif |
|
3359 |
scene.addItem(item); |
|
3360 |
||
3361 |
QGraphicsView view(&scene); |
|
3362 |
QVERIFY(view.viewport()->hasMouseTracking()); |
|
3363 |
} |
|
3364 |
||
3365 |
// Make sure we propagate mouse tracking to all views. |
|
3366 |
{ |
|
3367 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
|
3368 |
QGraphicsView view1(&scene); |
|
3369 |
QGraphicsView view2(&scene); |
|
3370 |
QGraphicsView view3(&scene); |
|
3371 |
||
3372 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
|
3373 |
#ifndef QT_NO_CURSOR |
|
3374 |
item->setCursor(Qt::CrossCursor); |
|
3375 |
#endif |
|
3376 |
scene.addItem(item); |
|
3377 |
||
3378 |
QVERIFY(view1.viewport()->hasMouseTracking()); |
|
3379 |
QVERIFY(view2.viewport()->hasMouseTracking()); |
|
3380 |
QVERIFY(view3.viewport()->hasMouseTracking()); |
|
3381 |
} |
|
3382 |
} |
|
3383 |
||
3384 |
void tst_QGraphicsView::mouseTracking2() |
|
3385 |
{ |
|
3386 |
// Make sure mouse move events propagates to the scene when |
|
3387 |
// mouse tracking is explicitly enabled on the view, |
|
3388 |
// even when all items ignore hover events / use default cursor. |
|
3389 |
||
3390 |
QGraphicsScene scene; |
|
3391 |
scene.addRect(0, 0, 100, 100); |
|
3392 |
||
3393 |
QGraphicsView view(&scene); |
|
3394 |
view.show(); |
|
3395 |
QTest::qWaitForWindowShown(&view); |
|
3396 |
||
3397 |
QVERIFY(!view.viewport()->hasMouseTracking()); |
|
3398 |
view.viewport()->setMouseTracking(true); // Explicitly enable mouse tracking. |
|
3399 |
QVERIFY(view.viewport()->hasMouseTracking()); |
|
3400 |
||
3401 |
EventSpy spy(&scene, QEvent::GraphicsSceneMouseMove); |
|
3402 |
QCOMPARE(spy.count(), 0); |
|
3403 |
QMouseEvent event(QEvent::MouseMove,view.viewport()->rect().center(), Qt::NoButton, |
|
3404 |
Qt::MouseButtons(Qt::NoButton), 0); |
|
3405 |
QApplication::sendEvent(view.viewport(), &event); |
|
3406 |
QCOMPARE(spy.count(), 1); |
|
3407 |
} |
|
3408 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3409 |
void tst_QGraphicsView::mouseTracking3() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3410 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3411 |
// Mouse tracking should be automatically enabled if AnchorUnderMouse is used for |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3412 |
// view transform or resize. We never disable mouse tracking if it is already enabled. |
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 |
{ // Make sure we enable mouse tracking when using AnchorUnderMouse for view transformation. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3415 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3416 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3417 |
QVERIFY(!view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3418 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3419 |
view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3420 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3421 |
} |
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 |
{ // Make sure we enable mouse tracking when using AnchorUnderMouse for view resizing. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3424 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3425 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3426 |
QVERIFY(!view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3427 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3428 |
view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3429 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3430 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3431 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3432 |
{ // Make sure we don't disable mouse tracking in setViewport/setScene (transformation anchor). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3433 |
QGraphicsView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3434 |
view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3435 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3436 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3437 |
QWidget *viewport = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3438 |
view.setViewport(viewport); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3439 |
QVERIFY(viewport->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3440 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3441 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3442 |
view.setScene(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3443 |
QVERIFY(viewport->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3444 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3445 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3446 |
{ // Make sure we don't disable mouse tracking in setViewport/setScene (resize anchor). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3447 |
QGraphicsView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3448 |
view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3449 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3450 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3451 |
QWidget *viewport = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3452 |
view.setViewport(viewport); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3453 |
QVERIFY(viewport->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3454 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3455 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3456 |
view.setScene(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3457 |
QVERIFY(viewport->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3458 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3459 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3460 |
// Make sure we don't disable mouse tracking when adding an item (transformation anchor). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3461 |
{ // Adding an item to the scene before the scene is set on the view. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3462 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3463 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3464 |
scene.addItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3465 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3466 |
QGraphicsView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3467 |
view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3468 |
view.setScene(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3469 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3470 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3471 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3472 |
{ // Adding an item to the scene after the scene is set on the view. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3473 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3474 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3475 |
view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3476 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3477 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3478 |
scene.addItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3479 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3480 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3481 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3482 |
// Make sure we don't disable mouse tracking when adding an item (resize anchor). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3483 |
{ // Adding an item to the scene before the scene is set on the view. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3484 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3485 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3486 |
scene.addItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3487 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3488 |
QGraphicsView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3489 |
view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3490 |
view.setScene(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3491 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3492 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3493 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3494 |
{ // Adding an item to the scene after the scene is set on the view. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3495 |
QGraphicsScene scene(-10000, -10000, 20000, 20000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3496 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3497 |
view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3498 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3499 |
QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3500 |
scene.addItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3501 |
QVERIFY(view.viewport()->hasMouseTracking()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3502 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3503 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3504 |
|
0 | 3505 |
class RenderTester : public QGraphicsRectItem |
3506 |
{ |
|
3507 |
public: |
|
3508 |
RenderTester(const QRectF &rect) |
|
3509 |
: QGraphicsRectItem(rect), paints(0) |
|
3510 |
{ } |
|
3511 |
||
3512 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
3513 |
QWidget *widget) |
|
3514 |
{ |
|
3515 |
QGraphicsRectItem::paint(painter, option, widget); |
|
3516 |
++paints; |
|
3517 |
} |
|
3518 |
||
3519 |
int paints; |
|
3520 |
}; |
|
3521 |
||
3522 |
void tst_QGraphicsView::render() |
|
3523 |
{ |
|
3524 |
// ### This test can be much more thorough - see QGraphicsScene::render. |
|
3525 |
QGraphicsScene scene; |
|
3526 |
CustomView view(&scene); |
|
3527 |
view.setFrameStyle(0); |
|
3528 |
view.resize(200, 200); |
|
3529 |
view.painted = false; |
|
3530 |
view.show(); |
|
3531 |
QTest::qWaitForWindowShown(&view); |
|
3532 |
QApplication::processEvents(); |
|
3533 |
QTRY_VERIFY(view.painted > 0); |
|
3534 |
||
3535 |
RenderTester *r1 = new RenderTester(QRectF(0, 0, 50, 50)); |
|
3536 |
RenderTester *r2 = new RenderTester(QRectF(50, 50, 50, 50)); |
|
3537 |
RenderTester *r3 = new RenderTester(QRectF(0, 50, 50, 50)); |
|
3538 |
RenderTester *r4 = new RenderTester(QRectF(50, 0, 50, 50)); |
|
3539 |
scene.addItem(r1); |
|
3540 |
scene.addItem(r2); |
|
3541 |
scene.addItem(r3); |
|
3542 |
scene.addItem(r4); |
|
3543 |
||
3544 |
qApp->processEvents(); |
|
3545 |
||
3546 |
QTRY_COMPARE(r1->paints, 1); |
|
3547 |
QCOMPARE(r2->paints, 1); |
|
3548 |
QCOMPARE(r3->paints, 1); |
|
3549 |
QCOMPARE(r4->paints, 1); |
|
3550 |
||
3551 |
QPixmap pix(200, 200); |
|
3552 |
pix.fill(Qt::transparent); |
|
3553 |
QPainter painter(&pix); |
|
3554 |
view.render(&painter); |
|
3555 |
painter.end(); |
|
3556 |
||
3557 |
QCOMPARE(r1->paints, 2); |
|
3558 |
QCOMPARE(r2->paints, 2); |
|
3559 |
QCOMPARE(r3->paints, 2); |
|
3560 |
QCOMPARE(r4->paints, 2); |
|
3561 |
} |
|
3562 |
||
3563 |
void tst_QGraphicsView::exposeRegion() |
|
3564 |
{ |
|
3565 |
RenderTester *item = new RenderTester(QRectF(0, 0, 20, 20)); |
|
3566 |
QGraphicsScene scene; |
|
3567 |
scene.addItem(item); |
|
3568 |
||
3569 |
item->paints = 0; |
|
3570 |
CustomView view; |
|
3571 |
view.setScene(&scene); |
|
3572 |
view.show(); |
|
3573 |
QTest::qWaitForWindowShown(&view); |
|
3574 |
QTRY_VERIFY(item->paints > 0); |
|
3575 |
||
3576 |
item->paints = 0; |
|
3577 |
view.lastUpdateRegions.clear(); |
|
3578 |
||
3579 |
// Update a small area in the viewport's topLeft() and bottomRight(). |
|
3580 |
// (the boundingRect() of this area covers the entire viewport). |
|
3581 |
QWidget *viewport = view.viewport(); |
|
3582 |
QRegion expectedExposeRegion = QRect(0, 0, 5, 5); |
|
3583 |
expectedExposeRegion += QRect(viewport->rect().bottomRight() - QPoint(5, 5), QSize(5, 5)); |
|
3584 |
viewport->update(expectedExposeRegion); |
|
3585 |
QApplication::processEvents(); |
|
3586 |
||
3587 |
// Make sure it triggers correct repaint on the view. |
|
3588 |
QTRY_COMPARE(view.lastUpdateRegions.size(), 1); |
|
3589 |
COMPARE_REGIONS(view.lastUpdateRegions.at(0), expectedExposeRegion); |
|
3590 |
||
3591 |
// Make sure the item didn't get any repaints. |
|
3592 |
#ifndef QT_MAC_USE_COCOA |
|
3593 |
QCOMPARE(item->paints, 0); |
|
3594 |
#endif |
|
3595 |
} |
|
3596 |
||
3597 |
void tst_QGraphicsView::update_data() |
|
3598 |
{ |
|
3599 |
// In view.viewport() coordinates. (viewport rect: QRect(0, 0, 200, 200)) |
|
3600 |
QTest::addColumn<QRect>("updateRect"); |
|
3601 |
QTest::newRow("empty") << QRect(); |
|
3602 |
QTest::newRow("outside left") << QRect(-200, 0, 100, 100); |
|
3603 |
QTest::newRow("outside right") << QRect(400, 0 ,100, 100); |
|
3604 |
QTest::newRow("outside top") << QRect(0, -200, 100, 100); |
|
3605 |
QTest::newRow("outside bottom") << QRect(0, 400, 100, 100); |
|
3606 |
QTest::newRow("partially inside left") << QRect(-50, 0, 100, 100); |
|
3607 |
QTest::newRow("partially inside right") << QRect(-150, 0, 100, 100); |
|
3608 |
QTest::newRow("partially inside top") << QRect(0, -150, 100, 100); |
|
3609 |
QTest::newRow("partially inside bottom") << QRect(0, 150, 100, 100); |
|
3610 |
QTest::newRow("on topLeft edge") << QRect(-100, -100, 100, 100); |
|
3611 |
QTest::newRow("on topRight edge") << QRect(200, -100, 100, 100); |
|
3612 |
QTest::newRow("on bottomRight edge") << QRect(200, 200, 100, 100); |
|
3613 |
QTest::newRow("on bottomLeft edge") << QRect(-200, 200, 100, 100); |
|
3614 |
QTest::newRow("inside topLeft") << QRect(-99, -99, 100, 100); |
|
3615 |
QTest::newRow("inside topRight") << QRect(199, -99, 100, 100); |
|
3616 |
QTest::newRow("inside bottomRight") << QRect(199, 199, 100, 100); |
|
3617 |
QTest::newRow("inside bottomLeft") << QRect(-199, 199, 100, 100); |
|
3618 |
QTest::newRow("large1") << QRect(50, -100, 100, 400); |
|
3619 |
QTest::newRow("large2") << QRect(-100, 50, 400, 100); |
|
3620 |
QTest::newRow("large3") << QRect(-100, -100, 400, 400); |
|
3621 |
QTest::newRow("viewport rect") << QRect(0, 0, 200, 200); |
|
3622 |
} |
|
3623 |
||
3624 |
void tst_QGraphicsView::update() |
|
3625 |
{ |
|
3626 |
QFETCH(QRect, updateRect); |
|
3627 |
||
3628 |
// Create a view with viewport rect equal to QRect(0, 0, 200, 200). |
|
3629 |
QGraphicsScene dummyScene; |
|
3630 |
CustomView view; |
|
3631 |
view.setScene(&dummyScene); |
|
3632 |
int left, top, right, bottom; |
|
3633 |
view.getContentsMargins(&left, &top, &right, &bottom); |
|
3634 |
view.resize(200 + left + right, 200 + top + bottom); |
|
3635 |
view.show(); |
|
3636 |
QTest::qWaitForWindowShown(&view); |
|
3637 |
||
3638 |
QApplication::setActiveWindow(&view); |
|
3639 |
QApplication::processEvents(); |
|
3640 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
3641 |
||
3642 |
const QRect viewportRect = view.viewport()->rect(); |
|
3643 |
QCOMPARE(viewportRect, QRect(0, 0, 200, 200)); |
|
3644 |
||
3645 |
#if defined QT_BUILD_INTERNAL |
|
3646 |
const bool intersects = updateRect.intersects(viewportRect); |
|
3647 |
QGraphicsViewPrivate *viewPrivate = static_cast<QGraphicsViewPrivate *>(qt_widget_private(&view)); |
|
3648 |
QTRY_COMPARE(viewPrivate->updateRect(updateRect), intersects); |
|
3649 |
QCOMPARE(viewPrivate->updateRegion(updateRect), intersects); |
|
3650 |
||
3651 |
view.lastUpdateRegions.clear(); |
|
3652 |
viewPrivate->processPendingUpdates(); |
|
3653 |
QVERIFY(viewPrivate->dirtyRegion.isEmpty()); |
|
3654 |
QVERIFY(viewPrivate->dirtyBoundingRect.isEmpty()); |
|
3655 |
QApplication::processEvents(); |
|
3656 |
if (!intersects) { |
|
3657 |
QTRY_VERIFY(view.lastUpdateRegions.isEmpty()); |
|
3658 |
} else { |
|
3659 |
QTRY_COMPARE(view.lastUpdateRegions.size(), 1); |
|
3660 |
// Note that we adjust by 2 for antialiasing. |
|
3661 |
QTRY_COMPARE(view.lastUpdateRegions.at(0), QRegion(updateRect.adjusted(-2, -2, 2, 2) & viewportRect)); |
|
3662 |
} |
|
3663 |
QTRY_VERIFY(!viewPrivate->fullUpdatePending); |
|
3664 |
#endif |
|
3665 |
} |
|
3666 |
||
3667 |
void tst_QGraphicsView::inputMethodSensitivity() |
|
3668 |
{ |
|
3669 |
QGraphicsScene scene; |
|
3670 |
QGraphicsView view(&scene); |
|
3671 |
view.show(); |
|
3672 |
QTest::qWaitForWindowShown(&view); |
|
3673 |
QApplication::setActiveWindow(&view); |
|
3674 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
3675 |
||
3676 |
QGraphicsRectItem *item = new QGraphicsRectItem; |
|
3677 |
||
3678 |
view.setAttribute(Qt::WA_InputMethodEnabled, true); |
|
3679 |
||
3680 |
scene.addItem(item); |
|
3681 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3682 |
||
3683 |
scene.removeItem(item); |
|
3684 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3685 |
||
3686 |
item->setFlag(QGraphicsItem::ItemAcceptsInputMethod); |
|
3687 |
scene.addItem(item); |
|
3688 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3689 |
||
3690 |
scene.removeItem(item); |
|
3691 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3692 |
||
3693 |
scene.addItem(item); |
|
3694 |
scene.setFocusItem(item); |
|
3695 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3696 |
||
3697 |
scene.removeItem(item); |
|
3698 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3699 |
||
3700 |
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
3701 |
scene.addItem(item); |
|
3702 |
scene.setFocusItem(item); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3703 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3704 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
3705 |
||
3706 |
item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false); |
|
3707 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3708 |
||
3709 |
item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); |
|
3710 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3711 |
||
3712 |
// introduce another item that is focusable but does not accept input methods |
|
3713 |
QGraphicsRectItem *item2 = new QGraphicsRectItem; |
|
3714 |
item2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
3715 |
scene.addItem(item2); |
|
3716 |
scene.setFocusItem(item2); |
|
3717 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3718 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
0 | 3719 |
|
3720 |
scene.setFocusItem(item); |
|
3721 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3722 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3723 |
|
3724 |
view.setScene(0); |
|
3725 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3726 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3727 |
|
3728 |
view.setScene(&scene); |
|
3729 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3730 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3731 |
|
3732 |
scene.setFocusItem(item2); |
|
3733 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3734 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
0 | 3735 |
|
3736 |
view.setScene(0); |
|
3737 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3738 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
0 | 3739 |
|
3740 |
scene.setFocusItem(item); |
|
3741 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3742 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3743 |
|
3744 |
view.setScene(&scene); |
|
3745 |
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3746 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
0 | 3747 |
} |
3748 |
||
3749 |
class InputContextTester : public QInputContext |
|
3750 |
{ |
|
3751 |
Q_OBJECT |
|
3752 |
public: |
|
3753 |
QString identifierName() { return QString(); } |
|
3754 |
bool isComposing() const { return false; } |
|
3755 |
QString language() { return QString(); } |
|
3756 |
void reset() { ++resets; } |
|
3757 |
int resets; |
|
3758 |
}; |
|
3759 |
||
3760 |
void tst_QGraphicsView::inputContextReset() |
|
3761 |
{ |
|
3762 |
QGraphicsScene scene; |
|
3763 |
QGraphicsView view(&scene); |
|
3764 |
QVERIFY(view.testAttribute(Qt::WA_InputMethodEnabled)); |
|
3765 |
||
3766 |
InputContextTester inputContext; |
|
3767 |
view.setInputContext(&inputContext); |
|
3768 |
||
3769 |
view.show(); |
|
3770 |
QTest::qWaitForWindowShown(&view); |
|
3771 |
QApplication::setActiveWindow(&view); |
|
3772 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
3773 |
||
3774 |
QGraphicsItem *item1 = new QGraphicsRectItem; |
|
3775 |
item1->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod); |
|
3776 |
||
3777 |
inputContext.resets = 0; |
|
3778 |
scene.addItem(item1); |
|
3779 |
QCOMPARE(inputContext.resets, 0); |
|
3780 |
||
3781 |
inputContext.resets = 0; |
|
3782 |
scene.setFocusItem(item1); |
|
3783 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *)item1); |
|
3784 |
QVERIFY(view.testAttribute(Qt::WA_InputMethodEnabled)); |
|
3785 |
QCOMPARE(inputContext.resets, 0); |
|
3786 |
||
3787 |
inputContext.resets = 0; |
|
3788 |
scene.setFocusItem(0); |
|
3789 |
QCOMPARE(inputContext.resets, 1); |
|
3790 |
||
3791 |
// introduce another item that is focusable but does not accept input methods |
|
3792 |
QGraphicsItem *item2 = new QGraphicsRectItem; |
|
3793 |
item1->setFlags(QGraphicsItem::ItemIsFocusable); |
|
3794 |
||
3795 |
inputContext.resets = 0; |
|
3796 |
scene.setFocusItem(item2); |
|
3797 |
QCOMPARE(inputContext.resets, 0); |
|
3798 |
||
3799 |
inputContext.resets = 0; |
|
3800 |
scene.setFocusItem(item1); |
|
3801 |
QCOMPARE(inputContext.resets, 0); |
|
3802 |
} |
|
3803 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3804 |
void tst_QGraphicsView::indirectPainting() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3805 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3806 |
class MyScene : public QGraphicsScene |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3807 |
{ public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3808 |
MyScene() : QGraphicsScene(), drawCount(0) {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3809 |
void drawItems(QPainter *, int, QGraphicsItem **, const QStyleOptionGraphicsItem *, QWidget *) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3810 |
{ ++drawCount; } |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3811 |
int drawCount; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3812 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3813 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3814 |
MyScene scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3815 |
QGraphicsItem *item = scene.addRect(0, 0, 50, 50); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3816 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3817 |
QGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3818 |
view.setOptimizationFlag(QGraphicsView::IndirectPainting); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3819 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3820 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3821 |
QTest::qWait(100); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3822 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3823 |
scene.drawCount = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3824 |
item->setPos(20, 20); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3825 |
QApplication::processEvents(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3826 |
QTRY_VERIFY(scene.drawCount > 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3827 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3828 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3829 |
void tst_QGraphicsView::compositionModeInDrawBackground() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3830 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3831 |
class MyView : public QGraphicsView |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3832 |
{ public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3833 |
MyView(QGraphicsScene *scene) : QGraphicsView(scene), |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3834 |
painted(false), compositionMode(QPainter::CompositionMode_SourceOver) {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3835 |
bool painted; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3836 |
QPainter::CompositionMode compositionMode; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3837 |
void drawBackground(QPainter *painter, const QRectF &) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3838 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3839 |
compositionMode = painter->compositionMode(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3840 |
painted = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3841 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3842 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3843 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3844 |
QGraphicsScene dummy; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3845 |
MyView view(&dummy); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3846 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3847 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3848 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3849 |
// Make sure the painter's composition mode is SourceOver in drawBackground. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3850 |
QTRY_VERIFY(view.painted); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3851 |
QCOMPARE(view.compositionMode, QPainter::CompositionMode_SourceOver); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3852 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3853 |
view.painted = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3854 |
view.setCacheMode(QGraphicsView::CacheBackground); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3855 |
view.viewport()->update(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3856 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3857 |
// Make sure the painter's composition mode is SourceOver in drawBackground |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3858 |
// with background cache enabled. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3859 |
QTRY_VERIFY(view.painted); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3860 |
QCOMPARE(view.compositionMode, QPainter::CompositionMode_SourceOver); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3861 |
} |
0 | 3862 |
void tst_QGraphicsView::task253415_reconnectUpdateSceneOnSceneChanged() |
3863 |
{ |
|
3864 |
QGraphicsView view; |
|
3865 |
QGraphicsView dummyView; |
|
3866 |
view.setWindowFlags(view.windowFlags() | Qt::WindowStaysOnTopHint); |
|
3867 |
view.resize(200, 200); |
|
3868 |
||
3869 |
QGraphicsScene scene1; |
|
3870 |
QObject::connect(&scene1, SIGNAL(changed(QList<QRectF>)), &dummyView, SLOT(updateScene(QList<QRectF>))); |
|
3871 |
view.setScene(&scene1); |
|
3872 |
||
3873 |
QTest::qWait(12); |
|
3874 |
||
3875 |
QGraphicsScene scene2; |
|
3876 |
QObject::connect(&scene2, SIGNAL(changed(QList<QRectF>)), &dummyView, SLOT(updateScene(QList<QRectF>))); |
|
3877 |
view.setScene(&scene2); |
|
3878 |
||
3879 |
QTest::qWait(12); |
|
3880 |
||
3881 |
bool wasConnected2 = QObject::disconnect(&scene2, SIGNAL(changed(QList<QRectF>)), &view, 0); |
|
3882 |
QVERIFY(wasConnected2); |
|
3883 |
} |
|
3884 |
||
3885 |
void tst_QGraphicsView::task255529_transformationAnchorMouseAndViewportMargins() |
|
3886 |
{ |
|
3887 |
#if defined(Q_OS_WINCE) |
|
3888 |
QSKIP("Qt/CE does not implement mouse tracking at this point", SkipAll); |
|
3889 |
#endif |
|
3890 |
||
3891 |
QGraphicsScene scene(-100, -100, 200, 200); |
|
3892 |
scene.addRect(QRectF(-50, -50, 100, 100), QPen(Qt::black), QBrush(Qt::blue)); |
|
3893 |
||
3894 |
class VpGraphicsView: public QGraphicsView |
|
3895 |
{ |
|
3896 |
public: |
|
3897 |
VpGraphicsView(QGraphicsScene *scene) |
|
3898 |
: QGraphicsView(scene) |
|
3899 |
{ |
|
3900 |
setViewportMargins(8, 16, 12, 20); |
|
3901 |
setTransformationAnchor(QGraphicsView::AnchorUnderMouse); |
|
3902 |
setMouseTracking(true); |
|
3903 |
} |
|
3904 |
}; |
|
3905 |
||
3906 |
VpGraphicsView view(&scene); |
|
3907 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
|
3908 |
view.show(); |
|
3909 |
QTest::qWaitForWindowShown(&view); |
|
3910 |
QTest::qWait(50); |
|
3911 |
QPoint mouseViewPos(20, 20); |
|
3912 |
sendMouseMove(view.viewport(), mouseViewPos); |
|
3913 |
||
3914 |
QPointF mouseScenePos = view.mapToScene(mouseViewPos); |
|
3915 |
view.setTransform(QTransform().scale(5, 5).rotate(5, Qt::ZAxis), true); |
|
3916 |
||
3917 |
QPointF newMouseScenePos = view.mapToScene(mouseViewPos); |
|
3918 |
||
3919 |
qreal slack = 1; |
|
3920 |
QVERIFY(qAbs(newMouseScenePos.x() - mouseScenePos.x()) < slack); |
|
3921 |
QVERIFY(qAbs(newMouseScenePos.y() - mouseScenePos.y()) < slack); |
|
3922 |
} |
|
3923 |
||
3924 |
void tst_QGraphicsView::task259503_scrollingArtifacts() |
|
3925 |
{ |
|
3926 |
QGraphicsScene scene(0, 0, 800, 600); |
|
3927 |
||
3928 |
QGraphicsRectItem card; |
|
3929 |
card.setRect(0, 0, 50, 50); |
|
3930 |
card.setPen(QPen(Qt::darkRed)); |
|
3931 |
card.setBrush(QBrush(Qt::cyan)); |
|
3932 |
card.setZValue(2.0); |
|
3933 |
card.setPos(300, 300); |
|
3934 |
scene.addItem(&card); |
|
3935 |
||
3936 |
class SAGraphicsView: public QGraphicsView |
|
3937 |
{ |
|
3938 |
public: |
|
3939 |
SAGraphicsView(QGraphicsScene *scene) |
|
3940 |
: QGraphicsView(scene) |
|
3941 |
, itSTimeToTest(false) |
|
3942 |
{ |
|
3943 |
setViewportUpdateMode( QGraphicsView::MinimalViewportUpdate ); |
|
3944 |
resize(QSize(640, 480)); |
|
3945 |
} |
|
3946 |
||
3947 |
QRegion updateRegion; |
|
3948 |
bool itSTimeToTest; |
|
3949 |
||
3950 |
void paintEvent(QPaintEvent *event) |
|
3951 |
{ |
|
3952 |
QGraphicsView::paintEvent(event); |
|
3953 |
||
3954 |
if (itSTimeToTest) |
|
3955 |
{ |
|
3956 |
// qDebug() << event->region(); |
|
3957 |
// qDebug() << updateRegion; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3958 |
QEXPECT_FAIL("", "The event region doesn't include the original item position region. See QTBUG-4416", Continue); |
0 | 3959 |
QCOMPARE(event->region(), updateRegion); |
3960 |
} |
|
3961 |
} |
|
3962 |
}; |
|
3963 |
||
3964 |
SAGraphicsView view(&scene); |
|
3965 |
view.show(); |
|
3966 |
QTest::qWaitForWindowShown(&view); |
|
3967 |
||
3968 |
int hsbValue = view.horizontalScrollBar()->value(); |
|
3969 |
view.horizontalScrollBar()->setValue(hsbValue / 2); |
|
3970 |
QTest::qWait(10); |
|
3971 |
view.horizontalScrollBar()->setValue(0); |
|
3972 |
QTest::qWait(10); |
|
3973 |
||
3974 |
QRect itemDeviceBoundingRect = card.deviceTransform(view.viewportTransform()).mapRect(card.boundingRect()).toRect(); |
|
3975 |
itemDeviceBoundingRect.adjust(-2, -2, 2, 2); |
|
3976 |
view.updateRegion = itemDeviceBoundingRect; |
|
3977 |
view.updateRegion += itemDeviceBoundingRect.translated(-100, 0); |
|
3978 |
view.itSTimeToTest = true; |
|
3979 |
card.setPos(200, 300); |
|
3980 |
QTest::qWait(10); |
|
3981 |
} |
|
3982 |
||
3983 |
void tst_QGraphicsView::QTBUG_4151_clipAndIgnore_data() |
|
3984 |
{ |
|
3985 |
QTest::addColumn<bool>("clip"); |
|
3986 |
QTest::addColumn<bool>("ignoreTransformations"); |
|
3987 |
QTest::addColumn<int>("numItems"); |
|
3988 |
||
3989 |
QTest::newRow("none") << false << false << 3; |
|
3990 |
QTest::newRow("clip") << true << false << 3; |
|
3991 |
QTest::newRow("ignore") << false << true << 3; |
|
3992 |
QTest::newRow("clip+ignore") << true << true << 3; |
|
3993 |
} |
|
3994 |
||
3995 |
void tst_QGraphicsView::QTBUG_4151_clipAndIgnore() |
|
3996 |
{ |
|
3997 |
QFETCH(bool, clip); |
|
3998 |
QFETCH(bool, ignoreTransformations); |
|
3999 |
QFETCH(int, numItems); |
|
4000 |
||
4001 |
QGraphicsScene scene; |
|
4002 |
||
4003 |
QGraphicsRectItem *parent = new QGraphicsRectItem(QRectF(0, 0, 50, 50), 0); |
|
4004 |
QGraphicsRectItem *child = new QGraphicsRectItem(QRectF(-10, -10, 40, 40), parent); |
|
4005 |
QGraphicsRectItem *ignore = new QGraphicsRectItem(QRectF(60, 60, 50, 50), 0); |
|
4006 |
||
4007 |
if (clip) |
|
4008 |
parent->setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
4009 |
if (ignoreTransformations) |
|
4010 |
ignore->setFlag(QGraphicsItem::ItemIgnoresTransformations); |
|
4011 |
||
4012 |
parent->setBrush(Qt::red); |
|
4013 |
child->setBrush(QColor(0, 0, 255, 128)); |
|
4014 |
ignore->setBrush(Qt::green); |
|
4015 |
||
4016 |
scene.addItem(parent); |
|
4017 |
scene.addItem(ignore); |
|
4018 |
||
4019 |
QGraphicsView view(&scene); |
|
4020 |
view.setFrameStyle(0); |
|
4021 |
view.resize(75, 75); |
|
4022 |
view.show(); |
|
4023 |
QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); |
|
4024 |
||
4025 |
QCOMPARE(view.items(view.rect()).size(), numItems); |
|
4026 |
} |
|
4027 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4028 |
void tst_QGraphicsView::QTBUG_5859_exposedRect() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4029 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4030 |
class CustomScene : public QGraphicsScene |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4031 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4032 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4033 |
CustomScene(const QRectF &rect) : QGraphicsScene(rect) { } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4034 |
void drawBackground(QPainter *painter, const QRectF &rect) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4035 |
{ lastBackgroundExposedRect = rect; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4036 |
QRectF lastBackgroundExposedRect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4037 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4038 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4039 |
class CustomRectItem : public QGraphicsRectItem |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4040 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4041 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4042 |
CustomRectItem(const QRectF &rect) : QGraphicsRectItem(rect) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4043 |
{ setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4044 |
void paint(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4045 |
{ lastExposedRect = option->exposedRect; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4046 |
QRectF lastExposedRect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4047 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4048 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4049 |
CustomScene scene(QRectF(0,0,50,50)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4050 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4051 |
CustomRectItem item(scene.sceneRect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4052 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4053 |
scene.addItem(&item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4054 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4055 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4056 |
view.scale(4.15, 4.15); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4057 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4058 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4059 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4060 |
view.viewport()->repaint(10,10,20,20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4061 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4062 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4063 |
QCOMPARE(item.lastExposedRect, scene.lastBackgroundExposedRect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4064 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4065 |
|
0 | 4066 |
QTEST_MAIN(tst_QGraphicsView) |
4067 |
#include "tst_qgraphicsview.moc" |