987 QTest::mouseMove(&view, QPoint(10, 10)); |
986 QTest::mouseMove(&view, QPoint(10, 10)); |
988 QTest::qWait(30); |
987 QTest::qWait(30); |
989 |
988 |
990 // in |
989 // in |
991 QTest::mouseMove(&view, QPoint(50, 50)); |
990 QTest::mouseMove(&view, QPoint(50, 50)); |
992 QTest::qWait(25); |
|
993 QTRY_COMPARE(widget->testAttribute(Qt::WA_UnderMouse), hasWidget ? true : false); |
991 QTRY_COMPARE(widget->testAttribute(Qt::WA_UnderMouse), hasWidget ? true : false); |
994 // ### this attribute isn't supported |
992 // ### this attribute isn't supported |
995 QCOMPARE(widget->enterCount, hasWidget ? 1 : 0); |
993 QCOMPARE(widget->enterCount, hasWidget ? 1 : 0); |
996 QCOMPARE(widget->hoverEnter, (hasWidget && hoverEnabled) ? 1 : 0); |
994 QCOMPARE(widget->hoverEnter, (hasWidget && hoverEnabled) ? 1 : 0); |
997 // does not work on all platforms |
995 // does not work on all platforms |
998 //QCOMPARE(widget->moveCount, 0); |
996 //QCOMPARE(widget->moveCount, 0); |
999 |
997 |
1000 // out |
998 // out |
1001 QTest::mouseMove(&view, QPoint(10, 10)); |
999 QTest::mouseMove(&view, QPoint(10, 10)); |
1002 QTest::qWait(25); |
|
1003 // QTRY_COMPARE(widget->testAttribute(Qt::WA_UnderMouse), false); |
1000 // QTRY_COMPARE(widget->testAttribute(Qt::WA_UnderMouse), false); |
1004 // ### this attribute isn't supported |
1001 // ### this attribute isn't supported |
1005 QCOMPARE(widget->leaveCount, hasWidget ? 1 : 0); |
1002 QTRY_COMPARE(widget->leaveCount, hasWidget ? 1 : 0); |
1006 QCOMPARE(widget->hoverLeave, (hasWidget && hoverEnabled) ? 1 : 0); |
1003 QTRY_COMPARE(widget->hoverLeave, (hasWidget && hoverEnabled) ? 1 : 0); |
1007 // does not work on all platforms |
1004 // does not work on all platforms |
1008 //QCOMPARE(widget->moveCount, 0); |
1005 //QCOMPARE(widget->moveCount, 0); |
1009 |
1006 |
1010 if (!hasWidget) |
1007 if (!hasWidget) |
1011 delete widget; |
1008 delete widget; |
1502 widget->paintEventRegion = QRegion(); |
1495 widget->paintEventRegion = QRegion(); |
1503 widget->npaints = 0; |
1496 widget->npaints = 0; |
1504 view.paintEventRegion = QRegion(); |
1497 view.paintEventRegion = QRegion(); |
1505 view.npaints = 0; |
1498 view.npaints = 0; |
1506 QTimer::singleShot(0, widget, SLOT(updateScroll())); |
1499 QTimer::singleShot(0, widget, SLOT(updateScroll())); |
1507 QTest::qWait(50); |
|
1508 QTRY_COMPARE(view.npaints, 2); |
1500 QTRY_COMPARE(view.npaints, 2); |
1509 // QRect(0, 0, 200, 12) is the first update, expanded (-2, -2, 2, 2) |
1501 // QRect(0, 0, 200, 12) is the first update, expanded (-2, -2, 2, 2) |
1510 // QRect(0, 12, 102, 10) is the scroll update, expanded (-2, -2, 2, 2), |
1502 // QRect(0, 12, 102, 10) is the scroll update, expanded (-2, -2, 2, 2), |
1511 // intersected with the above update. |
1503 // intersected with the above update. |
1512 QCOMPARE(view.paintEventRegion.rects(), |
1504 QCOMPARE(view.paintEventRegion.rects(), |
2481 QApplication::processEvents(); |
2473 QApplication::processEvents(); |
2482 |
2474 |
2483 QTest::mousePress(view.viewport(), Qt::LeftButton, 0, |
2475 QTest::mousePress(view.viewport(), Qt::LeftButton, 0, |
2484 view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
2476 view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
2485 |
2477 |
2486 QTest::qWait(12); |
2478 QTRY_COMPARE(box->pos(), QPoint()); |
2487 |
|
2488 QCOMPARE(box->pos(), QPoint()); |
|
2489 |
2479 |
2490 QCOMPARE(proxy->childItems().count(), 1); |
2480 QCOMPARE(proxy->childItems().count(), 1); |
2491 QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; |
2481 QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; |
2492 QVERIFY(child->isWidget()); |
2482 QVERIFY(child->isWidget()); |
2493 QVERIFY(child->widget()); |
2483 QVERIFY(child->widget()); |
2496 opt.editable = box->isEditable(); |
2486 opt.editable = box->isEditable(); |
2497 if (box->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) |
2487 if (box->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) |
2498 QSKIP("Does not work due to SH_Combobox_Popup", SkipAll); |
2488 QSKIP("Does not work due to SH_Combobox_Popup", SkipAll); |
2499 QCOMPARE(child->widget()->parent(), static_cast<QObject*>(box)); |
2489 QCOMPARE(child->widget()->parent(), static_cast<QObject*>(box)); |
2500 |
2490 |
2501 QTest::qWait(12); |
|
2502 QTRY_COMPARE(proxy->pos(), QPointF(box->pos())); |
2491 QTRY_COMPARE(proxy->pos(), QPointF(box->pos())); |
2503 QCOMPARE(child->x(), qreal(box->x())); |
2492 QCOMPARE(child->x(), qreal(box->x())); |
2504 QCOMPARE(child->y(), qreal(box->rect().bottom())); |
2493 QCOMPARE(child->y(), qreal(box->rect().bottom())); |
2505 #ifndef Q_OS_WIN |
2494 #ifndef Q_OS_WIN |
2506 // The popup's coordinates on Windows are in global space, |
2495 // The popup's coordinates on Windows are in global space, |
2581 QTRY_VERIFY(view.isActiveWindow()); |
2570 QTRY_VERIFY(view.isActiveWindow()); |
2582 |
2571 |
2583 // in |
2572 // in |
2584 QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
2573 QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
2585 sendMouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
2574 sendMouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
2586 QTest::qWait(12); |
|
2587 QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
2575 QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
2588 |
2576 |
2589 // out |
2577 // out |
2590 QTest::mouseMove(view.viewport(), QPoint(1, 1)); |
2578 QTest::mouseMove(view.viewport(), QPoint(1, 1)); |
2591 sendMouseMove(view.viewport(), QPoint(1, 1)); |
2579 sendMouseMove(view.viewport(), QPoint(1, 1)); |
2592 QTest::qWait(12); |
|
2593 QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); |
2580 QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); |
2594 #endif |
2581 #endif |
2595 } |
2582 } |
2596 |
2583 |
2597 void tst_QGraphicsProxyWidget::tooltip_basic() |
2584 void tst_QGraphicsProxyWidget::tooltip_basic() |
2598 { |
2585 { |
2599 // Confirm that mouse events are working properly by checking that |
2586 QString toolTip = "Qt rocks!"; |
2600 // when moving the mouse over a label with a tooptip the tooltip appears |
2587 QString toolTip2 = "Qt rocks even more!"; |
2601 QGraphicsScene scene; |
2588 |
|
2589 QPushButton *button = new QPushButton("button"); |
|
2590 QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; |
|
2591 QGraphicsProxyWidgetPrivate *proxyd = static_cast<QGraphicsProxyWidgetPrivate *>(QGraphicsItemPrivate::get(proxy)); |
|
2592 proxy->setWidget(button); |
|
2593 proxyd->lastWidgetUnderMouse = button; // force widget under mouse |
|
2594 |
|
2595 QVERIFY(button->toolTip().isEmpty()); |
|
2596 QVERIFY(proxy->toolTip().isEmpty()); |
|
2597 // Check that setting the tooltip on the proxy also set it on the widget |
|
2598 proxy->setToolTip(toolTip); |
|
2599 QCOMPARE(proxy->toolTip(), toolTip); |
|
2600 QCOMPARE(button->toolTip(), toolTip); |
|
2601 // Check that setting the tooltip on the widget also set it on the proxy |
|
2602 button->setToolTip(toolTip2); |
|
2603 QCOMPARE(proxy->toolTip(), toolTip2); |
|
2604 QCOMPARE(button->toolTip(), toolTip2); |
|
2605 |
|
2606 QGraphicsScene scene; |
|
2607 scene.addItem(proxy); |
|
2608 |
2602 QGraphicsView view(&scene); |
2609 QGraphicsView view(&scene); |
|
2610 view.setFixedSize(200, 200); |
2603 view.show(); |
2611 view.show(); |
2604 |
2612 QTest::qWaitForWindowShown(&view); |
2605 QSKIP("Tooltips don't work yet", SkipAll); |
2613 { |
2606 |
2614 QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), |
2607 SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
2615 view.viewport()->mapToGlobal(view.viewport()->rect().topLeft())); |
2608 QLabel *widget = new QLabel; |
2616 QApplication::sendEvent(view.viewport(), &helpEvent); |
2609 widget->setText("If it ain't tested it's broken"); |
2617 QTest::qWait(350); |
2610 widget->setToolTip("When in doubt, test"); |
2618 |
2611 proxy->setWidget(widget); |
2619 bool foundView = false; |
2612 widget->show(); |
2620 bool foundTipLabel = false; |
2613 scene.addItem(proxy); |
2621 foreach (QWidget *widget, QApplication::topLevelWidgets()) { |
2614 QTest::qWait(125); |
2622 if (widget == &view) |
2615 |
2623 foundView = true; |
2616 // in |
2624 if (widget->inherits("QTipLabel")) |
2617 QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
2625 foundTipLabel = true; |
2618 QTest::qWait(3000); |
2626 } |
2619 |
2627 QVERIFY(foundView); |
2620 QCOMPARE(proxy->childItems().count(), 1); |
2628 QVERIFY(!foundTipLabel); |
2621 QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; |
2629 } |
2622 QVERIFY(child->isWidget()); |
2630 |
2623 QVERIFY(child->widget()); |
2631 { |
2624 QCOMPARE(child->widget()->parent(), static_cast<QObject*>(widget)); |
2632 QHelpEvent helpEvent(QEvent::ToolTip, view.mapFromScene(proxy->boundingRect().center()), |
2625 QCOMPARE(child->widget()->x(), widget->x()); // ### ??? |
2633 view.viewport()->mapToGlobal(view.mapFromScene(proxy->boundingRect().center()))); |
2626 QCOMPARE(child->widget()->y(), widget->y() + widget->height()); // ### ??? |
2634 QApplication::sendEvent(view.viewport(), &helpEvent); |
|
2635 QTest::qWait(350); |
|
2636 |
|
2637 bool foundView = false; |
|
2638 bool foundTipLabel = false; |
|
2639 foreach (QWidget *widget, QApplication::topLevelWidgets()) { |
|
2640 if (widget == &view) |
|
2641 foundView = true; |
|
2642 if (widget->inherits("QTipLabel")) |
|
2643 foundTipLabel = true; |
|
2644 } |
|
2645 QVERIFY(foundView); |
|
2646 QVERIFY(foundTipLabel); |
|
2647 } |
2627 } |
2648 } |
2628 |
2649 |
2629 void tst_QGraphicsProxyWidget::childPos_data() |
2650 void tst_QGraphicsProxyWidget::childPos_data() |
2630 { |
2651 { |
2631 QTest::addColumn<bool>("moveCombo"); |
2652 QTest::addColumn<bool>("moveCombo"); |