475 EventSpy focusInSpy(widget, QEvent::FocusIn); |
478 EventSpy focusInSpy(widget, QEvent::FocusIn); |
476 EventSpy focusOutSpy(widget, QEvent::FocusOut); |
479 EventSpy focusOutSpy(widget, QEvent::FocusOut); |
477 |
480 |
478 scene.addItem(widget); |
481 scene.addItem(widget); |
479 |
482 |
480 QVERIFY(!widget->hasFocus()); |
483 QTRY_VERIFY(!widget->hasFocus()); |
481 widget->setFocusPolicy(Qt::StrongFocus); |
484 widget->setFocusPolicy(Qt::StrongFocus); |
482 QVERIFY(!widget->hasFocus()); |
485 QTRY_VERIFY(!widget->hasFocus()); |
483 |
486 |
484 QGraphicsWidget *subWidget = new QGraphicsWidget(widget); |
487 QGraphicsWidget *subWidget = new QGraphicsWidget(widget); |
485 QVERIFY(!subWidget->hasFocus()); |
488 QTRY_VERIFY(!subWidget->hasFocus()); |
486 |
489 |
487 scene.setFocus(); |
490 scene.setFocus(); |
488 |
491 |
489 QVERIFY(!widget->hasFocus()); |
492 QTRY_VERIFY(!widget->hasFocus()); |
490 QVERIFY(!subWidget->hasFocus()); |
493 QTRY_VERIFY(!subWidget->hasFocus()); |
491 |
494 |
492 widget->setFocus(); |
495 widget->setFocus(); |
493 |
496 |
494 QVERIFY(widget->hasFocus()); |
497 QTRY_VERIFY(widget->hasFocus()); |
495 QCOMPARE(focusInSpy.count(), 1); |
498 QTRY_COMPARE(focusInSpy.count(), 1); |
496 QVERIFY(!subWidget->hasFocus()); |
499 QTRY_VERIFY(!subWidget->hasFocus()); |
497 |
500 |
498 QGraphicsWidget *otherSubWidget = new QGraphicsWidget; |
501 QGraphicsWidget *otherSubWidget = new QGraphicsWidget; |
499 EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn); |
502 EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn); |
500 EventSpy otherFocusOutSpy(otherSubWidget, QEvent::FocusOut); |
503 EventSpy otherFocusOutSpy(otherSubWidget, QEvent::FocusOut); |
501 |
504 |
502 otherSubWidget->setFocusPolicy(Qt::StrongFocus); |
505 otherSubWidget->setFocusPolicy(Qt::StrongFocus); |
503 otherSubWidget->setParentItem(widget); |
506 otherSubWidget->setParentItem(widget); |
504 |
507 |
505 QVERIFY(widget->hasFocus()); |
508 QTRY_VERIFY(widget->hasFocus()); |
506 QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget); |
509 QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget); |
507 QVERIFY(!subWidget->hasFocus()); |
510 QTRY_VERIFY(!subWidget->hasFocus()); |
508 QVERIFY(!otherSubWidget->hasFocus()); |
511 QTRY_VERIFY(!otherSubWidget->hasFocus()); |
509 |
512 |
510 widget->hide(); |
513 widget->hide(); |
511 QVERIFY(!widget->hasFocus()); // lose but still has subfocus |
514 QTRY_VERIFY(!widget->hasFocus()); // lose but still has subfocus |
512 QCOMPARE(focusInSpy.count(), 1); |
515 QCOMPARE(focusInSpy.count(), 1); |
513 QCOMPARE(focusOutSpy.count(), 1); |
516 QCOMPARE(focusOutSpy.count(), 1); |
514 |
517 |
515 widget->show(); |
518 widget->show(); |
516 QVERIFY(!widget->hasFocus()); // no regain |
519 QTRY_VERIFY(!widget->hasFocus()); // no regain |
517 QCOMPARE(focusInSpy.count(), 1); |
520 QCOMPARE(focusInSpy.count(), 1); |
518 QCOMPARE(focusOutSpy.count(), 1); |
521 QCOMPARE(focusOutSpy.count(), 1); |
519 |
522 |
520 widget->hide(); |
523 widget->hide(); |
521 |
524 |
522 // try to setup subFocus on item that can't take focus |
525 // try to setup subFocus on item that can't take focus |
523 subWidget->setFocus(); |
526 subWidget->setFocus(); |
524 QVERIFY(!subWidget->hasFocus()); |
527 QTRY_VERIFY(!subWidget->hasFocus()); |
525 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
528 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
526 |
529 |
527 // try to setup subFocus on item that can take focus |
530 // try to setup subFocus on item that can take focus |
528 otherSubWidget->setFocus(); |
531 otherSubWidget->setFocus(); |
529 QVERIFY(!otherSubWidget->hasFocus()); |
532 QTRY_VERIFY(!otherSubWidget->hasFocus()); |
530 QCOMPARE(widget->focusWidget(), otherSubWidget); |
533 QCOMPARE(widget->focusWidget(), otherSubWidget); |
531 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
534 QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
532 |
535 |
533 widget->show(); |
536 widget->show(); |
534 |
537 |
535 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 |
536 QCOMPARE(otherFocusInSpy.count(), 1); |
539 QCOMPARE(otherFocusInSpy.count(), 1); |
537 QCOMPARE(otherFocusOutSpy.count(), 0); |
540 QCOMPARE(otherFocusOutSpy.count(), 0); |
538 |
541 |
539 delete otherSubWidget; |
542 delete otherSubWidget; |
540 |
543 |
541 QCOMPARE(otherFocusOutSpy.count(), 1); |
544 QTRY_COMPARE(otherFocusOutSpy.count(), 1); |
542 QVERIFY(!scene.focusItem()); |
545 QVERIFY(!scene.focusItem()); |
543 QVERIFY(!widget->focusWidget()); |
546 QVERIFY(!widget->focusWidget()); |
544 } |
547 } |
545 |
548 |
546 Q_DECLARE_METATYPE(Qt::FocusPolicy) |
549 Q_DECLARE_METATYPE(Qt::FocusPolicy) |
575 QEvent windowActivate(QEvent::WindowActivate); |
578 QEvent windowActivate(QEvent::WindowActivate); |
576 qApp->sendEvent(&scene, &windowActivate); |
579 qApp->sendEvent(&scene, &windowActivate); |
577 |
580 |
578 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
581 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
579 scene.addItem(widget); |
582 scene.addItem(widget); |
580 QCOMPARE(Qt::NoFocus, widget->focusPolicy()); |
583 QTRY_COMPARE(Qt::NoFocus, widget->focusPolicy()); |
581 |
584 |
582 QFETCH(Qt::FocusPolicy, focusPolicy1); |
585 QFETCH(Qt::FocusPolicy, focusPolicy1); |
583 widget->setFocusPolicy(focusPolicy1); |
586 widget->setFocusPolicy(focusPolicy1); |
584 QCOMPARE(widget->focusPolicy(), focusPolicy1); |
587 QTRY_COMPARE(widget->focusPolicy(), focusPolicy1); |
585 bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
588 bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
586 bool wasFocusable = isFocusable; |
589 bool wasFocusable = isFocusable; |
587 QVERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus)); |
590 QTRY_VERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus)); |
588 widget->setFocus(); |
591 widget->setFocus(); |
589 QCOMPARE(widget->hasFocus(), isFocusable); |
592 QTRY_COMPARE(widget->hasFocus(), isFocusable); |
590 |
593 |
591 QFETCH(Qt::FocusPolicy, focusPolicy2); |
594 QFETCH(Qt::FocusPolicy, focusPolicy2); |
592 widget->setFocusPolicy(focusPolicy2); |
595 widget->setFocusPolicy(focusPolicy2); |
593 QCOMPARE(widget->focusPolicy(), focusPolicy2); |
596 QCOMPARE(widget->focusPolicy(), focusPolicy2); |
594 isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
597 isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
687 QCOMPARE(scene.font(), appFont); |
690 QCOMPARE(scene.font(), appFont); |
688 QCOMPARE(root->font(), appFont); |
691 QCOMPARE(root->font(), appFont); |
689 |
692 |
690 EventSpy rootSpyFont(root, QEvent::FontChange); |
693 EventSpy rootSpyFont(root, QEvent::FontChange); |
691 EventSpy rootSpyPolish(root, QEvent::Polish); |
694 EventSpy rootSpyPolish(root, QEvent::Polish); |
692 QCOMPARE(rootSpyFont.count(), 0); |
695 QTRY_COMPARE(rootSpyFont.count(), 0); |
693 QApplication::processEvents(); //The polish event is sent |
696 QTRY_COMPARE(rootSpyPolish.count(), 1); |
694 QCOMPARE(rootSpyPolish.count(), 1); |
|
695 QApplication::processEvents(); //Process events to see if we get the font change event |
|
696 //The font is still the same so no fontChangeEvent |
697 //The font is still the same so no fontChangeEvent |
697 QCOMPARE(rootSpyFont.count(), 0); |
698 QTRY_COMPARE(rootSpyFont.count(), 0); |
698 |
699 |
699 QFont font; |
700 QFont font; |
700 font.setPointSize(43); |
701 font.setPointSize(43); |
701 root->setFont(font); |
702 root->setFont(font); |
702 QApplication::processEvents(); //Process events to get the font change event |
|
703 //The font changed |
703 //The font changed |
704 QCOMPARE(rootSpyFont.count(), 1); |
704 QTRY_COMPARE(rootSpyFont.count(), 1); |
705 |
705 |
706 //then roll back to the default one. |
706 //then roll back to the default one. |
707 root->setFont(appFont); |
707 root->setFont(appFont); |
708 QApplication::processEvents(); //Process events to get the font change event |
|
709 //The font changed |
708 //The font changed |
710 QCOMPARE(rootSpyFont.count(), 2); |
709 QTRY_COMPARE(rootSpyFont.count(), 2); |
711 } |
710 } |
712 |
711 |
713 void tst_QGraphicsWidget::fontPropagationWidgetItemWidget() |
712 void tst_QGraphicsWidget::fontPropagationWidgetItemWidget() |
714 { |
713 { |
715 QGraphicsWidget *widget = new QGraphicsWidget; |
714 QGraphicsWidget *widget = new QGraphicsWidget; |
766 // QRectF geometry() const public |
765 // QRectF geometry() const public |
767 void tst_QGraphicsWidget::geometry() |
766 void tst_QGraphicsWidget::geometry() |
768 { |
767 { |
769 SubQGraphicsWidget widget; |
768 SubQGraphicsWidget widget; |
770 QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
769 QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
771 |
770 QSignalSpy spy(&widget, SIGNAL(geometryChanged())); |
772 QFETCH(QPointF, pos); |
771 QFETCH(QPointF, pos); |
773 QFETCH(QSizeF, size); |
772 QFETCH(QSizeF, size); |
774 widget.setPos(pos); |
773 widget.setPos(pos); |
775 widget.resize(size); |
774 widget.resize(size); |
|
775 if (!size.isNull()) |
|
776 QCOMPARE(spy.count(), 1); |
776 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); |
777 } |
804 } |
778 |
805 |
779 void tst_QGraphicsWidget::getContentsMargins_data() |
806 void tst_QGraphicsWidget::getContentsMargins_data() |
780 { |
807 { |
781 QTest::addColumn<qreal>("left"); |
808 QTest::addColumn<qreal>("left"); |
1457 window->show(); |
1477 window->show(); |
1458 QApplication::setActiveWindow(window); |
1478 QApplication::setActiveWindow(window); |
1459 QTest::qWaitForWindowShown(window); |
1479 QTest::qWaitForWindowShown(window); |
1460 |
1480 |
1461 lineEdit->setFocus(); |
1481 lineEdit->setFocus(); |
1462 QTest::qWait(25); |
|
1463 QTRY_VERIFY(lineEdit->hasFocus()); |
1482 QTRY_VERIFY(lineEdit->hasFocus()); |
1464 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1483 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1465 QTest::qWait(25); |
|
1466 QTRY_VERIFY(w1_1->hasFocus()); |
1484 QTRY_VERIFY(w1_1->hasFocus()); |
1467 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1485 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1468 QTest::qWait(25); |
|
1469 QTRY_VERIFY(w1_2->hasFocus()); |
1486 QTRY_VERIFY(w1_2->hasFocus()); |
1470 |
1487 |
1471 // remove the tabFocusFirst and insert new item |
1488 // remove the tabFocusFirst and insert new item |
1472 delete w1_1; // calls _q_removeItemLater |
1489 delete w1_1; // calls _q_removeItemLater |
1473 QTest::qWait(25); |
|
1474 SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget; |
1490 SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget; |
1475 w1_3->setFocusPolicy(Qt::StrongFocus); |
1491 w1_3->setFocusPolicy(Qt::StrongFocus); |
1476 w1_3->setData(0, "w1_3"); |
1492 w1_3->setData(0, "w1_3"); |
1477 w1_3->setGeometry(50,0,25, 25); |
1493 w1_3->setGeometry(50,0,25, 25); |
1478 scene.addItem(w1_3); |
1494 scene.addItem(w1_3); |
1479 QTRY_VERIFY(w1_2->hasFocus()); |
1495 QTRY_VERIFY(w1_2->hasFocus()); |
1480 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1496 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1481 QTest::qWait(25); |
|
1482 QTRY_VERIFY(lineEdit->hasFocus()); |
1497 QTRY_VERIFY(lineEdit->hasFocus()); |
1483 // tabFocusFirst should now point to w1_2 |
1498 // tabFocusFirst should now point to w1_2 |
1484 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1499 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1485 QTest::qWait(25); |
|
1486 QTRY_VERIFY(w1_2->hasFocus()); |
1500 QTRY_VERIFY(w1_2->hasFocus()); |
1487 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1501 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1488 QTest::qWait(25); |
|
1489 QTRY_VERIFY(w1_3->hasFocus()); |
1502 QTRY_VERIFY(w1_3->hasFocus()); |
1490 scene.removeItem(w1_2); // does not call _q_removeItemLater |
1503 scene.removeItem(w1_2); // does not call _q_removeItemLater |
1491 delete w1_2; // calls _q_removeItemLater |
1504 delete w1_2; // calls _q_removeItemLater |
1492 |
1505 |
1493 SubQGraphicsWidget *w1_4 = new SubQGraphicsWidget; |
1506 SubQGraphicsWidget *w1_4 = new SubQGraphicsWidget; |
1494 w1_4->setFocusPolicy(Qt::StrongFocus); |
1507 w1_4->setFocusPolicy(Qt::StrongFocus); |
1495 w1_4->setData(0, "w1_4"); |
1508 w1_4->setData(0, "w1_4"); |
1496 w1_4->setGeometry(75,0,25, 25); |
1509 w1_4->setGeometry(75,0,25, 25); |
1497 scene.addItem(w1_4); |
1510 scene.addItem(w1_4); |
1498 QTRY_VERIFY(w1_3->hasFocus()); |
1511 QTRY_VERIFY(w1_3->hasFocus()); |
1499 QTest::qWait(25); |
|
1500 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1512 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1501 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1513 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
1502 QTest::qWait(25); |
|
1503 QTRY_VERIFY(lineEdit->hasFocus()); |
1514 QTRY_VERIFY(lineEdit->hasFocus()); |
1504 // tabFocusFirst should now point to w1_3 |
1515 // tabFocusFirst should now point to w1_3 |
1505 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1516 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
1506 QTest::qWait(25); |
|
1507 QTRY_VERIFY(w1_3->hasFocus()); |
1517 QTRY_VERIFY(w1_3->hasFocus()); |
1508 QTest::qWait(25); |
|
1509 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1518 QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
1510 delete window; |
1519 delete window; |
1511 } |
1520 } |
1512 } |
1521 } |
1513 |
1522 |
1752 |
1760 |
1753 widget->setMinimumSize(min); |
1761 widget->setMinimumSize(min); |
1754 widget->setPreferredSize(pref); |
1762 widget->setPreferredSize(pref); |
1755 widget->setMaximumSize(max); |
1763 widget->setMaximumSize(max); |
1756 |
1764 |
1757 QApplication::processEvents(); |
|
1758 |
|
1759 for (i = 0; i < compareInstructions.count(); ++i) { |
1765 for (i = 0; i < compareInstructions.count(); ++i) { |
1760 Inst input = compareInstructions.at(i); |
1766 Inst input = compareInstructions.at(i); |
1761 switch (input.first) { |
1767 switch (input.first) { |
1762 case MinimumSize: |
1768 case MinimumSize: |
1763 QCOMPARE(widget->minimumSize(), input.second.toSizeF()); |
1769 QTRY_COMPARE(widget->minimumSize(), input.second.toSizeF()); |
1764 break; |
1770 break; |
1765 case PreferredSize: |
1771 case PreferredSize: |
1766 QCOMPARE(widget->preferredSize(), input.second.toSizeF()); |
1772 QTRY_COMPARE(widget->preferredSize(), input.second.toSizeF()); |
1767 break; |
1773 break; |
1768 case MaximumSize: |
1774 case MaximumSize: |
1769 QCOMPARE(widget->maximumSize(), input.second.toSizeF()); |
1775 QTRY_COMPARE(widget->maximumSize(), input.second.toSizeF()); |
1770 break; |
1776 break; |
1771 case Size: |
1777 case Size: |
1772 QCOMPARE(widget->size(), input.second.toSizeF()); |
1778 QTRY_COMPARE(widget->size(), input.second.toSizeF()); |
1773 break; |
1779 break; |
1774 case MinimumWidth: |
1780 case MinimumWidth: |
1775 QCOMPARE(widget->minimumWidth(), qreal(input.second.toDouble())); |
1781 QTRY_COMPARE(widget->minimumWidth(), qreal(input.second.toDouble())); |
1776 break; |
1782 break; |
1777 case PreferredWidth: |
1783 case PreferredWidth: |
1778 QCOMPARE(widget->preferredWidth(), qreal(input.second.toDouble())); |
1784 QTRY_COMPARE(widget->preferredWidth(), qreal(input.second.toDouble())); |
1779 break; |
1785 break; |
1780 case MaximumWidth: |
1786 case MaximumWidth: |
1781 QCOMPARE(widget->maximumWidth(), qreal(input.second.toDouble())); |
1787 QTRY_COMPARE(widget->maximumWidth(), qreal(input.second.toDouble())); |
1782 break; |
1788 break; |
1783 default: |
1789 default: |
1784 qWarning("instruction not implemented"); |
1790 qWarning("instruction not implemented"); |
1785 break; |
1791 break; |
1786 } |
1792 } |
1831 QGraphicsView view(&scene); |
1837 QGraphicsView view(&scene); |
1832 view.show(); |
1838 view.show(); |
1833 #ifdef Q_WS_X11 |
1839 #ifdef Q_WS_X11 |
1834 qt_x11_wait_for_window_manager(&view); |
1840 qt_x11_wait_for_window_manager(&view); |
1835 #endif |
1841 #endif |
1836 QTest::qWait(100); |
1842 |
1837 |
1843 QTRY_VERIFY(!scene.itemAt(25, 25)); |
1838 QVERIFY(!scene.itemAt(25, 25)); |
|
1839 widget->setGeometry(0, 112, 360, 528); |
1844 widget->setGeometry(0, 112, 360, 528); |
1840 QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1845 QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1841 widget2->setGeometry(0, 573, 360, 67); |
1846 widget2->setGeometry(0, 573, 360, 67); |
1842 QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1847 QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
1843 QCOMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2); |
1848 QTRY_COMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2); |
1844 } |
1849 } |
1845 |
1850 |
1846 void tst_QGraphicsWidget::defaultSize() |
1851 void tst_QGraphicsWidget::defaultSize() |
1847 { |
1852 { |
1848 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
1853 SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
1853 QGraphicsView view(&scene); |
1858 QGraphicsView view(&scene); |
1854 view.show(); |
1859 view.show(); |
1855 #ifdef Q_WS_X11 |
1860 #ifdef Q_WS_X11 |
1856 qt_x11_wait_for_window_manager(&view); |
1861 qt_x11_wait_for_window_manager(&view); |
1857 #endif |
1862 #endif |
1858 QTest::qWait(50); |
|
1859 QSizeF initialSize = widget->size(); |
1863 QSizeF initialSize = widget->size(); |
1860 |
1864 |
1861 widget->resize(initialSize); |
1865 widget->resize(initialSize); |
1862 QCOMPARE(widget->geometry().size(), initialSize); |
1866 QCOMPARE(widget->geometry().size(), initialSize); |
1863 widget->setVisible(false); |
1867 widget->setVisible(false); |
1864 widget->setMinimumSize(10, 10); |
1868 widget->setMinimumSize(10, 10); |
1865 widget->setPreferredSize(60, 60); |
1869 widget->setPreferredSize(60, 60); |
1866 widget->setMaximumSize(110, 110); |
1870 widget->setMaximumSize(110, 110); |
1867 widget->setVisible(true); |
1871 widget->setVisible(true); |
1868 QTest::qWait(50); |
|
1869 // should still have its size set to initialsize |
1872 // should still have its size set to initialsize |
1870 QCOMPARE(widget->geometry().size(), initialSize); |
1873 QTRY_COMPARE(widget->geometry().size(), initialSize); |
1871 |
1874 |
1872 } |
1875 } |
1873 |
1876 |
1874 void tst_QGraphicsWidget::explicitMouseGrabber() |
1877 void tst_QGraphicsWidget::explicitMouseGrabber() |
1875 { |
1878 { |
2731 view->show(); |
2732 view->show(); |
2732 window->setGeometry(0, 0, 70, 70); |
2733 window->setGeometry(0, 0, 70, 70); |
2733 QTest::qWaitForWindowShown(view); |
2734 QTest::qWaitForWindowShown(view); |
2734 |
2735 |
2735 { // here we go - simulate a interactive resize of the window |
2736 { // here we go - simulate a interactive resize of the window |
2736 QTest::qWait(100); |
|
2737 QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner |
2737 QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner |
2738 QTest::qWait(100); |
|
2739 |
2738 |
2740 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); |
2741 view->grabMouse(); |
2740 view->grabMouse(); |
2742 // 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 |
2743 QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200); |
2742 QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200); |
2872 |
2868 |
2873 QGraphicsView view(&scene); |
2869 QGraphicsView view(&scene); |
2874 view.show(); |
2870 view.show(); |
2875 QTest::qWaitForWindowShown(&view); |
2871 QTest::qWaitForWindowShown(&view); |
2876 |
2872 |
2877 QTest::qWait(100); |
|
2878 scene.addItem(widget); |
2873 scene.addItem(widget); |
2879 QTest::qWait(100); |
2874 |
2880 |
2875 QTRY_COMPARE(widget->repaints, 1); |
2881 QCOMPARE(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); |
2882 } |
2917 } |
2883 |
2918 |
2884 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
2919 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
2885 { |
2920 { |
2886 QGraphicsScene scene; |
2921 QGraphicsScene scene; |