From 4df52eee2b40244ba1a3d115a43ed51cfd742105 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 7 Feb 2019 17:35:51 +0100 Subject: Menu: account for the scale when getting the size before positioning Fixes: QTBUG-73687 Change-Id: Id2d6a6b5c6651337ab7ae26d07011160b79654bf Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickpopup.cpp | 1 + src/quicktemplates2/qquickpopuppositioner.cpp | 14 +++++++------- tests/auto/controls/data/tst_popup.qml | 17 +++++++++-------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index ecb2568e..d108420e 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -471,6 +471,7 @@ void QQuickPopupPrivate::finalizeEnterTransition() if (focus) popupItem->setFocus(true); transitionState = NoTransition; + getPositioner()->reposition(); emit q->openedChanged(); emit q->opened(); } diff --git a/src/quicktemplates2/qquickpopuppositioner.cpp b/src/quicktemplates2/qquickpopuppositioner.cpp index ebd8ff29..dbe8ac1d 100644 --- a/src/quicktemplates2/qquickpopuppositioner.cpp +++ b/src/quicktemplates2/qquickpopuppositioner.cpp @@ -108,10 +108,11 @@ void QQuickPopupPositioner::reposition() return; } - const qreal w = popupItem->width(); - const qreal h = popupItem->height(); - const qreal iw = popupItem->implicitWidth(); - const qreal ih = popupItem->implicitHeight(); + const qreal scale = popupItem->scale(); + const qreal w = popupItem->width() * scale; + const qreal h = popupItem->height() * scale; + const qreal iw = popupItem->implicitWidth() * scale; + const qreal ih = popupItem->implicitHeight() * scale; bool widthAdjusted = false; bool heightAdjusted = false; @@ -257,10 +258,9 @@ void QQuickPopupPositioner::reposition() } if (!p->hasWidth && widthAdjusted && rect.width() > 0) - popupItem->setWidth(rect.width()); + popupItem->setWidth(rect.width() / scale); if (!p->hasHeight && heightAdjusted && rect.height() > 0) - popupItem->setHeight(rect.height()); - + popupItem->setHeight(rect.height() / scale); m_positioning = false; } diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml index 27043d1c..71d6f2d7 100644 --- a/tests/auto/controls/data/tst_popup.qml +++ b/tests/auto/controls/data/tst_popup.qml @@ -326,6 +326,7 @@ TestCase { var control = createTemporaryObject(popupControl, testCase, {visible: true, margins: 0}) verify(control) + control.scale = 1.0 control.width = control.implicitWidth = testCase.width + 10 control.height = control.implicitHeight = testCase.height + 10 @@ -1293,8 +1294,8 @@ TestCase { // Center the popup in the window via the overlay. control.anchors.centerIn = Qt.binding(function() { return control.parent; }) compare(centerInSpy.count, 1) - compare(control.x, (overlay.width - control.width) / 2) - compare(control.y, (overlay.height - control.height) / 2) + compare(control.x, (overlay.width - (control.width * control.scale)) / 2) + compare(control.y, (overlay.height - (control.width * control.scale)) / 2) // Ensure that it warns when trying to set it to an item that's not its parent. var anotherItem = createTemporaryObject(rect, applicationWindow.contentItem, { x: 100, y: 100, width: 50, height: 50 }) @@ -1317,14 +1318,14 @@ TestCase { compare(control.parent, anotherItem) compare(control.anchors.centerIn, anotherItem) compare(centerInSpy.count, 4) - compare(control.x, (anotherItem.width - control.width) / 2) - compare(control.y, (anotherItem.height - control.height) / 2) + compare(control.x, (anotherItem.width - (control.width * control.scale)) / 2) + compare(control.y, (anotherItem.height - (control.height * control.scale)) / 2) // Check that anchors.centerIn beats x and y coordinates as it does in QQuickItem. control.x = 33; control.y = 44; - compare(control.x, (anotherItem.width - control.width) / 2) - compare(control.y, (anotherItem.height - control.height) / 2) + compare(control.x, (anotherItem.width - (control.width * control.scale)) / 2) + compare(control.y, (anotherItem.height - (control.height * control.scale)) / 2) // Check that the popup's x and y coordinates are restored when it's no longer centered. control.anchors.centerIn = undefined @@ -1335,8 +1336,8 @@ TestCase { // Test centering in the overlay while having a different parent (anotherItem). control.anchors.centerIn = overlay compare(centerInSpy.count, 6) - compare(control.x, (overlay.width - control.width) / 2) - compare(control.y, (overlay.height - control.height) / 2) + compare(control.x, (overlay.width - (control.width * control.scale)) / 2) + compare(control.y, (overlay.height - (control.height * control.scale)) / 2) // TODO: do this properly by creating a component or something applicationWindow.visible = false -- cgit v1.2.3