summaryrefslogtreecommitdiff
path: root/.config/quickshell/Modules/Music.qml
blob: 8c790922999633fe697d122c29a7fa9399bc7d6a (plain)
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
import Quickshell
import QtQuick
import QtQuick.Layouts
import qs.Services

MouseArea {
	id: root
	anchors.centerIn: parent
	height: parent.implicitHeight
	width: musicRow.implicitWidth
	state: "popup-closed"

	hoverEnabled: true
	onEntered: state = "popup-open"

	property string fontFamily: "FiraCode Nerd Font"
	property int fontSize: 14

	property int contractAnimDuration: 150

	states: [
		State {
			name: "popup-closed"
			PropertyChanges { target: popup; visible: false }
			PropertyChanges { target: musicRow; visible: true; spacing: 4 }
			PropertyChanges { target: songContainer; bottomRightRadius: 4; topRightRadius: 4 }
			PropertyChanges { target: cavaContainer; bottomLeftRadius: 4; topLeftRadius: 4 }
			PropertyChanges { target: song; opacity: 1 }
			PropertyChanges { target: cava; opacity: 1 }
			PropertyChanges {
				target: popupRect
				width: musicRow.width
				height: 36
				opacity: 0
				border.color: Flexoki.bg
			}
		},
		State {
			name: "popup-open"
			PropertyChanges { target: popup; visible: true }
			PropertyChanges { target: musicRow; visible: false; spacing: -1 }
			PropertyChanges { target: songContainer; bottomRightRadius: 0; topRightRadius: 0 }
			PropertyChanges { target: cavaContainer; bottomLeftRadius: 0; topLeftRadius: 0 }
			PropertyChanges { target: song; opacity: 0 }
			PropertyChanges { target: cava; opacity: 0 }
			PropertyChanges {
				target: popupRect
				width: 700
				height: 500
				opacity: 1
				border.color: Flexoki.ui2
			}
		}
	]

	transitions: [
		Transition {
			from: "popup-closed"
			to: "popup-open"

			SequentialAnimation {
				// show immediately so mouseleave works
				PropertyAction { target: popup; property: "visible" }

				ParallelAnimation {
					NumberAnimation {
						target: songContainer
						properties: "bottomRightRadius,topRightRadius"
						duration: root.contractAnimDuration
						easing.type: Easing.InQuad
					}

					NumberAnimation {
						target: cavaContainer
						properties: "bottomLeftRadius,topLeftRadius"
						duration: root.contractAnimDuration
						easing.type: Easing.InQuad
					}

					NumberAnimation {
						target: musicRow
						property: "spacing"
						duration: root.contractAnimDuration
						easing.type: Easing.OutQuad
					}

					NumberAnimation {
						targets: [song, cava]
						property: "opacity"
						duration: root.contractAnimDuration
						easing.type: Easing.OutQuad
					}
				}

				PropertyAction { target: popupRect; property: "opacity" }
				PropertyAction { target: musicRow; property: "visible" }

				ParallelAnimation {
					NumberAnimation {
						target: popupRect
						property: "width"
						duration: 250
						easing.type: Easing.OutQuad
					}

					SpringAnimation {
						target: popupRect
						property: "height"
						spring: 5
						mass: 0.5
						damping: 0.2
						epsilon: 0.25
					}

					ColorAnimation {
						target: popupRect
						property: "border.color"
						duration: 250
						easing.type: Easing.OutQuad
					}
				}
			}
		},
		Transition {
			// TODO: this transition flickers sometimes
			from: "popup-open"
			to: "popup-closed"

			SequentialAnimation {
				ParallelAnimation {
					NumberAnimation {
						target: popupRect
						property: "width"
						duration: 250
						easing.type: Easing.OutQuad
					}

					NumberAnimation {
						target: popupRect
						property: "height"
						duration: 250
						easing.type: Easing.OutQuad
					}

					ColorAnimation {
						target: popupRect
						property: "border.color"
						duration: 250
						easing.type: Easing.OutQuad
					}
				}

				PropertyAction { target: musicRow; property: "visible" }
				PropertyAction { target: popup; properties: "visible" }
				PropertyAction { target: popupRect; property: "opacity" }

				ParallelAnimation {
					NumberAnimation {
						target: songContainer
						properties: "bottomRightRadius,topRightRadius"
						duration: root.contractAnimDuration
						easing.type: Easing.InQuad
					}

					NumberAnimation {
						target: cavaContainer
						properties: "bottomLeftRadius,topLeftRadius"
						duration: root.contractAnimDuration
						easing.type: Easing.InQuad
					}

					NumberAnimation {
						target: musicRow
						property: "spacing"
						duration: root.contractAnimDuration
						easing.type: Easing.OutQuad
					}

					NumberAnimation {
						targets: [song, cava]
						property: "opacity"
						duration: root.contractAnimDuration
						easing.type: Easing.OutQuad
					}
				}
			}
		},
	]

	PopupWindow {
		id: popup
		anchor.item: root
		anchor.rect.x: root.width / 2 - width / 2
		anchor.rect.y: 0
		implicitWidth: 1920
		implicitHeight: 600
		color: "transparent"
		visible: false


		Rectangle {
			id: popupRect
			anchors.horizontalCenter: parent.horizontalCenter
			anchors.top: parent.top
			color: Flexoki.bg
			border.width: 2
			radius: 18

			MouseArea {
				anchors.fill: parent
				hoverEnabled: true
				onExited: root.state = "popup-closed"
			}

			RowLayout {	
				id: popupContent

				anchors.fill: parent
				anchors.topMargin: 32
				anchors.bottomMargin: 32
				anchors.leftMargin: 100
				anchors.rightMargin: 100
				spacing: 60

				Image {
					id: cover
					asynchronous: true
					source: "file://" + Song.coverPath
					sourceSize.width: 300
					sourceSize.height: 300
					width: 300
					height: 300

					Connections {
						target: Song

						function onCoverLoaded() {
							cover.source = "file://" + Song.coverPath
						}
					}
				}

				ColumnLayout {
					Text {
						Layout.alignment: Qt.AlignHCenter
						color: Flexoki.re
						text: Song.artist
						font.pixelSize: root.fontSize
					}
					Text {
						Layout.alignment: Qt.AlignHCenter
						color: Flexoki.tx
						text: Song.album
						font.pixelSize: root.fontSize
					}
					Text {
						Layout.alignment: Qt.AlignHCenter
						color: Flexoki.tx
						text: Song.title
						font.pixelSize: root.fontSize
					}
				}
			}
		}
	}

	Row {
		id: musicRow
		anchors.centerIn: parent
		height: parent.height
		spacing: 4

		Rectangle {
			id: songContainer
			implicitWidth: song.implicitWidth + 16*2
			height: parent.height
			color: Flexoki.bg

			bottomLeftRadius: 18
			topLeftRadius: 18
			bottomRightRadius: 4
			topRightRadius: 4

			Text {
				id: song
				anchors.centerIn: parent
				text: {
					if (!Song.file) return "Not playing"
					var text = Song.file
					if (Song.title) {
						if (Song.artist) {
							text = Song.artist + " – " + Song.title
						} else {
							text = Song.title
						}
					}
					if (text.length > 60) {
						text = text.substring(0, 60) + "…"
					}
					return text
				}
				color: Flexoki.tx
				font { family: root.fontFamily; pixelSize: root.fontSize }
			}
		}

		Rectangle {
			id: cavaContainer
			implicitWidth: cava.implicitWidth + 16*2
			height: parent.height
			color: Flexoki.bg

			bottomLeftRadius: 4
			topLeftRadius: 4
			bottomRightRadius: 18
			topRightRadius: 18

			Row {
				id: cava
				anchors.centerIn: parent
				height: 15 + 4
				spacing: 2

				Repeater {
					model: Cava.heights

					delegate: Rectangle {
						required property int modelData
						y: 15 - modelData
						width: 8
						height: modelData + 4
						radius: 4
						color: Flexoki.tx

						Behavior on height {
							NumberAnimation { duration: 1000 / 30; easing.type: Easing.Linear }
						}
						Behavior on y {
							NumberAnimation { duration: 1000 / 30; easing.type: Easing.Linear }
						}
					}
				}
			}
		}
	}
}