C
Qt Quick Ultralite Thermostat Demo
/****************************************************************************** ** ** Copyright (C) 2023 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/import QtQuick 2.15 QtObject { enum Status { Heating, Cooling, Off } enum FanLevel { FanOff, FanQuarter, FanHalf, FanThreeQuarters, FanFull } id: root property string name; property string floor; property int temperature : 69; property bool auto_ property bool power: true property bool dryer property int fan property bool eco property bool streamer property int status property int leftHandleX: 10 property int rightHandleX: 200 function fanImage() : image { switch (fan) { case Room.FanOff: return "fan-off.png" case Room.FanQuarter: return "fan-1-on.png" case Room.FanHalf: return "fan-2-on.png" case Room.FanThreeQuarters: return "fan-3-on.png" case Room.FanFull: return "fan-4-on.png" default: return "fan-off.png" } } function fanOffImage() : image { return "fan-off.png" } function smallFanImage() : image { switch (fan) { case Room.FanOff: return "fan-off-small.png" case Room.FanQuarter: return "fan-1-on-small.png" case Room.FanHalf: return "fan-2-on-small.png" case Room.FanThreeQuarters: return "fan-3-on-small.png" case Room.FanFull: return "fan-4-on-small.png" default: return "fan-off-small.png" } } onPowerChanged: { if (!power) { status = Room.Off } else { status = Room.Heating } } onStatusChanged: { power = (status !== Room.Off) } property Timer statusChanger: Timer { running: true repeat: true interval: 5000 onTriggered: { if (root.status == Room.Off) { return; } if (Math.random() < 0.3) { root.status = root.status == Room.Heating ? Room.Cooling : Room.Heating } } } property Timer tempChanger: Timer { running: true repeat: true interval: 3000 onTriggered: { if (Math.random() < 0.3) { var min = Units.fahrenheitToTemperatureUnit(50); var max = Units.fahrenheitToTemperatureUnit(90); root.temperature += Math.random() < 0.5 ? -1 : 1 if (root.temperature < min) { root.temperature = min } else if (root.temperature > max) { root.temperature = max } } } } }