Debian Codegraph @

resources/qml/ui/TimelineEffects.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import QtQuick 2.15
6 import QtQuick.Particles 2.15
7
8 Item {
9 id: effectRoot
10 readonly property int maxLifespan: Math.max(confettiEmitter.lifeSpan, rainfallEmitter.lifeSpan)
11 required property bool shouldEffectsRun
12 visible: effectRoot.shouldEffectsRun
13
14 function pulseConfetti()
15 {
16 confettiEmitter.pulse(effectRoot.height * 2)
17 }
18
19 function pulseRainfall()
20 {
21 rainfallEmitter.pulse(effectRoot.height * 3.3)
22 }
23
24 function removeParticles()
25 {
26 particleSystem.reset()
27 }
28
29 ParticleSystem {
30 id: particleSystem
31
32 Component.onCompleted: stop();
33 paused: !effectRoot.shouldEffectsRun
34 running: effectRoot.shouldEffectsRun
35 }
36
37 Emitter {
38 id: confettiEmitter
39
40 group: "confetti"
41 width: effectRoot.width * 3/4
42 enabled: false
43 anchors.horizontalCenter: effectRoot.horizontalCenter
44 y: effectRoot.height
45 emitRate: Math.min(400 * Math.sqrt(effectRoot.width * effectRoot.height) / 870, 1000)
46 lifeSpan: 15000
47 system: particleSystem
48 maximumEmitted: 500
49 velocityFromMovement: 8
50 size: 16
51 sizeVariation: 4
52 velocity: PointDirection {
53 x: 0
54 y: -Math.min(450 * effectRoot.height / 700, 1000)
55 xVariation: Math.min(4 * effectRoot.width / 7, 450)
56 yVariation: 250
57 }
58 }
59
60 ImageParticle {
61 system: particleSystem
62 groups: ["confetti"]
63 source: "qrc:/confettiparticle.svg"
64 rotationVelocity: 0
65 rotationVelocityVariation: 360
66 colorVariation: 1
67 color: "white"
68 entryEffect: ImageParticle.None
69 xVector: PointDirection {
70 x: 1
71 y: 0
72 xVariation: 0.2
73 yVariation: 0.2
74 }
75 yVector: PointDirection {
76 x: 0
77 y: 0.5
78 xVariation: 0.2
79 yVariation: 0.2
80 }
81 }
82
83 Gravity {
84 system: particleSystem
85 groups: ["confetti"]
86 anchors.fill: effectRoot
87 magnitude: 350
88 angle: 90
89 }
90
91 Emitter {
92 id: rainfallEmitter
93
94 group: "rain"
95 width: effectRoot.width
96 enabled: false
97 anchors.horizontalCenter: effectRoot.horizontalCenter
98 y: -60
99 emitRate: effectRoot.width / 30
100 lifeSpan: 10000
101 system: particleSystem
102 velocity: PointDirection {
103 x: 0
104 y: 400
105 xVariation: 0
106 yVariation: 75
107 }
108
109 // causes high CPU load, see: https://bugreports.qt.io/browse/QTBUG-117923
110 //ItemParticle {
111 // system: particleSystem
112 // groups: ["rain"]
113 // fade: false
114 // visible: effectRoot.shouldEffectsRun
115 // delegate: Rectangle {
116 // width: 2
117 // height: 30 + 30 * Math.random()
118 // radius: 2
119 // color: "#0099ff"
120 // }
121 //}
122
123 ImageParticle {
124 system: particleSystem
125 groups: ["rain"]
126 source: "qrc:/confettiparticle.svg"
127 rotationVelocity: 0
128 rotationVelocityVariation: 0
129 colorVariation: 0
130 color: "#0099ff"
131 entryEffect: ImageParticle.None
132 xVector: PointDirection {
133 x: 0.01
134 y: 0
135 }
136 yVector: PointDirection {
137 x: 0
138 y: 5
139 }
140 }
141 }
142 }