Modify tst_popup.qml::test_anchors() to accommodate PopupWindow popups
The test test_anchors() in tst_popup.qml checks the success of centering a popup by querying its local position. This does not work for top level windows and so an extra calculation has to be added using the global co-ordinates of the popup to find its local position. There is also a bug when centering the popup in the overlay, and the overlay is not the parent. This bug is a result of not translating the expected results to the co-ordinate system of the parent. Task-number: QTBUG-126553 Pick-to: 6.8 Change-Id: I9605b6fd290180f777afd35573163fd3c9eff95f Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
This commit is contained in:
parent
b5d379d28b
commit
3eff6a639f
|
@ -1269,11 +1269,18 @@ TestCase {
|
||||||
verify(overlay.width > 0)
|
verify(overlay.width > 0)
|
||||||
verify(overlay.height > 0)
|
verify(overlay.height > 0)
|
||||||
|
|
||||||
|
const getCurrentPos = () => {
|
||||||
|
const parentPos = control.parent.mapToGlobal(0, 0)
|
||||||
|
const popupPos = control.contentItem.parent.mapToGlobal(0, 0)
|
||||||
|
return Qt.point(popupPos.x - parentPos.x, popupPos.y - parentPos.y)
|
||||||
|
}
|
||||||
|
|
||||||
// Center the popup in the window via the overlay.
|
// Center the popup in the window via the overlay.
|
||||||
control.anchors.centerIn = Qt.binding(function() { return control.parent; })
|
control.anchors.centerIn = Qt.binding(function() { return control.parent; })
|
||||||
compare(centerInSpy.count, 1)
|
compare(centerInSpy.count, 1)
|
||||||
compare(control.x, (overlay.width - (control.width * control.scale)) / 2)
|
let currentPos = getCurrentPos()
|
||||||
compare(control.y, (overlay.height - (control.width * control.scale)) / 2)
|
compare(currentPos.x, (overlay.width - (control.width * control.scale)) / 2)
|
||||||
|
compare(currentPos.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.
|
// Ensure that it warns when trying to set it to an item that's not its parent.
|
||||||
let anotherItem = createTemporaryObject(rect, applicationWindow.contentItem, { x: 100, y: 100, width: 50, height: 50 })
|
let anotherItem = createTemporaryObject(rect, applicationWindow.contentItem, { x: 100, y: 100, width: 50, height: 50 })
|
||||||
|
@ -1296,29 +1303,36 @@ TestCase {
|
||||||
compare(control.parent, anotherItem)
|
compare(control.parent, anotherItem)
|
||||||
compare(control.anchors.centerIn, anotherItem)
|
compare(control.anchors.centerIn, anotherItem)
|
||||||
compare(centerInSpy.count, 4)
|
compare(centerInSpy.count, 4)
|
||||||
compare(control.x, (anotherItem.width - (control.width * control.scale)) / 2)
|
currentPos = getCurrentPos()
|
||||||
compare(control.y, (anotherItem.height - (control.height * control.scale)) / 2)
|
compare(currentPos.x, (anotherItem.width - (control.width * control.scale)) / 2)
|
||||||
|
compare(currentPos.y, (anotherItem.height - (control.height * control.scale)) / 2)
|
||||||
|
|
||||||
// Check that anchors.centerIn beats x and y coordinates as it does in QQuickItem.
|
// Check that anchors.centerIn beats x and y coordinates as it does in QQuickItem.
|
||||||
control.x = 33;
|
control.x = 33;
|
||||||
control.y = 44;
|
control.y = 44;
|
||||||
compare(control.x, (anotherItem.width - (control.width * control.scale)) / 2)
|
currentPos = getCurrentPos()
|
||||||
compare(control.y, (anotherItem.height - (control.height * control.scale)) / 2)
|
compare(currentPos.x, (anotherItem.width - (control.width * control.scale)) / 2)
|
||||||
|
compare(currentPos.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.
|
// Check that the popup's x and y coordinates are restored when it's no longer centered.
|
||||||
control.anchors.centerIn = undefined
|
control.anchors.centerIn = undefined
|
||||||
compare(centerInSpy.count, 5)
|
compare(centerInSpy.count, 5)
|
||||||
compare(control.x, 33)
|
currentPos = getCurrentPos()
|
||||||
compare(control.y, 44)
|
compare(currentPos.x, 33)
|
||||||
|
compare(currentPos.y, 44)
|
||||||
|
|
||||||
// Test centering in the overlay while having a different parent (anotherItem).
|
// Test centering in the overlay while having a different parent (anotherItem).
|
||||||
control.anchors.centerIn = overlay
|
control.anchors.centerIn = overlay
|
||||||
compare(centerInSpy.count, 6)
|
compare(centerInSpy.count, 6)
|
||||||
compare(control.x, (overlay.width - (control.width * control.scale)) / 2)
|
currentPos = getCurrentPos()
|
||||||
compare(control.y, (overlay.height - (control.height * control.scale)) / 2)
|
// calculate the correct co-ordinates in the overlay's co-ordinate system
|
||||||
|
let expectedX = (overlay.width - (control.width * control.scale)) / 2
|
||||||
// TODO: do this properly by creating a component or something
|
let expectedY = (overlay.height - (control.height * control.scale)) / 2
|
||||||
applicationWindow.visible = false
|
// translate to the parent's (anotherItem's) co-ordinate system
|
||||||
|
expectedX -= anotherItem.x
|
||||||
|
expectedY -= anotherItem.y
|
||||||
|
compare(currentPos.x, expectedX)
|
||||||
|
compare(currentPos.y, expectedY)
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
|
Loading…
Reference in New Issue