C

Qt Cluster: Rendering and Recovery from Main UI Failure

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

// This file is part of the Qt Safe Renderer module

import QtQuick

Item {
    id: infoNote
    height: 70
    width: noteImage.width
    anchors.bottom: car.bottom
    visible: noteVisible && highlightType && !car.hidden
    property int fixedPositionX: 0
    property color textColor: "white"
    property bool noteVisible: false
    property int highlightType: main.carModelHighlightType

    Image {
        id: noteImage
        source: "image://etc/InfoNoteBackground.png"
        opacity: 0.75
    }

    Timer {
        id: waitForCamera
        interval: 800
        running: false
        onTriggered: {
            noteVisible = true
            if (fixedPositionX === 0)
                infoNote.x = car.item.x + (car.item.width - noteImage.width) / 2
            else
                x = fixedPositionX - (noteImage.width / 2)
        }
    }

    onHighlightTypeChanged: {
        if (highlightType)
            waitForCamera.restart()
        else
            noteVisible = false
    }

    Text {
        id: pressureText
        anchors.centerIn: parent
        visible: infoNote.visible && (highlightType >= 0 && highlightType <= 4)
        color: textColor
        font.pixelSize: 16
        font.weight: Font.DemiBold
    }

    Text {
        id: bulbText
        anchors.centerIn: parent
        visible: highlightType >= 5
        text: "Lightbulb"
        color: textColor
        font.pixelSize: 16
        font.weight: Font.DemiBold
    }

    Text {
        id: doorText
        anchors.centerIn: parent
        visible: highlightType === -1
        text: "Check doors"
        color: textColor
        font.pixelSize: 16
        font.weight: Font.DemiBold
    }

    onVisibleChanged: {
        if (visible) {
            infoNote.anchors.horizontalCenterOffset = 0
            if (highlightType === -1) {
                //infoNote.width = doorText.contentWidth + 40
                //infoNote.height = 40
            } else {
                if (highlightType <= 4) {
                    var pressure = Math.random() + 1
                    //var temperature = Math.random() * 12 + 20
                    pressureText.text = pressure.toFixed(1) + " bar"
                    //temperatureText.text = temperature.toFixed(1) + " \u00B0C"

                    //infoNote.width = pressureText.contentWidth + 40
                    //infoNote.height = 40
                } else {
                    switch (highlightType) {
                    case 5:
                        bulbText.text = "Check left headlight"
                        break

                    case 6:
                        bulbText.text = "Check right headlight"
                        break

                    case 7:
                        bulbText.text = "Check right daylight"
                        break

                    case 8:
                        bulbText.text = "Check left daylight"
                        break

                    case 9:
                        infoNote.anchors.verticalCenterOffset = 60
                        bulbText.text = "Check left taillight"
                        break

                    case 10:
                        infoNote.anchors.verticalCenterOffset = 60
                        bulbText.text = "Check right taillight"
                        break

                    default:
                        // Coding fault if we get here, undefined code
                        bulbText.text = "Check lights"
                    }

                    //infoNote.width = bulbText.contentWidth + 40
                    //infoNote.height = 40
                }
            }
        }
    }
}