C
Qt Quick Ultralite Motorcycle Cluster Demo
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
import QtQuick 2.4
Item {
id: root
width: 700
property int counter: 0
readonly property int opacityAnimationDuration: 1000
readonly property int listingAnimationDuration: 1000
readonly property int elementsCount: 17
property bool active: false
property bool isDayMode: true
readonly property list tachoElements: [
Qt.point(0, 81),
Qt.point(35, 63),
Qt.point(75, 43),
Qt.point(113, 25),
Qt.point(156, 7),
Qt.point(204, 0),
Qt.point(251, 0),
Qt.point(298, 0),
Qt.point(345, 0),
Qt.point(390, 0),
Qt.point(433, 0),
Qt.point(485, 0),
Qt.point(528, 7),
Qt.point(572, 25),
Qt.point(612, 43),
Qt.point(649, 63),
Qt.point(685, 81)
]
Repeater {
id: scale
model: root.tachoElements.length
Text {
text: index
y: root.tachoElements[index].y
x: root.tachoElements[index].x
color: index >= 13 ? Style.pureRed : (isDayMode ? Style.black : Style.white)
opacity: index >= counter ? 0.0 : 1.0
font.pixelSize: 18
font.family: "Barlow-mono"
Behavior on opacity {
NumberAnimation {
duration: root.opacityAnimationDuration
}
}
}
}
onActiveChanged: {
if (active) {
root.opacity = 1
startAnimation()
} else {
hiddingAnimation()
}
}
function startAnimation() {
showAnimation.start()
}
function hiddingAnimation() {
hideAnimation.start()
}
NumberAnimation {
id: showAnimation
target: root
property: "counter"
from: 0
to: root.elementsCount
duration: root.listingAnimationDuration
}
SequentialAnimation {
id: hideAnimation
NumberAnimation {
target: root
property: "opacity"
duration: 500
to: 0
}
ScriptAction {
script: {
root.counter = 0
}
}
}
}