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
import ClusterDemo

Item {
    anchors.fill: parent
    anchors.topMargin: 120
    property real defaultScale: 1.0
    property var previousView: calendarView
    property bool view: ValueSource.viewChange

    property int viewNumber: -1
    z: -1

    CenterViewMusic {
        id: musicView
        anchors.horizontalCenter: parent.horizontalCenter
        yTarget: 430
        width: 186
        height: 186
        visible: false
        y: defaultYPos
    }

    CenterViewContacts {
        id: contactView
        anchors.horizontalCenter: parent.horizontalCenter
        yTarget: 430
        width: 100
        height: 100
        visible: false
        y: defaultYPos
    }

    CenterViewCarInfo {
        id: carinfoView
        xTarget: (parent.width - width) / 2
        anchors.top: parent.top
        anchors.topMargin: 430
        width: 146
        height: 80
        x: defaultXPos
        visible: false
    }

    CenterViewCalendar {
        id: calendarView
        xTarget: (parent.width - width) / 2
        anchors.top: parent.top
        anchors.topMargin: 430
        width: 150
        height: 136
        x: defaultXPos
        visible: false
    }

    PropertyAnimation {
        id: shrinkCenter
        property: "scale"
        to: 0.0
        running: false
        duration: 500
        onStopped: {
            if (target != null)
                target.visible = false
        }
    }

    function handleViewChange(number) {
        var currentView
        if (number === 0)
            currentView = musicView
        else if (number === 1)
            currentView = contactView
        else if (number === 2)
            currentView = carinfoView
        else if (number === 3)
            currentView = calendarView
        if (previousView !== currentView) {
            currentView.scale = defaultScale
            currentView.visible = true
            shrinkCenter.target = previousView
            previousView = currentView
            shrinkCenter.start()
        }
    }

    onViewChanged: {
        if (view) {
            if (++viewNumber > 3)
                viewNumber = 0
            handleViewChange(viewNumber)
        }
    }

    // Used on automatic demo mode
    Timer {
        id: centerTimer
        property int viewNumber: -1
        running: ValueSource.automaticDemoMode
        repeat: true
        interval: 6000
        onTriggered: {
            if (++viewNumber > 3)
                viewNumber = 0
            handleViewChange(viewNumber)
        }
    }

    function stopAll() {
        centerTimer.stop()
    }
}