summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-10-21 12:24:52 +0200
committerFriedemann Kleint <Friedemann.Kleint@digia.com>2014-10-23 06:33:10 +0200
commited0245e1452f94918853b7d4066c1e5749b74f5d (patch)
tree9b6e9d656a12aa98cc549c5c86fa2b88287bba7e /tests/auto/widgets
parentf3699510d42e5ee910521c0463d9710f77ad4ff1 (diff)
Fix QWidget::mapTo/FromGlobal() when embedded in QGraphicsView.
Map the positions via QGraphicsScene and the first QGraphicsView (as is done in existing code). Fall back to the previous code path when no QGraphicsView exists, which is hit in the tests. Change-Id: I0754765d05cded6bc1b64045f2513fef8afde337 Task-number: QTBUG-41135 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index ab84c9e482..66d0f64ceb 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -174,6 +174,7 @@ private slots:
void clickFocus();
void windowFrameMargins();
void QTBUG_6986_sendMouseEventToAlienWidget();
+ void mapToGlobal();
};
// Subclass that exposes the protected functions.
@@ -3659,5 +3660,32 @@ void tst_QGraphicsProxyWidget::QTBUG_6986_sendMouseEventToAlienWidget()
QTRY_COMPARE(scene.hoverButton->hoverLeaveReceived, true);
}
+void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135
+{
+ const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
+ const QSize size = availableGeometry.size() / 5;
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ view.setWindowTitle(QTest::currentTestFunction());
+ view.resize(size);
+ view.move(availableGeometry.bottomRight() - QPoint(size.width(), size.height()) - QPoint(100, 100));
+ QWidget *embeddedWidget = new QWidget;
+ embeddedWidget->setFixedSize(size / 2);
+ scene.addWidget(embeddedWidget);
+ QApplication::setActiveWindow(&view);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ const QPoint embeddedCenter = embeddedWidget->geometry().center();
+ const QPoint embeddedCenterGlobal = embeddedWidget->mapToGlobal(embeddedCenter);
+ QCOMPARE(embeddedWidget->mapFromGlobal(embeddedCenterGlobal), embeddedCenter);
+ // This should be equivalent to the view center give or take rounding
+ // errors due to odd window margins
+ const QPoint viewCenter = view.geometry().center();
+ QVERIFY2((viewCenter - embeddedCenterGlobal).manhattanLength() <= 2,
+ qPrintable(QStringLiteral("%1, %2 != %3, %4")
+ .arg(viewCenter.x()).arg(viewCenter.y())
+ .arg(embeddedCenterGlobal.x()).arg(embeddedCenterGlobal.y())));
+}
+
QTEST_MAIN(tst_QGraphicsProxyWidget)
#include "tst_qgraphicsproxywidget.moc"