tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   109     void fontChangedEvent();
   109     void fontChangedEvent();
   110     void fontPropagationWidgetItemWidget();
   110     void fontPropagationWidgetItemWidget();
   111     void fontPropagationSceneChange();
   111     void fontPropagationSceneChange();
   112     void geometry_data();
   112     void geometry_data();
   113     void geometry();
   113     void geometry();
       
   114     void geometryChanged();
   114     void width();
   115     void width();
   115     void height();
   116     void height();
   116     void getContentsMargins_data();
   117     void getContentsMargins_data();
   117     void getContentsMargins();
   118     void getContentsMargins();
   118     void initStyleOption_data();
   119     void initStyleOption_data();
   169     void initialShow();
   170     void initialShow();
   170     void initialShow2();
   171     void initialShow2();
   171     void itemChangeEvents();
   172     void itemChangeEvents();
   172     void itemSendGeometryPosChangesDeactivated();
   173     void itemSendGeometryPosChangesDeactivated();
   173 
   174 
       
   175     void fontPropagatesResolveToChildren();
       
   176     void fontPropagatesResolveToGrandChildren();
       
   177     void fontPropagatesResolveInParentChange();
       
   178     void fontPropagatesResolveViaNonWidget();
       
   179     void fontPropagatesResolveFromScene();
       
   180 
   174     // Task fixes
   181     // Task fixes
   175     void task236127_bspTreeIndexFails();
   182     void task236127_bspTreeIndexFails();
   176     void task243004_setStyleCrash();
   183     void task243004_setStyleCrash();
   177     void task250119_shortcutContext();
   184     void task250119_shortcutContext();
   178     void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems();
   185     void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems();
   619     QFont font(fontName);
   626     QFont font(fontName);
   620     widget.setFont(font);
   627     widget.setFont(font);
   621     QCOMPARE(widget.font().family(), font.family());
   628     QCOMPARE(widget.font().family(), font.family());
   622 }
   629 }
   623 
   630 
       
   631 void tst_QGraphicsWidget::fontPropagatesResolveToChildren()
       
   632 {
       
   633     QGraphicsWidget *root = new QGraphicsWidget();
       
   634     QGraphicsWidget *child1 = new QGraphicsWidget(root);
       
   635 
       
   636     QGraphicsScene scene;
       
   637     scene.addItem(root);
       
   638 
       
   639     QFont font;
       
   640     font.setItalic(true);
       
   641     root->setFont(font);
       
   642 
       
   643     QGraphicsWidget *child2 = new QGraphicsWidget(root);
       
   644     QGraphicsWidget *child3 = new QGraphicsWidget();
       
   645     child3->setParentItem(root);
       
   646 
       
   647     QGraphicsView view;
       
   648     view.setScene(&scene);
       
   649     view.show();
       
   650     QTest::qWaitForWindowShown(&view);
       
   651 
       
   652     QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
       
   653     QCOMPARE(root->font().resolve(), uint(QFont::StyleResolved));
       
   654     QCOMPARE(child1->font().resolve(), uint(QFont::StyleResolved));
       
   655     QCOMPARE(child2->font().resolve(), uint(QFont::StyleResolved));
       
   656     QCOMPARE(child3->font().resolve(), uint(QFont::StyleResolved));
       
   657 }
       
   658 
       
   659 void tst_QGraphicsWidget::fontPropagatesResolveToGrandChildren()
       
   660 {
       
   661     QGraphicsWidget *root = new QGraphicsWidget();
       
   662     QGraphicsWidget *child1 = new QGraphicsWidget(root);
       
   663     QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
       
   664 
       
   665     QGraphicsScene scene;
       
   666     scene.addItem(root);
       
   667 
       
   668     QFont font;
       
   669     font.setItalic(true);
       
   670     root->setFont(font);
       
   671 
       
   672     QGraphicsWidget *child2 = new QGraphicsWidget(root);
       
   673     QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
       
   674     QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2);
       
   675 
       
   676     QGraphicsWidget *child3 = new QGraphicsWidget();
       
   677     QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3);
       
   678     QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3);
       
   679     child3->setParentItem(root);
       
   680     grandChild5->setParentItem(child3);
       
   681 
       
   682     QGraphicsView view;
       
   683     view.setScene(&scene);
       
   684     view.show();
       
   685     QTest::qWaitForWindowShown(&view);
       
   686 
       
   687     QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
       
   688     QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
       
   689     QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
       
   690     QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved));
       
   691     QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved));
       
   692     QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved));
       
   693 }
       
   694 
       
   695 void tst_QGraphicsWidget::fontPropagatesResolveViaNonWidget()
       
   696 {
       
   697     QGraphicsWidget *root = new QGraphicsWidget();
       
   698     QGraphicsPixmapItem *child1 = new QGraphicsPixmapItem(root);
       
   699     QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
       
   700 
       
   701     QGraphicsScene scene;
       
   702     scene.addItem(root);
       
   703 
       
   704     QFont font;
       
   705     font.setItalic(true);
       
   706     root->setFont(font);
       
   707 
       
   708     QGraphicsPixmapItem *child2 = new QGraphicsPixmapItem(root);
       
   709     QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
       
   710     QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2);
       
   711 
       
   712     QGraphicsPixmapItem *child3 = new QGraphicsPixmapItem();
       
   713     QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3);
       
   714     QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3);
       
   715     child3->setParentItem(root);
       
   716     grandChild5->setParentItem(child3);
       
   717 
       
   718     QGraphicsView view;
       
   719     view.setScene(&scene);
       
   720     view.show();
       
   721     QTest::qWaitForWindowShown(&view);
       
   722 
       
   723     QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
       
   724     QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
       
   725     QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
       
   726     QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved));
       
   727     QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved));
       
   728     QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved));
       
   729 }
       
   730 
       
   731 void tst_QGraphicsWidget::fontPropagatesResolveFromScene()
       
   732 {
       
   733     QGraphicsWidget *root = new QGraphicsWidget();
       
   734     QGraphicsWidget *child1 = new QGraphicsWidget(root);
       
   735     QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
       
   736 
       
   737     QGraphicsScene scene;
       
   738     scene.addItem(root);
       
   739 
       
   740     QFont font;
       
   741     font.setItalic(true);
       
   742     scene.setFont(font);
       
   743 
       
   744     QGraphicsWidget *child2 = new QGraphicsWidget(root);
       
   745     QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
       
   746     QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2);
       
   747 
       
   748     QGraphicsWidget *child3 = new QGraphicsWidget();
       
   749     QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3);
       
   750     QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3);
       
   751     child3->setParentItem(root);
       
   752     grandChild5->setParentItem(child3);
       
   753 
       
   754     QGraphicsView view;
       
   755     view.setScene(&scene);
       
   756     view.show();
       
   757     QTest::qWaitForWindowShown(&view);
       
   758 
       
   759     QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
       
   760     QCOMPARE(root->font().resolve(), uint(QFont::StyleResolved));
       
   761     QCOMPARE(child1->font().resolve(), uint(QFont::StyleResolved));
       
   762     QCOMPARE(child2->font().resolve(), uint(QFont::StyleResolved));
       
   763     QCOMPARE(child3->font().resolve(), uint(QFont::StyleResolved));
       
   764     QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
       
   765     QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
       
   766     QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved));
       
   767     QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved));
       
   768     QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved));
       
   769 }
       
   770 
       
   771 void tst_QGraphicsWidget::fontPropagatesResolveInParentChange()
       
   772 {
       
   773     QGraphicsWidget *root = new QGraphicsWidget();
       
   774 
       
   775     QGraphicsWidget *child1 = new QGraphicsWidget(root);
       
   776     QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
       
   777 
       
   778     QGraphicsWidget *child2 = new QGraphicsWidget(root);
       
   779     QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
       
   780 
       
   781     QGraphicsScene scene;
       
   782     scene.addItem(root);
       
   783 
       
   784     QFont italicFont;
       
   785     italicFont.setItalic(true);
       
   786     child1->setFont(italicFont);
       
   787 
       
   788     QFont boldFont;
       
   789     boldFont.setBold(true);
       
   790     child2->setFont(boldFont);
       
   791 
       
   792     QVERIFY(grandChild1->font().italic());
       
   793     QVERIFY(!grandChild1->font().bold());
       
   794     QVERIFY(!grandChild2->font().italic());
       
   795     QVERIFY(grandChild2->font().bold());
       
   796 
       
   797     QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
       
   798     QCOMPARE(grandChild2->font().resolve(), uint(QFont::WeightResolved));
       
   799 
       
   800     grandChild2->setParentItem(child1);
       
   801 
       
   802     QGraphicsView view;
       
   803     view.setScene(&scene);
       
   804     view.show();
       
   805     QTest::qWaitForWindowShown(&view);
       
   806 
       
   807     QVERIFY(grandChild1->font().italic());
       
   808     QVERIFY(!grandChild1->font().bold());
       
   809     QVERIFY(grandChild2->font().italic());
       
   810     QVERIFY(!grandChild2->font().bold());
       
   811 
       
   812     QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
       
   813     QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
       
   814 
       
   815 }
       
   816 
   624 void tst_QGraphicsWidget::fontPropagation()
   817 void tst_QGraphicsWidget::fontPropagation()
   625 {
   818 {
   626     QGraphicsWidget *root = new QGraphicsWidget;
   819     QGraphicsWidget *root = new QGraphicsWidget;
   627     QGraphicsWidget *child0 = new QGraphicsWidget(root);
   820     QGraphicsWidget *child0 = new QGraphicsWidget(root);
   628     QGraphicsWidget *child1 = new QGraphicsWidget(child0);
   821     QGraphicsWidget *child1 = new QGraphicsWidget(child0);
   725     QFont font;
   918     QFont font;
   726     font.setPointSize(43);
   919     font.setPointSize(43);
   727     widget->setFont(font);
   920     widget->setFont(font);
   728 
   921 
   729     QCOMPARE(widget2->font().pointSize(), 43);
   922     QCOMPARE(widget2->font().pointSize(), 43);
       
   923     QCOMPARE(widget2->font().resolve(), uint(QFont::SizeResolved));
       
   924 
       
   925     widget->setFont(QFont());
       
   926 
       
   927     QCOMPARE(widget2->font().pointSize(), qApp->font().pointSize());
   730     QCOMPARE(widget2->font().resolve(), QFont().resolve());
   928     QCOMPARE(widget2->font().resolve(), QFont().resolve());
   731 
       
   732     widget->setFont(QFont());
       
   733 
       
   734     QCOMPARE(widget2->font().pointSize(), qApp->font().pointSize());
       
   735 }
   929 }
   736 
   930 
   737 void tst_QGraphicsWidget::fontPropagationSceneChange()
   931 void tst_QGraphicsWidget::fontPropagationSceneChange()
   738 {
   932 {
   739     QGraphicsWidget *widget = new QGraphicsWidget;
   933     QGraphicsWidget *widget = new QGraphicsWidget;
   774     QSignalSpy spy(&widget, SIGNAL(geometryChanged()));
   968     QSignalSpy spy(&widget, SIGNAL(geometryChanged()));
   775     QFETCH(QPointF, pos);
   969     QFETCH(QPointF, pos);
   776     QFETCH(QSizeF, size);
   970     QFETCH(QSizeF, size);
   777     widget.setPos(pos);
   971     widget.setPos(pos);
   778     widget.resize(size);
   972     widget.resize(size);
   779     if (!size.isNull())
   973     if (!size.isNull() && !pos.isNull())
       
   974         QCOMPARE(spy.count(), 2);
       
   975     if (!size.isNull() && pos.isNull())
   780         QCOMPARE(spy.count(), 1);
   976         QCOMPARE(spy.count(), 1);
   781     QCOMPARE(widget.geometry(), QRectF(pos, size));
   977     QCOMPARE(widget.geometry(), QRectF(pos, size));
       
   978 }
       
   979 
       
   980 void tst_QGraphicsWidget::geometryChanged()
       
   981 {
       
   982     QGraphicsWidget w;
       
   983     w.setGeometry(0, 0, 200, 200);
       
   984     QCOMPARE(w.geometry(), QRectF(0, 0, 200, 200));
       
   985     QSignalSpy spy(&w, SIGNAL(geometryChanged()));
       
   986     w.setGeometry(0, 0, 100, 100);
       
   987     QCOMPARE(spy.count(), 1);
       
   988     QCOMPARE(w.geometry(), QRectF(0, 0, 100, 100));
       
   989     w.setPos(10, 10);
       
   990     QCOMPARE(spy.count(), 2);
       
   991     QCOMPARE(w.geometry(), QRectF(10, 10, 100, 100));
       
   992 
   782 }
   993 }
   783 
   994 
   784 void tst_QGraphicsWidget::width()
   995 void tst_QGraphicsWidget::width()
   785 {
   996 {
   786     QGraphicsWidget w;
   997     QGraphicsWidget w;
   870     view.show();
  1081     view.show();
   871 #ifdef Q_WS_X11
  1082 #ifdef Q_WS_X11
   872     qt_x11_wait_for_window_manager(&view);
  1083     qt_x11_wait_for_window_manager(&view);
   873 #endif
  1084 #endif
   874     QApplication::setActiveWindow(&view);
  1085     QApplication::setActiveWindow(&view);
   875     QTRY_COMPARE(QApplication::activeWindow(), &view);
  1086     QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view);
   876 
  1087 
   877     view.setAlignment(Qt::AlignTop | Qt::AlignLeft);
  1088     view.setAlignment(Qt::AlignTop | Qt::AlignLeft);
   878     SubQGraphicsWidget *widget = new SubQGraphicsWidget;
  1089     SubQGraphicsWidget *widget = new SubQGraphicsWidget;
   879     widget->setAcceptsHoverEvents(true);
  1090     widget->setAcceptsHoverEvents(true);
   880     QStyleOption option;
  1091     QStyleOption option;
  1202     view.show();
  1413     view.show();
  1203 #ifdef Q_WS_X11
  1414 #ifdef Q_WS_X11
  1204     qt_x11_wait_for_window_manager(&view);
  1415     qt_x11_wait_for_window_manager(&view);
  1205 #endif
  1416 #endif
  1206     QApplication::setActiveWindow(&view);
  1417     QApplication::setActiveWindow(&view);
  1207     QTRY_COMPARE(QApplication::activeWindow(), &view);
  1418     QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view);
  1208 
  1419 
  1209     QGraphicsWidget *lastItem = 0;
  1420     QGraphicsWidget *lastItem = 0;
  1210     QTest::ignoreMessage(QtWarningMsg, "QGraphicsWidget::setTabOrder(0, 0) is undefined");
  1421     QTest::ignoreMessage(QtWarningMsg, "QGraphicsWidget::setTabOrder(0, 0) is undefined");
  1211     QGraphicsWidget::setTabOrder(0, 0);
  1422     QGraphicsWidget::setTabOrder(0, 0);
  1212 
  1423 
  1265     QGraphicsScene scene;
  1476     QGraphicsScene scene;
  1266     QGraphicsView view(&scene);
  1477     QGraphicsView view(&scene);
  1267     view.show();
  1478     view.show();
  1268     QApplication::setActiveWindow(&view);
  1479     QApplication::setActiveWindow(&view);
  1269     QTest::qWaitForWindowShown(&view);
  1480     QTest::qWaitForWindowShown(&view);
  1270     QTRY_COMPARE(QApplication::activeWindow(), &view);
  1481     QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view);
  1271 
  1482 
  1272     int i;
  1483     int i;
  1273     QGraphicsWidget *w1, *w2, *w3, *w4;
  1484     QGraphicsWidget *w1, *w2, *w3, *w4;
  1274     for (i = 1; i < 4; ++i) {
  1485     for (i = 1; i < 4; ++i) {
  1275         QGraphicsWidget *wid = new QGraphicsWidget;
  1486         QGraphicsWidget *wid = new QGraphicsWidget;
  1405     QGraphicsScene scene;
  1616     QGraphicsScene scene;
  1406     QGraphicsView view(&scene);
  1617     QGraphicsView view(&scene);
  1407     view.show();
  1618     view.show();
  1408     QApplication::setActiveWindow(&view);
  1619     QApplication::setActiveWindow(&view);
  1409     QTest::qWaitForWindowShown(&view);
  1620     QTest::qWaitForWindowShown(&view);
  1410     QTRY_COMPARE(QApplication::activeWindow(), &view);
  1621     QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view);
  1411 
  1622 
  1412     {
  1623     {
  1413         // parent/child focus
  1624         // parent/child focus
  1414         SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window);
  1625         SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window);
  1415         w->setFocusPolicy(Qt::StrongFocus);
  1626         w->setFocusPolicy(Qt::StrongFocus);
  1532     view.show();
  1743     view.show();
  1533 #ifdef Q_WS_X11
  1744 #ifdef Q_WS_X11
  1534     qt_x11_wait_for_window_manager(&view);
  1745     qt_x11_wait_for_window_manager(&view);
  1535 #endif
  1746 #endif
  1536     QApplication::setActiveWindow(&view);
  1747     QApplication::setActiveWindow(&view);
  1537     QTRY_COMPARE(QApplication::activeWindow(), &view);
  1748     QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view);
  1538 
  1749 
  1539     // delete item in focus chain with no focus and verify chain
  1750     // delete item in focus chain with no focus and verify chain
  1540     SubQGraphicsWidget *parent = new SubQGraphicsWidget(0, Qt::Window);
  1751     SubQGraphicsWidget *parent = new SubQGraphicsWidget(0, Qt::Window);
  1541     SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window);
  1752     SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window);
  1542     w->resize(50,50);
  1753     w->resize(50,50);
  2483     QGraphicsScene scene;
  2694     QGraphicsScene scene;
  2484     QGraphicsView view;
  2695     QGraphicsView view;
  2485     view.setScene(&scene);
  2696     view.setScene(&scene);
  2486     view.show();
  2697     view.show();
  2487     QApplication::setActiveWindow(&view);
  2698     QApplication::setActiveWindow(&view);
  2488     QTRY_COMPARE(QApplication::activeWindow(), &view);
  2699     QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view);
  2489 
  2700 
  2490 
  2701 
  2491     // *** Event: ***
  2702     // *** Event: ***
  2492 
  2703 
  2493     GraphicsWidget_task250119 w_event;
  2704     GraphicsWidget_task250119 w_event;