tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -181,6 +181,7 @@
     void updateAndDelete();
     void inputMethod();
     void clickFocus();
+    void windowFrameMargins();
 };
 
 // Subclass that exposes the protected functions.
@@ -1286,8 +1287,9 @@
     QGraphicsScene scene;
     QGraphicsView view(&scene);
     view.show();
+    QApplication::setActiveWindow(&view);
     QTest::qWaitForWindowShown(&view);
-    QTest::qWait(70);
+    QTRY_VERIFY(view.isActiveWindow());
 
     SubQGraphicsProxyWidget proxy;
 
@@ -1298,14 +1300,14 @@
     w->show();
     QTest::qWaitForWindowShown(w);
     QApplication::processEvents();
-    QTest::qWait(100);
+    QTest::qWait(30);
     proxy.setWidget(w);
     scene.addItem(&proxy);
 
     //make sure we flush all the paint events
-    QTest::qWait(70);
+    QTest::qWait(30);
     QTRY_VERIFY(proxy.paintCount > 1);
-    QTest::qWait(110);
+    QTest::qWait(30);
     proxy.paintCount = 0;
 
     w->update();
@@ -2573,20 +2575,22 @@
     proxy->setWidget(widget);
     proxy->show();
     scene.addItem(proxy);
+    QApplication::setActiveWindow(&view);
     QTest::qWaitForWindowShown(&view);
     QApplication::processEvents();
+    QTRY_VERIFY(view.isActiveWindow());
 
     // in
     QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center())));
     sendMouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center())));
-    QTest::qWait(125);
-    QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor);
+    QTest::qWait(12);
+    QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor);
 
     // out
     QTest::mouseMove(view.viewport(), QPoint(1, 1));
     sendMouseMove(view.viewport(), QPoint(1, 1));
-    QTest::qWait(125);
-    QCOMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor);
+    QTest::qWait(12);
+    QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor);
 #endif
 }
 
@@ -2746,10 +2750,12 @@
     widget->resize(100, 100);
     QGraphicsProxyWidget *proxy = scene.addWidget(widget);
     proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
+
+    QApplication::setActiveWindow(&view);
     view.show();
     QTest::qWaitForWindowShown(&view);
     QApplication::sendPostedEvents();
-    QTest::qWait(150);
+    QTRY_VERIFY(view.isActiveWindow());
 
     qRegisterMetaType<QList<QRectF> >("QList<QRectF>");
     QSignalSpy signalSpy(&scene, SIGNAL(changed(const QList<QRectF> &)));
@@ -3501,6 +3507,29 @@
     QVERIFY(!proxy->widget()->hasFocus());
 }
 
+void tst_QGraphicsProxyWidget::windowFrameMargins()
+{
+    // Make sure the top margin is non-zero when passing Qt::Window.
+    QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, Qt::Window);
+
+    qreal left, top, right, bottom;
+    proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+    QVERIFY(top > 0);
+
+    proxy->setWidget(new QPushButton("testtest"));
+    proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+    QVERIFY(top > 0);
+
+    QGraphicsScene scene;
+    scene.addItem(proxy);
+    proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+    QVERIFY(top > 0);
+
+    proxy->unsetWindowFrameMargins();
+    proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+    QVERIFY(top > 0);
+}
+
 QTEST_MAIN(tst_QGraphicsProxyWidget)
 #include "tst_qgraphicsproxywidget.moc"