BabeTable.qml 4.03 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1 2 3
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
4
import org.kde.kirigami 2.2 as Kirigami
5
import "../../utils/Player.js" as Player
6

7
import ".."
Camilo Higuita's avatar
Camilo Higuita committed
8

9
BabeList
Camilo Higuita's avatar
Camilo Higuita committed
10
{
11
    id: babeTableRoot
12
    holder.message: "<h2>This list is empty</h2><p>You can sdd new music sources from the settings</p>"
Camilo Higuita's avatar
Camilo Higuita committed
13
    //    cacheBuffer : 300
14
    headerBarColor: backgroundColor
15 16
    textColor: foregroundColor

Camilo Higuita's avatar
Camilo Higuita committed
17
    property bool trackNumberVisible
18
    property bool quickPlayVisible : true
19
    property bool coverArtVisible : false
Camilo Higuita's avatar
Camilo Higuita committed
20
    property bool menuItemVisible : isMobile
21 22
    property bool trackDuration
    property bool trackRating
23 24
    property bool allowMenu: true
    property bool isArtworkRemote : false
25

26
    property alias headerMenu: headerMenu
27
    property alias contextMenu : contextMenu
28

29 30 31
    property alias playAllBtn : playAllBtn
    property alias appendBtn : appendBtn
    property alias menuBtn : menuBtn
32

Camilo Higuita's avatar
Camilo Higuita committed
33 34
    signal rowClicked(int index)
    signal rowPressed(int index)
35
    signal quickPlayTrack(int index)
36
    signal queueTrack(int index)
37

38
    signal artworkDoubleClicked(int index)
39 40 41

    signal playAll()
    signal appendAll()
Camilo Higuita's avatar
Camilo Higuita committed
42

43
    headerBarLeft:  BabeButton
44
    {
45 46 47
        id : playAllBtn
        visible : headerBarVisible && count > 0
        anim : true
48
        iconName : "media-playlist-play"
49 50
        onClicked : playAll()
    }
51

52
    headerBarRight: [
53

54
        BabeButton
55
        {
56 57 58
            id: appendBtn
            visible: headerBarVisible && count > 0
            anim : true
59
            iconName : "media-playlist-append"//"media-repeat-track-amarok"
60 61 62 63 64 65 66 67
            onClicked: appendAll()
        },

        BabeButton
        {
            id: menuBtn
            iconName: /*"application-menu"*/ "overflow-menu"
            onClicked: headerMenu.popup()
68
        }
69
    ]
70

71 72 73 74 75 76 77 78
    PlaylistDialog
    {
        id: playlistDialog
    }

    HeaderMenu
    {
        id: headerMenu
79
        onSaveListClicked: saveList()
80
        onQueueListClicked: queueList()
81
    }
82

83 84 85 86
    TableMenu
    {
        id: contextMenu
    }
Camilo Higuita's avatar
Camilo Higuita committed
87

88
    ListModel { id: listModel }
Camilo Higuita's avatar
Camilo Higuita committed
89 90 91

    model: listModel

92

93
    //    property alias animBabe: delegate.animBabe
94
    delegate: TableDelegate
Camilo Higuita's avatar
Camilo Higuita committed
95 96 97
    {
        id: delegate
        width: list.width
98
        number : trackNumberVisible ? true : false
99
        quickPlay: quickPlayVisible
100
        coverArt : coverArtVisible
101 102
        trackDurationVisible : trackDuration
        trackRatingVisible : trackRating
Camilo Higuita's avatar
Camilo Higuita committed
103
        menuItem: menuItemVisible
104 105
        color: babeTableRoot.textColor
        bgColor: headerBarColor
106
        remoteArtwork: isArtworkRemote
Camilo Higuita's avatar
Camilo Higuita committed
107 108 109
        Connections
        {
            target: delegate
110

111 112
            onPressAndHold: if(isMobile && allowMenu) openItemMenu(index)
            onRightClicked: if(allowMenu) openItemMenu(index)
113

Camilo Higuita's avatar
Camilo Higuita committed
114 115
            onClicked:
            {
Camilo Higuita's avatar
Camilo Higuita committed
116
                currentIndex = index
117
                if(root.isMobile)
118
                    rowClicked(index)
119

120 121 122 123
            }

            onDoubleClicked:
            {
124
                if(!root.isMobile)
125
                    rowClicked(index)
126 127
            }

128
            onPlay: quickPlayTrack(index)
129

130
            onArtworkCoverDoubleClicked: artworkDoubleClicked(index)
131

Camilo Higuita's avatar
Camilo Higuita committed
132 133 134
        }
    }

135 136 137
    function openItemMenu(index)
    {
        currentIndex = index
138
        contextMenu.rate = bae.getTrackStars(model.get(currentIndex).url)
139
        contextMenu.babe = bae.trackBabe(model.get(currentIndex).url)
140
        if(root.isMobile) contextMenu.open()
141 142
        else
            contextMenu.popup()
143
        rowPressed(index)
144
    }
145

146 147 148
    function saveList()
    {
        var trackList = []
149 150 151 152 153 154 155 156 157
        if(model.count > 0)
        {
            for(var i = 0; i < model.count; ++i)
                trackList.push(model.get(i).url)

            playlistDialog.tracks = trackList
            playlistDialog.open()
        }
    }
158

159 160 161 162 163 164 165 166 167 168 169
    function queueList()
    {
        var trackList = []

        if(model.count > 0)
        {
            for(var i = 0; i < model.count; ++i)
                trackList.push(model.get(i))

            Player.queueTracks(trackList)
        }
170 171
    }

172
    //    Component.onCompleted: forceActiveFocus()
Camilo Higuita's avatar
Camilo Higuita committed
173
}