mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
mobile/UI: rewrite screen size logic
This has been a thorn in my side for a long time. The old code was terrible and insanely fragile. The new code is really dumb and quite fragile. So definitely an improvement? Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b40354c7f2
commit
0de26e44a5
1 changed files with 37 additions and 19 deletions
|
@ -17,6 +17,9 @@ Kirigami.ApplicationWindow {
|
||||||
reachableModeEnabled: false // while it's a good idea, it seems to confuse more than help
|
reachableModeEnabled: false // while it's a good idea, it seems to confuse more than help
|
||||||
wideScreen: false // workaround for probably Kirigami bug. See commits.
|
wideScreen: false // workaround for probably Kirigami bug. See commits.
|
||||||
|
|
||||||
|
// ensure we get all information on screen rotation
|
||||||
|
Screen.orientationUpdateMask: Qt.LandscapeOrientation | Qt.PortraitOrientation | Qt.InvertedLandscapeOrientation | Qt.InvertedPortraitOrientation
|
||||||
|
|
||||||
// the documentation claims that the ApplicationWindow should pick up the font set on
|
// the documentation claims that the ApplicationWindow should pick up the font set on
|
||||||
// the C++ side. But as a matter of fact, it doesn't, unless you add this line:
|
// the C++ side. But as a matter of fact, it doesn't, unless you add this line:
|
||||||
font: Qt.application.font
|
font: Qt.application.font
|
||||||
|
@ -688,35 +691,50 @@ if you have network connectivity and want to sync your data to cloud storage."),
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
// break the binding
|
// break the binding
|
||||||
initialWidth = initialWidth * 1
|
initialWidth = initialWidth * 1
|
||||||
manager.appendTextToLog("screenSizeObject constructor completed, initial width " + initialWidth)
|
manager.appendTextToLog("[screensetup] screenSizeObject constructor completed, initial width " + initialWidth)
|
||||||
setupUnits()
|
setupUnits()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
manager.appendTextToLog("Window width changed to " + width + " orientation " + Screen.primaryOrientation)
|
manager.appendTextToLog("[screensetup] width changed now " + width + " x " + height + " vs screen " + Screen.width + " x " + Screen.height)
|
||||||
if (screenSizeObject.initialWidth !== undefined) {
|
if (screenSizeObject.lastOrientation === undefined) {
|
||||||
if (width !== screenSizeObject.initialWidth && screenSizeObject.firstChange) {
|
manager.appendTextToLog("[screensetup] found initial orientation " + Screen.orientation)
|
||||||
screenSizeObject.firstChange = false
|
screenSizeObject.lastOrientation = Screen.orientation
|
||||||
screenSizeObject.lastOrientation = Screen.primaryOrientation
|
}
|
||||||
screenSizeObject.initialWidth = width
|
manager.appendTextToLog("[screensetup] window width changed to " + width + " orientation " + Screen.orientation)
|
||||||
screenSizeObject.initialHeight = height
|
// on Android devices we often get incorrect size updates during startup from Kirigami and we need to ignore those,
|
||||||
manager.appendTextToLog("first real change, so recalculating units and recording size as " + width + " x " + height)
|
// or more specifically, reset the Kirigami sizes when we notice them
|
||||||
setupUnits()
|
if (Screen.orientation === screenSizeObject.lastOrientation) {
|
||||||
} else if (screenSizeObject.lastOrientation !== undefined && screenSizeObject.lastOrientation !== Screen.primaryOrientation) {
|
// not rotation
|
||||||
manager.appendTextToLog("Screen rotated, no action necessary")
|
if (width > Screen.width || height > Screen.height) {
|
||||||
screenSizeObject.lastOrientation = Screen.primaryOrientation
|
manager.appendTextToLog("[screensetup] received size update that exceeds screen size")
|
||||||
setupUnits()
|
if (screenSizeObject.initialWidth !== undefined) {
|
||||||
} else {
|
manager.appendTextToLog("[screensetup] resetting to initial size " + screenSizeObject.initialWidth + " x " + screenSizeObject.initialHeight)
|
||||||
manager.appendTextToLog("size change without rotation to " + width + " x " + height)
|
|
||||||
if ((Qt.platform.os === "android" || Qt.platform.os === "ios") && width > screenSizeObject.initialWidth) {
|
|
||||||
manager.appendTextToLog("resetting to initial width " + screenSizeObject.initialWidth + " and height " + screenSizeObject.initialHeight)
|
|
||||||
rootItem.width = screenSizeObject.initialWidth
|
rootItem.width = screenSizeObject.initialWidth
|
||||||
rootItem.height = screenSizeObject.initialHeight
|
rootItem.height = screenSizeObject.initialHeight
|
||||||
|
} else {
|
||||||
|
// we don't have a size that we believe, yet - using Screen size is almost certainly wrong
|
||||||
|
manager.appendTextToLog("[screensetup] restricting to screen size " + Screen.width + " x " + Screen.height)
|
||||||
|
rootItem.width = Screen.width
|
||||||
|
rootItem.heigh = Screen.height
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// this could be a realistic size
|
||||||
|
if (screenSizeObject.initialWidth !== undefined) {
|
||||||
|
if (screenSizeObject.initialHeight < height) {
|
||||||
|
manager.appendTextToLog("[screensetup] remembering better height")
|
||||||
|
screenSizeObject.initialHeight = height
|
||||||
|
}
|
||||||
|
if (screenSizeObject.initialWidth < width) {
|
||||||
|
manager.appendTextToLog("[screensetup] remembering better height")
|
||||||
|
screenSizeObject.initialWidth = width
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
manager.appendTextToLog("width changed before initial width initialized, ignoring")
|
manager.appendTextToLog("[screensetup] remembering new orientation")
|
||||||
|
screenSizeObject.lastOrientation = Screen.orientation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue