mobile UI: redo the screen size magic

This still is way to fragile. Ordering of object completion doesn't appear
consistent. Hopefully bringing the properties all into one (now reasonably
named) object will help.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-02-06 13:26:39 -08:00
parent f1a08eb952
commit eb410aee55

View file

@ -32,8 +32,6 @@ Kirigami.ApplicationWindow {
property alias defaultCylinderIndex: settingsWindow.defaultCylinderIndex property alias defaultCylinderIndex: settingsWindow.defaultCylinderIndex
property bool filterToggle: false property bool filterToggle: false
property string filterPattern: "" property string filterPattern: ""
property bool firstChange: true
property int lastOrientation: undefined
property int colWidth: undefined property int colWidth: undefined
onNotificationTextChanged: { onNotificationTextChanged: {
@ -593,42 +591,41 @@ if you have network connectivity and want to sync your data to cloud storage."),
} }
QtObject { QtObject {
id: placeHolder id: screenSizeObject
property int initialWidth: rootItem.width property int initialWidth: rootItem.width
property int initialHeight: rootItem.height property int initialHeight: rootItem.height
property bool firstChange: true
property int lastOrientation: undefined
Component.onCompleted: { Component.onCompleted: {
// break the binding // break the binding
initialWidth = initialWidth * 1 initialWidth = initialWidth * 1
manager.appendTextToLog("SubsufaceTheme constructor completed, initial width " + initialWidth) manager.appendTextToLog("screenSizeObject constructor completed, initial width " + initialWidth)
if (rootItem.firstChange) // only run the setup if we haven't seen a change, yet setupUnits()
setupUnits() // but don't count this as a change (after all, it's not)
else
manager.appendTextToLog("Already adjusted size, ignoring this")
} }
} }
onWidthChanged: { onWidthChanged: {
manager.appendTextToLog("Window width changed to " + width + " orientation " + Screen.primaryOrientation) manager.appendTextToLog("Window width changed to " + width + " orientation " + Screen.primaryOrientation)
if (placeHolder.initialWidth !== undefined) { if (screenSizeObject.initialWidth !== undefined) {
if (width !== placeHolder.initialWidth && rootItem.firstChange) { if (width !== screenSizeObject.initialWidth && screenSizeObject.firstChange) {
rootItem.firstChange = false screenSizeObject.firstChange = false
rootItem.lastOrientation = Screen.primaryOrientation screenSizeObject.lastOrientation = Screen.primaryOrientation
placeHolder.initialWidth = width screenSizeObject.initialWidth = width
placeHolder.initialHeight = height screenSizeObject.initialHeight = height
manager.appendTextToLog("first real change, so recalculating units and recording size as " + width + " x " + height) manager.appendTextToLog("first real change, so recalculating units and recording size as " + width + " x " + height)
setupUnits() setupUnits()
} else if (rootItem.lastOrientation !== undefined && rootItem.lastOrientation !== Screen.primaryOrientation) { } else if (screenSizeObject.lastOrientation !== undefined && screenSizeObject.lastOrientation !== Screen.primaryOrientation) {
manager.appendTextToLog("Screen rotated, no action necessary") manager.appendTextToLog("Screen rotated, no action necessary")
rootItem.lastOrientation = Screen.primaryOrientation screenSizeObject.lastOrientation = Screen.primaryOrientation
setupUnits() setupUnits()
} else { } else {
manager.appendTextToLog("size change without rotation to " + width + " x " + height) manager.appendTextToLog("size change without rotation to " + width + " x " + height)
if (width > placeHolder.initialWidth) { if ((Qt.platform.os === "android" || Qt.platform.os === "ios") && width > screenSizeObject.initialWidth) {
manager.appendTextToLog("resetting to initial width " + placeHolder.initialWidth + " and height " + placeHolder.initialHeight) manager.appendTextToLog("resetting to initial width " + screenSizeObject.initialWidth + " and height " + screenSizeObject.initialHeight)
rootItem.width = placeHolder.initialWidth rootItem.width = screenSizeObject.initialWidth
rootItem.height = placeHolder.initialHeight rootItem.height = screenSizeObject.initialHeight
} }
} }
} else { } else {