~ahayzen/+junk/music-app-u1db-conversion

« back to all changes in this revision

Viewing changes to common/SongsSheet.qml

  • Committer: Tarmac
  • Author(s): Victor Thompson
  • Date: 2014-01-12 22:38:36 UTC
  • mfrom: (287.2.21 use-sheet-pattern-good)
  • Revision ID: tarmac-20140112223836-9oqna68t2k0m9b7a
Use sheet component for recent albums, artist albums, tracks in an artist's album, playlists, and genres. Fixes: https://bugs.launchpad.net/bugs/1201094, https://bugs.launchpad.net/bugs/1238801, https://bugs.launchpad.net/bugs/1238834, https://bugs.launchpad.net/bugs/1240032, https://bugs.launchpad.net/bugs/1267315, https://bugs.launchpad.net/bugs/1268061.

Approved by Andrew Hayzen, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Andrew Hayzen <ahayzen@gmail.com>
 
3
 *                    Daniel Holm <d.holmen@gmail.com>
 
4
 *                    Victor Thompson <victor.thompson@gmail.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.0
 
20
import Ubuntu.Components 0.1
 
21
import Ubuntu.Components.ListItems 0.1
 
22
import Ubuntu.Components.Popups 0.1
 
23
import Ubuntu.Components.ListItems 0.1 as ListItem
 
24
import QtQuick.LocalStorage 2.0
 
25
import "../meta-database.js" as Library
 
