From bdbcecefe300a11e397790b4da7d6370ff5288e8 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 15 Feb 2022 10:09:47 +0100 Subject: [PATCH] Add support for the virtual button thing class --- nymea-app/ui/devicepages/ButtonThingPage.qml | 32 +++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/nymea-app/ui/devicepages/ButtonThingPage.qml b/nymea-app/ui/devicepages/ButtonThingPage.qml index 4453ec84..c9a22c15 100644 --- a/nymea-app/ui/devicepages/ButtonThingPage.qml +++ b/nymea-app/ui/devicepages/ButtonThingPage.qml @@ -38,13 +38,19 @@ import "../customviews" ThingPageBase { id: root + readonly property bool isVirtualButton: thing.thingClassId.toString().indexOf("820b2f2d-0d92-48c8-8fd4-f94ce8fc4103") >= 0 + readonly property bool isVirtualSwitch: thing.thingClassId.toString().indexOf("8ea0a168-74ff-4445-8c13-74aab195af4e") >= 0 + readonly property bool isVirtual: isVirtualButton || isVirtualSwitch + + readonly property State powerState: thing ? thing.stateByName("power") : null + EmptyViewPlaceholder { anchors { left: parent.left; right: parent.right; margins: app.margins } anchors.verticalCenter: parent.verticalCenter title: qsTr("This switch has not been used yet.") text: qsTr("Press a button on the switch to see logs appearing here.") - visible: !logsModel.busy && logsModel.count === 0 + visible: !logsModel.busy && logsModel.count === 0 && !root.isVirtual buttonVisible: false imageSource: "../images/system-shutdown.svg" } @@ -52,6 +58,7 @@ ThingPageBase { GenericTypeLogView { id: logView anchors.fill: parent + visible: !root.isVirtual logsModel: LogsModel { id: logsModel @@ -87,4 +94,27 @@ ThingPageBase { rulePage.addRule(rule); } } + + CircleBackground { + id: background + anchors.fill: parent + anchors.margins: Style.hugeMargins + iconSource: "system-shutdown" + visible: root.isVirtual + onColor: Style.accentColor + on: root.isVirtualButton ? pressAnimationTimer.running : root.powerState && root.powerState.value === true + onClicked: { + PlatformHelper.vibrate(PlatformHelper.HapticsFeedbackSelection) + if (root.isVirtualButton) { + root.thing.executeAction("press", []) + pressAnimationTimer.start() + } else { + root.thing.executeAction("power", [{paramName: "power", value: !background.on}]) + } + } + Timer { + id: pressAnimationTimer + interval: Style.animationDuration + } + } }