mobile/settings: attempt to fix the layout

The hardcoded widths with fixed values was just flat our broken and
created all kinds of strange artifacts.

But even with this somewhat more idiomatic approach this still isn't
perfect - on wider screens it doesn't shrink back to the minimum column
width. But that seems like a bit of a corner case. Overall this feels
like a huge improvement.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-03-20 22:54:32 -07:00
parent 559547b7e6
commit fbea54f8dd

View file

@ -7,32 +7,29 @@ import org.subsurfacedivelog.mobile 1.0
TemplatePage { TemplatePage {
objectName: "Settings" objectName: "Settings"
id: settingsPage title: qsTr("Settings")
width: rootItem.colWidth - Kirigami.Units.gridUnit
property alias defaultCylinderModel: defaultCylinderBox.model property alias defaultCylinderModel: defaultCylinderBox.model
property alias defaultCylinderIndex: defaultCylinderBox.currentIndex property alias defaultCylinderIndex: defaultCylinderBox.currentIndex
property real contentColumeWidth: width - 2 * Kirigami.Units.gridUnit
title: qsTr("Settings")
property real gridWidth: settingsPage.width - Kirigami.Units.gridUnit
property var describe: [qsTr("Undefined"), property var describe: [qsTr("Undefined"),
qsTr("Incorrect username/password combination"), qsTr("Incorrect username/password combination"),
qsTr("Credentials need to be verified"), qsTr("Credentials need to be verified"),
qsTr("Credentials verified"), qsTr("Credentials verified"),
qsTr("No cloud mode")] qsTr("No cloud mode")]
Column { Column {
width: gridWidth width: contentColumeWidth
TemplateSection { TemplateSection {
id: sectionGeneral id: sectionGeneral
title: qsTr("General settings") title: qsTr("General settings")
isExpanded: true isExpanded: true
width: parent.width
GridLayout { GridLayout {
id: cloudSetting id: cloudSetting
visible: sectionGeneral.isExpanded visible: sectionGeneral.isExpanded
columns: 3 columns: 3
width: parent.width
TemplateLabel { TemplateLabel {
text: qsTr("Cloud status") text: qsTr("Cloud status")
font.pointSize: subsurfaceTheme.headingPointSize font.pointSize: subsurfaceTheme.headingPointSize
@ -43,11 +40,10 @@ TemplatePage {
} }
TemplateLabel { TemplateLabel {
text: qsTr("Email") text: qsTr("Email")
Layout.preferredWidth: gridWidth * 0.15
} }
TemplateLabel { TemplateLabel {
text: Backend.cloud_verification_status === Enums.CS_NOCLOUD ? qsTr("Not applicable") : PrefCloudStorage.cloud_storage_email text: Backend.cloud_verification_status === Enums.CS_NOCLOUD ? qsTr("Not applicable") : PrefCloudStorage.cloud_storage_email
Layout.preferredWidth: gridWidth * 0.60 Layout.fillWidth: true
} }
TemplateButton { TemplateButton {
id: changeCloudSettings id: changeCloudSettings
@ -59,12 +55,10 @@ TemplatePage {
} }
TemplateLabel { TemplateLabel {
text: qsTr("Status") text: qsTr("Status")
Layout.preferredWidth: gridWidth * 0.15
Layout.preferredHeight: Kirigami.Units.gridUnit * 1.5 Layout.preferredHeight: Kirigami.Units.gridUnit * 1.5
} }
TemplateLabel { TemplateLabel {
text: describe[Backend.cloud_verification_status] text: describe[Backend.cloud_verification_status]
Layout.preferredWidth: gridWidth * 0.60
Layout.preferredHeight: Kirigami.Units.gridUnit * 1.5 Layout.preferredHeight: Kirigami.Units.gridUnit * 1.5
} }
} }
@ -76,7 +70,6 @@ TemplatePage {
visible: sectionGeneral.isExpanded visible: sectionGeneral.isExpanded
columns: 2 columns: 2
width: parent.width width: parent.width
TemplateLabel { TemplateLabel {
text: qsTr("Default Cylinder") text: qsTr("Default Cylinder")
font.pointSize: subsurfaceTheme.headingPointSize font.pointSize: subsurfaceTheme.headingPointSize
@ -108,6 +101,7 @@ TemplatePage {
id: divecomputers id: divecomputers
visible: sectionGeneral.isExpanded visible: sectionGeneral.isExpanded
columns: 2 columns: 2
width: parent.width
TemplateLabel { TemplateLabel {
text: qsTr("Dive computers") text: qsTr("Dive computers")
font.pointSize: subsurfaceTheme.headingPointSize font.pointSize: subsurfaceTheme.headingPointSize
@ -118,7 +112,7 @@ TemplatePage {
} }
TemplateLabel { TemplateLabel {
text: qsTr("Forget remembered dive computers") text: qsTr("Forget remembered dive computers")
Layout.preferredWidth: gridWidth * 0.75 Layout.fillWidth: true
} }
TemplateButton { TemplateButton {
id: forgetDCButton id: forgetDCButton
@ -133,16 +127,24 @@ TemplatePage {
} }
} }
} }
}
}
TemplateSection { TemplateSection {
id: sectionTheme id: sectionTheme
title: qsTr("Theme") title: qsTr("Theme")
width: parent.width
GridLayout { GridLayout {
visible: sectionTheme.isExpanded visible: sectionTheme.isExpanded
columns: 2 columns: 2
width: parent.width
TemplateLabel {
text: qsTr("Color theme")
font.pointSize: subsurfaceTheme.headingPointSize
font.weight: Font.Light
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.largeSpacing / 2
Layout.columnSpan: 2
}
TemplateComboBox { TemplateComboBox {
editable: false editable: false
Layout.columnSpan: 2 Layout.columnSpan: 2
@ -157,12 +159,10 @@ TemplatePage {
subsurfaceTheme.currentTheme = currentIndex === 0 ? "Blue" : currentIndex === 1 ? "Pink" : "Dark" subsurfaceTheme.currentTheme = currentIndex === 0 ? "Blue" : currentIndex === 1 ? "Pink" : "Dark"
} }
} }
Rectangle { Rectangle {
color: subsurfaceTheme.backgroundColor color: subsurfaceTheme.backgroundColor
width: rootItem.width / 2 - 20 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("background") text: qsTr("background")
color: subsurfaceTheme.textColor color: subsurfaceTheme.textColor
@ -173,9 +173,8 @@ TemplatePage {
} }
Rectangle { Rectangle {
color: subsurfaceTheme.backgroundColor color: subsurfaceTheme.backgroundColor
width: rootItem.width / 2 - 60 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("text") text: qsTr("text")
color: subsurfaceTheme.textColor color: subsurfaceTheme.textColor
@ -184,14 +183,12 @@ TemplatePage {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
} }
Rectangle { Rectangle {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.primaryColor color: subsurfaceTheme.primaryColor
width: rootItem.width / 2 - 20 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("primary") text: qsTr("primary")
color: subsurfaceTheme.primaryTextColor color: subsurfaceTheme.primaryTextColor
@ -204,9 +201,8 @@ TemplatePage {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.primaryTextColor color: subsurfaceTheme.primaryTextColor
width: rootItem.width / 2 - 60 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("primary text") text: qsTr("primary text")
color: subsurfaceTheme.primaryColor color: subsurfaceTheme.primaryColor
@ -215,14 +211,12 @@ TemplatePage {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
} }
Rectangle { Rectangle {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.darkerPrimaryColor color: subsurfaceTheme.darkerPrimaryColor
width: rootItem.width / 2 - 20 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("darker primary") text: qsTr("darker primary")
color: subsurfaceTheme.darkerPrimaryTextColor color: subsurfaceTheme.darkerPrimaryTextColor
@ -235,9 +229,8 @@ TemplatePage {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.darkerPrimaryTextColor color: subsurfaceTheme.darkerPrimaryTextColor
width: rootItem.width / 2 - 60 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("darker primary text") text: qsTr("darker primary text")
color: subsurfaceTheme.darkerPrimaryColor color: subsurfaceTheme.darkerPrimaryColor
@ -246,14 +239,12 @@ TemplatePage {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
} }
Rectangle { Rectangle {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.lightPrimaryColor color: subsurfaceTheme.lightPrimaryColor
width: rootItem.width / 2 - 20 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("light primary") text: qsTr("light primary")
color: subsurfaceTheme.lightPrimaryTextColor color: subsurfaceTheme.lightPrimaryTextColor
@ -266,9 +257,8 @@ TemplatePage {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.lightPrimaryTextColor color: subsurfaceTheme.lightPrimaryTextColor
width: rootItem.width / 2 - 60 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("light primary text") text: qsTr("light primary text")
color: subsurfaceTheme.lightPrimaryColor color: subsurfaceTheme.lightPrimaryColor
@ -277,8 +267,6 @@ TemplatePage {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
} }
TemplateLabel { TemplateLabel {
text: "" text: ""
} }
@ -286,9 +274,8 @@ TemplatePage {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.secondaryTextColor color: subsurfaceTheme.secondaryTextColor
width: rootItem.width / 2 - 60 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("secondary text") text: qsTr("secondary text")
color: subsurfaceTheme.primaryColor color: subsurfaceTheme.primaryColor
@ -297,14 +284,12 @@ TemplatePage {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
} }
Rectangle { Rectangle {
border.width: 2 border.width: 2
border.color: "black" border.color: "black"
color: subsurfaceTheme.drawerColor color: subsurfaceTheme.drawerColor
width: rootItem.width / 2 - 20 Layout.fillWidth: true
height: subsurfaceTheme.regularPointSize + 10 Layout.preferredHeight: 2 * Kirigami.Units.gridUnit
TemplateLabel { TemplateLabel {
text: qsTr("drawer") text: qsTr("drawer")
color: subsurfaceTheme.textColor color: subsurfaceTheme.textColor
@ -316,12 +301,20 @@ TemplatePage {
TemplateLabel { TemplateLabel {
text: "" text: ""
} }
Row { TemplateLabel {
Layout.preferredWidth: gridWidth * 0.8 text: qsTr("Font size")
font.pointSize: subsurfaceTheme.headingPointSize
font.weight: Font.Light
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.largeSpacing / 2
Layout.columnSpan: 2
}
RowLayout {
Layout.columnSpan: 2 Layout.columnSpan: 2
spacing: Kirigami.Units.largeSpacing spacing: Kirigami.Units.largeSpacing
TemplateButton { TemplateButton {
text: qsTr("smaller") text: qsTr("smaller")
Layout.fillWidth: true
enabled: subsurfaceTheme.currentScale !== 0.85 enabled: subsurfaceTheme.currentScale !== 0.85
onClicked: { onClicked: {
subsurfaceTheme.currentScale = 0.85 subsurfaceTheme.currentScale = 0.85
@ -329,6 +322,7 @@ TemplatePage {
} }
TemplateButton { TemplateButton {
text: qsTr("regular") text: qsTr("regular")
Layout.fillWidth: true
enabled: subsurfaceTheme.currentScale !== 1.0 enabled: subsurfaceTheme.currentScale !== 1.0
onClicked: { onClicked: {
subsurfaceTheme.currentScale = 1.0 subsurfaceTheme.currentScale = 1.0
@ -336,6 +330,7 @@ TemplatePage {
} }
TemplateButton { TemplateButton {
text: qsTr("larger") text: qsTr("larger")
Layout.fillWidth: true
enabled: subsurfaceTheme.currentScale !== 1.15 enabled: subsurfaceTheme.currentScale !== 1.15
onClicked: { onClicked: {
subsurfaceTheme.currentScale = 1.15 subsurfaceTheme.currentScale = 1.15
@ -349,12 +344,13 @@ TemplatePage {
TemplateSection { TemplateSection {
id: sectionUnits id: sectionUnits
title: qsTr("Units") title: qsTr("Units")
width: parent.width
Row { RowLayout {
visible: sectionUnits.isExpanded visible: sectionUnits.isExpanded
width: parent.width
TemplateRadioButton { TemplateRadioButton {
text: qsTr("Metric") text: qsTr("Metric")
Layout.fillWidth: true
checked: (Backend.unit_system === Enums.METRIC) checked: (Backend.unit_system === Enums.METRIC)
onClicked: { onClicked: {
Backend.unit_system = Enums.METRIC Backend.unit_system = Enums.METRIC
@ -364,6 +360,7 @@ TemplatePage {
} }
TemplateRadioButton { TemplateRadioButton {
text: qsTr("Imperial") text: qsTr("Imperial")
Layout.fillWidth: true
checked: (Backend.unit_system === Enums.IMPERIAL) checked: (Backend.unit_system === Enums.IMPERIAL)
onClicked: { onClicked: {
Backend.unit_system = Enums.IMPERIAL Backend.unit_system = Enums.IMPERIAL
@ -373,6 +370,7 @@ TemplatePage {
} }
TemplateRadioButton { TemplateRadioButton {
text: qsTr("Personalize") text: qsTr("Personalize")
Layout.fillWidth: true
checked: (Backend.unit_system === Enums.PERSONALIZE) checked: (Backend.unit_system === Enums.PERSONALIZE)
onClicked: { onClicked: {
Backend.unit_system = Enums.PERSONALIZE Backend.unit_system = Enums.PERSONALIZE
@ -384,7 +382,9 @@ TemplatePage {
GridLayout { GridLayout {
visible: sectionUnits.isExpanded visible: sectionUnits.isExpanded
width: parent.width - 2 * Kirigami.Units.gridUnit
enabled: (Backend.unit_system === Enums.PERSONALIZE) enabled: (Backend.unit_system === Enums.PERSONALIZE)
anchors.horizontalCenter: parent.horizontalCenter
columns: 3 columns: 3
ButtonGroup { id: unitDepth } ButtonGroup { id: unitDepth }
@ -499,12 +499,13 @@ TemplatePage {
TemplateSection { TemplateSection {
id: sectionAdvanced id: sectionAdvanced
title: qsTr("Advanced") title: qsTr("Advanced")
width: parent.width
GridLayout { GridLayout {
id: gpsPrefs id: gpsPrefs
visible: sectionAdvanced.isExpanded visible: sectionAdvanced.isExpanded
width: parent.width
columns: 2 columns: 2
TemplateLabel { TemplateLabel {
text: qsTr("GPS location service") text: qsTr("GPS location service")
font.pointSize: subsurfaceTheme.headingPointSize font.pointSize: subsurfaceTheme.headingPointSize
@ -513,30 +514,26 @@ TemplatePage {
Layout.bottomMargin: Kirigami.Units.largeSpacing / 2 Layout.bottomMargin: Kirigami.Units.largeSpacing / 2
Layout.columnSpan: 2 Layout.columnSpan: 2
} }
TemplateLabel { TemplateLabel {
text: qsTr("Distance threshold (meters)") text: qsTr("Distance threshold (meters)")
Layout.preferredWidth: gridWidth * 0.75 //Layout.preferredWidth: gridWidth * 0.75
} }
TemplateTextField { TemplateTextField {
id: distanceThreshold id: distanceThreshold
text: PrefLocationService.distance_threshold text: PrefLocationService.distance_threshold
Layout.preferredWidth: gridWidth * 0.25 //Layout.preferredWidth: gridWidth * 0.25
onEditingFinished: { onEditingFinished: {
PrefLocationService.distance_threshold = distanceThreshold.text PrefLocationService.distance_threshold = distanceThreshold.text
} }
} }
TemplateLabel { TemplateLabel {
text: qsTr("Time threshold (minutes)") text: qsTr("Time threshold (minutes)")
Layout.preferredWidth: gridWidth * 0.75 //Layout.preferredWidth: gridWidth * 0.75
} }
TemplateTextField { TemplateTextField {
id: timeThreshold id: timeThreshold
text: PrefLocationService.time_threshold / 60 text: PrefLocationService.time_threshold / 60
Layout.preferredWidth: gridWidth * 0.25 //Layout.preferredWidth: gridWidth * 0.25
onEditingFinished: { onEditingFinished: {
PrefLocationService.time_threshold = timeThreshold.text * 60 PrefLocationService.time_threshold = timeThreshold.text * 60
} }
@ -548,6 +545,7 @@ TemplatePage {
GridLayout { GridLayout {
id: whichBluetoothDevices id: whichBluetoothDevices
visible: sectionAdvanced.isExpanded visible: sectionAdvanced.isExpanded
width: parent.width
columns: 2 columns: 2
TemplateLabel { TemplateLabel {
text: qsTr("Bluetooth") text: qsTr("Bluetooth")
@ -557,15 +555,15 @@ TemplatePage {
Layout.bottomMargin: Kirigami.Units.largeSpacing / 2 Layout.bottomMargin: Kirigami.Units.largeSpacing / 2
Layout.columnSpan: 2 Layout.columnSpan: 2
} }
TemplateLabel { TemplateLabel {
text: qsTr("Temporarily show all bluetooth devices \neven if not recognized as dive computers.\nPlease report DCs that need this setting") text: qsTr("Temporarily show all bluetooth devices \neven if not recognized as dive computers.\nPlease report DCs that need this setting")
Layout.preferredWidth: gridWidth * 0.75 Layout.fillWidth: true
//Layout.preferredWidth: gridWidth * 0.75
} }
SsrfSwitch { SsrfSwitch {
id: nonDCButton id: nonDCButton
checked: manager.showNonDiveComputers checked: manager.showNonDiveComputers
Layout.preferredWidth: gridWidth * 0.25 //Layout.preferredWidth: gridWidth * 0.25
onClicked: { onClicked: {
manager.showNonDiveComputers = checked manager.showNonDiveComputers = checked
} }
@ -577,6 +575,7 @@ TemplatePage {
GridLayout { GridLayout {
id: display id: display
visible: sectionAdvanced.isExpanded visible: sectionAdvanced.isExpanded
width: parent.width
columns: 2 columns: 2
TemplateLabel { TemplateLabel {
text: qsTr("Display") text: qsTr("Display")
@ -588,24 +587,25 @@ TemplatePage {
} }
TemplateLabel { TemplateLabel {
text: qsTr("Show only one column in Portrait mode") text: qsTr("Show only one column in Portrait mode")
Layout.preferredWidth: gridWidth * 0.75 Layout.fillWidth: true
//Layout.preferredWidth: gridWidth * 0.75
} }
SsrfSwitch { SsrfSwitch {
id: singleColumnButton id: singleColumnButton
checked: PrefDisplay.singleColumnPortrait checked: PrefDisplay.singleColumnPortrait
Layout.preferredWidth: gridWidth * 0.25 //Layout.preferredWidth: gridWidth * 0.25
onClicked: { onClicked: {
PrefDisplay.singleColumnPortrait = checked PrefDisplay.singleColumnPortrait = checked
} }
} }
} }
TemplateLine { TemplateLine {
visible: sectionAdvanced.isExpanded visible: sectionAdvanced.isExpanded
} }
GridLayout { GridLayout {
id: developer id: developer
visible: sectionAdvanced.isExpanded visible: sectionAdvanced.isExpanded
width: parent.width
columns: 2 columns: 2
TemplateLabel { TemplateLabel {
text: qsTr("Developer") text: qsTr("Developer")
@ -615,15 +615,15 @@ TemplatePage {
Layout.bottomMargin: Kirigami.Units.largeSpacing / 2 Layout.bottomMargin: Kirigami.Units.largeSpacing / 2
Layout.columnSpan: 2 Layout.columnSpan: 2
} }
TemplateLabel { TemplateLabel {
text: qsTr("Display Developer menu") text: qsTr("Display Developer menu")
Layout.preferredWidth: gridWidth * 0.75 Layout.fillWidth: true
//Layout.preferredWidth: gridWidth * 0.75
} }
SsrfSwitch { SsrfSwitch {
id: developerButton id: developerButton
checked: PrefDisplay.show_developer checked: PrefDisplay.show_developer
Layout.preferredWidth: gridWidth * 0.25 //sLayout.preferredWidth: gridWidth * 0.25
onClicked: { onClicked: {
PrefDisplay.show_developer = checked PrefDisplay.show_developer = checked
} }