TableDelegate.qml 3.38 KB
Newer Older
1
import QtQuick 2.10
Camilo Higuita's avatar
Camilo Higuita committed
2
import QtQuick.Layouts 1.3
3
import QtQuick.Controls 2.10
4
import QtGraphicalEffects 1.0
camilo higuita's avatar
camilo higuita committed
5

6
import org.kde.kirigami 2.7 as Kirigami
Camilo Higuita's avatar
Camilo Higuita committed
7
import org.kde.mauikit 1.0 as Maui
Camilo Higuita's avatar
Camilo Higuita committed
8

camilo higuita's avatar
camilo higuita committed
9 10 11
import "../../view_models"
import "../../utils/Help.js" as H

12
Maui.ItemDelegate
Camilo Higuita's avatar
Camilo Higuita committed
13
{
14
    id: control
15

16 17
    isCurrentItem: ListView.isCurrentItem || isSelected

18
    property bool showQuickActions: true
19 20
    property bool number : false
    property bool coverArt : false
21 22 23
    property bool showEmblem: true
    property bool keepEmblemOverlay: selectionMode
    property bool isSelected : false
24 25
    property string trackMood : model.color

26
    readonly property color bgColor : Kirigami.Theme.backgroundColor
27
    readonly property int altHeight : Maui.Style.rowHeight * 1.4
Camilo Higuita's avatar
Camilo Higuita committed
28 29
    readonly property bool sameAlbum :
    {
30
        if(coverArt)
Camilo Higuita's avatar
Camilo Higuita committed
31
        {
32
            if(list.get(index-1))
33
            {
34
                if(list.get(index-1).album === album && list.get(index-1).artist === artist) true
35 36
                else false
            }else false
Camilo Higuita's avatar
Camilo Higuita committed
37 38 39
        }else false
    }

Camilo Higuita's avatar
Camilo Higuita committed
40
    width: parent.width
41
    height: sameAlbum ? Maui.Style.rowHeight : altHeight
camilo higuita's avatar
camilo higuita committed
42 43
    padding: 0

44 45
    rightPadding: leftPadding
    leftPadding: Maui.Style.space.small
46

47
    signal play()
48
    signal append()
49
    signal leftClicked()
50
    signal leftEmblemClicked(int index)
camilo higuita's avatar
camilo higuita committed
51

52 53
    signal artworkCoverClicked()
    signal artworkCoverDoubleClicked()
54

55
    Kirigami.Theme.backgroundColor: trackMood.length > 0 ? Qt.tint(bgColor, Qt.rgba(Qt.lighter(trackMood, 1.3).r, Qt.lighter(trackMood, 1.3).g, Qt.lighter(trackMood, 1.3).b,  0.3)):  bgColor
camilo higuita's avatar
camilo higuita committed
56

57 58 59 60
    function rate(stars)
    {
        trackRating.text = stars
    }
61

62 63 64
    RowLayout
    {
        anchors.fill: parent
camilo higuita's avatar
camilo higuita committed
65

66
        Item
67
        {
68 69 70
            Layout.fillHeight: true
            Layout.preferredWidth: _leftEmblemIcon.height + Maui.Style.space.small
            visible: (control.keepEmblemOverlay || control.isSelected) && control.showEmblem
camilo higuita's avatar
camilo higuita committed
71

72 73 74 75 76 77 78 79 80
            Maui.Badge
            {
                id: _leftEmblemIcon
                anchors.centerIn: parent
                iconName: control.isSelected ? "list-remove" : "list-add"
                onClicked: control.leftEmblemClicked(index)
                size: Maui.Style.iconSizes.small
            }
        }
camilo higuita's avatar
camilo higuita committed
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
        Maui.ListItemTemplate
        {
            id: _template
            Layout.fillWidth: true
            Layout.fillHeight: true
            isCurrentItem: control.isCurrentItem
            iconSizeHint: height - Maui.Style.space.small
            label1.text: control.number ? model.track + ". " + model.title :  model.title
            label2.text: model.artist + " | " + model.album
            label2.visible: control.coverArt ? !control.sameAlbum : true

            label3.text: model.fav ? (model.fav == "1" ? "\uf2D1" : "") : ""
            label3.font.family: "Material Design Icons"
            label4.font.family: "Material Design Icons"
            label4.text: model.rate ? H.setStars(model.rate) : ""

            iconVisible: !control.sameAlbum && control.coverArt
            imageSource: model.artwork ? model.artwork : "qrc:/assets/cover.png"
        }
101 102 103 104 105 106 107 108 109

        ToolButton
        {
            Layout.fillHeight: true
            Layout.preferredWidth: implicitWidth
            visible: showQuickActions && (Kirigami.Settings.isMobile ? true : control.hovered)
            icon.name: "media-playlist-append"
            onClicked: control.append()
        }
camilo higuita's avatar
camilo higuita committed
110
    }
Camilo Higuita's avatar
Camilo Higuita committed
111
}