~ahayzen/music-app/refactor-use-sdk-listitems

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
/*
 * Copyright (C) 2013, 2014, 2015
 *      Andrew Hayzen <ahayzen@gmail.com>
 *      Daniel Holm <d.holmen@gmail.com>
 *      Victor Thompson <victor.thompson@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.4
import QtQuick.LocalStorage 2.0
import Ubuntu.Components 1.3
import "Delegates"
import "Flickables"
import "ListItemActions"
import "../logic/meta-database.js" as Library


MultiSelectListView {
    id: queueList
    anchors {
        fill: parent
    }
    footer: Item {
        height: mainView.height - (styleMusic.common.expandHeight + queueList.currentHeight) + units.gu(8)
    }
    model: trackQueue.model
    objectName: "nowPlayingqueueList"

    onCountChanged: customdebug("Queue: Now has: " + queueList.count + " tracks")

    delegate: MusicListItem {
        id: queueListItem
        color: player.currentIndex === index ? "#2c2c34" : styleMusic.mainView.backgroundColor
        column: Column {
            Label {
                id: trackTitle
                color: player.currentIndex === index ? UbuntuColors.blue : styleMusic.common.music
                fontSize: "small"
                objectName: "titleLabel"
                text: model.title
            }

            Label {
                id: trackArtist
                color: styleMusic.common.subtitle
                fontSize: "x-small"
                objectName: "artistLabel"
                text: model.author
            }
        }
        leadingActions: ListItemActions {
            actions: [
                Remove {
                    onTriggered: trackQueue.removeQueueList([index])
                }
            ]
        }
        multiselectable: true
        objectName: "nowPlayingListItem" + index
        reorderable: true
        trailingActions: ListItemActions {
            actions: [
                AddToPlaylist {
                }
            ]
            delegate: ActionDelegate {

            }
        }

        onItemClicked: {
            customdebug("File: " + model.filename) // debugger
            trackQueueClick(index);  // toggle track state
        }
    }

    onReorder: {
        Library.moveQueueItem(from, to);

        // Maintain currentIndex with current song
        if (from === player.currentIndex) {
            player.currentIndex = to;
        } else if (from < player.currentIndex && to >= player.currentIndex) {
            player.currentIndex -= 1;
        } else if (from > player.currentIndex && to <= player.currentIndex) {
            player.currentIndex += 1;
        }

        queueIndex = player.currentIndex
    }
}