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
439
440
441
442
443
444
445
446
447
|
/*
* Copyright (C) 2013 Victor Thompson <victor.thompson@gmail.com>
* Daniel Holm <d.holmen@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1
import Ubuntu.Components.Popups 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import QtMultimedia 5.0
import QtQuick.LocalStorage 2.0
import QtGraphicalEffects 1.0
import "settings.js" as Settings
import "meta-database.js" as Library
import "playlists.js" as Playlists
import "common"
Page {
id: mainpage
title: i18n.tr("Albums")
property string artist: ""
property string album: ""
property string songtitle: ""
property string cover: ""
property string length: ""
property string file: ""
property string year: ""
onVisibleChanged: {
if (visible === true)
{
musicToolbar.setPage(mainpage);
}
}
MusicSettings {
id: musicSettings
}
GridView {
id: albumlist
anchors.fill: parent
anchors.leftMargin: units.gu(1)
anchors.topMargin: units.gu(1)
anchors.bottomMargin: units.gu(1)
cellHeight: (parent.height - units.gu(2))/3
cellWidth: (parent.height - units.gu(2))/3
model: albumModel.model
delegate: albumDelegate
flow: GridView.TopToBottom
Component {
id: albumDelegate
Item {
id: albumItem
height: albumlist.cellHeight - units.gu(1)
width: albumlist.cellHeight - units.gu(1)
anchors.margins: units.gu(1)
UbuntuShape {
id: albumShape
height: albumItem.width
width: albumItem.width
image: Image {
id: icon
fillMode: Image.Stretch
property string artist: model.artist
property string album: model.album
property string title: model.title
property string cover: model.cover
property string length: model.length
property string file: model.file
property string year: model.year
source: cover !== "" ? cover : "images/cover_default.png"
}
UbuntuShape { // Background so can see text in current state
id: albumBg2
anchors.bottom: parent.bottom
color: styleMusic.common.black
height: units.gu(4)
width: parent.width
}
Rectangle { // Background so can see text in current state
id: albumBg
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(2)
color: styleMusic.common.black
height: units.gu(3)
width: parent.width
}
Label {
id: albumArtist
objectName: "albums-albumartist"
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(1)
anchors.left: parent.left
anchors.leftMargin: units.gu(.25)
anchors.right: parent.right
anchors.rightMargin: units.gu(.25)
horizontalAlignment: Text.AlignHCenter
color: styleMusic.nowPlaying.labelSecondaryColor
elide: Text.ElideRight
text: artist
fontSize: "x-small"
}
Label {
id: albumLabel
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(3)
anchors.left: parent.left
anchors.leftMargin: units.gu(.25)
anchors.right: parent.right
anchors.rightMargin: units.gu(.25)
horizontalAlignment: Text.AlignHCenter
color: styleMusic.common.white
elide: Text.ElideRight
text: album
fontSize: "small"
}
}
MouseArea {
anchors.fill: parent
onDoubleClicked: {
}
onPressAndHold: {
}
onClicked: {
albumTracksModel.filterAlbumTracks(album)
mainpage.artist = artist
mainpage.album = album
mainpage.file = file
mainpage.year = year
mainpage.cover = cover
PopupUtils.open(albumSheet)
}
}
}
}
}
Component {
id: albumSheet
DefaultSheet {
id: sheet
anchors.bottomMargin: units.gu(.5)
doneButton: false
contentsHeight: parent.height
contentsWidth: parent.width
ListView {
clip: true
id: albumtrackslist
width: parent.width
anchors.top: parent.top
anchors.bottom: parent.bottom
model: albumTracksModel.model
delegate: albumTracksDelegate
header: ListItem.Standard {
id: albumInfo
width: parent.width
height: units.gu(20)
UbuntuShape {
id: albumImage
anchors.left: parent.left
anchors.top: parent.top
anchors.verticalCenter: parent.verticalCenter
anchors.margins: units.gu(1)
height: parent.height
width: height
image: Image {
source: Library.hasCover(mainpage.file) ? mainpage.cover : Qt.resolvedUrl("images/cover_default.png")
}
}
Label {
id: albumArtist
objectName: "albumsheet-albumartist"
wrapMode: Text.NoWrap
maximumLineCount: 1
fontSize: "small"
anchors.left: albumImage.right
anchors.leftMargin: units.gu(1)
anchors.top: parent.top
anchors.topMargin: units.gu(1.5)
anchors.right: parent.right
anchors.rightMargin: units.gu(1.5)
elide: Text.ElideRight
text: mainpage.artist
}
Label {
id: albumLabel
wrapMode: Text.NoWrap
maximumLineCount: 2
fontSize: "medium"
color: styleMusic.common.music
anchors.left: albumImage.right
anchors.leftMargin: units.gu(1)
anchors.top: albumArtist.bottom
anchors.topMargin: units.gu(0.8)
anchors.right: parent.right
anchors.rightMargin: units.gu(1.5)
elide: Text.ElideRight
text: mainpage.album
}
Label {
id: albumYear
wrapMode: Text.NoWrap
maximumLineCount: 1
fontSize: "x-small"
anchors.left: albumImage.right
anchors.leftMargin: units.gu(1)
anchors.top: albumLabel.bottom
anchors.topMargin: units.gu(2)
anchors.right: parent.right
anchors.rightMargin: units.gu(1.5)
elide: Text.ElideRight
text: i18n.tr("%1 | %2 song", "%1 | %2 songs", albumTracksModel.model.count).arg(mainpage.year, albumTracksModel.model.count)
}
}
onCountChanged: {
albumtrackslist.currentIndex = albumTracksModel.indexOf(currentFile)
}
Component {
id: albumTracksDelegate
ListItem.Standard {
id: track
iconFrame: false
progression: false
height: styleMusic.albums.itemHeight
MouseArea {
anchors.fill: parent
onDoubleClicked: {
}
onClicked: {
if (focus == false) {
focus = true
}
trackClicked(albumTracksModel, index) // play track
Library.addRecent(album, artist, cover, album, "album")
mainView.hasRecent = true
recentModel.filterRecent()
// TODO: This closes the SDK defined sheet
// component. It should be able to close
// albumSheet.
PopupUtils.close(sheet)
}
}
Label {
id: trackTitle
wrapMode: Text.NoWrap
maximumLineCount: 1
fontSize: "medium"
anchors.left: parent.left
anchors.leftMargin: units.gu(2)
anchors.top: parent.top
anchors.topMargin: units.gu(1)
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(1)
anchors.right: expandItem.left
anchors.rightMargin: units.gu(1.5)
elide: Text.ElideRight
text: model.title == "" ? model.file : model.title
}
Image {
id: expandItem
anchors.right: parent.right
anchors.rightMargin: units.gu(2)
source: expandable.visible ? "images/dropdown-menu-up.svg" : "images/dropdown-menu.svg"
height: styleMusic.common.expandedItem
width: styleMusic.common.expandedItem
y: parent.y + (styleMusic.albums.itemHeight / 2) - (height / 2)
}
MouseArea {
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.top: parent.top
width: styleMusic.common.expandedItem * 3
onClicked: {
if(expandable.visible) {
customdebug("clicked collapse")
expandable.visible = false
track.height = styleMusic.albums.itemHeight
}
else {
customdebug("clicked expand")
collapseExpand(-1); // collapse all others
expandable.visible = true
track.height = styleMusic.albums.expandedHeight
}
}
}
Rectangle {
id: expandable
color: "transparent"
height: styleMusic.albums.expandHeight
visible: false
MouseArea {
anchors.fill: parent
onClicked: {
customdebug("User pressed outside the playlist item and expanded items.")
}
}
Component.onCompleted: {
collapseExpand.connect(onCollapseExpand);
}
function onCollapseExpand(indexCol)
{
if ((indexCol === index || indexCol === -1) && expandable !== undefined && expandable.visible === true)
{
customdebug("auto collapse")
expandable.visible = false
track.height = styleMusic.albums.itemHeight
}
}
// background for expander
Rectangle {
anchors.top: parent.top
anchors.topMargin: styleMusic.albums.itemHeight
color: styleMusic.common.black
height: styleMusic.albums.expandedHeight - styleMusic.albums.itemHeight
width: track.width
opacity: 0.4
}
// add to playlist
Rectangle {
id: playlistRow
anchors.top: parent.top
anchors.topMargin: ((styleMusic.albums.expandedHeight - styleMusic.albums.itemHeight) / 2)
+ styleMusic.albums.itemHeight
- (height / 2)
anchors.left: parent.left
anchors.leftMargin: styleMusic.albums.expandedLeftMargin
color: "transparent"
height: styleMusic.common.expandedItem
width: units.gu(15)
Icon {
id: playlistTrack
color: styleMusic.common.white
name: "add"
height: styleMusic.common.expandedItem
width: styleMusic.common.expandedItem
}
Label {
anchors.left: playlistTrack.right
anchors.leftMargin: units.gu(0.5)
color: styleMusic.common.white
fontSize: "small"
text: i18n.tr("Add to playlist")
wrapMode: Text.WordWrap
}
MouseArea {
anchors.fill: parent
onClicked: {
expandable.visible = false
track.height = styleMusic.albums.itemHeight
chosenArtist = artist
chosenTitle = title
chosenTrack = file
chosenAlbum = album
chosenCover = cover
chosenGenre = genre
chosenIndex = index
console.debug("Debug: Add track to playlist")
PopupUtils.open(Qt.resolvedUrl("MusicaddtoPlaylist.qml"), mainView,
{
title: i18n.tr("Select playlist")
} )
}
}
}
// Queue
Rectangle {
id: queueRow
anchors.top: parent.top
anchors.topMargin: ((styleMusic.albums.expandedHeight - styleMusic.albums.itemHeight) / 2)
+ styleMusic.albums.itemHeight
- (height / 2)
anchors.left: playlistRow.left
anchors.leftMargin: units.gu(15)
color: "transparent"
height: styleMusic.common.expandedItem
width: units.gu(15)
Image {
id: queueTrack
source: "images/queue.png"
height: styleMusic.common.expandedItem
width: styleMusic.common.expandedItem
}
Label {
anchors.left: queueTrack.right
anchors.leftMargin: units.gu(0.5)
color: styleMusic.common.white
fontSize: "small"
text: i18n.tr("Queue")
wrapMode: Text.WordWrap
}
MouseArea {
anchors.fill: parent
onClicked: {
expandable.visible = false
track.height = styleMusic.albums.itemHeight
console.debug("Debug: Add track to queue: " + title)
trackQueue.model.append({"title": title, "artist": artist, "file": file, "album": album, "cover": cover, "genre": genre})
}
}
}
}
onFocusChanged: {
}
Component.onCompleted: {
}
}
}
}
}
}
}
|