C

Qt Quick Ultralite Thermostat Demo

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

import QtQuick 2.15
import QtQuick.Templates 2.15
import QtQuickUltralite.Extras 2.0
import Thermo 1.0

Button {
    id: root
    width: Theme.roomButtonSize
    height: Theme.roomButtonSize
    checkable: true

    property alias pulsing: anim.running

    property color pulsingColor;
    SequentialAnimation {
        running: false
        loops: Animation.Infinite
        id: anim
        ColorAnimation {
            from: ColorStyle.blue
            to: ColorStyle.greyMedium3
            target: root
            property: "pulsingColor"
        }
        PauseAnimation { }
        ColorAnimation {
            to: ColorStyle.blue
            from: ColorStyle.greyMedium3
            target: root
            property: "pulsingColor"
        }
    }

    contentItem: Item {
        Image {
            source: root.pressed ? "btn-bg-down.png" : (root.enabled && root.checked)  ? "btn-bg-big-on.png" : "btn-bg-big-off.png";
            anchors.horizontalCenter: parent.horizontalCenter;
            y: root.pressed ? 0 : -6; // Because of the 6 pixel shadow in the on and off image
        }

        ColorizedImage {
            source: root.icon.source
            anchors.centerIn: parent
            property color toggledColor: (root.enabled && root.checked) ? ColorStyle.blue : ColorStyle.greyMedium3
            Behavior on toggledColor { ColorAnimation{} }
            color: root.pulsing ? root.pulsingColor : toggledColor
        }
    }
}