tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp
branchRCL_3
changeset 7 3f74d0d4af4c
parent 4 3b1da2848fc7
equal deleted inserted replaced
6:dee5afe5301f 7:3f74d0d4af4c
    69     void patternBackground();
    69     void patternBackground();
    70 
    70 
    71     void viewportCrash();
    71     void viewportCrash();
    72     void task214488_layoutDirection_data();
    72     void task214488_layoutDirection_data();
    73     void task214488_layoutDirection();
    73     void task214488_layoutDirection();
    74     void wheelEvent_data();
       
    75     void wheelEvent();
       
    76 };
    74 };
    77 
    75 
    78 tst_QAbstractScrollArea::tst_QAbstractScrollArea()
    76 tst_QAbstractScrollArea::tst_QAbstractScrollArea()
    79 {
    77 {
    80 }
    78 }
   296         setAttribute(Qt::WA_PaintOnScreen, true);
   294         setAttribute(Qt::WA_PaintOnScreen, true);
   297         setAttribute(Qt::WA_PaintOnScreen, false);
   295         setAttribute(Qt::WA_PaintOnScreen, false);
   298 
   296 
   299         setAttribute(Qt::WA_DropSiteRegistered, true);
   297         setAttribute(Qt::WA_DropSiteRegistered, true);
   300 
   298 
   301         startTimer(200);
   299         startTimer(2000);
   302     }
   300     }
   303 
   301 
   304     void timerEvent(QTimerEvent *)
   302     void timerEvent(QTimerEvent *event)
   305     {
   303     {
   306         // should not crash.
   304         // should not crash.
   307         (void)new QScrollArea(this);
   305         (void)new QScrollArea(this);
   308         accept();
   306         accept();
   309     }
   307     }
   385 
   383 
   386     scrollArea.render(&image);
   384     scrollArea.render(&image);
   387     QCOMPARE(image.pixel(QPoint(20,20)) , QColor(Qt::red).rgb());
   385     QCOMPARE(image.pixel(QPoint(20,20)) , QColor(Qt::red).rgb());
   388 }
   386 }
   389 
   387 
   390 Q_DECLARE_METATYPE(QWheelEvent *);
       
   391 
       
   392 void tst_QAbstractScrollArea::wheelEvent_data()
       
   393 {
       
   394     QTest::addColumn<QSize>("widgetSize");
       
   395     QTest::addColumn<QPoint>("initialOffset");
       
   396     QTest::addColumn<QWheelEvent *>("event");
       
   397     QTest::addColumn<int>("movedX");  // -1 , 0 , or 1
       
   398     QTest::addColumn<int>("movedY");
       
   399 
       
   400     QPoint pos(100,100);
       
   401     int delta =-120;
       
   402 
       
   403     QTest::newRow("1")  << QSize(600,600) << QPoint(50,50)
       
   404                         << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0;
       
   405 
       
   406     QTest::newRow("2")  << QSize(600,600) << QPoint(50,50)
       
   407                         << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1;
       
   408 
       
   409     QTest::newRow("3")  << QSize(600,600) << QPoint(50,50)
       
   410                         << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0;
       
   411 
       
   412     QTest::newRow("4")  << QSize(600,600) << QPoint(50,50)
       
   413                         << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1;
       
   414 
       
   415     QTest::newRow("5")  << QSize(20,600) << QPoint(0,50)
       
   416                         << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 0 << 1;
       
   417 
       
   418     QTest::newRow("6")  << QSize(20,600) << QPoint(0,50)
       
   419                         << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1;
       
   420 
       
   421     QTest::newRow("7")  << QSize(20,600) << QPoint(0,50)
       
   422                         << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << 0 << -1;
       
   423 
       
   424     QTest::newRow("8")  << QSize(20,600) << QPoint(0,50)
       
   425                         << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1;
       
   426 
       
   427     QTest::newRow("9")  << QSize(600,20) << QPoint(50,0)
       
   428                         << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0;
       
   429 
       
   430     QTest::newRow("a")  << QSize(600,20) << QPoint(50,0)
       
   431                         << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 1 << 0;
       
   432 
       
   433     QTest::newRow("b")  << QSize(600,20) << QPoint(50,0)
       
   434                         << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0;
       
   435 
       
   436     QTest::newRow("c")  << QSize(600,20) << QPoint(50,0)
       
   437                         << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << -1 << 0;
       
   438 }
       
   439 
       
   440 
       
   441 
       
   442 
       
   443 void tst_QAbstractScrollArea::wheelEvent()
       
   444 {
       
   445     QFETCH(QSize, widgetSize);
       
   446     QFETCH(QPoint, initialOffset);
       
   447     QFETCH(QWheelEvent *, event);
       
   448     QFETCH(int, movedX);
       
   449     QFETCH(int, movedY);
       
   450 
       
   451     QScrollArea scrollArea;
       
   452     scrollArea.resize(200, 200);
       
   453     QLabel widget("H e l l o");
       
   454     widget.resize(widgetSize);
       
   455     scrollArea.setWidget(&widget);
       
   456     scrollArea.show();
       
   457     QTest::qWait(20);
       
   458 
       
   459     scrollArea.verticalScrollBar()->setValue(initialOffset.y());
       
   460     scrollArea.horizontalScrollBar()->setValue(initialOffset.x());
       
   461 
       
   462     QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y());
       
   463     QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x());
       
   464 
       
   465     QApplication::sendEvent(scrollArea.viewport(), event);
       
   466 
       
   467     if(movedX == 0)
       
   468         QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x());
       
   469     else
       
   470         QVERIFY(movedX * scrollArea.horizontalScrollBar()->value() > movedX * initialOffset.x());
       
   471 
       
   472     if(movedY == 0)
       
   473         QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y());
       
   474     else
       
   475         QVERIFY(movedY * scrollArea.verticalScrollBar()->value() > movedY * initialOffset.y());
       
   476 
       
   477     delete event;
       
   478 }
       
   479 
       
   480 
       
   481 QTEST_MAIN(tst_QAbstractScrollArea)
   388 QTEST_MAIN(tst_QAbstractScrollArea)
   482 #include "tst_qabstractscrollarea.moc"
   389 #include "tst_qabstractscrollarea.moc"