Debian Codegraph @

examples/charts/qmlchartsgallery/qml/WheelOfFortune.qml

raw
1 // Copyright (C) 2023 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 import QtQuick
5 import QtCharts
6
7 Item {
8 id: root
9 property int __activeIndex: 1
10 property real __intervalCoefficient: 0
11
12 //![1]
13 ChartView {
14 id: chartView
15 anchors.fill: parent
16 title: "Wheel of Fortune"
17 legend.visible: false
18 antialiasing: true
19
20 PieSeries {
21 id: wheelOfFortune
22 horizontalPosition: 0.3
23 }
24
25 SplineSeries {
26 id: splineSeries
27 }
28
29 ScatterSeries {
30 id: scatterSeries
31 }
32 }
33 //![1]
34
35 //![2]
36 Component.onCompleted: {
37 __intervalCoefficient = Math.random() + 0.25;
38
39 for (var i = 0; i < 20; i++)
40 wheelOfFortune.append("", 1);
41
42 var interval = 1;
43 for (var j = 0; interval < 800; j++) {
44 interval = __intervalCoefficient * j * j;
45 splineSeries.append(j, interval);
46 }
47 chartView.axisX(scatterSeries).max = j;
48 chartView.axisY(scatterSeries).max = 1000;
49 }
50 //![2]
51
52 Timer {
53 id: timer
54 property color switchColor
55 triggeredOnStart: true
56 running: true
57 repeat: true
58 interval: 100
59 onTriggered: {
60 var index = root.__activeIndex % wheelOfFortune.count;
61 if (interval < 700) {
62 //![3]
63 wheelOfFortune.at(index).exploded = false;
64 root.__activeIndex++;
65 index = root.__activeIndex % wheelOfFortune.count;
66 wheelOfFortune.at(index).exploded = true;
67 //![3]
68 interval = splineSeries.at(root.__activeIndex).y;
69 //![4]
70 scatterSeries.clear();
71 scatterSeries.append(root.__activeIndex, interval);
72 scatterSeries.color = Qt.tint(scatterSeries.color, "#05FF0000");
73 scatterSeries.markerSize += 0.5;
74 //![4]
75 } else {
76 //![5]
77 // Switch the colors of the slice and the border
78 wheelOfFortune.at(index).borderWidth = 2;
79 switchColor = wheelOfFortune.at(index).borderColor;
80 wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color;
81 wheelOfFortune.at(index).color = switchColor;
82 //![5]
83 }
84 }
85 }
86 }