1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
41 #include <QtTest/QtTest>
42 #include <QtQuick1/qdeclarativeview.h>
43 #include <qdeclarativeengine.h>
44 #include <QtQuick1/private/qdeclarativerectangle_p.h>
45 #include <QtQuick1/private/qdeclarativepositioners_p.h>
46 #include <QtQuick1/private/qdeclarativetransition_p.h>
47 #include <QtQuick1/private/qdeclarativeitem_p.h>
48 #include <qdeclarativeexpression.h>
49 #include <QtGui/qgraphicswidget.h>
50 #include "../../../shared/util.h"
53 // In Symbian OS test data is located in applications private dir
57 class tst_QDeclarativePositioners : public QObject
61 tst_QDeclarativePositioners();
64 void test_horizontal();
65 void test_horizontal_rtl();
66 void test_horizontal_spacing();
67 void test_horizontal_spacing_rightToLeft();
68 void test_horizontal_animated();
69 void test_horizontal_animated_rightToLeft();
71 void test_vertical_spacing();
72 void test_vertical_animated();
74 void test_grid_topToBottom();
75 void test_grid_rightToLeft();
76 void test_grid_spacing();
77 void test_grid_animated();
78 void test_grid_animated_rightToLeft();
79 void test_grid_zero_columns();
80 void test_propertychanges();
83 void test_flow_rightToLeft();
84 void test_flow_topToBottom();
85 void test_flow_resize();
86 void test_flow_resize_rightToLeft();
87 void test_flow_implicit_resize();
88 void test_conflictinganchors();
89 void test_vertical_qgraphicswidget();
90 void test_mirroring();
91 void testQtQuick11Attributes();
92 void testQtQuick11Attributes_data();
94 QDeclarativeView *createView(const QString &filename);
97 tst_QDeclarativePositioners::tst_QDeclarativePositioners()
101 void tst_QDeclarativePositioners::test_horizontal()
103 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
105 canvas->rootObject()->setProperty("testRightToLeft", false);
107 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
110 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
113 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
116 QCOMPARE(one->x(), 0.0);
117 QCOMPARE(one->y(), 0.0);
118 QCOMPARE(two->x(), 50.0);
119 QCOMPARE(two->y(), 0.0);
120 QCOMPARE(three->x(), 70.0);
121 QCOMPARE(three->y(), 0.0);
123 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
124 QCOMPARE(row->width(), 110.0);
125 QCOMPARE(row->height(), 50.0);
130 void tst_QDeclarativePositioners::test_horizontal_rtl()
132 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
134 canvas->rootObject()->setProperty("testRightToLeft", true);
136 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
139 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
142 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
145 QCOMPARE(one->x(), 60.0);
146 QCOMPARE(one->y(), 0.0);
147 QCOMPARE(two->x(), 40.0);
148 QCOMPARE(two->y(), 0.0);
149 QCOMPARE(three->x(), 0.0);
150 QCOMPARE(three->y(), 0.0);
152 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
153 QCOMPARE(row->width(), 110.0);
154 QCOMPARE(row->height(), 50.0);
156 // Change the width of the row and check that items stay to the right
158 QCOMPARE(one->x(), 150.0);
159 QCOMPARE(one->y(), 0.0);
160 QCOMPARE(two->x(), 130.0);
161 QCOMPARE(two->y(), 0.0);
162 QCOMPARE(three->x(), 90.0);
163 QCOMPARE(three->y(), 0.0);
168 void tst_QDeclarativePositioners::test_horizontal_spacing()
170 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
172 canvas->rootObject()->setProperty("testRightToLeft", false);
174 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
177 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
180 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
183 QCOMPARE(one->x(), 0.0);
184 QCOMPARE(one->y(), 0.0);
185 QCOMPARE(two->x(), 60.0);
186 QCOMPARE(two->y(), 0.0);
187 QCOMPARE(three->x(), 90.0);
188 QCOMPARE(three->y(), 0.0);
190 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
191 QCOMPARE(row->width(), 130.0);
192 QCOMPARE(row->height(), 50.0);
197 void tst_QDeclarativePositioners::test_horizontal_spacing_rightToLeft()
199 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
201 canvas->rootObject()->setProperty("testRightToLeft", true);
203 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
206 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
209 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
212 QCOMPARE(one->x(), 80.0);
213 QCOMPARE(one->y(), 0.0);
214 QCOMPARE(two->x(), 50.0);
215 QCOMPARE(two->y(), 0.0);
216 QCOMPARE(three->x(), 00.0);
217 QCOMPARE(three->y(), 0.0);
219 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
220 QCOMPARE(row->width(), 130.0);
221 QCOMPARE(row->height(), 50.0);
226 void tst_QDeclarativePositioners::test_horizontal_animated()
228 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
230 canvas->rootObject()->setProperty("testRightToLeft", false);
232 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
235 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
238 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
241 //Note that they animate in
242 QCOMPARE(one->x(), -100.0);
243 QCOMPARE(two->x(), -100.0);
244 QCOMPARE(three->x(), -100.0);
246 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
248 QCOMPARE(row->width(), 100.0);
249 QCOMPARE(row->height(), 50.0);
251 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
252 //Note that this means the duration of the animation is NOT tested
254 QTRY_COMPARE(one->x(), 0.0);
255 QTRY_COMPARE(one->y(), 0.0);
256 QTRY_COMPARE(two->opacity(), 0.0);
257 QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
258 QTRY_COMPARE(two->y(), 0.0);
259 QTRY_COMPARE(three->x(), 50.0);
260 QTRY_COMPARE(three->y(), 0.0);
263 two->setOpacity(1.0);
264 QCOMPARE(two->opacity(), 1.0);
266 // New size should be immediate
267 QCOMPARE(row->width(), 150.0);
268 QCOMPARE(row->height(), 50.0);
270 QTest::qWait(0);//Let the animation start
271 QCOMPARE(two->x(), -100.0);
272 QCOMPARE(three->x(), 50.0);
274 QTRY_COMPARE(two->x(), 50.0);
275 QTRY_COMPARE(three->x(), 100.0);
280 void tst_QDeclarativePositioners::test_horizontal_animated_rightToLeft()
282 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
284 canvas->rootObject()->setProperty("testRightToLeft", true);
286 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
289 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
292 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
295 //Note that they animate in
296 QCOMPARE(one->x(), -100.0);
297 QCOMPARE(two->x(), -100.0);
298 QCOMPARE(three->x(), -100.0);
300 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
302 QCOMPARE(row->width(), 100.0);
303 QCOMPARE(row->height(), 50.0);
305 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
306 //Note that this means the duration of the animation is NOT tested
308 QTRY_COMPARE(one->x(), 50.0);
309 QTRY_COMPARE(one->y(), 0.0);
310 QTRY_COMPARE(two->opacity(), 0.0);
311 QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
312 QTRY_COMPARE(two->y(), 0.0);
313 QTRY_COMPARE(three->x(), 0.0);
314 QTRY_COMPARE(three->y(), 0.0);
317 two->setOpacity(1.0);
318 QCOMPARE(two->opacity(), 1.0);
320 // New size should be immediate
321 QCOMPARE(row->width(), 150.0);
322 QCOMPARE(row->height(), 50.0);
324 QTest::qWait(0);//Let the animation start
325 QCOMPARE(one->x(), 50.0);
326 QCOMPARE(two->x(), -100.0);
328 QTRY_COMPARE(one->x(), 100.0);
329 QTRY_COMPARE(two->x(), 50.0);
334 void tst_QDeclarativePositioners::test_vertical()
336 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical.qml");
338 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
341 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
344 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
347 QCOMPARE(one->x(), 0.0);
348 QCOMPARE(one->y(), 0.0);
349 QCOMPARE(two->x(), 0.0);
350 QCOMPARE(two->y(), 50.0);
351 QCOMPARE(three->x(), 0.0);
352 QCOMPARE(three->y(), 60.0);
354 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
356 QCOMPARE(column->height(), 80.0);
357 QCOMPARE(column->width(), 50.0);
362 void tst_QDeclarativePositioners::test_vertical_spacing()
364 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-spacing.qml");
366 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
369 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
372 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
375 QCOMPARE(one->x(), 0.0);
376 QCOMPARE(one->y(), 0.0);
377 QCOMPARE(two->x(), 0.0);
378 QCOMPARE(two->y(), 60.0);
379 QCOMPARE(three->x(), 0.0);
380 QCOMPARE(three->y(), 80.0);
382 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
383 QCOMPARE(column->height(), 100.0);
384 QCOMPARE(column->width(), 50.0);
389 void tst_QDeclarativePositioners::test_vertical_animated()
391 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-animated.qml");
393 //Note that they animate in
394 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
396 QCOMPARE(one->y(), -100.0);
398 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
400 QCOMPARE(two->y(), -100.0);
402 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
404 QCOMPARE(three->y(), -100.0);
406 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
408 QCOMPARE(column->height(), 100.0);
409 QCOMPARE(column->width(), 50.0);
411 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
412 //Note that this means the duration of the animation is NOT tested
414 QTRY_COMPARE(one->y(), 0.0);
415 QTRY_COMPARE(one->x(), 0.0);
416 QTRY_COMPARE(two->opacity(), 0.0);
417 QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet
418 QTRY_COMPARE(two->x(), 0.0);
419 QTRY_COMPARE(three->y(), 50.0);
420 QTRY_COMPARE(three->x(), 0.0);
423 two->setOpacity(1.0);
424 QTRY_COMPARE(two->opacity(), 1.0);
425 QCOMPARE(column->height(), 150.0);
426 QCOMPARE(column->width(), 50.0);
427 QTest::qWait(0);//Let the animation start
428 QCOMPARE(two->y(), -100.0);
429 QCOMPARE(three->y(), 50.0);
431 QTRY_COMPARE(two->y(), 50.0);
432 QTRY_COMPARE(three->y(), 100.0);
437 void tst_QDeclarativePositioners::test_grid()
439 QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
441 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
443 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
445 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
447 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
449 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
452 QCOMPARE(one->x(), 0.0);
453 QCOMPARE(one->y(), 0.0);
454 QCOMPARE(two->x(), 50.0);
455 QCOMPARE(two->y(), 0.0);
456 QCOMPARE(three->x(), 70.0);
457 QCOMPARE(three->y(), 0.0);
458 QCOMPARE(four->x(), 0.0);
459 QCOMPARE(four->y(), 50.0);
460 QCOMPARE(five->x(), 50.0);
461 QCOMPARE(five->y(), 50.0);
463 QDeclarative1Grid *grid = canvas->rootObject()->findChild<QDeclarative1Grid*>("grid");
464 QCOMPARE(grid->flow(), QDeclarative1Grid::LeftToRight);
465 QCOMPARE(grid->width(), 100.0);
466 QCOMPARE(grid->height(), 100.0);
471 void tst_QDeclarativePositioners::test_grid_topToBottom()
473 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-toptobottom.qml");
475 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
477 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
479 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
481 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
483 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
486 QCOMPARE(one->x(), 0.0);
487 QCOMPARE(one->y(), 0.0);
488 QCOMPARE(two->x(), 0.0);
489 QCOMPARE(two->y(), 50.0);
490 QCOMPARE(three->x(), 0.0);
491 QCOMPARE(three->y(), 100.0);
492 QCOMPARE(four->x(), 50.0);
493 QCOMPARE(four->y(), 0.0);
494 QCOMPARE(five->x(), 50.0);
495 QCOMPARE(five->y(), 50.0);
497 QDeclarative1Grid *grid = canvas->rootObject()->findChild<QDeclarative1Grid*>("grid");
498 QCOMPARE(grid->flow(), QDeclarative1Grid::TopToBottom);
499 QCOMPARE(grid->width(), 100.0);
500 QCOMPARE(grid->height(), 120.0);
505 void tst_QDeclarativePositioners::test_grid_rightToLeft()
507 QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
509 canvas->rootObject()->setProperty("testRightToLeft", true);
511 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
513 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
515 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
517 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
519 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
522 QCOMPARE(one->x(), 50.0);
523 QCOMPARE(one->y(), 0.0);
524 QCOMPARE(two->x(), 30.0);
525 QCOMPARE(two->y(), 0.0);
526 QCOMPARE(three->x(), 0.0);
527 QCOMPARE(three->y(), 0.0);
528 QCOMPARE(four->x(), 50.0);
529 QCOMPARE(four->y(), 50.0);
530 QCOMPARE(five->x(), 40.0);
531 QCOMPARE(five->y(), 50.0);
533 QDeclarative1Grid *grid = canvas->rootObject()->findChild<QDeclarative1Grid*>("grid");
534 QCOMPARE(grid->layoutDirection(), Qt::RightToLeft);
535 QCOMPARE(grid->width(), 100.0);
536 QCOMPARE(grid->height(), 100.0);
538 // Change the width of the grid and check that items stay to the right
540 QCOMPARE(one->x(), 150.0);
541 QCOMPARE(one->y(), 0.0);
542 QCOMPARE(two->x(), 130.0);
543 QCOMPARE(two->y(), 0.0);
544 QCOMPARE(three->x(), 100.0);
545 QCOMPARE(three->y(), 0.0);
546 QCOMPARE(four->x(), 150.0);
547 QCOMPARE(four->y(), 50.0);
548 QCOMPARE(five->x(), 140.0);
549 QCOMPARE(five->y(), 50.0);
554 void tst_QDeclarativePositioners::test_grid_spacing()
556 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-spacing.qml");
558 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
560 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
562 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
564 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
566 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
569 QCOMPARE(one->x(), 0.0);
570 QCOMPARE(one->y(), 0.0);
571 QCOMPARE(two->x(), 54.0);
572 QCOMPARE(two->y(), 0.0);
573 QCOMPARE(three->x(), 78.0);
574 QCOMPARE(three->y(), 0.0);
575 QCOMPARE(four->x(), 0.0);
576 QCOMPARE(four->y(), 54.0);
577 QCOMPARE(five->x(), 54.0);
578 QCOMPARE(five->y(), 54.0);
580 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
581 QCOMPARE(grid->width(), 128.0);
582 QCOMPARE(grid->height(), 104.0);
587 void tst_QDeclarativePositioners::test_grid_animated()
589 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
591 canvas->rootObject()->setProperty("testRightToLeft", false);
593 //Note that all animate in
594 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
596 QCOMPARE(one->x(), -100.0);
597 QCOMPARE(one->y(), -100.0);
599 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
601 QCOMPARE(two->x(), -100.0);
602 QCOMPARE(two->y(), -100.0);
604 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
606 QCOMPARE(three->x(), -100.0);
607 QCOMPARE(three->y(), -100.0);
609 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
611 QCOMPARE(four->x(), -100.0);
612 QCOMPARE(four->y(), -100.0);
614 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
616 QCOMPARE(five->x(), -100.0);
617 QCOMPARE(five->y(), -100.0);
619 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
621 QCOMPARE(grid->width(), 150.0);
622 QCOMPARE(grid->height(), 100.0);
624 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
625 //Note that this means the duration of the animation is NOT tested
627 QTRY_COMPARE(one->y(), 0.0);
628 QTRY_COMPARE(one->x(), 0.0);
629 QTRY_COMPARE(two->opacity(), 0.0);
630 QTRY_COMPARE(two->y(), -100.0);
631 QTRY_COMPARE(two->x(), -100.0);
632 QTRY_COMPARE(three->y(), 0.0);
633 QTRY_COMPARE(three->x(), 50.0);
634 QTRY_COMPARE(four->y(), 0.0);
635 QTRY_COMPARE(four->x(), 100.0);
636 QTRY_COMPARE(five->y(), 50.0);
637 QTRY_COMPARE(five->x(), 0.0);
640 two->setOpacity(1.0);
641 QCOMPARE(two->opacity(), 1.0);
642 QCOMPARE(grid->width(), 150.0);
643 QCOMPARE(grid->height(), 100.0);
644 QTest::qWait(0);//Let the animation start
645 QCOMPARE(two->x(), -100.0);
646 QCOMPARE(two->y(), -100.0);
647 QCOMPARE(one->x(), 0.0);
648 QCOMPARE(one->y(), 0.0);
649 QCOMPARE(three->x(), 50.0);
650 QCOMPARE(three->y(), 0.0);
651 QCOMPARE(four->x(), 100.0);
652 QCOMPARE(four->y(), 0.0);
653 QCOMPARE(five->x(), 0.0);
654 QCOMPARE(five->y(), 50.0);
655 //Let the animation complete
656 QTRY_COMPARE(two->x(), 50.0);
657 QTRY_COMPARE(two->y(), 0.0);
658 QTRY_COMPARE(one->x(), 0.0);
659 QTRY_COMPARE(one->y(), 0.0);
660 QTRY_COMPARE(three->x(), 100.0);
661 QTRY_COMPARE(three->y(), 0.0);
662 QTRY_COMPARE(four->x(), 0.0);
663 QTRY_COMPARE(four->y(), 50.0);
664 QTRY_COMPARE(five->x(), 50.0);
665 QTRY_COMPARE(five->y(), 50.0);
670 void tst_QDeclarativePositioners::test_grid_animated_rightToLeft()
672 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
674 canvas->rootObject()->setProperty("testRightToLeft", true);
676 //Note that all animate in
677 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
679 QCOMPARE(one->x(), -100.0);
680 QCOMPARE(one->y(), -100.0);
682 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
684 QCOMPARE(two->x(), -100.0);
685 QCOMPARE(two->y(), -100.0);
687 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
689 QCOMPARE(three->x(), -100.0);
690 QCOMPARE(three->y(), -100.0);
692 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
694 QCOMPARE(four->x(), -100.0);
695 QCOMPARE(four->y(), -100.0);
697 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
699 QCOMPARE(five->x(), -100.0);
700 QCOMPARE(five->y(), -100.0);
702 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
704 QCOMPARE(grid->width(), 150.0);
705 QCOMPARE(grid->height(), 100.0);
707 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
708 //Note that this means the duration of the animation is NOT tested
710 QTRY_COMPARE(one->y(), 0.0);
711 QTRY_COMPARE(one->x(), 100.0);
712 QTRY_COMPARE(two->opacity(), 0.0);
713 QTRY_COMPARE(two->y(), -100.0);
714 QTRY_COMPARE(two->x(), -100.0);
715 QTRY_COMPARE(three->y(), 0.0);
716 QTRY_COMPARE(three->x(), 50.0);
717 QTRY_COMPARE(four->y(), 0.0);
718 QTRY_COMPARE(four->x(), 0.0);
719 QTRY_COMPARE(five->y(), 50.0);
720 QTRY_COMPARE(five->x(), 100.0);
723 two->setOpacity(1.0);
724 QCOMPARE(two->opacity(), 1.0);
725 QCOMPARE(grid->width(), 150.0);
726 QCOMPARE(grid->height(), 100.0);
727 QTest::qWait(0);//Let the animation start
728 QCOMPARE(two->x(), -100.0);
729 QCOMPARE(two->y(), -100.0);
730 QCOMPARE(one->x(), 100.0);
731 QCOMPARE(one->y(), 0.0);
732 QCOMPARE(three->x(), 50.0);
733 QCOMPARE(three->y(), 0.0);
734 QCOMPARE(four->x(), 0.0);
735 QCOMPARE(four->y(), 0.0);
736 QCOMPARE(five->x(), 100.0);
737 QCOMPARE(five->y(), 50.0);
738 //Let the animation complete
739 QTRY_COMPARE(two->x(), 50.0);
740 QTRY_COMPARE(two->y(), 0.0);
741 QTRY_COMPARE(one->x(), 100.0);
742 QTRY_COMPARE(one->y(), 0.0);
743 QTRY_COMPARE(three->x(), 0.0);
744 QTRY_COMPARE(three->y(), 0.0);
745 QTRY_COMPARE(four->x(), 100.0);
746 QTRY_COMPARE(four->y(), 50.0);
747 QTRY_COMPARE(five->x(), 50.0);
748 QTRY_COMPARE(five->y(), 50.0);
753 void tst_QDeclarativePositioners::test_grid_zero_columns()
755 QDeclarativeView *canvas = createView(SRCDIR "/data/gridzerocolumns.qml");
757 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
759 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
761 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
763 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
765 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
768 QCOMPARE(one->x(), 0.0);
769 QCOMPARE(one->y(), 0.0);
770 QCOMPARE(two->x(), 50.0);
771 QCOMPARE(two->y(), 0.0);
772 QCOMPARE(three->x(), 70.0);
773 QCOMPARE(three->y(), 0.0);
774 QCOMPARE(four->x(), 120.0);
775 QCOMPARE(four->y(), 0.0);
776 QCOMPARE(five->x(), 0.0);
777 QCOMPARE(five->y(), 50.0);
779 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
780 QCOMPARE(grid->width(), 170.0);
781 QCOMPARE(grid->height(), 60.0);
786 void tst_QDeclarativePositioners::test_propertychanges()
788 QDeclarativeView *canvas = createView(SRCDIR "/data/propertychangestest.qml");
790 QDeclarative1Grid *grid = qobject_cast<QDeclarative1Grid*>(canvas->rootObject());
792 QDeclarative1Transition *rowTransition = canvas->rootObject()->findChild<QDeclarative1Transition*>("rowTransition");
793 QDeclarative1Transition *columnTransition = canvas->rootObject()->findChild<QDeclarative1Transition*>("columnTransition");
795 QSignalSpy addSpy(grid, SIGNAL(addChanged()));
796 QSignalSpy moveSpy(grid, SIGNAL(moveChanged()));
797 QSignalSpy columnsSpy(grid, SIGNAL(columnsChanged()));
798 QSignalSpy rowsSpy(grid, SIGNAL(rowsChanged()));
801 QVERIFY(rowTransition);
802 QVERIFY(columnTransition);
803 QCOMPARE(grid->add(), columnTransition);
804 QCOMPARE(grid->move(), columnTransition);
805 QCOMPARE(grid->columns(), 4);
806 QCOMPARE(grid->rows(), -1);
808 grid->setAdd(rowTransition);
809 grid->setMove(rowTransition);
810 QCOMPARE(grid->add(), rowTransition);
811 QCOMPARE(grid->move(), rowTransition);
812 QCOMPARE(addSpy.count(),1);
813 QCOMPARE(moveSpy.count(),1);
815 grid->setAdd(rowTransition);
816 grid->setMove(rowTransition);
817 QCOMPARE(addSpy.count(),1);
818 QCOMPARE(moveSpy.count(),1);
822 QCOMPARE(addSpy.count(),2);
823 QCOMPARE(moveSpy.count(),2);
825 grid->setColumns(-1);
827 QCOMPARE(grid->columns(), -1);
828 QCOMPARE(grid->rows(), 3);
829 QCOMPARE(columnsSpy.count(),1);
830 QCOMPARE(rowsSpy.count(),1);
832 grid->setColumns(-1);
834 QCOMPARE(columnsSpy.count(),1);
835 QCOMPARE(rowsSpy.count(),1);
839 QCOMPARE(columnsSpy.count(),2);
840 QCOMPARE(rowsSpy.count(),2);
845 void tst_QDeclarativePositioners::test_repeater()
847 QDeclarativeView *canvas = createView(SRCDIR "/data/repeatertest.qml");
849 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
852 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
855 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
858 QCOMPARE(one->x(), 0.0);
859 QCOMPARE(one->y(), 0.0);
860 QCOMPARE(two->x(), 50.0);
861 QCOMPARE(two->y(), 0.0);
862 QCOMPARE(three->x(), 100.0);
863 QCOMPARE(three->y(), 0.0);
868 void tst_QDeclarativePositioners::test_flow()
870 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
872 canvas->rootObject()->setProperty("testRightToLeft", false);
874 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
876 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
878 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
880 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
882 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
885 QCOMPARE(one->x(), 0.0);
886 QCOMPARE(one->y(), 0.0);
887 QCOMPARE(two->x(), 50.0);
888 QCOMPARE(two->y(), 0.0);
889 QCOMPARE(three->x(), 0.0);
890 QCOMPARE(three->y(), 50.0);
891 QCOMPARE(four->x(), 0.0);
892 QCOMPARE(four->y(), 70.0);
893 QCOMPARE(five->x(), 50.0);
894 QCOMPARE(five->y(), 70.0);
896 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
898 QCOMPARE(flow->width(), 90.0);
899 QCOMPARE(flow->height(), 120.0);
904 void tst_QDeclarativePositioners::test_flow_rightToLeft()
906 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
908 canvas->rootObject()->setProperty("testRightToLeft", true);
910 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
912 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
914 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
916 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
918 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
921 QCOMPARE(one->x(), 40.0);
922 QCOMPARE(one->y(), 0.0);
923 QCOMPARE(two->x(), 20.0);
924 QCOMPARE(two->y(), 0.0);
925 QCOMPARE(three->x(), 40.0);
926 QCOMPARE(three->y(), 50.0);
927 QCOMPARE(four->x(), 40.0);
928 QCOMPARE(four->y(), 70.0);
929 QCOMPARE(five->x(), 30.0);
930 QCOMPARE(five->y(), 70.0);
932 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
934 QCOMPARE(flow->width(), 90.0);
935 QCOMPARE(flow->height(), 120.0);
940 void tst_QDeclarativePositioners::test_flow_topToBottom()
942 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest-toptobottom.qml");
944 canvas->rootObject()->setProperty("testRightToLeft", false);
946 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
948 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
950 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
952 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
954 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
957 QCOMPARE(one->x(), 0.0);
958 QCOMPARE(one->y(), 0.0);
959 QCOMPARE(two->x(), 50.0);
960 QCOMPARE(two->y(), 0.0);
961 QCOMPARE(three->x(), 50.0);
962 QCOMPARE(three->y(), 50.0);
963 QCOMPARE(four->x(), 100.0);
964 QCOMPARE(four->y(), 00.0);
965 QCOMPARE(five->x(), 100.0);
966 QCOMPARE(five->y(), 50.0);
968 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
970 QCOMPARE(flow->height(), 90.0);
971 QCOMPARE(flow->width(), 150.0);
973 canvas->rootObject()->setProperty("testRightToLeft", true);
976 QCOMPARE(flow->height(), 90.0);
977 QCOMPARE(flow->width(), 150.0);
979 QCOMPARE(one->x(), 100.0);
980 QCOMPARE(one->y(), 0.0);
981 QCOMPARE(two->x(), 80.0);
982 QCOMPARE(two->y(), 0.0);
983 QCOMPARE(three->x(), 50.0);
984 QCOMPARE(three->y(), 50.0);
985 QCOMPARE(four->x(), 0.0);
986 QCOMPARE(four->y(), 0.0);
987 QCOMPARE(five->x(), 40.0);
988 QCOMPARE(five->y(), 50.0);
993 void tst_QDeclarativePositioners::test_flow_resize()
995 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
997 QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
1000 root->setProperty("testRightToLeft", false);
1002 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
1004 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
1006 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
1007 QVERIFY(three != 0);
1008 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
1010 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
1013 QCOMPARE(one->x(), 0.0);
1014 QCOMPARE(one->y(), 0.0);
1015 QCOMPARE(two->x(), 50.0);
1016 QCOMPARE(two->y(), 0.0);
1017 QCOMPARE(three->x(), 70.0);
1018 QCOMPARE(three->y(), 0.0);
1019 QCOMPARE(four->x(), 0.0);
1020 QCOMPARE(four->y(), 50.0);
1021 QCOMPARE(five->x(), 50.0);
1022 QCOMPARE(five->y(), 50.0);
1027 void tst_QDeclarativePositioners::test_flow_resize_rightToLeft()
1029 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
1031 QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
1033 root->setWidth(125);
1034 root->setProperty("testRightToLeft", true);
1036 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
1038 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
1040 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
1041 QVERIFY(three != 0);
1042 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
1044 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
1047 QCOMPARE(one->x(), 75.0);
1048 QCOMPARE(one->y(), 0.0);
1049 QCOMPARE(two->x(), 55.0);
1050 QCOMPARE(two->y(), 0.0);
1051 QCOMPARE(three->x(), 5.0);
1052 QCOMPARE(three->y(), 0.0);
1053 QCOMPARE(four->x(), 75.0);
1054 QCOMPARE(four->y(), 50.0);
1055 QCOMPARE(five->x(), 65.0);
1056 QCOMPARE(five->y(), 50.0);
1061 void tst_QDeclarativePositioners::test_flow_implicit_resize()
1063 QDeclarativeView *canvas = createView(SRCDIR "/data/flow-testimplicitsize.qml");
1064 QVERIFY(canvas->rootObject() != 0);
1066 QDeclarative1Flow *flow = canvas->rootObject()->findChild<QDeclarative1Flow*>("flow");
1069 QCOMPARE(flow->width(), 100.0);
1070 QCOMPARE(flow->height(), 120.0);
1072 canvas->rootObject()->setProperty("flowLayout", 0);
1073 QCOMPARE(flow->flow(), QDeclarative1Flow::LeftToRight);
1074 QCOMPARE(flow->width(), 220.0);
1075 QCOMPARE(flow->height(), 50.0);
1077 canvas->rootObject()->setProperty("flowLayout", 1);
1078 QCOMPARE(flow->flow(), QDeclarative1Flow::TopToBottom);
1079 QCOMPARE(flow->width(), 100.0);
1080 QCOMPARE(flow->height(), 120.0);
1082 canvas->rootObject()->setProperty("flowLayout", 2);
1083 QCOMPARE(flow->layoutDirection(), Qt::RightToLeft);
1084 QCOMPARE(flow->width(), 220.0);
1085 QCOMPARE(flow->height(), 50.0);
1090 QString warningMessage;
1092 void interceptWarnings(QtMsgType type, const char *msg)
1095 warningMessage = msg;
1098 void tst_QDeclarativePositioners::test_conflictinganchors()
1100 QtMsgHandler oldMsgHandler = qInstallMsgHandler(interceptWarnings);
1101 QDeclarativeEngine engine;
1102 QDeclarativeComponent component(&engine);
1104 component.setData("import QtQuick 1.0\nColumn { Item {} }", QUrl::fromLocalFile(""));
1105 QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
1107 QVERIFY(warningMessage.isEmpty());
1110 component.setData("import QtQuick 1.0\nRow { Item {} }", QUrl::fromLocalFile(""));
1111 item = qobject_cast<QDeclarativeItem*>(component.create());
1113 QVERIFY(warningMessage.isEmpty());
1116 component.setData("import QtQuick 1.0\nGrid { Item {} }", QUrl::fromLocalFile(""));
1117 item = qobject_cast<QDeclarativeItem*>(component.create());
1119 QVERIFY(warningMessage.isEmpty());
1122 component.setData("import QtQuick 1.0\nFlow { Item {} }", QUrl::fromLocalFile(""));
1123 item = qobject_cast<QDeclarativeItem*>(component.create());
1125 QVERIFY(warningMessage.isEmpty());
1128 component.setData("import QtQuick 1.0\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1129 item = qobject_cast<QDeclarativeItem*>(component.create());
1131 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1132 warningMessage.clear();
1135 component.setData("import QtQuick 1.0\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1136 item = qobject_cast<QDeclarativeItem*>(component.create());
1138 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1139 warningMessage.clear();
1142 component.setData("import QtQuick 1.0\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
1143 item = qobject_cast<QDeclarativeItem*>(component.create());
1145 QVERIFY(warningMessage.isEmpty());
1146 warningMessage.clear();
1149 component.setData("import QtQuick 1.0\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
1150 item = qobject_cast<QDeclarativeItem*>(component.create());
1152 QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
1153 warningMessage.clear();
1156 component.setData("import QtQuick 1.0\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1157 item = qobject_cast<QDeclarativeItem*>(component.create());
1159 QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
1160 warningMessage.clear();
1163 component.setData("import QtQuick 1.0\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1164 item = qobject_cast<QDeclarativeItem*>(component.create());
1166 QVERIFY(warningMessage.isEmpty());
1167 warningMessage.clear();
1170 component.setData("import QtQuick 1.0\nGrid { Item { anchors.horizontalCenter: parent.horizontalCenter } }", QUrl::fromLocalFile(""));
1171 item = qobject_cast<QDeclarativeItem*>(component.create());
1173 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1174 warningMessage.clear();
1177 component.setData("import QtQuick 1.0\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1178 item = qobject_cast<QDeclarativeItem*>(component.create());
1180 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1181 warningMessage.clear();
1184 component.setData("import QtQuick 1.0\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile(""));
1185 item = qobject_cast<QDeclarativeItem*>(component.create());
1187 QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
1190 component.setData("import QtQuick 1.0\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1191 item = qobject_cast<QDeclarativeItem*>(component.create());
1193 QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
1194 qInstallMsgHandler(oldMsgHandler);
1198 void tst_QDeclarativePositioners::test_vertical_qgraphicswidget()
1200 QDeclarativeView *canvas = createView(SRCDIR "/data/verticalqgraphicswidget.qml");
1202 QGraphicsWidget *one = canvas->rootObject()->findChild<QGraphicsWidget*>("one");
1205 QGraphicsWidget *two = canvas->rootObject()->findChild<QGraphicsWidget*>("two");
1208 QGraphicsWidget *three = canvas->rootObject()->findChild<QGraphicsWidget*>("three");
1209 QVERIFY(three != 0);
1211 QCOMPARE(one->x(), 0.0);
1212 QCOMPARE(one->y(), 0.0);
1213 QCOMPARE(two->x(), 0.0);
1214 QCOMPARE(two->y(), 50.0);
1215 QCOMPARE(three->x(), 0.0);
1216 QCOMPARE(three->y(), 60.0);
1218 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
1220 QCOMPARE(column->height(), 80.0);
1221 QCOMPARE(column->width(), 50.0);
1223 two->resize(QSizeF(two->size().width(), 20.0));
1224 QCOMPARE(three->x(), 0.0);
1225 QCOMPARE(three->y(), 70.0);
1227 two->setOpacity(0.0);
1228 QCOMPARE(one->x(), 0.0);
1229 QCOMPARE(one->y(), 0.0);
1230 QCOMPARE(three->x(), 0.0);
1231 QCOMPARE(three->y(), 50.0);
1233 one->setVisible(false);
1234 QCOMPARE(three->x(), 0.0);
1235 QCOMPARE(three->y(), 0.0);
1240 void tst_QDeclarativePositioners::test_mirroring()
1242 QList<QString> qmlFiles;
1243 qmlFiles << "horizontal.qml" << "gridtest.qml" << "flowtest.qml";
1244 QList<QString> objectNames;
1245 objectNames << "one" << "two" << "three" << "four" << "five";
1247 foreach(const QString qmlFile, qmlFiles) {
1248 QDeclarativeView *canvasA = createView(QString(SRCDIR) + "/data/" + qmlFile);
1249 QDeclarativeItem *rootA = qobject_cast<QDeclarativeItem*>(canvasA->rootObject());
1251 QDeclarativeView *canvasB = createView(QString(SRCDIR) + "/data/" + qmlFile);
1252 QDeclarativeItem *rootB = qobject_cast<QDeclarativeItem*>(canvasB->rootObject());
1254 rootA->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1257 foreach(const QString objectName, objectNames) {
1258 // horizontal.qml only has three items
1259 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1261 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1262 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1263 QVERIFY(itemA->x() != itemB->x());
1266 QDeclarativeItemPrivate* rootPrivateB = QDeclarativeItemPrivate::get(rootB);
1268 rootPrivateB->effectiveLayoutMirror = true; // LayoutMirroring.enabled: true
1269 rootPrivateB->isMirrorImplicit = false;
1270 rootPrivateB->inheritMirrorFromItem = true; // LayoutMirroring.childrenInherit: true
1271 rootPrivateB->resolveLayoutMirror();
1274 foreach(const QString objectName, objectNames) {
1275 // horizontal.qml only has three items
1276 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1278 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1279 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1280 QCOMPARE(itemA->x(), itemB->x());
1283 rootA->setProperty("testRightToLeft", false); // layoutDirection: Qt.LeftToRight
1284 rootB->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1286 // LTR == RTL + mirror
1287 foreach(const QString objectName, objectNames) {
1288 // horizontal.qml only has three items
1289 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1291 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1292 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1293 QCOMPARE(itemA->x(), itemB->x());
1300 void tst_QDeclarativePositioners::testQtQuick11Attributes()
1302 QFETCH(QString, code);
1303 QFETCH(QString, warning);
1304 QFETCH(QString, error);
1306 QDeclarativeEngine engine;
1309 QDeclarativeComponent valid(&engine);
1310 valid.setData("import QtQuick 1.1; " + code.toUtf8(), QUrl(""));
1311 obj = valid.create();
1313 QVERIFY(valid.errorString().isEmpty());
1316 QDeclarativeComponent invalid(&engine);
1317 invalid.setData("import QtQuick 1.0; " + code.toUtf8(), QUrl(""));
1318 QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
1319 obj = invalid.create();
1320 QCOMPARE(invalid.errorString(), error);
1324 void tst_QDeclarativePositioners::testQtQuick11Attributes_data()
1326 QTest::addColumn<QString>("code");
1327 QTest::addColumn<QString>("warning");
1328 QTest::addColumn<QString>("error");
1330 QTest::newRow("Flow.layoutDirection") << "Flow { layoutDirection: Qt.LeftToRight }"
1331 << "QDeclarativeComponent: Component is not ready"
1332 << ":1 \"Flow.layoutDirection\" is not available in QtQuick 1.0.\n";
1334 QTest::newRow("Row.layoutDirection") << "Row { layoutDirection: Qt.LeftToRight }"
1335 << "QDeclarativeComponent: Component is not ready"
1336 << ":1 \"Row.layoutDirection\" is not available in QtQuick 1.0.\n";
1338 QTest::newRow("Grid.layoutDirection") << "Grid { layoutDirection: Qt.LeftToRight }"
1339 << "QDeclarativeComponent: Component is not ready"
1340 << ":1 \"Grid.layoutDirection\" is not available in QtQuick 1.0.\n";
1343 QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename)
1345 QDeclarativeView *canvas = new QDeclarativeView(0);
1347 canvas->setSource(QUrl::fromLocalFile(filename));
1353 QTEST_MAIN(tst_QDeclarativePositioners)
1355 #include "tst_qdeclarativepositioners.moc"