From 2b42b20a24daf028e62e7f02d20df61d4f0cc43e Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 8 Mar 2019 17:44:04 +0100 Subject: [PATCH] some tunings in the heating experience --- .../connection/nymeaconnection.cpp | 2 +- nymea-app/ui/components/Led.qml | 18 +- nymea-app/ui/customviews/GenericTypeGraph.qml | 2 +- .../delegates/statedelegates/LedDelegate.qml | 2 +- .../devicelistpages/SensorsDeviceListPage.qml | 2 +- nymea-app/ui/devicepages/DeviceLogPage.qml | 2 +- nymea-app/ui/experiences/heating/Main.qml | 280 ++++++++++-------- .../ui/mainviews/DevicesPageDelegate.qml | 2 +- nymea-app/ui/mainviews/FavoritesView.qml | 2 +- 9 files changed, 178 insertions(+), 134 deletions(-) diff --git a/libnymea-app-core/connection/nymeaconnection.cpp b/libnymea-app-core/connection/nymeaconnection.cpp index 8142ec09..a1db8ce5 100644 --- a/libnymea-app-core/connection/nymeaconnection.cpp +++ b/libnymea-app-core/connection/nymeaconnection.cpp @@ -137,7 +137,7 @@ Connection *NymeaConnection::currentConnection() const void NymeaConnection::sendData(const QByteArray &data) { if (connected()) { -// qDebug() << "sending data:" << data; + qDebug() << "sending data:" << data; m_currentTransport->sendData(data); } else { qWarning() << "Connection: Not connected. Cannot send."; diff --git a/nymea-app/ui/components/Led.qml b/nymea-app/ui/components/Led.qml index 7ca8b7ae..2822b226 100644 --- a/nymea-app/ui/components/Led.qml +++ b/nymea-app/ui/components/Led.qml @@ -5,13 +5,27 @@ Item { implicitHeight: app.iconSize * .8 implicitWidth: height - property bool on: false + // TODO: Convert to enum once we have Qt 5.10 + // on, off, green, orange, red + property string state: "off" Rectangle { height: Math.min(parent.height, parent.height) width: height radius: width / 2 - color: root.on ? "lightgreen" : "lightgray" + color: { + switch (root.state) { + case "on": + case "green": + return "#91dd77"; + case "off": + return "lightgray"; + case "orange": + return "#dddd77"; + case "red": + return "#dd7777" + } + } border.width: 1 border.color: app.foregroundColor } diff --git a/nymea-app/ui/customviews/GenericTypeGraph.qml b/nymea-app/ui/customviews/GenericTypeGraph.qml index d6ec772e..a5d69c03 100644 --- a/nymea-app/ui/customviews/GenericTypeGraph.qml +++ b/nymea-app/ui/customviews/GenericTypeGraph.qml @@ -57,7 +57,7 @@ Item { Led { visible: root.stateType.type.toLowerCase() === "bool" - on: root.valueState.value === true + state: root.valueState.value === true ? "on" : "off" } Label { diff --git a/nymea-app/ui/delegates/statedelegates/LedDelegate.qml b/nymea-app/ui/delegates/statedelegates/LedDelegate.qml index 22fb94a5..8eb5163b 100644 --- a/nymea-app/ui/delegates/statedelegates/LedDelegate.qml +++ b/nymea-app/ui/delegates/statedelegates/LedDelegate.qml @@ -7,5 +7,5 @@ import "../../components" Led { property bool value - on: value === true + state: value === true ? "on" : "off" } diff --git a/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml b/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml index 541e1044..4c7fd110 100644 --- a/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml @@ -118,7 +118,7 @@ DeviceListPageBase { Led { id: led visible: sensorValueDelegate.stateType && sensorValueDelegate.stateType.type.toLowerCase() == "bool" - on: visible && sensorValueDelegate.stateValue.value === true + state: visible && sensorValueDelegate.stateValue.value === true ? "on" : "off" } Item { Layout.preferredWidth: led.width diff --git a/nymea-app/ui/devicepages/DeviceLogPage.qml b/nymea-app/ui/devicepages/DeviceLogPage.qml index 8481e246..01b00219 100644 --- a/nymea-app/ui/devicepages/DeviceLogPage.qml +++ b/nymea-app/ui/devicepages/DeviceLogPage.qml @@ -268,7 +268,7 @@ Page { property var value Led { implicitHeight: app.smallFont - on: boolLed.value === "true" + state: boolLed.value === "true" ? "on" : "off" } } } diff --git a/nymea-app/ui/experiences/heating/Main.qml b/nymea-app/ui/experiences/heating/Main.qml index 29127a59..c3ad8af5 100644 --- a/nymea-app/ui/experiences/heating/Main.qml +++ b/nymea-app/ui/experiences/heating/Main.qml @@ -16,7 +16,9 @@ Item { readonly property State temperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.deviceClass.stateTypes.findByName("temperature").id) : null readonly property State targetTemperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.deviceClass.stateTypes.findByName("targetTemperature").id) : null + readonly property State co2LevelState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.deviceClass.stateTypes.findByName("co2").id) : null readonly property State ventilationModeState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.deviceClass.stateTypes.findByName("ventilationMode").id) : null + readonly property State ventilationLevelState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.deviceClass.stateTypes.findByName("activeVentilationLevel").id) : null function ventilationModeToSliderValue(ventilationMode) { switch (ventilationMode) { @@ -135,149 +137,177 @@ Item { anchors.fill: parent anchors.margins: app.margins - RowLayout { - spacing: app.margins - ColorIcon { - Layout.preferredHeight: app.iconSize - Layout.preferredWidth: app.iconSize - name: "qrc:/ui/images/weathericons/wind.svg" - color: app.accentColor - } - Led { - } - } + ColumnLayout { - Label { - text: qsTr("Current temperature") - font.pixelSize: app.smallFont - } - - RowLayout { - ColorIcon { - Layout.preferredHeight: app.iconSize - Layout.preferredWidth: app.iconSize - name: "qrc:/ui/images/sensors/temperature.svg" - color: app.accentColor + RowLayout { + spacing: app.margins + ColorIcon { + Layout.preferredHeight: app.iconSize + Layout.preferredWidth: app.iconSize + name: "qrc:/ui/images/weathericons/wind.svg" + color: app.accentColor + } + Led { + state: { + if (!root.co2LevelState) { + return "off" + } + if (root.co2LevelState.value < 900) { + return "green" + } + if (root.co2LevelState.value < 2000) { + return "orange" + } + return "red" + } + } } + Label { - text: root.temperatureState ? root.temperatureState.value.toFixed(1) + "°C" : "N/A" - Layout.fillWidth: true - font.pixelSize: app.largeFont * 2 - } - } - - Item { - Layout.preferredHeight: app.margins * 2 - Layout.fillWidth: true - } - - Label { - text: qsTr("Temperature, °C") - font.pixelSize: app.largeFont - } - Label { - text: (d.pendingCallId !== -1 || d.setTempPending) ? d.queuedTargetTemp.toFixed(1) : - root.targetTemperatureState ? root.targetTemperatureState.value.toFixed(1) : "N/A" - font.pixelSize: app.largeFont * 4 - } - - Item { - Layout.preferredHeight: app.margins * 2 - Layout.fillWidth: true - } - ColorIcon { - Layout.preferredHeight: app.iconSize * 1.5 - Layout.preferredWidth: height - Layout.leftMargin: width - color: app.accentColor - name: "qrc:/ui/images/share.svg" - } - Label { - text: qsTr("Automate this thing") - color: app.accentColor - font.pixelSize: app.smallFont - } - - Item { - Layout.fillWidth: true - Layout.fillHeight: true - } - - RowLayout { - Layout.leftMargin: parent.width * .05 - Layout.rightMargin: parent.width * .2 - spacing: app.margins - ColorIcon { - Layout.preferredHeight: app.iconSize - Layout.preferredWidth: app.iconSize - color: app.accentColor - name: "qrc:/ui/images/ventilation.svg" + text: qsTr("Current temperature") + font.pixelSize: app.smallFont } RowLayout { - Layout.fillWidth: true - Layout.maximumHeight: app.iconSize - spacing: 0 + ColorIcon { + Layout.preferredHeight: app.iconSize + Layout.preferredWidth: app.iconSize + name: "qrc:/ui/images/sensors/temperature.svg" + color: app.accentColor + } + Label { + text: root.temperatureState ? root.temperatureState.value.toFixed(1) + "°C" : "N/A" + Layout.fillWidth: true + font.pixelSize: app.largeFont * 2 + } + } + } - Repeater { - model: ListModel { - ListElement { text: qsTr("Auto") } - ListElement { text: qsTr("Party") } - ListElement { text: qsTr("Manual") } - } + ColumnLayout { - Rectangle { - Layout.fillWidth: true - Layout.fillHeight: true - border.width: 1 - border.color: app.accentColor - color: root.ventilationModeState && root.ventilationModeToUiMode(root.ventilationModeState.value) === index ? app.accentColor : "transparent" - Label { - anchors.centerIn: parent - text: model.text - font.pixelSize: app.smallFont + Label { + text: qsTr("Temperature, °C") + font.pixelSize: app.largeFont + } + Label { + text: (d.pendingCallId !== -1 || d.setTempPending) ? d.queuedTargetTemp.toFixed(1) : + root.targetTemperatureState ? root.targetTemperatureState.value.toFixed(1) : "N/A" + font.pixelSize: app.largeFont * 4 + } + } + + + ColumnLayout { + Layout.fillWidth: false + ColorIcon { + Layout.preferredHeight: app.iconSize * 1.5 + Layout.preferredWidth: height + Layout.alignment: Qt.AlignHCenter + color: app.accentColor + name: "qrc:/ui/images/share.svg" + MouseArea { + anchors.fill: parent + onClicked: pageStack.push("qrc:/ui/magic/DeviceRulesPage.qml", {device: root.duwWpDevice}) + } + } + Label { + text: qsTr("Automate this thing") + color: app.accentColor + font.pixelSize: app.smallFont + } + } + + ColumnLayout { + + RowLayout { + Layout.leftMargin: parent.width * .05 + Layout.rightMargin: parent.width * .2 + spacing: app.margins + ColorIcon { + Layout.preferredHeight: app.iconSize + Layout.preferredWidth: app.iconSize + color: app.accentColor + name: "qrc:/ui/images/ventilation.svg" + PropertyAnimation on rotation { + running: root.ventilationLevelState !== null + duration: root.ventilationLevelState !== null && root.ventilationLevelState.value > 0 + ? 2000 / root.ventilationLevelState.value + : 0 + from: 360 + to: 0 + loops: Animation.Infinite + onDurationChanged: { + running = false; + running = true; } - MouseArea { - anchors.fill: parent - onClicked: { - root.setVentilationMode(index, ventilationSlider.value) + } + } + + RowLayout { + Layout.fillWidth: true + Layout.maximumHeight: app.iconSize + spacing: 0 + + Repeater { + model: ListModel { + ListElement { text: qsTr("Auto") } + ListElement { text: qsTr("Party") } + ListElement { text: qsTr("Manual") } + } + + Rectangle { + Layout.fillWidth: true + Layout.fillHeight: true + border.width: 1 + border.color: app.accentColor + color: root.ventilationModeState && root.ventilationModeToUiMode(root.ventilationModeState.value) === index ? app.accentColor : "transparent" + Label { + anchors.centerIn: parent + text: model.text + font.pixelSize: app.smallFont + } + MouseArea { + anchors.fill: parent + onClicked: { + root.setVentilationMode(index, ventilationSlider.value) + } } } } } } + + Slider { + id: ventilationSlider + Layout.fillWidth: true + Layout.leftMargin: parent.width * .05 + Layout.rightMargin: parent.width * .05 + from: 0 + to: 3 + stepSize: 1 + live: false + snapMode: Slider.SnapAlways + enabled: root.ventilationModeState && root.ventilationModeToUiMode(root.ventilationModeState.value) === 2 + opacity: enabled ? 1 : .2 + value: root.ventilationModeState ? root.ventilationModeToSliderValue(root.ventilationModeState.value) : 0 + onMoved: root.setVentilationMode(2, valueAt(visualPosition)) + } } - Slider { - id: ventilationSlider - Layout.fillWidth: true - Layout.leftMargin: parent.width * .05 - Layout.rightMargin: parent.width * .05 - from: 0 - to: 4 - stepSize: 1 - live: false - snapMode: Slider.SnapAlways - enabled: root.ventilationModeState && root.ventilationModeToUiMode(root.ventilationModeState.value) === 2 - opacity: enabled ? 1 : .2 - value: root.ventilationModeState ? root.ventilationModeToSliderValue(root.ventilationModeState.value) : 0 - onMoved: root.setVentilationMode(2, ventilationSlider.value) - } +// ProgressButton { +// imageSource: "qrc:/ui/images/system-shutdown.svg" +// Layout.preferredHeight: app.iconSize * 1.5 +// Layout.preferredWidth: height +// Layout.alignment: Qt.AlignHCenter +// } - ProgressButton { - imageSource: "qrc:/ui/images/system-shutdown.svg" - Layout.preferredHeight: app.iconSize * 1.5 - Layout.preferredWidth: height - Layout.alignment: Qt.AlignHCenter - } - - Label { - text: qsTr("Hold to turn off") - font.pixelSize: app.smallFont - Layout.fillWidth: true - horizontalAlignment: Text.AlignHCenter - } +// Label { +// text: qsTr("Hold to turn off") +// font.pixelSize: app.smallFont +// Layout.fillWidth: true +// horizontalAlignment: Text.AlignHCenter +// } } Item { diff --git a/nymea-app/ui/mainviews/DevicesPageDelegate.qml b/nymea-app/ui/mainviews/DevicesPageDelegate.qml index bcc4e168..5528ebe4 100644 --- a/nymea-app/ui/mainviews/DevicesPageDelegate.qml +++ b/nymea-app/ui/mainviews/DevicesPageDelegate.qml @@ -511,7 +511,7 @@ MainPageTile { Led { Layout.preferredHeight: app.iconSize * .5 Layout.preferredWidth: height - on: sensorsRoot.shownStateType && sensorsRoot.device.stateValue(sensorsRoot.shownStateType.id) === true + state: sensorsRoot.shownStateType && sensorsRoot.device.stateValue(sensorsRoot.shownStateType.id) === true ? "on" : "off" visible: sensorsRoot.shownStateType && sensorsRoot.shownStateType.type.toLowerCase() === "bool" } } diff --git a/nymea-app/ui/mainviews/FavoritesView.qml b/nymea-app/ui/mainviews/FavoritesView.qml index eb51c485..f6507c65 100644 --- a/nymea-app/ui/mainviews/FavoritesView.qml +++ b/nymea-app/ui/mainviews/FavoritesView.qml @@ -347,7 +347,7 @@ Item { } } Led { - on: sensorsRoot.currentState.value === true + state: sensorsRoot.currentState.value === true ? "on" : "off" visible: sensorsRoot.currentStateType.type.toLowerCase() === "bool" }