PlaylistsView.qml 4.46 KB
Newer Older
1 2 3
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
4
import org.kde.kirigami 2.2 as Kirigami
5 6

import "../../view_models/BabeTable"
7
import "../../view_models/BabeMenu"
8
import "../../view_models"
Camilo Higuita's avatar
Camilo Higuita committed
9
import "../../db/Queries.js" as Q
10 11


12 13 14 15 16 17 18
//    transform: Translate
//    {
//        x: (playlistViewDrawer.position * playlistViewRoot.width * 0.33)*-1
//    }

Kirigami.PageRow
{
19
    id: playlistViewRoot
Camilo Higuita's avatar
Camilo Higuita committed
20
    property string playlistQuery
21

22 23
    property alias playlistViewModel : playlistViewModel

24 25
    signal rowClicked(var track)
    signal quickPlayTrack(var track)
Camilo Higuita's avatar
Camilo Higuita committed
26
    signal playAll(var tracks)
27
    signal playSync(var playlist)
Camilo Higuita's avatar
Camilo Higuita committed
28
    signal appendAll(var tracks)
29

Camilo Higuita's avatar
Camilo Higuita committed
30
    clip: true
31 32 33
    separatorVisible: wideMode
    initialPage:[playlistList, playlistViewDrawer]
    defaultColumnWidth: Kirigami.Units.gridUnit * 15
34
    interactive: false
35

Camilo Higuita's avatar
Camilo Higuita committed
36
    Page
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    {
        id: playlistList
        ColumnLayout
        {
            anchors.fill: parent
            spacing: 0
            Layout.margins: 0

            PlaylistsViewModel
            {
                id: playlistViewModel

                Layout.fillHeight: true
                Layout.fillWidth: true

52
                onPlaySync: syncAndPlay(index)
53

54 55 56 57 58
            }

            ColorTagsBar
            {
                Layout.fillWidth: true
59 60
                height: rowHeightAlt
                recSize: toolBarIconSize
61 62 63 64
                Rectangle
                {
                    anchors.fill: parent
                    z: -999
65
                    color:midColor
66
                }
Camilo Higuita's avatar
Camilo Higuita committed
67 68 69 70 71 72
                onColorClicked:
                {
                    populate(Q.GET.colorTracks_.arg(color))
                    if(!playlistViewRoot.wideMode)
                        playlistViewRoot.currentIndex = 1
                }
73 74 75 76 77 78 79 80
            }


        }
    }


    Page
81 82
    {
        id: playlistViewDrawer
83
        anchors.fill: parent
84 85 86

        background: Rectangle
        {
87
            color: altColor
88 89 90 91 92 93 94 95 96
        }

        BabeTable
        {
            id: filterList
            width: parent.width
            height: parent.height
            quickPlayVisible: true
            coverArtVisible: true
97 98
            trackRating: true
            trackDuration: false
99
            headerBar: true
100
            headerClose: !playlistViewRoot.wideMode
Camilo Higuita's avatar
Camilo Higuita committed
101
            headerTitle: playlistViewRoot.wideMode ? "" : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
102 103 104
            onHeaderClosed: if(!playlistViewRoot.wideMode)
                                playlistViewRoot.currentIndex = 0

105
            holder.message:  "<h2>"+playlistViewModel.model.get(playlistViewModel.currentIndex).playlist+"</h2><p>Your playlist is empty,<br>start adding new music to it</p>"
Camilo Higuita's avatar
Camilo Higuita committed
106
            holder.emoji: "qrc:/assets/face-hug.png"
107

108

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
            headerMenu.menuItem:  [
                BabeMenuItem
                {
                    text: "Sync tags"
                    onTriggered: {}
                },
                BabeMenuItem
                {
                    text: "Play-n-Sync"
                    onTriggered: syncAndPlay(playlistViewModel.currentIndex)
                }
            ]



124

125 126 127 128 129 130 131 132
            Connections
            {
                target: filterList
                onRowClicked: playlistViewRoot.rowClicked(filterList.model.get(index))
                onQuickPlayTrack:
                {
                    playlistViewRoot.quickPlayTrack(filterList.model.get(index))
                }
Camilo Higuita's avatar
Camilo Higuita committed
133 134
                onPlayAll: playAll(bae.get(playlistQuery))
                onAppendAll: appendAll(bae.get(playlistQuery))
135
                onPulled: populate(playlistQuery)
136 137 138 139 140 141 142
            }
        }

    }

    function populate(query)
    {
Camilo Higuita's avatar
Camilo Higuita committed
143
        playlistQuery = query
144 145 146 147 148 149 150 151 152 153
        filterList.clearTable()

        var tracks = bae.get(query)

        if(tracks.length>0)
            for(var i in tracks)
                filterList.model.append(tracks[i])

    }

154
    function refresh()
155
    {
156 157 158 159 160 161 162 163 164 165
        var i = 9
        for(i; i < playlistViewModel.count; i++)
            playlistViewModel.remove(i)

        setPlaylists()
    }

    function setPlaylists()
    {
        var playlists = bae.get(Q.GET.playlists)
166 167 168 169
        if(playlists.length > 0)
            for(var i in playlists)
                playlistViewModel.model.append(playlists[i])
    }
170

171 172 173 174 175 176
    function syncAndPlay(index)
    {
        if(!playlistViewModel.model.get(index).playlistIcon)
            playlistViewRoot.playSync(playlistViewModel.model.get(index).playlist)
    }

177
    Component.onCompleted: setPlaylists()
178
}