474 EventSpy focusInSpy(widget, QEvent::FocusIn); |
478 EventSpy focusInSpy(widget, QEvent::FocusIn); |
475 EventSpy focusOutSpy(widget, QEvent::FocusOut); |
479 EventSpy focusOutSpy(widget, QEvent::FocusOut); |
476 |
480 |
477 scene.addItem(widget); |
481 scene.addItem(widget); |
478 |
482 |
479 QVERIFY(!widget->hasFocus()); |
483 QTRY_VERIFY(!widget->hasFocus()); |
480 widget->setFocusPolicy(Qt::StrongFocus); |
484 widget->setFocusPolicy(Qt::StrongFocus); |
481 QVERIFY(!widget->hasFocus()); |
485 QTRY_VERIFY(!widget->hasFocus()); |
482 |
486 |
483 QGraphicsWidget *subWidget = new QGraphicsWidget(widget); |
487 QGraphicsWidget *subWidget = new QGraphicsWidget(widget); |
484 QVERIFY(!subWidget->hasFocus()); |
488 QTRY_VERIFY(!subWidget->hasFocus()); |
485 |
489 |
486 scene.setFocus(); |
490 scene.setFocus(); |
487 |
491 |
488 QVERIFY(!widget->hasFocus()); |
492 QTRY_VERIFY(!widget->hasFocus()); |
489 QVERIFY(!subWidget->hasFocus()); |
493 QTRY_VERIFY(!subWidget->hasFocus()); |
490 |
494 |
491 widget->setFocus(); |
495 widget->setFocus(); |
492 |
496 |
493 QVERIFY(widget->hasFocus()); |
497 QTRY_VERIFY(widget->hasFocus()); |
494 QCOMPARE(focusInSpy.count(), 1); |
498 QTRY_COMPARE(focusInSpy.count(), 1); |
495 QVERIFY(!subWidget->hasFocus()); |
499 QTRY_VERIFY(!subWidget->hasFocus()); |
496 |
500 |
497 QGraphicsWidget *otherSubWidget = new QGraphicsWidget; |
501 QGraphicsWidget *otherSubWidget = new QGraphicsWidget; |
498 EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn); |
502 EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn); |
499 EventSpy otherFocusOutSpy(otherSubWidget, QEvent::FocusOut); |
503 EventSpy otherFocusOutSpy(otherSubWidget, QEvent::FocusOut); |
500 |
504 |
501 otherSubWidget->setFocusPolicy(Qt::StrongFocus); |
505 otherSubWidget->setFocusPolicy(Qt::StrongFocus); |
502 otherSubWidget->setParentItem(widget); |
506 otherSubWidget->setParentItem(widget); |
503 |
507 |
504 QVERIFY(widget->hasFocus()); |
508 QTRY_VERIFY(widget->hasFocus()); |
505 QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget); |
509 QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget); |
506 QVERIFY(!subWidget->hasFocus()); |
510 QTRY_VERIFY(!subWidget->hasFocus()); |
507 QVERIFY(!otherSubWidget->hasFocus()); |
511 QTRY_VERIFY(!otherSubWidget->hasFocus()); |
508 |
512 |
509 widget->hide(); |
513 widget->hide(); |
510 QVERIFY(!widget->hasFocus()); // lose but still has subfocus |
514 QTRY_VERIFY(!widget->hasFocus()); // lose but still has subfocus |
511 QCOMPARE(focusInSpy.count(), 1); |
515 QCOMPARE(focusInSpy.count(), 1); |
512 QCOMPARE(focusOutSpy.count(), 1); |
516 QCOMPARE(focusOutSpy.count(), 1); |
513 |
517 |
514 widget->show(); |
518 widget->show(); |
515 QVERIFY(!widget->hasFocus()); // no regain |
519 QTRY_VERIFY(!widget->hasFocus()); // no regain |
516 QCOMPARE(focusInSpy.count(), 1); |
520 QCOMPARE(focusInSpy.count(), 1); |
517 QCOMPARE(focusOutSpy.count(), 1); |
521 QCOMPARE(focusOutSpy.count(), 1); |
518 |
522 |
519 widget->hide(); |
523 widget->hide(); |
520 |
524 |
521 // try to setup subFocus on item that can't take focus |
525 // try to setup subFocus on item that can't take focus |
522 subWidget->setFocus(); |
526 subWidget->setFocus(); |
523 QVERIFY(!subWidget->hasFocus()); |
527 QTRY_VERIFY(!subWidget->hasFocus()); |
524 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
528 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
525 |
529 |
526 // try to setup subFocus on item that can take focus |
530 // try to setup subFocus on item that can take focus |
527 otherSubWidget->setFocus(); |
531 otherSubWidget->setFocus(); |
528 QVERIFY(!otherSubWidget->hasFocus()); |
532 QTRY_VERIFY(!otherSubWidget->hasFocus()); |
529 QCOMPARE(widget->focusWidget(), otherSubWidget); |
533 QCOMPARE(widget->focusWidget(), otherSubWidget); |
530 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
534 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
531 |
535 |
532 widget->show(); |
536 widget->show(); |
533 |
537 |
534 QCOMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item |
538 QTRY_COMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item |
535 QCOMPARE(otherFocusInSpy.count(), 1); |
539 QCOMPARE(otherFocusInSpy.count(), 1); |
536 QCOMPARE(otherFocusOutSpy.count(), 0); |
540 QCOMPARE(otherFocusOutSpy.count(), 0); |
537 |
541 |
538 delete otherSubWidget; |
542 delete otherSubWidget; |
539 |
543 |
540 QCOMPARE(otherFocusOutSpy.count(), 1); |
544 QTRY_COMPARE(otherFocusOutSpy.count(), 1); |
541 QVERIFY(!scene.focusItem()); |
545 QVERIFY(!scene.focusItem()); |
542 QVERIFY(!widget->focusWidget()); |
546 QVERIFY(!widget->focusWidget()); |
543 } |
547 } |
544 |
548 |
545 Q_DECLARE_METATYPE(Qt::FocusPolicy) |
549 Q_DECLARE_METATYPE(Qt::FocusPolicy) |
574 QEvent windowActivate(QEvent::WindowActivate); |
578 QEvent windowActivate(QEvent::WindowActivate); |
575 qApp->sendEvent(&scene, &windowActivate); |
579 qApp->sendEvent(&scene, &windowActivate); |
576 |
580 |
577 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
581 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
578 scene.addItem(widget); |
582 scene.addItem(widget); |
579 QCOMPARE(Qt::NoFocus, widget->focusPolicy()); |
583 QTRY_COMPARE(Qt::NoFocus, widget->focusPolicy()); |
580 |
584 |
581 QFETCH(Qt::FocusPolicy, focusPolicy1); |
585 QFETCH(Qt::FocusPolicy, focusPolicy1); |
582 widget->setFocusPolicy(focusPolicy1); |
586 widget->setFocusPolicy(focusPolicy1); |
583 QCOMPARE(widget->focusPolicy(), focusPolicy1); |
587 QTRY_COMPARE(widget->focusPolicy(), focusPolicy1); |
584 bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
588 bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
585 bool wasFocusable = isFocusable; |
589 bool wasFocusable = isFocusable; |
586 QVERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus)); |
590 QTRY_VERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus)); |
587 widget->setFocus(); |
591 widget->setFocus(); |
588 QCOMPARE(widget->hasFocus(), isFocusable); |
592 QTRY_COMPARE(widget->hasFocus(), isFocusable); |
589 |
593 |
590 QFETCH(Qt::FocusPolicy, focusPolicy2); |
594 QFETCH(Qt::FocusPolicy, focusPolicy2); |
591 widget->setFocusPolicy(focusPolicy2); |
595 widget->setFocusPolicy(focusPolicy2); |
592 QCOMPARE(widget->focusPolicy(), focusPolicy2); |
596 QCOMPARE(widget->focusPolicy(), focusPolicy2); |
593 isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
597 isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
686 QCOMPARE(scene.font(), appFont); |
690 QCOMPARE(scene.font(), appFont); |
687 QCOMPARE(root->font(), appFont); |
691 QCOMPARE(root->font(), appFont); |
688 |
692 |
689 EventSpy rootSpyFont(root, QEvent::FontChange); |
693 EventSpy rootSpyFont(root, QEvent::FontChange); |
690 EventSpy rootSpyPolish(root, QEvent::Polish); |
694 EventSpy rootSpyPolish(root, QEvent::Polish); |
691 QCOMPARE(rootSpyFont.count(), 0); |
695 QTRY_COMPARE(rootSpyFont.count(), 0); |
692 QApplication::processEvents(); //The polish event is sent |
696 QTRY_COMPARE(rootSpyPolish.count(), 1); |
693 QCOMPARE(rootSpyPolish.count(), 1); |
|
694 QApplication::processEvents(); //Process events to see if we get the font change event |
|
695 //The font is still the same so no fontChangeEvent |
697 //The font is still the same so no fontChangeEvent |
696 QCOMPARE(rootSpyFont.count(), 0); |
698 QTRY_COMPARE(rootSpyFont.count(), 0); |
697 |
699 |
698 QFont font; |
700 QFont font; |
699 font.setPointSize(43); |
701 font.setPointSize(43); |
700 root->setFont(font); |
702 root->setFont(font); |
701 QApplication::processEvents(); //Process events to get the font change event |
|
702 //The font changed |
703 //The font changed |
703 QCOMPARE(rootSpyFont.count(), 1); |
704 QTRY_COMPARE(rootSpyFont.count(), 1); |
704 |
705 |
705 //then roll back to the default one. |
706 //then roll back to the default one. |
706 root->setFont(appFont); |
707 root->setFont(appFont); |
707 QApplication::processEvents(); //Process events to get the font change event |
|
708 //The font changed |
708 //The font changed |
709 QCOMPARE(rootSpyFont.count(), 2); |
709 QTRY_COMPARE(rootSpyFont.count(), 2); |
710 } |
710 } |
711 |
711 |
712 void tst_QGraphicsWidget::fontPropagationWidgetItemWidget() |
712 void tst_QGraphicsWidget::fontPropagationWidgetItemWidget() |
713 { |
713 { |
714 QGraphicsWidget *widget = new QGraphicsWidget; |
714 QGraphicsWidget *widget = new QGraphicsWidget; |
765 // QRectF geometry() const public |
765 // QRectF geometry() const public |
766 void tst_QGraphicsWidget::geometry() |
766 void tst_QGraphicsWidget::geometry() |
767 { |
767 { |
768 SubQGraphicsWidget widget; |
768 SubQGraphicsWidget widget; |
769 QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
769 QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
770 |
770 QSignalSpy spy(&widget, SIGNAL(geometryChanged())); |
771 QFETCH(QPointF, pos); |
771 QFETCH(QPointF, pos); |
772 QFETCH(QSizeF, size); |
772 QFETCH(QSizeF, size); |
773 widget.setPos(pos); |
773 widget.setPos(pos); |
774 widget.resize(size); |
774 widget.resize(size); |
|
775 if (!size.isNull()) |
|
776 QCOMPARE(spy.count(), 1); |
775 QCOMPARE(widget.geometry(), QRectF(pos, size)); |
777 QCOMPARE(widget.geometry(), QRectF(pos, size)); |
|
778 } |
|
779 |
|
780 void tst_QGraphicsWidget::width() |
|
781 { |
|
782 QGraphicsWidget w; |
|
783 QCOMPARE(w.property("width").toReal(), qreal(0)); |
|
784 QSignalSpy spy(&w, SIGNAL(widthChanged())); |
|
785 w.setProperty("width", qreal(50)); |
|
786 QCOMPARE(w.property("width").toReal(), qreal(50)); |
|
787 QCOMPARE(spy.count(), 1); |
|
788 //calling old school setGeometry should work too |
|
789 w.setGeometry(0, 0, 200, 200); |
|
790 QCOMPARE(spy.count(), 2); |
|
791 } |
|
792 |
|
793 void tst_QGraphicsWidget::height() |
|
794 { |
|
795 QGraphicsWidget w; |
|
796 QCOMPARE(w.property("height").toReal(), qreal(0)); |
|
797 QSignalSpy spy(&w, SIGNAL(heightChanged())); |
|
798 w.setProperty("height", qreal(50)); |
|
799 QCOMPARE(w.property("height").toReal(), qreal(50)); |
|
800 QCOMPARE(spy.count(), 1); |
|
801 //calling old school setGeometry should work too |
|
802 w.setGeometry(0, 0, 200, 200); |
|
803 QCOMPARE(spy.count(), 2); |
776 } |
804 } |
777 |
805 |
778 void tst_QGraphicsWidget::getContentsMargins_data() |
806 void tst_QGraphicsWidget::getContentsMargins_data() |
779 { |
807 { |
780 QTest::addColumn<qreal>("left"); |
808 QTest::addColumn<qreal>("left"); |
1456 window->show(); |
1477 window->show(); |
1457 QApplication::setActiveWindow(window); |
1478 QApplication::setActiveWindow(window); |
1458 QTest::qWaitForWindowShown(window); |
1479 QTest::qWaitForWindowShown(window); |
1459 |
1480 |
1460 lineEdit->setFocus(); |
1481 lineEdit->setFocus(); |
1461 QTest::qWait(25); |
|
1462 QTRY_VERIFY(lineEdit->hasFocus()); |
1482 QTRY_VERIFY(lineEdit->hasFocus()); |
1463 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1483 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1464 QTest::qWait(25); |
|
1465 QTRY_VERIFY(w1_1->hasFocus()); |
1484 QTRY_VERIFY(w1_1->hasFocus()); |
1466 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1485 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1467 QTest::qWait(25); |
|
1468 QTRY_VERIFY(w1_2->hasFocus()); |
1486 QTRY_VERIFY(w1_2->hasFocus()); |
1469 |
1487 |
1470 // remove the tabFocusFirst and insert new item |
1488 // remove the tabFocusFirst and insert new item |
1471 delete w1_1; // calls _q_removeItemLater |
1489 delete w1_1; // calls _q_removeItemLater |
1472 QTest::qWait(25); |
|
1473 SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget; |
1490 SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget; |
1474 w1_3->setFocusPolicy(Qt::StrongFocus); |
1491 w1_3->setFocusPolicy(Qt::StrongFocus); |
1475 w1_3->setData(0, "w1_3"); |
1492 w1_3->setData(0, "w1_3"); |
1476 w1_3->setGeometry(50,0,25, 25); |
1493 w1_3->setGeometry(50,0,25, 25); |
1477 scene.addItem(w1_3); |
1494 scene.addItem(w1_3); |
1478 QTRY_VERIFY(w1_2->hasFocus()); |
1495 QTRY_VERIFY(w1_2->hasFocus()); |
1479 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1496 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1480 QTest::qWait(25); |
|
1481 QTRY_VERIFY(lineEdit->hasFocus()); |
1497 QTRY_VERIFY(lineEdit->hasFocus()); |
1482 // tabFocusFirst should now point to w1_2 |
1498 // tabFocusFirst should now point to w1_2 |
1483 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1499 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1484 QTest::qWait(25); |
|
1485 QTRY_VERIFY(w1_2->hasFocus()); |
1500 QTRY_VERIFY(w1_2->hasFocus()); |
1486 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1501 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1487 QTest::qWait(25); |
|
1488 QTRY_VERIFY(w1_3->hasFocus()); |
1502 QTRY_VERIFY(w1_3->hasFocus()); |
1489 scene.removeItem(w1_2); // does not call _q_removeItemLater |
1503 scene.removeItem(w1_2); // does not call _q_removeItemLater |
1490 delete w1_2; // calls _q_removeItemLater |
1504 delete w1_2; // calls _q_removeItemLater |
1491 |
1505 |
1492 SubQGraphicsWidget *w1_4 = new SubQGraphicsWidget; |
1506 SubQGraphicsWidget *w1_4 = new SubQGraphicsWidget; |
1493 w1_4->setFocusPolicy(Qt::StrongFocus); |
1507 w1_4->setFocusPolicy(Qt::StrongFocus); |
1494 w1_4->setData(0, "w1_4"); |
1508 w1_4->setData(0, "w1_4"); |
1495 w1_4->setGeometry(75,0,25, 25); |
1509 w1_4->setGeometry(75,0,25, 25); |
1496 scene.addItem(w1_4); |
1510 scene.addItem(w1_4); |
1497 QTRY_VERIFY(w1_3->hasFocus()); |
1511 QTRY_VERIFY(w1_3->hasFocus()); |
1498 QTest::qWait(25); |
|
1499 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1512 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1500 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1513 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1501 QTest::qWait(25); |
|
1502 QTRY_VERIFY(lineEdit->hasFocus()); |
1514 QTRY_VERIFY(lineEdit->hasFocus()); |
1503 // tabFocusFirst should now point to w1_3 |
1515 // tabFocusFirst should now point to w1_3 |
1504 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1516 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1505 QTest::qWait(25); |
|
1506 QTRY_VERIFY(w1_3->hasFocus()); |
1517 QTRY_VERIFY(w1_3->hasFocus()); |
1507 QTest::qWait(25); |
|
1508 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1518 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1509 delete window; |
1519 delete window; |
1510 } |
1520 } |
1511 } |
1521 } |
1512 |
1522 |
1751 |
1760 |
1752 widget->setMinimumSize(min); |
1761 widget->setMinimumSize(min); |
1753 widget->setPreferredSize(pref); |
1762 widget->setPreferredSize(pref); |
1754 widget->setMaximumSize(max); |
1763 widget->setMaximumSize(max); |
1755 |
1764 |
1756 QApplication::processEvents(); |
|
1757 |
|
1758 for (i = 0; i < compareInstructions.count(); ++i) { |
1765 for (i = 0; i < compareInstructions.count(); ++i) { |
1759 Inst input = compareInstructions.at(i); |
1766 Inst input = compareInstructions.at(i); |
1760 switch (input.first) { |
1767 switch (input.first) { |
1761 case MinimumSize: |
1768 case MinimumSize: |
1762 QCOMPARE(widget->minimumSize(), input.second.toSizeF()); |
1769 QTRY_COMPARE(widget->minimumSize(), input.second.toSizeF()); |
1763 break; |
1770 break; |
1764 case PreferredSize: |
1771 case PreferredSize: |
1765 QCOMPARE(widget->preferredSize(), input.second.toSizeF()); |
1772 QTRY_COMPARE(widget->preferredSize(), input.second.toSizeF()); |
1766 break; |
1773 break; |
1767 case MaximumSize: |
1774 case MaximumSize: |
1768 QCOMPARE(widget->maximumSize(), input.second.toSizeF()); |
1775 QTRY_COMPARE(widget->maximumSize(), input.second.toSizeF()); |
1769 break; |
1776 break; |
1770 case Size: |
1777 case Size: |
1771 QCOMPARE(widget->size(), input.second.toSizeF()); |
1778 QTRY_COMPARE(widget->size(), input.second.toSizeF()); |
1772 break; |
1779 break; |
1773 case MinimumWidth: |
1780 case MinimumWidth: |
1774 QCOMPARE(widget->minimumWidth(), qreal(input.second.toDouble())); |
1781 QTRY_COMPARE(widget->minimumWidth(), qreal(input.second.toDouble())); |
1775 break; |
1782 break; |
1776 case PreferredWidth: |
1783 case PreferredWidth: |
1777 QCOMPARE(widget->preferredWidth(), qreal(input.second.toDouble())); |
1784 QTRY_COMPARE(widget->preferredWidth(), qreal(input.second.toDouble())); |
1778 break; |
1785 break; |
1779 case MaximumWidth: |
1786 case MaximumWidth: |
1780 QCOMPARE(widget->maximumWidth(), qreal(input.second.toDouble())); |
1787 QTRY_COMPARE(widget->maximumWidth(), qreal(input.second.toDouble())); |
1781 break; |
1788 break; |
1782 default: |
1789 default: |
1783 qWarning("instruction not implemented"); |
1790 qWarning("instruction not implemented"); |
1784 break; |
1791 break; |
1785 } |
1792 } |
1830 QGraphicsView view(&scene); |
1837 QGraphicsView view(&scene); |
1831 view.show(); |
1838 view.show(); |
1832 #ifdef Q_WS_X11 |
1839 #ifdef Q_WS_X11 |
1833 qt_x11_wait_for_window_manager(&view); |
1840 qt_x11_wait_for_window_manager(&view); |
1834 #endif |
1841 #endif |
1835 QTest::qWait(100); |
1842 |
1836 |
1843 QTRY_VERIFY(!scene.itemAt(25, 25)); |
1837 QVERIFY(!scene.itemAt(25, 25)); |
|
1838 widget->setGeometry(0, 112, 360, 528); |
1844 widget->setGeometry(0, 112, 360, 528); |
1839 QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1845 QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1840 widget2->setGeometry(0, 573, 360, 67); |
1846 widget2->setGeometry(0, 573, 360, 67); |
1841 QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1847 QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1842 QCOMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2); |
1848 QTRY_COMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2); |
1843 } |
1849 } |
1844 |
1850 |
1845 void tst_QGraphicsWidget::defaultSize() |
1851 void tst_QGraphicsWidget::defaultSize() |
1846 { |
1852 { |
1847 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
1853 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
1852 QGraphicsView view(&scene); |
1858 QGraphicsView view(&scene); |
1853 view.show(); |
1859 view.show(); |
1854 #ifdef Q_WS_X11 |
1860 #ifdef Q_WS_X11 |
1855 qt_x11_wait_for_window_manager(&view); |
1861 qt_x11_wait_for_window_manager(&view); |
1856 #endif |
1862 #endif |
1857 QTest::qWait(50); |
|
1858 QSizeF initialSize = widget->size(); |
1863 QSizeF initialSize = widget->size(); |
1859 |
1864 |
1860 widget->resize(initialSize); |
1865 widget->resize(initialSize); |
1861 QCOMPARE(widget->geometry().size(), initialSize); |
1866 QCOMPARE(widget->geometry().size(), initialSize); |
1862 widget->setVisible(false); |
1867 widget->setVisible(false); |
1863 widget->setMinimumSize(10, 10); |
1868 widget->setMinimumSize(10, 10); |
1864 widget->setPreferredSize(60, 60); |
1869 widget->setPreferredSize(60, 60); |
1865 widget->setMaximumSize(110, 110); |
1870 widget->setMaximumSize(110, 110); |
1866 widget->setVisible(true); |
1871 widget->setVisible(true); |
1867 QTest::qWait(50); |
|
1868 // should still have its size set to initialsize |
1872 // should still have its size set to initialsize |
1869 QCOMPARE(widget->geometry().size(), initialSize); |
1873 QTRY_COMPARE(widget->geometry().size(), initialSize); |
1870 |
1874 |
1871 } |
1875 } |
1872 |
1876 |
1873 void tst_QGraphicsWidget::explicitMouseGrabber() |
1877 void tst_QGraphicsWidget::explicitMouseGrabber() |
1874 { |
1878 { |
2730 view->show(); |
2732 view->show(); |
2731 window->setGeometry(0, 0, 70, 70); |
2733 window->setGeometry(0, 0, 70, 70); |
2732 QTest::qWaitForWindowShown(view); |
2734 QTest::qWaitForWindowShown(view); |
2733 |
2735 |
2734 { // here we go - simulate a interactive resize of the window |
2736 { // here we go - simulate a interactive resize of the window |
2735 QTest::qWait(100); |
|
2736 QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner |
2737 QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner |
2737 QTest::qWait(100); |
|
2738 |
2738 |
2739 QTest::mousePress(view->viewport(), Qt::LeftButton, 0, view->mapFromScene(71, 71), 200); |
2739 QTest::mousePress(view->viewport(), Qt::LeftButton, 0, view->mapFromScene(71, 71), 200); |
2740 view->grabMouse(); |
2740 view->grabMouse(); |
2741 // move both mouse cursor and set correct event in order to emulate resize |
2741 // move both mouse cursor and set correct event in order to emulate resize |
2742 QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200); |
2742 QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200); |
2848 widget->hide(); |
2847 widget->hide(); |
2849 scene.addItem(widget); |
2848 scene.addItem(widget); |
2850 |
2849 |
2851 widget->events.clear(); |
2850 widget->events.clear(); |
2852 |
2851 |
2853 QApplication::processEvents(); |
|
2854 |
|
2855 // Make sure the item got polish event. |
2852 // Make sure the item got polish event. |
2856 QVERIFY(widget->events.contains(QEvent::Polish)); |
2853 QTRY_VERIFY(widget->events.contains(QEvent::Polish)); |
|
2854 } |
|
2855 |
|
2856 void tst_QGraphicsWidget::initialShow() |
|
2857 { |
|
2858 class MyGraphicsWidget : public QGraphicsWidget |
|
2859 { public: |
|
2860 MyGraphicsWidget() : repaints(0) {} |
|
2861 int repaints; |
|
2862 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } |
|
2863 void polishEvent() { update(); } |
|
2864 }; |
|
2865 |
|
2866 QGraphicsScene scene; |
|
2867 MyGraphicsWidget *widget = new MyGraphicsWidget; |
|
2868 |
|
2869 QGraphicsView view(&scene); |
|
2870 view.show(); |
|
2871 QTest::qWaitForWindowShown(&view); |
|
2872 |
|
2873 scene.addItem(widget); |
|
2874 |
|
2875 QTRY_COMPARE(widget->repaints, 1); |
|
2876 } |
|
2877 |
|
2878 void tst_QGraphicsWidget::initialShow2() |
|
2879 { |
|
2880 class MyGraphicsWidget : public QGraphicsWidget |
|
2881 { public: |
|
2882 MyGraphicsWidget() : repaints(0) {} |
|
2883 int repaints; |
|
2884 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } |
|
2885 void polishEvent() { update(); } |
|
2886 }; |
|
2887 |
|
2888 // Don't let paint events triggered by the windowing system |
|
2889 // influence our test case. We're only interested in knowing |
|
2890 // whether a QGraphicsWidget generates an additional repaint |
|
2891 // on the inital show. Hence create a dummy scenario to find out |
|
2892 // how many repaints we should expect. |
|
2893 QGraphicsScene dummyScene(0, 0, 200, 200); |
|
2894 dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100)); |
|
2895 |
|
2896 QGraphicsView *dummyView = new QGraphicsView(&dummyScene); |
|
2897 dummyView->setWindowFlags(Qt::X11BypassWindowManagerHint); |
|
2898 EventSpy paintSpy(dummyView->viewport(), QEvent::Paint); |
|
2899 dummyView->show(); |
|
2900 QTest::qWaitForWindowShown(dummyView); |
|
2901 const int expectedRepaintCount = paintSpy.count(); |
|
2902 delete dummyView; |
|
2903 dummyView = 0; |
|
2904 |
|
2905 MyGraphicsWidget *widget = new MyGraphicsWidget; |
|
2906 widget->resize(100, 100); |
|
2907 |
|
2908 QGraphicsScene scene(0, 0, 200, 200); |
|
2909 scene.addItem(widget); |
|
2910 |
|
2911 QGraphicsView view(&scene); |
|
2912 view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
|
2913 view.show(); |
|
2914 QTest::qWaitForWindowShown(&view); |
|
2915 |
|
2916 QTRY_COMPARE(widget->repaints, expectedRepaintCount); |
2857 } |
2917 } |
2858 |
2918 |
2859 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
2919 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
2860 { |
2920 { |
2861 QGraphicsScene scene; |
2921 QGraphicsScene scene; |