C

Qt Cluster: Rendering and Recovery from Main UI Failure

// Copyright (C) 2016 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR QTAS OR GPL-3.0-only

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

import QtQuick

Item {
    id: musicContainer

    property url currentCover: "image://etc/cover.png"
    property string currentSong: "Doesn't Mean Anything"
    property string currentArtist: "Alicia Keys"
    opacity: 0.5
    property alias yTarget: startupAnimation.to
    property int defaultYPos: 600

    Rectangle {
        id: image
        width: 186
        height: 186
        border.color: "#EF2973"
        border.width: 2
        color: "black"

        Image {
            anchors.margins: 2
            fillMode: Image.PreserveAspectCrop
            anchors.fill: parent
            asynchronous: true
            source: musicContainer.currentCover
        }
    }

    Text {
        id: title
        anchors.top: image.bottom
        anchors.topMargin: 15
        anchors.horizontalCenter: image.horizontalCenter
        text: musicContainer.currentSong
        color: "gray"
        font.pixelSize: 18
    }

    Text {
        anchors.top: title.bottom
        anchors.horizontalCenter: image.horizontalCenter
        text: musicContainer.currentArtist
        color: "lightGray"
        font.pixelSize: 18
    }

    Timer {
        id: fadeOutTimer
        interval: 3000
        running: false
        repeat: false
        onTriggered: {
            musicContainer.opacity = 0.5
        }
    }

    Behavior on opacity { PropertyAnimation { duration: 500 } }

    PropertyAnimation on y {
        id: startupAnimation
        duration: 500
        easing.type: Easing.InCubic
        onStopped: {
            musicContainer.opacity = 1.0
            fadeOutTimer.start()
        }
    }

    onVisibleChanged: {
        if (visible) {
            y = defaultYPos
            startupAnimation.start()
        }
    }
}