26
 
 
27
Item {
 
28
    id: sheetItem
 
29
 
 
30
    property string line1: ""
 
31
    property string line2: ""
 
32
    property string songtitle: ""
 
33
    property string cover: ""
 
34
    property string length: ""
 
35
    property string file: ""
 
36
    property string year: ""
 
37
    property bool isAlbum: false
 
38
    property alias sheet: sheetComponent
 
39
 
 
40
    Component {
 
41
        id: sheetComponent
 
42
        DefaultSheet {
 
43
            id: sheet
 
44
            anchors.bottomMargin: units.gu(.5)
 
45
            doneButton: false
 
46
            contentsHeight: parent.height
 
47
            contentsWidth: parent.width
 
48
 
 
49
            ListView {
 
50
                clip: true
 
51
                id: albumtrackslist
 
52
                width: parent.width
 
53
                anchors.top: parent.top
 
54
                anchors.bottom: parent.bottom
 
55
                model: albumTracksModel.model
 
56
                delegate: albumTracksDelegate
 
57
                header: ListItem.Standard {
 
58
                    id: albumInfo
 
59
                    width: parent.width
 
60
                    height: units.gu(20)
 
61
 
 
62
                    UbuntuShape {
 
63
                        id: albumImage
 
64
                        anchors.left: parent.left
 
65
                        anchors.top: parent.top
 
66
                        anchors.verticalCenter: parent.verticalCenter
 
67
                        anchors.margins: units.gu(1)
 
68
                        height: parent.height
 
69
                        width: height
 
70
                        image: Image {
 
71
                            source: cover || "../images/cover_default.png"
 
72
                        }
 
73
                    }
 
74
                    Label {
 
75
                        id: albumArtist
 
76
                        objectName: "albumsheet-albumartist"
 
77
                        wrapMode: Text.NoWrap
 
78
                        maximumLineCount: 1
 
79
                        fontSize: "small"
 
80
                        anchors.left: albumImage.right
 
81
                        anchors.leftMargin: units.gu(1)
 
82
                        anchors.top: parent.top
 
83
                        anchors.topMargin: units.gu(1.5)
 
84
                        anchors.right: parent.right
 
85
                        anchors.rightMargin: units.gu(1.5)
 
86
                        elide: Text.ElideRight
 
87
                        text: line1
 
88
                    }
 
89
                    Label {
 
90
                        id: albumLabel
 
91
                        wrapMode: Text.NoWrap
 
92
                        maximumLineCount: 2
 
93
                        fontSize: "medium"
 
94
                        color: styleMusic.common.music
 
95
                        anchors.left: albumImage.right
 
96
                        anchors.leftMargin: units.gu(1)
 
97
                        anchors.top: albumArtist.bottom
 
98
                        anchors.topMargin: units.gu(0.8)
 
99
                        anchors.right: parent.right
 
100
                        anchors.rightMargin: units.gu(1.5)
 
101
                        elide: Text.ElideRight
 
102
                        text: line2
 
103
                    }
 
104
                    Label {
 
105
                        id: albumYear
 
106
                        wrapMode: Text.NoWrap
 
107
                        maximumLineCount: 1
 
108
                        fontSize: "x-small"
 
109
                        anchors.left: albumImage.right
 
110
                        anchors.leftMargin: units.gu(1)
 
111
                        anchors.top: albumLabel.bottom
 
112
                        anchors.topMargin: units.gu(2)
 
113
                        anchors.right: parent.right
 
114
                        anchors.rightMargin: units.gu(1.5)
 
115
                        elide: Text.ElideRight
 
116
                        text: isAlbum ? i18n.tr(year + " | %1 song", year + " | %1 songs", albumTracksModel.model.count).arg(albumTracksModel.model.count)
 
117
                                      : i18n.tr("%1 song", "%1 songs", albumTracksModel.model.count).arg(albumTracksModel.model.count)
 
118
 
 
119
                    }
 
120
                }
 
121
 
 
122
                onCountChanged: {
 
123
                    albumtrackslist.currentIndex = albumTracksModel.indexOf(currentFile)
 
124
                }
 
125
 
 
126
                Component {
 
127
                    id: albumTracksDelegate
 
128
 
 
129
                    ListItem.Standard {
 
130
                        id: track
 
131
                        objectName: "albumsheet-track"
 
132
                        iconFrame: false
 
133
                        progression: false
 
134
                        height: isAlbum ? styleMusic.albums.itemHeight : styleMusic.common.albumSize + units.gu(2)
 
135
 
 
136
                        MouseArea {
 
137
                            anchors.fill: parent
 
138
                            onDoubleClicked: {
 
139
                            }
 
140
                            onClicked: {
 
141
                                if (focus == false) {
 
142
                                    focus = true
 
143
                                }
 
144
                                trackClicked(albumTracksModel, index)  // play track
 
145
                                if (isAlbum) {
 
146
                                    Library.addRecent(sheetItem.line2, sheetItem.line1, sheetItem.cover, sheetItem.line2, "album")
 
147
                                    mainView.hasRecent = true
 
148
                                    recentModel.filterRecent()
 
149
                                } else if (sheetItem.line1 == "Playlist") {
 
150
                                    Library.addRecent(sheetItem.line2, "Playlist", sheetItem.cover, sheetItem.line2, "playlist")
 
151
                                    mainView.hasRecent = true
 
152
                                    recentModel.filterRecent()
 
153
                                }
 
154
 
 
155
                                // TODO: This closes the SDK defined sheet
 
156
                                //       component. It should be able to close
 
157
                                //       albumSheet.
 
158
                                PopupUtils.close(sheet)
 
159
                            }
 
160
                        }
 
161
 
 
162
                        UbuntuShape {
 
163
                            id: trackCover
 
164
                            anchors {
 
165
                                left: parent.left
 
166
                                leftMargin: units.gu(2)
 
167
                                top: parent.top
 
168
                                topMargin: units.gu(1)
 
169
                            }
 
170
                            width: styleMusic.common.albumSize
 
171
                            height: styleMusic.common.albumSize
 
172
                            visible: !isAlbum
 
173
                            image: Image {
 
174
                                source: model.cover !== "" ? model.cover : Qt.resolvedUrl("../images/cover_default_icon.png")
 
175
                            }
 
176
                        }
 
177
 
 
178
                        Label {
 
179
                            id: trackArtist
 
180
                            wrapMode: Text.NoWrap
 
181
                            maximumLineCount: 2
 
182
                            fontSize: "x-small"
 
183
                            visible: !isAlbum
 
184
                            anchors {
 
185
                                left: trackCover.right
 
186
                                leftMargin: units.gu(2)
 
187
                                top: parent.top
 
188
                                topMargin: units.gu(1.5)
 
189
                                right: expandItem.left
 
190
                                rightMargin: units.gu(1.5)
 
191
                            }
 
192
                            elide: Text.ElideRight
 
193
                            text: model.artist
 
194
                        }
 
195
 
 
196
                        Label {
 
197
                            id: trackTitle
 
198
                            objectName: "albumsheet-tracktitle"
 
199
                            wrapMode: Text.NoWrap
 
200
                            maximumLineCount: 1
 
201
                            fontSize: "medium"
 
202
                            anchors {
 
203
                                left: isAlbum ? parent.left : trackCover.right
 
204
                                leftMargin: units.gu(2)
 
205
                                top: isAlbum ? parent.top : trackArtist.bottom
 
206
                                topMargin: units.gu(1)
 
207
                                right: expandItem.left
 
208
                                rightMargin: units.gu(1.5)
 
209
                            }
 
210
                            elide: Text.ElideRight
 
211
                            text: model.title
 
212
                        }
 
213
 
 
214
                        Label {
 
215
                            id: trackAlbum
 
216
                            wrapMode: Text.NoWrap
 
217
                            maximumLineCount: 2
 
218
                            fontSize: "xx-small"
 
219
                            visible: !isAlbum
 
220
                            anchors {
 
221
                                left: trackCover.right
 
222
                                leftMargin: units.gu(2)
 
223
                                top: trackTitle.bottom
 
224
                                topMargin: units.gu(2)
 
225
                                right: expandItem.left
 
226
                                rightMargin: units.gu(1.5)
 
227
                            }
 
228
                            elide: Text.ElideRight
 
229
                            text: model.album
 
230
                        }
 
231
 
 
232
                        Image {
 
233
                            id: expandItem
 
234
                            objectName: "albumsheet-expanditem"
 
235
                            anchors.right: parent.right
 
236
                            anchors.rightMargin: units.gu(2)
 
237
                            source: expandable.visible ? "../images/dropdown-menu-up.svg" : "../images/dropdown-menu.svg"
 
238
                            height: styleMusic.common.expandedItem
 
239
                            width: styleMusic.common.expandedItem
 
240
                            y: parent.y + ((isAlbum ? styleMusic.albums.itemHeight : styleMusic.common.albumSize + units.gu(2)) / 2) - (height / 2)
 
241
                        }
 
242
 
 
243
                        MouseArea {
 
244
                            anchors.bottom: parent.bottom
 
245
                            anchors.right: parent.right
 
246
                            anchors.top: parent.top
 
247
                            width: styleMusic.common.expandedItem * 3
 
248
                            onClicked: {
 
249
                                if(expandable.visible) {
 
250
                                    customdebug("clicked collapse")
 
251
                                    expandable.visible = false
 
252
                                    track.height = isAlbum ? styleMusic.albums.itemHeight : styleMusic.common.albumSize + units.gu(2)
 
253
                                }
 
254
                                else {
 
255
                                    customdebug("clicked expand")
 
256
                                    collapseExpand(-1);  // collapse all others
 
257
                                    expandable.visible = true
 
258
                                    track.height = isAlbum ? styleMusic.albums.expandedHeight : styleMusic.common.expandedHeight
 
259
                                }
 
260
                            }
 
261
                        }
 
262
 
 
263
                        Rectangle {
 
264
                            id: expandable
 
265
                            color: "transparent"
 
266
                            height: styleMusic.albums.expandHeight
 
267
                            visible: false
 
268
                            MouseArea {
 
269
                                anchors.fill: parent
 
270
                                onClicked: {
 
271
                                    customdebug("User pressed outside the playlist item and expanded items.")
 
272
                                }
 
273
                            }
 
274
 
 
275
                            Component.onCompleted: {
 
276
                                collapseExpand.connect(onCollapseExpand);
 
277
                            }
 
278
 
 
279
                            function onCollapseExpand(indexCol)
 
280
                            {
 
281
                                if ((indexCol === index || indexCol === -1) && expandable !== undefined && expandable.visible === true)
 
282
                                {
 
283
                                    customdebug("auto collapse")
 
284
                                    expandable.visible = false
 
285
                                    track.height = isAlbum ? styleMusic.albums.itemHeight : styleMusic.common.albumSize + unis.gu(2)
 
286
                                }
 
287
                            }
 
288
 
 
289
                            // background for expander
 
290
                            Rectangle {
 
291
                                id: expandedBackground
 
292
                                anchors.top: parent.top
 
293
                                anchors.topMargin: isAlbum ? styleMusic.albums.itemHeight : styleMusic.common.albumSize + units.gu(2)
 
294
                                color: styleMusic.common.black
 
295
                                height: styleMusic.albums.expandedHeight - styleMusic.albums.itemHeight
 
296
                                width: track.width
 
297
                                opacity: 0.4
 
298
                            }
 
299
 
 
300
                            // add to playlist
 
301
                            Rectangle {
 
302
                                id: playlistRow
 
303
                                anchors.top: expandedBackground.top
 
304
                                anchors.left: parent.left
 
305
                                anchors.leftMargin: styleMusic.albums.expandedLeftMargin
 
306
                                color: "transparent"
 
307
                                height: expandedBackground.height
 
308
                                width: units.gu(15)
 
309
                                Icon {
 
310
                                    id: playlistTrack
 
311
                                    anchors.verticalCenter: parent.verticalCenter
 
312
                                    color: styleMusic.common.white
 
313
                                    name: "add"
 
314
                                    height: styleMusic.common.expandedItem
 
315
                                    width: styleMusic.common.expandedItem
 
316
                                }
 
317
                                Label {
 
318
                                    anchors.left: playlistTrack.right
 
319
                                    anchors.leftMargin: units.gu(0.5)
 
320
                                    anchors.verticalCenter: parent.verticalCenter
 
321
                                    color: styleMusic.common.white
 
322
                                    fontSize: "small"
 
323
                                    width: parent.width - playlistTrack.width - units.gu(1)
 
324
                                    text: i18n.tr("Add to playlist")
 
325
                                    wrapMode: Text.WordWrap
 
326
                                    maximumLineCount: 3
 
327
                                }
 
328
                                MouseArea {
 
329
                                    anchors.fill: parent
 
330
                                    onClicked: {
 
331
                                        expandable.visible = false
 
332
                                        track.height = isAlbum ? styleMusic.albums.itemHeight : styleMusic.common.albumSize + units.gu(2)
 
333
                                        chosenArtist = artist
 
334
                                        chosenTitle = title
 
335
                                        chosenTrack = file
 
336
                                        chosenAlbum = album
 
337
                                        chosenCover = cover
 
338
                                        chosenGenre = genre
 
339
                                        chosenIndex = index
 
340
                                        console.debug("Debug: Add track to playlist")
 
341
                                        PopupUtils.open(Qt.resolvedUrl("../MusicaddtoPlaylist.qml"), mainView,
 
342
                                                        {
 
343
                                                            title: i18n.tr("Select playlist")
 
344
                                                        } )
 
345
                                    }
 
346
                                }
 
347
                            }
 
348
                            // Queue
 
349
                            Rectangle {
 
350
                                id: queueRow
 
351
                                anchors.top: expandedBackground.top
 
352
                                anchors.left: playlistRow.left
 
353
                                anchors.leftMargin: units.gu(15)
 
354
                                color: "transparent"
 
355
                                height: expandedBackground.height
 
356
                                width: units.gu(15)
 
357
                                Image {
 
358
                                    id: queueTrack
 
359
                                    objectName: "albumsheet-queuetrack"
 
360
                                    anchors.verticalCenter: parent.verticalCenter
 
361
                                    source: "../images/queue.png"
 
362
                                    height: styleMusic.common.expandedItem
 
363
                                    width: styleMusic.common.expandedItem
 
364
                                }
 
365
                                Label {
 
366
                                    anchors.left: queueTrack.right
 
367
                                    anchors.leftMargin: units.gu(0.5)
 
368
                                    anchors.verticalCenter: parent.verticalCenter
 
369
                                    color: styleMusic.common.white
 
370
                                    fontSize: "small"
 
371
                                    width: parent.width - queueTrack.width - units.gu(1)
 
372
                                    text: i18n.tr("Add to queue")
 
373
                                    wrapMode: Text.WordWrap
 
374
                                    maximumLineCount: 3
 
375
                                }
 
376
                                MouseArea {
 
377
                                    anchors.fill: parent
 
378
                                    onClicked: {
 
379
                                        expandable.visible = false
 
380
                                        track.height = isAlbum ? styleMusic.albums.itemHeight : styleMusic.common.albumSize + units.gu(2)
 
381
                                        console.debug("Debug: Add track to queue: " + title)
 
382
                                        trackQueue.model.append({"title": title, "artist": artist, "file": file, "album": album, "cover": cover, "genre": genre})
 
383
                                    }
 
384
                                }
 
385
                            }
 
386
                        }
 
387
 
 
388
                        onFocusChanged: {
 
389
                        }
 
390
                        Component.onCompleted: {
 
391
                            if (index === 0)
 
392
                            {
 
393
                                sheetItem.file = model.file;
 
394
                                sheetItem.year = model.year;
 
395
                            }
 
396
                        }
 
397
                    }
 
398
                }
 
399
            }
 
400
        }
 
401
    }
 
402
}
 
403