tests/auto/qwidget/tst_qwidget.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   330     void sendUpdateRequestImmediately();
   330     void sendUpdateRequestImmediately();
   331     void painterRedirection();
   331     void painterRedirection();
   332     void doubleRepaint();
   332     void doubleRepaint();
   333 #ifndef Q_WS_MAC
   333 #ifndef Q_WS_MAC
   334     void resizeInPaintEvent();
   334     void resizeInPaintEvent();
       
   335     void opaqueChildren();
   335 #endif
   336 #endif
   336 
   337 
   337     void setMaskInResizeEvent();
   338     void setMaskInResizeEvent();
   338     void moveInResizeEvent();
   339     void moveInResizeEvent();
   339 
   340 
   381 
   382 
   382     void destroyBackingStore();
   383     void destroyBackingStore();
   383 
   384 
   384     void activateWindow();
   385     void activateWindow();
   385 
   386 
       
   387     void openModal_taskQTBUG_5804();
       
   388 
   386 #ifdef Q_OS_SYMBIAN
   389 #ifdef Q_OS_SYMBIAN
   387     void cbaVisibility();
   390     void cbaVisibility();
   388 #endif
   391 #endif
       
   392 
       
   393     void focusProxyAndInputMethods();
       
   394     void scrollWithoutBackingStore();
   389 
   395 
   390 private:
   396 private:
   391     bool ensureScreenSize(int width, int height);
   397     bool ensureScreenSize(int width, int height);
   392     QWidget *testWidget;
   398     QWidget *testWidget;
   393 };
   399 };
  2980         if (child == child3) {
  2986         if (child == child3) {
  2981 #ifdef Q_OS_WINCE
  2987 #ifdef Q_OS_WINCE
  2982             qApp->processEvents();
  2988             qApp->processEvents();
  2983 #endif
  2989 #endif
  2984 #ifndef Q_WS_MAC
  2990 #ifndef Q_WS_MAC
  2985             QEXPECT_FAIL(0, "Task 153869", Continue);
  2991             QEXPECT_FAIL(0, "See QTBUG-493", Continue);
  2986 #endif
  2992 #endif
  2987             QCOMPARE(child->numPaintEvents, 0);
  2993             QCOMPARE(child->numPaintEvents, 0);
  2988         } else {
  2994         } else {
  2989             QCOMPARE(child->numPaintEvents, 0);
  2995             QCOMPARE(child->numPaintEvents, 0);
  2990         }
  2996         }
  3325     QCOMPARE(wr->objectName(), QString("w2"));
  3331     QCOMPARE(wr->objectName(), QString("w2"));
  3326 
  3332 
  3327     w2->lower();
  3333     w2->lower();
  3328     qApp->processEvents();
  3334     qApp->processEvents();
  3329     QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)));
  3335     QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)));
  3330     QCOMPARE(wr->objectName(), QString("w1"));
  3336     const bool match = (wr->objectName() == QString("w1"));
  3331 
       
  3332     w2->raise();
  3337     w2->raise();
       
  3338     QVERIFY(match);
       
  3339 
  3333     qApp->processEvents();
  3340     qApp->processEvents();
  3334     QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)));
  3341     QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)));
  3335     QCOMPARE(wr->objectName(), QString("w2"));
  3342     QCOMPARE(wr->objectName(), QString("w2"));
  3336 
  3343 
  3337 
  3344 
  6317         QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1)));
  6324         QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1)));
  6318 
  6325 
  6319         widget.show();
  6326         widget.show();
  6320         expected =
  6327         expected =
  6321             EventRecorder::EventList()
  6328             EventRecorder::EventList()
       
  6329             << qMakePair(&widget, QEvent::WinIdChange)
  6322             << qMakePair(&widget, QEvent::Polish)
  6330             << qMakePair(&widget, QEvent::Polish)
  6323             << qMakePair(&widget, QEvent::Move)
  6331             << qMakePair(&widget, QEvent::Move)
  6324             << qMakePair(&widget, QEvent::Resize)
  6332             << qMakePair(&widget, QEvent::Resize)
  6325             << qMakePair(&widget, QEvent::Show);
  6333             << qMakePair(&widget, QEvent::Show);
  6326 
  6334 
  6402         spy.clear();
  6410         spy.clear();
  6403 
  6411 
  6404         widget.show();
  6412         widget.show();
  6405         expected =
  6413         expected =
  6406             EventRecorder::EventList()
  6414             EventRecorder::EventList()
       
  6415             << qMakePair(&widget, QEvent::WinIdChange)
  6407             << qMakePair(&widget, QEvent::Polish)
  6416             << qMakePair(&widget, QEvent::Polish)
  6408 #ifdef QT_HAS_QT3SUPPORT
  6417 #ifdef QT_HAS_QT3SUPPORT
  6409             << qMakePair(&widget, QEvent::ChildInserted)
  6418             << qMakePair(&widget, QEvent::ChildInserted)
  6410             << qMakePair(&widget, QEvent::ChildInserted)
  6419             << qMakePair(&widget, QEvent::ChildInserted)
  6411 #endif
  6420 #endif
  6499         spy.clear();
  6508         spy.clear();
  6500 
  6509 
  6501         widget.show();
  6510         widget.show();
  6502         expected =
  6511         expected =
  6503             EventRecorder::EventList()
  6512             EventRecorder::EventList()
       
  6513             << qMakePair(&widget, QEvent::WinIdChange)
  6504             << qMakePair(&widget, QEvent::Polish)
  6514             << qMakePair(&widget, QEvent::Polish)
  6505 #ifdef QT_HAS_QT3SUPPORT
  6515 #ifdef QT_HAS_QT3SUPPORT
  6506             << qMakePair(&widget, QEvent::ChildInserted)
  6516             << qMakePair(&widget, QEvent::ChildInserted)
  6507 #endif
  6517 #endif
  6508             << qMakePair(&widget, QEvent::ChildPolished)
  6518             << qMakePair(&widget, QEvent::ChildPolished)
  8270 
  8280 
  8271     QTest::qWait(10);
  8281     QTest::qWait(10);
  8272     // Make sure the resize triggers another update.
  8282     // Make sure the resize triggers another update.
  8273     QTRY_COMPARE(widget.numPaintEvents, 1);
  8283     QTRY_COMPARE(widget.numPaintEvents, 1);
  8274 }
  8284 }
       
  8285 
       
  8286 void tst_QWidget::opaqueChildren()
       
  8287 {
       
  8288     QWidget widget;
       
  8289     widget.resize(200, 200);
       
  8290 
       
  8291     QWidget child(&widget);
       
  8292     child.setGeometry(-700, -700, 200, 200);
       
  8293 
       
  8294     QWidget grandChild(&child);
       
  8295     grandChild.resize(200, 200);
       
  8296 
       
  8297     QWidget greatGrandChild(&grandChild);
       
  8298     greatGrandChild.setGeometry(50, 50, 200, 200);
       
  8299     greatGrandChild.setPalette(Qt::red);
       
  8300     greatGrandChild.setAutoFillBackground(true); // Opaque child widget.
       
  8301 
       
  8302     widget.show();
       
  8303 #ifdef Q_WS_X11
       
  8304     qt_x11_wait_for_window_manager(&widget);
       
  8305 #endif
       
  8306     QTest::qWait(100);
       
  8307 
       
  8308     // Child, grandChild and greatGrandChild are outside the ancestor clip.
       
  8309     QRegion expectedOpaqueRegion(50, 50, 150, 150);
       
  8310     QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion);
       
  8311 
       
  8312     // Now they are all inside the ancestor clip.
       
  8313     child.setGeometry(50, 50, 150, 150);
       
  8314     QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion);
       
  8315 
       
  8316     // Set mask on greatGrandChild.
       
  8317     const QRegion mask(10, 10, 50, 50);
       
  8318     greatGrandChild.setMask(mask);
       
  8319     expectedOpaqueRegion &= mask.translated(50, 50);
       
  8320     QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion);
       
  8321 
       
  8322     // Make greatGrandChild "transparent".
       
  8323     greatGrandChild.setAutoFillBackground(false);
       
  8324     QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), QRegion());
       
  8325 }
  8275 #endif
  8326 #endif
  8276 
  8327 
  8277 
  8328 
  8278 class MaskSetWidget : public QWidget
  8329 class MaskSetWidget : public QWidget
  8279 {
  8330 {
  9496 
  9547 
  9497     // Ensure the existing effect is deleted when deleting the widget.
  9548     // Ensure the existing effect is deleted when deleting the widget.
  9498     delete widget;
  9549     delete widget;
  9499     QVERIFY(!blurEffect);
  9550     QVERIFY(!blurEffect);
  9500     delete anotherWidget;
  9551     delete anotherWidget;
       
  9552 
       
  9553     // Ensure the effect is uninstalled when deleting it
       
  9554     widget = new QWidget;
       
  9555     blurEffect = new QGraphicsBlurEffect;
       
  9556     widget->setGraphicsEffect(blurEffect);
       
  9557     delete blurEffect;
       
  9558     QVERIFY(!widget->graphicsEffect());
       
  9559 
       
  9560     // Ensure the existing effect is uninstalled and deleted when setting a null effect
       
  9561     blurEffect = new QGraphicsBlurEffect;
       
  9562     widget->setGraphicsEffect(blurEffect);
       
  9563     widget->setGraphicsEffect(0);
       
  9564     QVERIFY(!widget->graphicsEffect());
       
  9565     QVERIFY(!blurEffect);
       
  9566 
       
  9567     delete widget;
  9501 }
  9568 }
  9502 
  9569 
  9503 void tst_QWidget::activateWindow()
  9570 void tst_QWidget::activateWindow()
  9504 {
  9571 {
  9505     // Test case for task 260685
  9572     // Test case for task 260685
  9533 
  9600 
  9534     QTRY_VERIFY(mainwindow->isActiveWindow());
  9601     QTRY_VERIFY(mainwindow->isActiveWindow());
  9535     QTRY_VERIFY(!mainwindow2->isActiveWindow());
  9602     QTRY_VERIFY(!mainwindow2->isActiveWindow());
  9536 }
  9603 }
  9537 
  9604 
       
  9605 void tst_QWidget::openModal_taskQTBUG_5804()
       
  9606 {
       
  9607     class Widget : public QWidget
       
  9608     {
       
  9609     public:
       
  9610         Widget(QWidget *parent) : QWidget(parent)
       
  9611         {
       
  9612         }
       
  9613         ~Widget()
       
  9614         {
       
  9615             QMessageBox msgbox;
       
  9616             QTimer::singleShot(10, &msgbox, SLOT(accept()));
       
  9617             msgbox.exec(); //open a modal dialog
       
  9618         }
       
  9619     };
       
  9620 
       
  9621     QWidget *win = new QWidget;
       
  9622     new Widget(win);
       
  9623     win->show();
       
  9624     QTest::qWaitForWindowShown(win);
       
  9625     delete win;
       
  9626 }
       
  9627 
  9538 #ifdef Q_OS_SYMBIAN
  9628 #ifdef Q_OS_SYMBIAN
  9539 void tst_QWidget::cbaVisibility()
  9629 void tst_QWidget::cbaVisibility()
  9540 {
  9630 {
  9541     // Test case for task 261048
  9631     // Test case for task 261048
  9542 
  9632 
  9571     CEikButtonGroupContainer* buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba();
  9661     CEikButtonGroupContainer* buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba();
  9572     QVERIFY(buttonGroup->IsVisible());
  9662     QVERIFY(buttonGroup->IsVisible());
  9573 }
  9663 }
  9574 #endif
  9664 #endif
  9575 
  9665 
       
  9666 class InputContextTester : public QInputContext
       
  9667 {
       
  9668     Q_OBJECT
       
  9669 public:
       
  9670     QString identifierName() { return QString(); }
       
  9671     bool isComposing() const { return false; }
       
  9672     QString language() { return QString(); }
       
  9673     void reset() { ++resets; }
       
  9674     int resets;
       
  9675 };
       
  9676 
       
  9677 void tst_QWidget::focusProxyAndInputMethods()
       
  9678 {
       
  9679     InputContextTester *inputContext = new InputContextTester;
       
  9680     QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint);
       
  9681     toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
       
  9682     toplevel->setInputContext(inputContext); // ownership is transferred
       
  9683 
       
  9684     QWidget *child = new QWidget(toplevel);
       
  9685     child->setFocusProxy(toplevel);
       
  9686     child->setAttribute(Qt::WA_InputMethodEnabled, true);
       
  9687 
       
  9688     toplevel->setFocusPolicy(Qt::WheelFocus);
       
  9689     child->setFocusPolicy(Qt::WheelFocus);
       
  9690 
       
  9691     QVERIFY(!child->hasFocus());
       
  9692     QVERIFY(!toplevel->hasFocus());
       
  9693 
       
  9694     toplevel->show();
       
  9695     QTest::qWaitForWindowShown(toplevel);
       
  9696     QApplication::setActiveWindow(toplevel);
       
  9697     QVERIFY(toplevel->hasFocus());
       
  9698     QVERIFY(child->hasFocus());
       
  9699 
       
  9700     // verify that toggling input methods on the child widget
       
  9701     // correctly propagate to the focus proxy's input method
       
  9702     // and that the input method gets the focus proxy passed
       
  9703     // as the focus widget instead of the child widget.
       
  9704     // otherwise input method queries go to the wrong widget
       
  9705 
       
  9706     QCOMPARE(inputContext->focusWidget(), toplevel);
       
  9707 
       
  9708     child->setAttribute(Qt::WA_InputMethodEnabled, false);
       
  9709     QVERIFY(!inputContext->focusWidget());
       
  9710 
       
  9711     child->setAttribute(Qt::WA_InputMethodEnabled, true);
       
  9712     QCOMPARE(inputContext->focusWidget(), toplevel);
       
  9713 
       
  9714     child->setEnabled(false);
       
  9715     QVERIFY(!inputContext->focusWidget());
       
  9716 
       
  9717     child->setEnabled(true);
       
  9718     QCOMPARE(inputContext->focusWidget(), toplevel);
       
  9719 
       
  9720     delete toplevel;
       
  9721 }
       
  9722 
       
  9723 class scrollWidgetWBS : public QWidget
       
  9724 {
       
  9725 public:
       
  9726     void deleteBackingStore()
       
  9727     {
       
  9728         if (static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) {
       
  9729             delete static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore;    
       
  9730             static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore = 0;
       
  9731         }
       
  9732     }
       
  9733     void enableBackingStore()
       
  9734     {
       
  9735         if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) {
       
  9736             static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore = new QWidgetBackingStore(this);
       
  9737             static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBuffer(this->rect());
       
  9738             repaint();
       
  9739         }
       
  9740     }
       
  9741 };
       
  9742 
       
  9743 void tst_QWidget::scrollWithoutBackingStore()
       
  9744 {
       
  9745     scrollWidgetWBS scrollable;
       
  9746     scrollable.resize(100,100);
       
  9747     QLabel child(QString("@"),&scrollable);
       
  9748     child.resize(50,50);
       
  9749     scrollable.show();
       
  9750     QTest::qWaitForWindowShown(&scrollable);
       
  9751     scrollable.scroll(50,50);
       
  9752     QCOMPARE(child.pos(),QPoint(50,50));
       
  9753     scrollable.deleteBackingStore();
       
  9754     scrollable.scroll(-25,-25);
       
  9755     QCOMPARE(child.pos(),QPoint(25,25));
       
  9756     scrollable.enableBackingStore();
       
  9757     QCOMPARE(child.pos(),QPoint(25,25));
       
  9758 }
       
  9759 
  9576 QTEST_MAIN(tst_QWidget)
  9760 QTEST_MAIN(tst_QWidget)
  9577 #include "tst_qwidget.moc"
  9761 #include "tst_qwidget.moc"