PlayListBasicView.qml 5.07 KB
Newer Older
1
/*
Matthieu Gallien's avatar
Matthieu Gallien committed
2 3 4
   SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>

   SPDX-License-Identifier: LGPL-3.0-or-later
5 6 7 8 9 10 11 12
 */

import QtQuick 2.10
import QtQuick.Controls 2.2
import QtQml.Models 2.1

import org.kde.elisa 1.0

13 14
ScrollView {
    id: scrollView
15 16

    property alias playListModel: playListModelDelegate.model
17
    property string title
18 19 20 21 22

    signal startPlayback()
    signal pausePlayback()
    signal displayError(var errorText)

23 24
    ListView {
        id: playListView
25

26 27 28 29
        focus: true
        clip: true
        keyNavigationEnabled: true
        activeFocusOnTab: true
30

31
        currentIndex: -1
32

33 34
        Accessible.role: Accessible.List
        Accessible.name: scrollView.title
35

36 37 38 39 40 41 42
        section.property: 'albumSection'
        section.criteria: ViewSection.FullString
        section.labelPositioning: ViewSection.InlineLabels
        section.delegate: BasicPlayListAlbumHeader {
            headerData: JSON.parse(section)
            width: playListView.width
        }
43

44 45 46
        /* currently disabled animations due to display corruption
        because of https://bugreports.qt.io/browse/QTBUG-49868
        causing https://bugs.kde.org/show_bug.cgi?id=406524
47
        and https://bugs.kde.org/show_bug.cgi?id=398093
48 49 50 51 52 53 54
        add: Transition {
            NumberAnimation {
                property: "opacity";
                from: 0;
                to: 1;
                duration: Kirigami.Units.shortDuration }
        }
55

56 57 58 59 60 61 62
        populate: Transition {
            NumberAnimation {
                property: "opacity";
                from: 0;
                to: 1;
                duration: Kirigami.Units.shortDuration }
        }
63

64 65 66 67 68 69 70
        remove: Transition {
            NumberAnimation {
                property: "opacity";
                from: 1.0;
                to: 0;
                duration: Kirigami.Units.shortDuration }
        }
71

72 73 74 75 76 77 78
        displaced: Transition {
            NumberAnimation {
                properties: "x,y";
                duration: Kirigami.Units.shortDuration
                easing.type: Easing.InOutQuad }
        }
        */
79

80 81
        model: DelegateModel {
            id: playListModelDelegate
82

83 84 85
            groups: [
                DelegateModelGroup { name: "selected" }
            ]
86

87 88 89 90
            delegate: DraggableItem {
                id: item
                width: playListView.width
                placeholderHeight: topItem.placeholderHeight
91 92 93

                focus: true

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
                PlayListEntry {
                    id: entry

                    focus: true

                    width: parent.width

                    index: model.index
                    isAlternateColor: item.DelegateModel.itemsIndex % 2
                    isSelected: playListView.currentIndex === index
                    containsMouse: item.containsMouse

                    databaseId: model.databaseId ? model.databaseId : 0
                    entryType: model.entryType ? model.entryType : ElisaUtils.Unknown
                    title: model.title ? model.title : ''
                    artist: model.artist ? model.artist : ''
                    album: model.album ? model.album : ''
                    albumArtist: model.albumArtist ? model.albumArtist : ''
                    duration: model.duration ? model.duration : ''
                    fileName: model.trackResource ? model.trackResource : ''
                    imageUrl: model.imageUrl ? model.imageUrl : ''
                    trackNumber: model.trackNumber ? model.trackNumber : -1
                    discNumber: model.discNumber ? model.discNumber : -1
                    rating: model.rating ? model.rating : 0
                    isSingleDiscAlbum: model.isSingleDiscAlbum !== undefined ? model.isSingleDiscAlbum : true
                    isValid: model.isValid
                    isPlaying: model.isPlaying
121
                    metadataModifiableRole: model.metadataModifiableRole
122

123 124 125 126
                    onStartPlayback: scrollView.startPlayback()
                    onPausePlayback: scrollView.pausePlayback()
                    onRemoveFromPlaylist: scrollView.playListModel.removeRow(trackIndex)
                    onSwitchToTrack: scrollView.playListModel.switchTo(trackIndex)
127 128 129 130 131

                    onActiveFocusChanged: {
                        if (activeFocus && playListView.currentIndex !== index) {
                            playListView.currentIndex = index
                        }
132 133
                    }
                }
134

135
                draggedItemParent: playListView
136

137 138 139 140
                onClicked: {
                    playListView.currentIndex = index
                    entry.forceActiveFocus()
                }
141

142 143 144 145 146
                onDoubleClicked: {
                    if (model.isValid) {
                        scrollView.playListModel.switchTo(model.index)
                        scrollView.startPlayback()
                    }
147 148
                }

149 150 151
                onMoveItemRequested: {
                    playListModel.moveRow(from, to);
                }
152 153
            }
        }
154

155 156 157 158
        onCountChanged: if (count === 0) {
                            currentIndex = -1;
                        }
    }
159
}