diff options
author | Yoann Lopes <yoann.lopes@nokia.com> | 2010-04-15 08:41:18 (GMT) |
---|---|---|
committer | Yoann Lopes <yoann.lopes@nokia.com> | 2010-04-15 10:29:27 (GMT) |
commit | 9da13ea53aec6d841ba7f416531d6c52d4368df4 (patch) | |
tree | 1930b996312a87026046f8c8fa040b78bafb9912 /tests/auto/qgraphicsproxywidget | |
parent | 9dcf1eabc373991340b0c0b697f5b0788fde4f4b (diff) | |
download | Qt-9da13ea53aec6d841ba7f416531d6c52d4368df4.zip Qt-9da13ea53aec6d841ba7f416531d6c52d4368df4.tar.gz Qt-9da13ea53aec6d841ba7f416531d6c52d4368df4.tar.bz2 |
Fixes tooltips for QGraphicsProxyWidget.
Help event was not propagated to the widget. Also fixes tooltip value
propagation when setting it on the proxy or on the widget.
Autotest included.
Task-number: QTBUG-5349
Reviewed-by: bnilsen
Diffstat (limited to 'tests/auto/qgraphicsproxywidget')
-rw-r--r-- | tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 99 |
1 files changed, 77 insertions, 22 deletions
diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index e46709b..a5a039a 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -43,6 +43,7 @@ #include <QtTest/QtTest> #include <QtGui> #include "../../shared/util.h" +#include <private/qgraphicsproxywidget_p.h> #include <private/qlayoutengine_p.h> // qSmartMin functions... #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) #include <QMacStyle> @@ -2582,33 +2583,87 @@ void tst_QGraphicsProxyWidget::changingCursor_basic() void tst_QGraphicsProxyWidget::tooltip_basic() { - // Confirm that mouse events are working properly by checking that - // when moving the mouse over a label with a tooptip the tooltip appears + QString toolTip = "Qt rocks!"; + QString toolTip2 = "Qt rocks even more!"; + + QPushButton *button = new QPushButton("button"); + QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; + QGraphicsProxyWidgetPrivate *proxyd = static_cast<QGraphicsProxyWidgetPrivate *>(QGraphicsItemPrivate::get(proxy)); + proxy->setWidget(button); + proxyd->lastWidgetUnderMouse = button; // force widget under mouse + + QVERIFY(button->toolTip().isEmpty()); + QVERIFY(proxy->toolTip().isEmpty()); + // Check that setting the tooltip on the proxy also set it on the widget + proxy->setToolTip(toolTip); + QCOMPARE(proxy->toolTip(), toolTip); + QCOMPARE(button->toolTip(), toolTip); + // Check that setting the tooltip on the widget also set it on the proxy + button->setToolTip(toolTip2); + QCOMPARE(proxy->toolTip(), toolTip2); + QCOMPARE(button->toolTip(), toolTip2); + QGraphicsScene scene; + scene.addItem(proxy); + QGraphicsView view(&scene); + view.setFixedSize(200, 200); view.show(); + QTest::qWaitForWindowShown(&view); + { + QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), + view.viewport()->mapToGlobal(view.viewport()->rect().topLeft())); + QApplication::sendEvent(view.viewport(), &helpEvent); + QTest::qWait(350); + + bool foundView = false; + bool foundTipLabel = false; + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + if (widget == &view) + foundView = true; + if (widget->inherits("QTipLabel")) + foundTipLabel = true; + } + QVERIFY(foundView); + QVERIFY(!foundTipLabel); + } - QSKIP("Tooltips don't work yet", SkipAll); - - SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; - QLabel *widget = new QLabel; - widget->setText("If it ain't tested it's broken"); - widget->setToolTip("When in doubt, test"); - proxy->setWidget(widget); - widget->show(); - scene.addItem(proxy); - QTest::qWait(125); - - // in - QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); + { + QHelpEvent helpEvent(QEvent::ToolTip, view.mapFromScene(proxy->boundingRect().center()), + view.viewport()->mapToGlobal(view.mapFromScene(proxy->boundingRect().center()))); + QApplication::sendEvent(view.viewport(), &helpEvent); + QTest::qWait(350); + + bool foundView = false; + bool foundTipLabel = false; + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + if (widget == &view) + foundView = true; + if (widget->inherits("QTipLabel")) + foundTipLabel = true; + } + QVERIFY(foundView); + QVERIFY(foundTipLabel); + } - QTRY_COMPARE(proxy->childItems().count(), 1); - QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; - QVERIFY(child->isWidget()); - QVERIFY(child->widget()); - QCOMPARE(child->widget()->parent(), static_cast<QObject*>(widget)); - QCOMPARE(child->widget()->x(), widget->x()); // ### ??? - QCOMPARE(child->widget()->y(), widget->y() + widget->height()); // ### ??? + { + QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), + view.viewport()->mapToGlobal(view.viewport()->rect().topLeft())); + QApplication::sendEvent(view.viewport(), &helpEvent); + // Wait 350ms because the tooltip only hides after 300ms... + QTest::qWait(350); + + bool foundView = false; + bool foundTipLabel = false; + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + if (widget == &view) + foundView = true; + if (widget->inherits("QTipLabel") && widget->isVisible()) + foundTipLabel = true; + } + QVERIFY(foundView); + QVERIFY(!foundTipLabel); + } } void tst_QGraphicsProxyWidget::childPos_data() |