TableDelegate.qml 7.57 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1 2 3
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
4 5
import "../utils/Icons.js" as MdiFont
import "../utils"
Camilo Higuita's avatar
Camilo Higuita committed
6 7 8 9

ItemDelegate
{
    id: delegate
10 11 12 13

    width: parent.width
    height: 64

14
    signal play()
15
    signal rightClicked()
16

17
    property string textColor: bae.foregroundColor()
18
    property bool number : false
19
    property bool quickPlay : true
20
    property bool coverArt : false
21 22 23

    property bool trackDurationVisible : false
    property bool trackRatingVisible: false
24
    //    property bool playingIndicator: false
25 26 27
    property string trackMood : art
    property alias trackRating : trackRating

Camilo Higuita's avatar
Camilo Higuita committed
28 29
    checkable: true

30 31
    background: Rectangle
    {
32 33 34 35 36 37 38
        color:
        {
            if(trackMood.length>0)
                Qt.lighter(trackMood)
            else
                index % 2 === 0 ? bae.midColor() : "transparent"
        }
39

40 41
        opacity: 0.3
    }
42 43 44 45 46 47
    MouseArea
    {
        anchors.fill: parent
        acceptedButtons: Qt.RightButton
        onClicked:
        {
48 49
            if(!bae.isMobile() && mouse.button === Qt.RightButton)
                rightClicked()
50 51 52
        }
    }

53
    contentItem: RowLayout
Camilo Higuita's avatar
Camilo Higuita committed
54
    {
Camilo Higuita's avatar
Camilo Higuita committed
55
        id: gridLayout
56 57 58
        height: delegate.height
        width: delegate.width
        spacing: 20
59

60
        Item
61
        {
62 63 64 65 66 67 68 69 70 71 72 73
            visible:
            {
                if(coverArt)
                {
                    if(listModel.get(index-1))
                        if(listModel.get(index-1).album === album)
                            artworkCover.source = ""
                    true

                }else false
            }

74
            Layout.fillHeight: true
75 76 77 78 79 80 81 82 83 84 85 86 87
            //            Layout.fillWidth: true
            //            height: parent.height
            width: parent.height
            ToolButton
            {
                height: delegate.height
                width: delegate.height
                anchors.verticalCenter: parent.verticalCenter

                Image
                {
                    id: artworkCover
                    anchors.fill: parent
88 89 90 91 92 93
                    source:
                    {
                        if(artwork)
                            (artwork.length>0 && artwork !== "none")? "file://"+encodeURIComponent(artwork) : "qrc:/assets/cover.png"
                        else "qrc:/assets/cover.png"
                    }
94 95 96 97 98 99
                    fillMode: Image.PreserveAspectFit
                    cache: false
                    antialiasing: true
                }

            }
100
        }
Camilo Higuita's avatar
Camilo Higuita committed
101

102
        Item
Camilo Higuita's avatar
Camilo Higuita committed
103
        {
104
            visible: quickPlay
Camilo Higuita's avatar
Camilo Higuita committed
105
            Layout.fillHeight: true
106 107 108 109 110 111 112
            //            Layout.fillWidth: true
            //            height: parent.height
            width: parent.height
            ToolButton
            {
                id: playBtn
                anchors.centerIn: parent
Camilo Higuita's avatar
Camilo Higuita committed
113

114 115 116
                BabeIcon { text: MdiFont.Icon.playCircle }
                onClicked: delegate.play()
            }
Camilo Higuita's avatar
Camilo Higuita committed
117 118
        }

Camilo Higuita's avatar
Camilo Higuita committed
119

120
        Item
Camilo Higuita's avatar
Camilo Higuita committed
121
        {
122
            height: delegate.height
Camilo Higuita's avatar
Camilo Higuita committed
123 124

            Layout.fillHeight: true
125
            Layout.fillWidth: true
Camilo Higuita's avatar
Camilo Higuita committed
126

127
            Layout.alignment: Qt.AlignVCenter
Camilo Higuita's avatar
Camilo Higuita committed
128

129 130 131 132 133
            GridLayout
            {
                anchors.fill: parent
                rows:2
                columns:3
Camilo Higuita's avatar
Camilo Higuita committed
134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
                Label
                {
                    id: trackNumber
                    visible: number
                    width: 16
                    Layout.fillHeight: true
                    Layout.row: 1
                    Layout.column: 1

                    Layout.alignment: Qt.AlignCenter
                    verticalAlignment:  Qt.AlignVCenter

                    text: track
                    font.bold: true
                    elide: Text.ElideRight

                    font.pointSize: 10
                    color: textColor
                }
Camilo Higuita's avatar
Camilo Higuita committed
154

Camilo Higuita's avatar
Camilo Higuita committed
155

156 157 158
                Label
                {
                    id: trackTitle
159

160 161 162 163 164 165 166 167
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.row: 1
                    Layout.column: 2
                    verticalAlignment:  Qt.AlignVCenter
                    text: title
                    font.bold: true
                    elide: Text.ElideRight
168

169 170
                    font.pointSize: 10
                    color: textColor
171

172
                }
173

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
                Label
                {
                    id: trackInfo

                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.row: 2
                    Layout.column: 2
                    verticalAlignment:  Qt.AlignVCenter
                    text: artist + " | " + album
                    font.bold: false
                    elide: Text.ElideRight
                    font.pointSize: 9
                    color: textColor

                }
190 191


192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
                //        Item
                //        {
                //            Layout.row: 1
                //            Layout.rowSpan: 2
                //            Layout.column: 4
                //            height: 48
                //            width: height
                //            Layout.fillWidth: true
                //            Layout.fillHeight: true
                //            Layout.alignment: Qt.AlignCenter

                //            AnimatedImage
                //            {
                //                id: animation
                //                cache: true
                //                visible: playingIndicator
                //                height: 22
                //                width: 22
                //                horizontalAlignment: Qt.AlignLeft
                //                verticalAlignment:  Qt.AlignVCenter
                //                source: "qrc:/assets/bars.gif"
                //            }
                //        }

                Label
                {
                    id: trackDuration
                    visible: trackDurationVisible
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.row: 1
                    Layout.column: 3
                    horizontalAlignment: Qt.AlignRight
                    verticalAlignment:  Qt.AlignVCenter
                    text: player.transformTime(duration)
                    font.bold: false
                    elide: Text.ElideRight
                    font.pointSize: 8
                    color: textColor
                }

                Label
                {
                    id: trackRating
                    visible: trackRatingVisible
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.row: 2
                    Layout.column: 3
                    horizontalAlignment: Qt.AlignRight
                    verticalAlignment:  Qt.AlignVCenter
                    text: stars
                    font.bold: false
                    elide: Text.ElideRight
                    font.pointSize: 8
                    color: textColor
                }
            }
        }
Camilo Higuita's avatar
Camilo Higuita committed
251
    }
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278

    function setStars(stars)
    {

        switch (parseInt(stars))
        {
        case 0:
            return  " ";

        case 1:
            return  "\xe2\x98\x86 ";

        case 2:
            return "\xe2\x98\x86 \xe2\x98\x86 ";

        case 3:
            return  "\xe2\x98\x86 \xe2\x98\x86 \xe2\x98\x86 ";

        case 4:
            return  "\xe2\x98\x86 \xe2\x98\x86 \xe2\x98\x86 \xe2\x98\x86 ";

        case 5:
            return "\xe2\x98\x86 \xe2\x98\x86 \xe2\x98\x86 \xe2\x98\x86 \xe2\x98\x86 ";

        default: return "error";
        }
    }
Camilo Higuita's avatar
Camilo Higuita committed
279
}