-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.qml
439 lines (413 loc) · 16.4 KB
/
main.qml
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import QtQuick 6.2
import QtQuick.Window 6.2
import QtQuick.Controls 6.2
import QtQuick.Layouts 1.15
import QtMultimedia
import Qt5Compat.GraphicalEffects
Window {
id: window
width: 1000 // @disable-check M16
height: 500 // @disable-check M16
visible: true // @disable-check M16
title: qsTr("网易云音乐") // @disable-check M16
color: "#eeeeee"
function init() {
var json
var userAccount = neteaseAPI.userAccount()
if (userAccount !== "") {
json = JSON.parse(userAccount)
userProfile = {
"logined": true,
"id": json.profile.userId.toString(),
"name": json.profile.nickname,
"avatarUrl": json.profile.avatarUrl
}
}
var recordRecentSong = neteaseAPI.recordRecentSong("300")
if (recordRecentSong !== "") {
json = JSON.parse(recordRecentSong)
recentSongCountText.text = json.data.total.toString() + qsTr("首")
}
var userPlaylist = neteaseAPI.userPlaylist(userProfile.id)
if (userPlaylist !== "") {
json = JSON.parse(userPlaylist)
var playlists = json.playlist
for (var playlist in playlists) {
if (!playlists[playlist].subscribed) {
myPlaylistView.model.append({
"id": playlists[playlist].id,
"name": playlists[playlist].name,
"trackCount": playlists[playlist].trackCount,
"coverUrl": playlists[playlist].coverImgUrl,
})
} else {
subscribedPlaylistView.model.append({
"id": playlists[playlist].id,
"name": playlists[playlist].name,
"trackCount": playlists[playlist].trackCount,
"coverUrl": playlists[playlist].coverImgUrl,
})
}
}
}
}
Component.onCompleted: {
var userAccount = neteaseAPI.userAccount()
if (userAccount !== "") {
var json = JSON.parse(userAccount)
userProfile = {
"logined": true,
"id": json.profile.userId.toString(),
"name": json.profile.nickname,
"avatarUrl": json.profile.avatarUrl
}
}
}
property var userProfile: {
"logined": false,
"name": "",
"id": "",
"avatarUrl": ""
} //与js不同,这不是键值对
MediaPlayer {
id: player
audioOutput: AudioOutput {}
loops: MediaPlayer.Infinite
onPositionChanged: {
if (player.playbackState == MediaPlayer.PlayingState)
for (var i = 0; i < lyricView.model.count; i++) {
if (Math.trunc(lyricView.model.get(i).time / 500) === Math.trunc(player.position / 500)) {
lyricView.currentIndex = i
break
}
}
}
}
TopToolbar {
id: topToolbar
z: 2
}
RowLayout {
anchors.top: topToolbar.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: bottomToolbar.top
spacing: 0
Rectangle {
id: leftListView
z: 2
Layout.alignment: Qt.AlignLeft
Layout.preferredWidth: window.width / 5
Layout.fillHeight: true
color: "#ffffff"
Rectangle {
z: 2
width: parent.width
height: 50
Button {
anchors.fill: parent
visible: !userProfile.logined
text: qsTr("登录")
onReleased: {
loginPage.open()
}
}
Image {
id: avatar
anchors.left: parent.left
anchors.leftMargin: 5
anchors.verticalCenter: parent.verticalCenter
width: 45
height: 45
source: userProfile.avatarUrl
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle {
width: 45
height: 45
radius: 22.5
}
}
}
Text {
id: user_name_text
anchors.left: avatar.right
anchors.leftMargin: 5
anchors.verticalCenter: parent.verticalCenter
text: userProfile.name
}
}
Flickable {
y: 54
height: parent.height - 50
width: parent.width
flickableDirection: Flickable.VerticalFlick
contentHeight: (myPlaylistView.model.count + subscribedPlaylistView.model.count) * 50 + 70
contentWidth: width
Component.onCompleted: {
var userPlaylist = neteaseAPI.userPlaylist(userProfile.id)
if (userPlaylist !== "") {
var json = JSON.parse(userPlaylist)
var playlists = json.playlist
for (var playlist in playlists) {
if (!playlists[playlist].subscribed) {
myPlaylistView.model.append({
"id": playlists[playlist].id,
"name": playlists[playlist].name,
"trackCount": playlists[playlist].trackCount,
"coverUrl": playlists[playlist].coverImgUrl,
})
} else {
subscribedPlaylistView.model.append({
"id": playlists[playlist].id,
"name": playlists[playlist].name,
"trackCount": playlists[playlist].trackCount,
"coverUrl": playlists[playlist].coverImgUrl,
})
}
}
}
}
Column {
id: left_column
anchors.fill: parent
spacing: 5
MouseArea {
width: parent.width
height: 50
Component.onCompleted: {
var recordRecentSong = neteaseAPI.recordRecentSong("300")
if (recordRecentSong !== "") {
var json = JSON.parse(recordRecentSong)
recentSongCountText.text = json.data.total.toString() + qsTr("首")
}
}
onReleased: {
if (stackView.currentItem.objectName === "recentSongPlaylistPage") {
stackView.replace(recentSongPlaylistPage)
}
else {
stackView.push(recentSongPlaylistPage)
}
}
Image {
id: recentSongCover
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
width: 45
height: 45
source: "images/historical_music_icon.svg"
anchors.leftMargin: 12
}
Text {
anchors.left: recentSongCover.right
verticalAlignment: Text.AlignBottom
lineHeight: 0.8
anchors.leftMargin: 10
width: parent.width - 75
height: 35
wrapMode: Text.WordWrap
font.pointSize: 11
text: qsTr("最近播放")
elide: Text.ElideRight
clip: true
color: "#000000"
}
Text {
id: recentSongCountText
anchors.left: recentSongCover.right
y: 38
verticalAlignment: Text.AlignBottom
font.pointSize: 8
anchors.leftMargin: 10
width: parent.width - 75
height: 10
color: "#9f000000"
text: ""
}
}
Text {
width: parent.width - 20
height: 15
color: "#8e8e8e"
text: qsTr("我的歌单")
verticalAlignment: Text.AlignBottom
anchors.horizontalCenter: parent.horizontalCenter
Rectangle {
width: parent.width
height: 0.8
color: "#acacac"
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
}
MyPlaylistView {
id: myPlaylistView
model: ListModel {
id: myPlaylist
}
}
Text {
width: parent.width - 20
height: 35
color: "#8e8e8e"
text: qsTr("收藏的歌单")
verticalAlignment: Text.AlignBottom
anchors.horizontalCenter: parent.horizontalCenter
Rectangle {
width: parent.width
height: 0.8
color: "#acacac"
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
}
SubscribedPlaylistView {
id: subscribedPlaylistView
model: ListModel {
id: subscribedPlaylist
}
}
}
}
}
Rectangle {
Layout.maximumWidth: 3
Layout.minimumWidth: 3
Layout.preferredWidth: 3
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
color: "red"
}
StackView {
id: stackView
Layout.alignment: Qt.AlignLeft
Layout.preferredWidth: 500
Layout.fillWidth: true
Layout.fillHeight: true
initialItem: initPage
Component {
id: initPage
Rectangle {
objectName: "initPage"
}
}
Component {
id: playlistPage
PlaylistPage {
objectName: "playlistPage"
}
}
Component {
id: recentSongPlaylistPage
RecentSongPlaylistPage {
objectName: "recentSongPlaylistPage"
}
}
Component {
id: searchPage
SearchPage {
objectName: "searchPage"
}
}
}
Rectangle {
Layout.maximumWidth: 3
Layout.minimumWidth: 3
Layout.preferredWidth: 3
Layout.fillHeight: true
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
color: "red"
}
Rectangle {
id: songPage
Layout.minimumWidth: 200
Layout.preferredWidth: 300
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignRight
ListView {
id: lyricView
anchors.fill: parent
anchors.rightMargin: 40
anchors.leftMargin: 40
spacing: 10
highlightRangeMode: autoScroll? ListView.StrictlyEnforceRange : ListView.NoHighlightRange
preferredHighlightBegin: height / 2
preferredHighlightEnd: height / 2
property bool hasLyric: false
property bool hasTranslatedLyric: false
property bool hasRomanianLyric: false
property bool autoScroll: false
model: ListModel {}
delegate: Column {
id: lyricColumn
anchors.left: parent.left
anchors.right: parent.right
height: originalLyricText.contentHeight + translatedLyricText.contentHeight + romanianLyricText.contentHeight
Text {
id: originalLyricText
visible: lyricView.hasLyric
anchors.left: parent.left
anchors.right: parent.right
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
lineHeight: 0.9
height: contentHeight
wrapMode: Text.WordWrap
font.pointSize: 10
text: originalLyric
}
Text {
id: translatedLyricText
visible: lyricView.hasTranslatedLyric
anchors.left: parent.left
anchors.right: parent.right
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
lineHeight: 0.9
height: contentHeight
wrapMode: Text.WordWrap
font.pointSize: 10
text: translatedLyric
}
Text {
id: romanianLyricText
visible: lyricView.hasRomanianLyric
anchors.left: parent.left
anchors.right: parent.right
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
lineHeight: 0.9
height: contentHeight
wrapMode: Text.WordWrap
font.pointSize: 10
text: romanianLyric
}
}
}
}
}
BottomToolbar {
id: bottomToolbar
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
height: 80
}
LoginPage {
id: loginPage
x: (window.width - width) / 2
y: (window.height - height) / 2
}
BannedToast {
id: bannedToast
x: (window.width - width) / 2
y: (window.height - height) / 2
}
}
/*##^##
Designer {
D{i:0;formeditorZoom:0.2}
}
##^##*/