From 65871e264506706ea6c5e2cce10916da1acc503f Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 5 Jan 2024 00:23:49 +0100 Subject: [PATCH] Some layout fixes in the Sensor page --- nymea-app/ui/customviews/StateChart.qml | 1 + nymea-app/ui/devicepages/SensorDevicePage.qml | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/nymea-app/ui/customviews/StateChart.qml b/nymea-app/ui/customviews/StateChart.qml index 9fcc348c..0f2b531c 100644 --- a/nymea-app/ui/customviews/StateChart.qml +++ b/nymea-app/ui/customviews/StateChart.qml @@ -159,6 +159,7 @@ Item { horizontalAlignment: Text.AlignHCenter text: root.stateType.displayName visible: root.titleVisible + elide: Text.ElideMiddle // MouseArea { // anchors.fill: parent // onClicked: { diff --git a/nymea-app/ui/devicepages/SensorDevicePage.qml b/nymea-app/ui/devicepages/SensorDevicePage.qml index 7f0137c3..20788953 100644 --- a/nymea-app/ui/devicepages/SensorDevicePage.qml +++ b/nymea-app/ui/devicepages/SensorDevicePage.qml @@ -81,7 +81,7 @@ ThingPageBase { } Flickable { - id: listView + id: flickable anchors { fill: parent } topMargin: app.margins / 2 interactive: contentHeight > height @@ -97,15 +97,12 @@ ThingPageBase { Layout.fillWidth: true Layout.leftMargin: sensorsModel.count == 1 ? Style.hugeMargins : Style.bigMargins Layout.rightMargin: sensorsModel.count == 1 ? Style.hugeMargins : Style.bigMargins - Layout.preferredHeight: cellWidth * Math.min(400, Math.ceil(flowRepeater.count / columns)) + Layout.preferredHeight: flow.cellWidth * flow.totalRows - property int columns: Math.min(flowRepeater.count, Math.floor(listView.width / 150)) - property int cellWidth: width / columns - property int totalRows: flowRepeater.count / columns - -// columns: 2// Math.ceil(width / 600) -// columnSpacing: Style.margins -// rowSpacing: Style.margins + property int columns: Math.min(flowRepeater.count, Math.floor(flickable.width / 150)) + property int cellWidth: Math.min(400, width / columns) + property int filledRows: flowRepeater.count / columns + property int totalRows: Math.ceil(flowRepeater.count / columns) Repeater { id: flowRepeater @@ -113,9 +110,9 @@ ThingPageBase { delegate: SensorView { width: Math.floor(flow.width / itemsInRow) - height: Math.min(400, flow.cellWidth) + height: flow.cellWidth property int row: Math.floor(index / flow.columns) - property int itemsInRow: row < flow.totalRows ? flow.columns : (flowRepeater.count % flow.columns) + property int itemsInRow: row < flow.filledRows ? flow.columns : (flowRepeater.count % flow.columns) thing: root.thing interfaceName: modelData @@ -124,7 +121,6 @@ ThingPageBase { } } - GridLayout { columns: Math.ceil(width / 600) rowSpacing: 0 @@ -152,10 +148,30 @@ ThingPageBase { Component { id: stateChartComponent StateChart { + id: stateChart thing: root.thing stateType: parent.stateType color: app.interfaceToColor(interfaceName) iconSource: app.interfaceToIcon(interfaceName) + Binding { + target: stateChart + property: "title" + when: ["presencesensor", "daylightsensor", "closablesensor", "watersensor", "firesensor"].indexOf(interfaceName) >= 0 + value: { + switch (interfaceName) { + case "presencesensor": + return stateChart.valueState.value === true ? qsTr("Presence") : qsTr("Vacant") + case "daylightsensor": + return stateChart.valueState.value === true ? qsTr("Daytime") : qsTr("Nighttime") + case "closablesensor": + return stateChart.valueState.value === true ? qsTr("Closed") : qsTr("Open") + case "watersensor": + return stateChart.valueState.value === true ? qsTr("Wet") : qsTr("Dry") + case "firesensor": + return stateChart.valueState.value === true ? qsTr("Fire") : qsTr("No fire") + } + } + } } }