AlbumsView.qml 5.71 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1 2 3 4 5 6 7
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3

import "../view_models"
import "../utils/Icons.js" as MdiFont
import "../utils"
8
import "../db/Queries.js" as Q
Camilo Higuita's avatar
Camilo Higuita committed
9 10 11

BabeGrid
{
12
    id: albumsViewGrid
Camilo Higuita's avatar
Camilo Higuita committed
13
    visible: true
14 15 16 17 18 19 20 21 22 23 24

    property int hintSize : Math.sqrt(root.width*root.height)*0.25
    albumSize:
    {
        if(hintSize>200)
            200
        else if (hintSize < 150)
            bae.isMobile() && hintSize < 120 ? 120 : 150
        else
            hintSize
    }
Camilo Higuita's avatar
Camilo Higuita committed
25

Camilo Higuita's avatar
Camilo Higuita committed
26
    signal rowClicked(var track)
27
    signal playAlbum(var tracks)
28 29
    signal playTrack(var track)
    signal queueTrack(var track)
30
    signal appendAlbum(var tracks)
31

Camilo Higuita's avatar
Camilo Higuita committed
32 33 34 35
    transform: Translate
    {
        y: (drawer.position * albumsViewGrid.height * 0.33)*-1
    }
36

Camilo Higuita's avatar
Camilo Higuita committed
37 38 39 40 41 42 43
    Drawer
    {
        id: drawer
        height: parent.height * 0.4
        width: parent.width
        edge: Qt.BottomEdge
        interactive: false
44 45
        focus: true
        modal:true
46
        background: Rectangle
47 48 49
        {
            anchors.fill: parent
            z: -999
50
            color: bae.altColor()
51 52
        }

Camilo Higuita's avatar
Camilo Higuita committed
53
        Column
Camilo Higuita's avatar
Camilo Higuita committed
54
        {
Camilo Higuita's avatar
Camilo Higuita committed
55 56 57
            anchors.fill: parent

            Rectangle
Camilo Higuita's avatar
Camilo Higuita committed
58
            {
Camilo Higuita's avatar
Camilo Higuita committed
59 60 61 62
                id: titleBar
                width: parent.width
                height: 48
                z: 1
63
                color: bae.midColor()
Camilo Higuita's avatar
Camilo Higuita committed
64
                Row
Camilo Higuita's avatar
Camilo Higuita committed
65
                {
Camilo Higuita's avatar
Camilo Higuita committed
66
                    anchors.fill: parent
Camilo Higuita's avatar
Camilo Higuita committed
67

68 69
                    ToolButton
                    {
70 71
                        id: playAllBtn

72 73 74
                        width: parent.height
                        height: parent.height

Camilo Higuita's avatar
Camilo Higuita committed
75
                        BabeIcon {text: MdiFont.Icon.playBoxOutline}
76 77 78

                        onClicked:
                        {
79 80
                            drawer.close()

81
                            var data = albumsViewGrid.gridModel.get(albumsViewGrid.grid.currentIndex)
82 83
                            var query = Q.Query.albumTracks_.arg(data.album)
                            query = query.arg(data.artist)
84
                            var tracks = bae.get(query)
85

86
                            albumsViewGrid.playAlbum(tracks)
87 88 89
                        }
                    }

90 91 92 93 94 95 96
                    ToolButton
                    {
                        id: appendBtn

                        width: parent.height
                        height: parent.height

Camilo Higuita's avatar
Camilo Higuita committed
97
                        BabeIcon {text: MdiFont.Icon.playlistPlus}
98 99 100

                        onClicked:
                        {
101
                            var data = albumsView.gridModel.get(albumsViewGrid.grid.currentIndex)
102 103
                            var query = Q.Query.albumTracks_.arg(data.album)
                            query = query.arg(data.artist)
104
                            var tracks = bae.get(query)
105
                            albumsViewGrid.appendAlbum(tracks)
106 107 108 109 110
                            drawer.close()

                        }
                    }

Camilo Higuita's avatar
Camilo Higuita committed
111
                    Label
Camilo Higuita's avatar
Camilo Higuita committed
112
                    {
Camilo Higuita's avatar
Camilo Higuita committed
113
                        id: albumTitle
114
                        width: parent.width - closeBtn.width - playAllBtn.width - appendBtn.width
Camilo Higuita's avatar
Camilo Higuita committed
115 116 117 118 119
                        height: parent.height
                        elide: Text.ElideRight
                        font.pointSize: 12
                        font.bold: true
                        lineHeight: 0.7
120
                        color: bae.foregroundColor()
Camilo Higuita's avatar
Camilo Higuita committed
121 122 123

                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment:  Text.AlignVCenter
Camilo Higuita's avatar
Camilo Higuita committed
124 125
                    }

Camilo Higuita's avatar
Camilo Higuita committed
126 127

                    ToolButton
Camilo Higuita's avatar
Camilo Higuita committed
128
                    {
Camilo Higuita's avatar
Camilo Higuita committed
129 130 131
                        id: closeBtn
                        width: parent.height
                        height: parent.height
Camilo Higuita's avatar
Camilo Higuita committed
132

Camilo Higuita's avatar
Camilo Higuita committed
133
                        BabeIcon { text: MdiFont.Icon.close }
134 135
                        onClicked: drawer.close()

Camilo Higuita's avatar
Camilo Higuita committed
136 137
                    }
                }
Camilo Higuita's avatar
Camilo Higuita committed
138
            }
Camilo Higuita's avatar
Camilo Higuita committed
139 140

            BabeTable
Camilo Higuita's avatar
Camilo Higuita committed
141
            {
Camilo Higuita's avatar
Camilo Higuita committed
142 143 144
                id: drawerList
                width: parent.width
                height: parent.height - titleBar.height
Camilo Higuita's avatar
Camilo Higuita committed
145
                trackNumberVisible: true
Camilo Higuita's avatar
Camilo Higuita committed
146 147
                onRowClicked:
                {
Camilo Higuita's avatar
Camilo Higuita committed
148
                    drawer.close()
149
                    albumsViewGrid.rowClicked(model.get(index))
Camilo Higuita's avatar
Camilo Higuita committed
150
                }
151

152
                onQuickPlayTrack:
153 154
                {
                    drawer.close()
155
                    albumsViewGrid.playTrack(model.get(index))
156 157 158 159 160 161 162
                }

                onQueueTrack:
                {
                    albumsViewGrid.queueTrack(model.get(index))
                    drawer.close()
                }
Camilo Higuita's avatar
Camilo Higuita committed
163
            }
Camilo Higuita's avatar
Camilo Higuita committed
164

Camilo Higuita's avatar
Camilo Higuita committed
165 166 167 168 169
        }
    }

    onAlbumCoverClicked:
    {
Camilo Higuita's avatar
Camilo Higuita committed
170
        albumTitle.text = album
Camilo Higuita's avatar
Camilo Higuita committed
171
        drawer.open()
Camilo Higuita's avatar
Camilo Higuita committed
172 173
        drawerList.clearTable()

174 175 176
        var query = Q.Query.albumTracks_.arg(album)
        query = query.arg(artist)

177
        var map = bae.get(query)
178 179 180 181 182

        for(var i in map)
            drawerList.model.append(map[i])
    }

183 184

    function populate()
185
    {
186
        var map = bae.get(Q.Query.allAlbumsAsc)
187 188
        for(var i in map)
            gridModel.append(map[i])
Camilo Higuita's avatar
Camilo Higuita committed
189 190
    }

191 192 193 194 195 196
    function filter(tracks)
    {
        var matches = []
        for(var i = 0; i<tracks.length; i++)
            matches.push(find(tracks[i].album))

197 198
        for(var j = 0 ; j < albumsViewGrid.gridModel.count; j++)
            albumsViewGrid.gridModel.remove(j,1)
199 200


201 202 203 204 205
        //        for(var match in matches)
        //        {
        //            albumsViewGrid.gridModel.get(match).hide = true
        //            console.log(match)
        //        }
206 207 208 209 210 211 212 213 214 215 216
    }

    function find(query)
    {
        var indexes = []
        for(var i = 0 ; i < albumsViewGrid.gridModel.count; i++)
            if(albumsViewGrid.gridModel.get(i).album.includes(query))
                indexes.push(i)

    }

217
    Component.onCompleted: populate()
Camilo Higuita's avatar
Camilo Higuita committed
218
}