-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathQCLeftBar.qml
431 lines (402 loc) · 17 KB
/
QCLeftBar.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
import QtQuick
import QtQuick.Controls
import "./singletonComponent"
import "./qcComponent"
import "./theme"
Rectangle {
id: leftBar
property QCTheme thisTheme: ThemeManager.theme
property var findMusicData: { // 发现音乐数据
"headerText":"发现音乐",
"btnData": [
{btnIcon:"qrc:/Images/discoverMusic.svg",btnText:"发现音乐",isActive:true,qml:"pageQml/PageFindMusic.qml"},
{btnIcon:"qrc:/Images/playList.svg",btnText:"歌单",isActive:true,qml:"pageQml/PageMusicPlayList.qml"},
],"isActive" :true
}
property var myMusicData: { // 我的音乐数据
"headerText": "我的音乐",
"btnData": [
{btnIcon:"qrc:/Images/myFavorite.svg",btnText:"我喜欢的音乐",isActive:true,qml:"pageQml/PageMusicFavoriteDetail.qml"},
{btnIcon:"qrc:/Images/folder.svg",btnText:"文件夹",isActive:true,qml:"pageQml/PageLocalFolderDetail.qml"},
{btnIcon:"qrc:/Images/recentlyPlayed.svg",btnText:"最近播放",isActive:true,qml:"pageQml/PageHistoryRecordDetail.qml"},
{btnIcon:"qrc:/Images/download.svg",btnText:"下载",isActive:true,qml:"pageQml/PageLocalDownloadDetail.qml"},
],
"isActive": true
}
property var myCreatePlaylistData: { // 我创建的歌单数据
"headerText": "我创建的歌单",
"btnData": [
],
"isActive": true
}
property string thisQml: "pageQml/PageFindMusic.qml"
property string thisBtnText: "发现音乐"
property string savePlayListInfoPath: "userInfo/playlistInfo.json"
property int btnHeight: 40
property int fontSize: 11
width: 200
height: parent.height
color: "#"+ thisTheme.backgroundColor
Component.onCompleted: {
let data = []
for(let i = 0 ; i < MyPlayListManager.data.length;i++) {
let t = {btnIcon:"qrc:/Images/addPlayList.svg",btnText: MyPlayListManager.data[i].name ,
isActive:true,qml:"pageQml/PageMyMusicPlayListDetail.qml"}
data.push(t)
}
leftBar.myCreatePlaylistData.btnData = data
leftBar.myCreatePlaylistDataChanged()
// console.log("leftBar: " + JSON.stringify(myCreatePlaylistData))
}
Connections {
target: MyPlayListManager
function onDataChanged() {
let data = []
for(let i = 0 ; i < MyPlayListManager.data.length;i++) {
let t = {btnIcon:"qrc:/Images/addPlayList.svg",btnText: MyPlayListManager.data[i].name ,isActive:true,
qml:"pageQml/PageMyMusicPlayListDetail.qml"}
data.push(t)
}
leftBar.myCreatePlaylistData.btnData = data
leftBar.myCreatePlaylistDataChanged()
// console.log("leftBar: " + JSON.stringify(myCreatePlaylistData))
}
}
Flickable {
id: leftBarFlickable
width: parent.width
height: parent.height
contentHeight: height
contentWidth: width
Column {
id: leftBarColumn
spacing: 10
ListView { // 发现音乐
id: findMusicListView
width: leftBarFlickable.width
height: contentHeight
spacing: 3
interactive: false
model: leftBar.findMusicData.btnData
header: Text {
width: parent.width
height: text === "" ?0: contentHeight +5
anchors.left: parent.left
anchors.leftMargin: 10
elide: Text.ElideRight
font.pointSize: leftBar.fontSize-1
text: leftBar.findMusicData.headerText
color: "#"+ thisTheme.fontColor
}
delegate: findMusicDelegate
}
ListView { // 我的音乐
id: myMusicListView
width: leftBarFlickable.width
height: contentHeight
spacing: 3
interactive: false
model: leftBar.myMusicData.btnData
header: Text {
width: parent.width
height: text === "" ?0: contentHeight +5
anchors.left: parent.left
anchors.leftMargin: 10
font.pointSize: leftBar.fontSize-1
text: leftBar.myMusicData.headerText
elide: Text.ElideRight
color: "#"+ thisTheme.fontColor
}
delegate: myMusicDelegate
}
ListView { // 创建的歌单
id: myCreatePlayListListView
property var popup: null
width: leftBarFlickable.width
height: contentHeight
spacing: 3
interactive: false
model: leftBar.myCreatePlaylistData.btnData
delegate: createPlayListDelegate
header: Item {
width: parent.width
height: children[0].height + 10
Text {
width: parent.width - 15
height: text === "" ? 0: contentHeight
elide: Text.ElideRight
anchors.left: parent.left
anchors.leftMargin: 10
font.pointSize: leftBar.fontSize-1
text: leftBar.myCreatePlaylistData.headerText
color: "#"+ thisTheme.fontColor
}
MouseArea {
anchors.right: parent.right
anchors.rightMargin: 10
width: 15
height: width
cursorShape: Qt.PointingHandCursor
onClicked: {
if(myCreatePlayListListView.popup == null) {
let cmp = Qt.createComponent("qcComponent/QCCreatePlayListPopup.qml")
myCreatePlayListListView.popup = cmp.createObject(windowPage)
}
myCreatePlayListListView.popup.open()
}
Canvas {
anchors.fill: parent
onPaint: {
let ctx = getContext("2d");
ctx.strokeStyle = "#" + thisTheme.fontColor;
ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.moveTo(width/2,0)
ctx.lineTo(width/2,height);
ctx.moveTo(0,height/2)
ctx.lineTo(width,height/2);
ctx.closePath();
ctx.stroke();
}
}
}
}
}
}
}
Component { // 发现音乐单项实例
id: findMusicDelegate
Rectangle {
property bool isHoverd: false
property bool isThisBtn: leftBar.thisBtnText === leftBar.findMusicData.btnData[index].btnText
width: leftBarFlickable.width - 15
height: leftBar.btnHeight
radius: 50
color: if(isHoverd) return "#1F" + thisTheme.iconColor
else return "#00000000"
Rectangle {
width: isThisBtn ? parent.width : 0
height: parent.height
color: if(isThisBtn) return "#2F" + thisTheme.iconColor
else return "#1F" + thisTheme.iconColor
radius: parent.radius
Behavior on width {
NumberAnimation {
duration: 200
easing.type: Easing.InOutQuad
}
}
}
Row {
width: parent.width
height: parent.height-10
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: parent.radius / 4
spacing: 10
QCImage {
id: icon
width: 20
height: width
anchors.verticalCenter: parent.verticalCenter
sourceSize: Qt.size(32,32)
source: leftBar.findMusicData.btnData[index].btnIcon
color: "#"+ thisTheme.fontColor
}
Text {
width: parent.width
height: contentHeight
font.pointSize: leftBar.fontSize
font.bold: isThisBtn ? true : false
elide: Text.ElideRight
anchors.verticalCenter: parent.verticalCenter
text: leftBar.findMusicData.btnData[index].btnText
color: "#"+ thisTheme.fontColor
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: function (mouse) {
if(leftBar.thisBtnText === leftBar.findMusicData.btnData[index].btnText) return
let func = () => {
leftBar.thisQml = leftBar.findMusicData.btnData[index].qml
leftBar.thisBtnText = leftBar.findMusicData.btnData[index].btnText
}
func()
rightContent.push({callBack:func,name: leftBar.findMusicData.btnData[index].btnText,data: {}})
}
onEntered: {
parent.isHoverd = true
}
onExited: {
parent.isHoverd = false
}
}
onParentChanged: {
if(parent != null ) {
anchors.horizontalCenter = parent.horizontalCenter
}
}
}
}
Component { // 我的音乐单项实例
id: myMusicDelegate
Rectangle {
property bool isHoverd: false
property bool isThisBtn: leftBar.thisBtnText === leftBar.myMusicData.btnData[index].btnText
width: leftBarFlickable.width - 15
height: leftBar.btnHeight
radius: 50
color: if(isHoverd) return "#1F" + thisTheme.iconColor
else return "#00000000"
Rectangle {
width: isThisBtn ? parent.width : 0
height: parent.height
color: if(isThisBtn) return "#2F" + thisTheme.iconColor
else return "#1F" + thisTheme.iconColor
radius: parent.radius
Behavior on width {
NumberAnimation {
duration: 200
easing.type: Easing.InOutQuad
}
}
}
Row {
width: parent.width
height: parent.height-10
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: parent.radius / 4
spacing: 10
QCImage {
id: icon
width: 20
height: width
anchors.verticalCenter: parent.verticalCenter
sourceSize: Qt.size(32,32)
source: leftBar.myMusicData.btnData[index].btnIcon
color: "#"+ thisTheme.fontColor
}
Text {
width: parent.width - icon.width - parent.spacing
height: contentHeight
font.pointSize: leftBar.fontSize
font.bold: isThisBtn ? true : false
elide: Text.ElideRight
anchors.verticalCenter: parent.verticalCenter
text: leftBar.myMusicData.btnData[index].btnText
color: "#"+ thisTheme.fontColor
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: function (mouse){
if(leftBar.thisBtnText === leftBar.myMusicData.btnData[index].btnText) return
let func = () => {
leftBar.thisQml = leftBar.myMusicData.btnData[index].qml
leftBar.thisBtnText = leftBar.myMusicData.btnData[index].btnText
}
func()
rightContent.push({callBack:func,name: leftBar.myMusicData.btnData[index].btnText,data: {}})
}
onEntered: {
parent.isHoverd = true
}
onExited: {
parent.isHoverd = false
}
}
onParentChanged: {
if(parent != null ) {
anchors.horizontalCenter = parent.horizontalCenter
}
}
}
}
Component { // 新建歌单单项实例
id: createPlayListDelegate
Rectangle {
property bool isHoverd: false
property bool isThisBtn: leftBar.thisBtnText === leftBar.myCreatePlaylistData.btnData[index].btnText
width: leftBarFlickable.width - 15
height: leftBar.btnHeight
radius: 50
color: if(isHoverd) return "#1F" + thisTheme.iconColor
else return "#00000000"
Rectangle {
width: isThisBtn ? parent.width : 0
height: parent.height
color: if(isThisBtn) return "#2F" + thisTheme.iconColor
else return "#1F" + thisTheme.iconColor
radius: parent.radius
Behavior on width {
NumberAnimation {
duration: 200
easing.type: Easing.InOutQuad
}
}
}
Row {
width: parent.width
height: parent.height-10
anchors.verticalCenter: parent.verticalCenter
padding: parent.radius / 4
spacing: 10
QCImage {
id: icon
width: 20
height: width
anchors.verticalCenter: parent.verticalCenter
sourceSize: Qt.size(32,32)
source: leftBar.myCreatePlaylistData.btnData[index].btnIcon
color: "#"+ thisTheme.fontColor
}
Text {
width: parent.width - icon.width - parent.spacing - parent.padding
height: contentHeight
font.pointSize: leftBar.fontSize
font.bold: isThisBtn ? true : false
elide: Text.ElideRight
anchors.verticalCenter: parent.verticalCenter
text: leftBar.myCreatePlaylistData.btnData[index].btnText
color: "#"+ thisTheme.fontColor
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: function (mouse){
if(leftBar.thisBtnText === leftBar.myCreatePlaylistData.btnData[index].btnText) return
let func = () => {
leftBar.thisQml = leftBar.myCreatePlaylistData.btnData[index].qml
leftBar.thisBtnText = leftBar.myCreatePlaylistData.btnData[index].btnText
rightContent.item.playListInfo = MyPlayListManager.data[index]
}
func()
rightContent.push({callBack:func,name: "playList: "+ leftBar.myCreatePlaylistData.btnData[index].btnText,data: {}})
}
onEntered: {
parent.isHoverd = true
}
onExited: {
parent.isHoverd = false
}
}
onParentChanged: {
if(parent != null ) {
anchors.horizontalCenter = parent.horizontalCenter
}
}
}
}
function getBtnCurrent(name) {
var thisIndex = 0
return thisBtnText === name
}
}