Debian Codegraph @

resources/qml/ui/Ripple.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import QtQuick
6
7 Item {
8 id: ripple
9
10 property color color: "#22000000"
11 property real maxRadius: Math.max(width, height)
12 readonly property real radiusAnimationRate: 0.05
13 readonly property real radiusTailAnimationRate: 0.5
14 readonly property real opacityAnimationDuration: 300
15 property var rippleTarget: parent
16
17 anchors.fill: parent
18
19 PointHandler {
20 id: ph
21
22 onGrabChanged: (_, point) => {
23 circle.centerX = point.position.x
24 circle.centerY = point.position.y
25 }
26
27 target: Rectangle {
28 id: backgroundLayer
29 parent: rippleTarget
30
31 anchors.fill: parent
32 color: "transparent"
33 clip: true
34
35 Rectangle {
36 id: circle
37
38 property real centerX
39 property real centerY
40
41 x: centerX - radius
42 y: centerY - radius
43
44 height: radius*2
45 width: radius*2
46 radius: 0
47 color: ripple.color
48
49 state: ph.active ? "ACTIVE" : "NORMAL"
50 states: [
51 State {
52 name: "NORMAL"
53 },
54 State {
55 name: "ACTIVE"
56 }
57 ]
58 transitions: [
59 Transition {
60 from: "NORMAL"
61 to: "ACTIVE"
62
63 SequentialAnimation {
64 //PropertyAction { target: circle; property: "centerX"; value: ph.point.position.x }
65 //PropertyAction { target: circle; property: "centerY"; value: ph.point.position.y }
66 PropertyAction { target: circle; property: "visible"; value: true }
67 PropertyAction { target: circle; property: "opacity"; value: 1 }
68
69 NumberAnimation {
70 id: radius_animation
71
72 target: circle
73 properties: "radius"
74 from: 0
75 to: ripple.maxRadius
76 duration: ripple.maxRadius / ripple.radiusAnimationRate
77
78 easing {
79 type: Easing.OutQuad
80 }
81
82 }
83
84 }
85
86 },
87 Transition {
88 from: "ACTIVE"
89 to: "NORMAL"
90
91 SequentialAnimation {
92 ParallelAnimation {
93 NumberAnimation {
94 id: radius_tail_animation
95
96 target: circle
97 properties: "radius"
98 to: ripple.maxRadius
99 duration: ripple.maxRadius / ripple.radiusTailAnimationRate
100
101 easing {
102 type: Easing.Linear
103 }
104
105 }
106
107 NumberAnimation {
108 id: opacity_animation
109
110 target: circle
111 properties: "opacity"
112 to: 0
113 duration: ripple.opacityAnimationDuration
114
115 easing {
116 type: Easing.InQuad
117 }
118
119 }
120
121 }
122 PropertyAction { target: circle; property: "visible"; value: false }
123 }
124 }
125 ]
126 }
127 }
128 }
129 }