C

Qt Quick Ultralite Thermostat Demo

/****************************************************************************** ** ** Copyright (C) 2020 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 import QtCharts 2.15 import Thermo 1.0 ThermoView { id: root property int selected: 0 property color tickLabelColor: ColorStyle.greyDark1 property color tickLabelTransparent: "#0090989d" // transparent version of greyDark1 property int transitionDuration: 1000 property bool enableBehaviors: true property int displayedData: 0 // switches in the middle of a transition animation function resetBarValues() { bsv1.value = axisY.min bsv2.value = axisY.min bsv3.value = axisY.min bsv4.value = axisY.min bsv5.value = axisY.min bsv6.value = axisY.min } SequentialAnimation { id: toYear ParallelAnimation { ScriptAction { script: { resetBarValues() axisX.labelsColor = tickLabelTransparent axisY.labelsColor = tickLabelTransparent } } PauseAnimation { duration: transitionDuration } } ScriptAction { script: { enableBehaviors = false displayedData = 1 axisY.min = 10 axisY.max = 100 resetBarValues() enableBehaviors = true } } ParallelAnimation { ScriptAction { script: { bsv1.value = 70 bsv2.value = 50 bsv3.value = 55 bsv4.value = 57 bsv5.value = 35 bsv6.value = 15 axisX.labelsColor = tickLabelColor axisY.labelsColor = tickLabelColor } } PauseAnimation { duration: transitionDuration } } } SequentialAnimation { id: toMonth ParallelAnimation { ScriptAction { script: { resetBarValues() axisX.labelsColor = tickLabelTransparent axisY.labelsColor = tickLabelTransparent } } PauseAnimation { duration: transitionDuration } } ScriptAction { script: { enableBehaviors = false displayedData = 0 axisY.min = 1 axisY.max = 4 resetBarValues() enableBehaviors = true } } ParallelAnimation { ScriptAction { script: { bsv1.value = 2.6 bsv2.value = 2.1 bsv3.value = 1.5 bsv4.value = 1.7 bsv5.value = 1.95 bsv6.value = 1.55 axisX.labelsColor = tickLabelColor axisY.labelsColor = tickLabelColor } } PauseAnimation { duration: transitionDuration } } } ChartView { anchors.fill: parent margins.left: Theme.statsViewChartLeftMargin margins.right: Theme.statsViewChartRightMargin margins.bottom: Theme.statsViewChartBottomMargin margins.top: Theme.statsViewChartTopMargin backgroundColor: ColorStyle.greyLight3 BarSeries { axisX: BarCategoryAxis { id: axisX gridVisible: false lineVisible: false labelsFont.pixelSize: Theme.statsViewChartLabelFontSize labelsColor: tickLabelColor Behavior on labelsColor { ColorAnimation { duration: transitionDuration } } BarCategoryValue { value: displayedData ? qsTr("Jan") : qsTr("05/11") } BarCategoryValue { value: displayedData ? qsTr("Feb") : qsTr("05/12") } BarCategoryValue { value: displayedData ? qsTr("Mar") : qsTr("05/13") } BarCategoryValue { value: displayedData ? qsTr("Apr") : qsTr("05/14") } BarCategoryValue { value: displayedData ? qsTr("May") : qsTr("05/15") } BarCategoryValue { value: displayedData ? qsTr("Jun") : qsTr("05/16") } } axisY: ValueAxis { id: axisY min: 1.0 max: 4.0 tickCount: 4 gridLineColor: ColorStyle.greyMedium1 lineVisible: false labelsFont.pixelSize: Theme.statsViewChartLabelFontSize labelsColor: tickLabelColor labelFormat: "%d kWh" Behavior on labelsColor { ColorAnimation { duration: transitionDuration } } } BarSet { color: ColorStyle.blue BarSetValue { id: bsv1 value: 2.6 Behavior on value { enabled: enableBehaviors; NumberAnimation { duration: transitionDuration } } } BarSetValue { id: bsv2 value: 2.1 Behavior on value { enabled: enableBehaviors; NumberAnimation { duration: transitionDuration } } } BarSetValue { id: bsv3 value: 1.5 Behavior on value { enabled: enableBehaviors; NumberAnimation { duration: transitionDuration } } } BarSetValue { id: bsv4 value: 1.7 Behavior on value { enabled: enableBehaviors; NumberAnimation { duration: transitionDuration } } } BarSetValue { id: bsv5 value: 1.95 Behavior on value { enabled: enableBehaviors; NumberAnimation { duration: transitionDuration } } } BarSetValue { id: bsv6 value: 1.55 Behavior on value { enabled: enableBehaviors; NumberAnimation { duration: transitionDuration } } } } } } Image { anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top anchors.topMargin: Theme.statsViewToggleTopMargin source: root.selected === 0 ? "toggle-month.png" : "toggle-year.png" Text { text: qsTr("Month") x: Theme.statsViewButtonMonthHCenter - width / 2 y: Theme.statsViewButtonVCenter - baselineOffset / 2 font.pixelSize: Theme.statsViewButtonFontSize font.family: "Roboto" color: root.selected === 0 ? ColorStyle.blue : ColorStyle.greyDark4 } Text { text: qsTr("Year") x: Theme.statsViewButtonYearHCenter - width / 2 y: Theme.statsViewButtonVCenter - baselineOffset / 2 font.pixelSize: Theme.statsViewButtonFontSize font.family: "Roboto" color: root.selected === 1 ? ColorStyle.blue : ColorStyle.greyDark4 } MouseArea { width: parent.width / 2 height: parent.height onClicked: { if (root.selected != 0) { root.selected = 0 toYear.stop() toMonth.start() } } } MouseArea { x: parent.width / 2 width: parent.width / 2 height: parent.height onClicked: { if (root.selected != 1) { root.selected = 1 toMonth.stop() toYear.start() } } } } }