forked from papyros/qml-material
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInk.qml
More file actions
237 lines (175 loc) · 6.17 KB
/
Copy pathInk.qml
File metadata and controls
237 lines (175 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
* QML Material - An application framework implementing Material Design.
*
* Copyright (C) 2014-2016 Michael Spencer <sonrisesoftware@gmail.com>
* 2014 Marcin Baszczewski
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import QtQuick 2.4
import Material 0.3
import Material.Extras 0.1
/*!
\qmltype Ink
\inqmlmodule Material
\brief Represents a ripple ink animation used in buttons and many other components.
*/
MouseArea {
id: view
clip: true
hoverEnabled: Device.hoverEnabled
z: 2
property int startRadius: circular ? width/10 : width/6
property int endRadius
property Item lastCircle
property color color: Qt.rgba(0,0,0,0.1)
property bool circular: false
property bool centered: false
property int focusWidth: width - 32 * Units.dp
property bool focused
property color focusColor: "transparent"
property bool showFocus: true
onPressed: {
createTapCircle(mouse.x, mouse.y)
}
onCanceled: {
lastCircle.removeCircle();
}
onReleased: {
lastCircle.removeCircle();
}
function createTapCircle(x, y) {
endRadius = centered ? width/2 : radius(x, y)
showFocus = false
lastCircle = tapCircle.createObject(view, {
"circleX": centered ? width/2 : x,
"circleY": centered ? height/2 : y
});
}
function radius(x, y) {
var dist1 = Math.max(dist(x, y, 0, 0), dist(x, y, width, height))
var dist2 = Math.max(dist(x, y, width, 0), dist(x, y, 0, height))
return Math.max(dist1, dist2)
}
function dist(x1, y1, x2, y2) {
var xs = 0;
var ys = 0;
xs = x2 - x1;
xs = xs * xs;
ys = y2 - y1;
ys = ys * ys;
return Math.sqrt( xs + ys );
}
Rectangle {
id: focusBackground
anchors.fill: parent
color: Theme.isDarkColor(focusColor) && focusColor.a > 0
? Qt.rgba(0,0,0,0.2) : Qt.rgba(0,0,0,0.1)
opacity: showFocus && focused ? 1 : 0
Behavior on opacity {
NumberAnimation { duration: 500; easing.type: Easing.InOutQuad }
}
}
Rectangle {
id: focusCircle
anchors.centerIn: parent
width: focused
? focusedState ? focusWidth
: Math.min(parent.width - 8 * Units.dp, focusWidth + 12 * Units.dp)
: parent.width/5
height: width
radius: width/2
opacity: showFocus && focused ? 1 : 0
Behavior on opacity {
NumberAnimation { duration: 500; easing.type: Easing.InOutQuad }
}
Behavior on width {
NumberAnimation { duration: focusTimer.interval; }
}
color: focusColor.a === 0 ? Qt.rgba(1,1,1,0.4) : focusColor
property bool focusedState
Timer {
id: focusTimer
running: focused
repeat: true
interval: 800
onTriggered: focusCircle.focusedState = !focusCircle.focusedState
}
}
Component {
id: tapCircle
Item {
id: circleItem
anchors.fill: parent
property bool done
function removeCircle() {
done = true
if (fillSizeAnimation.running) {
fillOpacityAnimation.stop()
closeAnimation.start()
circleItem.destroy(500);
} else {
showFocus = true
fadeAnimation.start();
circleItem.destroy(300);
}
}
property real circleX
property real circleY
property bool closed
Item {
id: circleParent
anchors.fill: parent
visible: !circular
Rectangle {
id: circleRectangle
x: circleItem.circleX - radius
y: circleItem.circleY - radius
width: radius * 2
height: radius * 2
opacity: 0
color: view.color
NumberAnimation {
id: fillSizeAnimation
running: true
target: circleRectangle; property: "radius"; duration: 500;
from: startRadius; to: endRadius; easing.type: Easing.InOutQuad
onStopped: {
if (done)
showFocus = true
}
}
NumberAnimation {
id: fillOpacityAnimation
running: true
target: circleRectangle; property: "opacity"; duration: 300;
from: 0; to: 1; easing.type: Easing.InOutQuad
}
NumberAnimation {
id: fadeAnimation
target: circleRectangle; property: "opacity"; duration: 300;
from: 1; to: 0; easing.type: Easing.InOutQuad
}
SequentialAnimation {
id: closeAnimation
NumberAnimation {
target: circleRectangle; property: "opacity"; duration: 250;
to: 1; easing.type: Easing.InOutQuad
}
NumberAnimation {
target: circleRectangle; property: "opacity"; duration: 250;
from: 1; to: 0; easing.type: Easing.InOutQuad
}
}
}
}
CircleMask {
anchors.fill: parent
source: circleParent
visible: circular
}
}
}
}