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" |