ListBrowserView.qml 6.25 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
 */

import QtQuick 2.7
Alexander Stippich's avatar
Alexander Stippich committed
8
import QtQuick.Controls 2.2
9
import QtQuick.Window 2.2
Alexander Stippich's avatar
Alexander Stippich committed
10
import QtQml.Models 2.2
11 12
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
13
import org.kde.kirigami 2.12 as Kirigami
14
import org.kde.elisa 1.0
15

16
FocusScope {
17
    id: listView
18

19 20 21 22
    property bool isSubPage: false
    property alias mainTitle: navigationBar.mainTitle
    property alias secondaryTitle: navigationBar.secondaryTitle
    property alias image: navigationBar.image
23
    property int databaseId
24
    property alias delegate: delegateModel.delegate
25
    property bool showSection: false
26
    property AbstractProxyModel contentModel
27
    property alias expandedFilterView: navigationBar.expandedFilterView
28
    property bool haveTreeModel: false
29 30 31
    property alias showRating: navigationBar.showRating
    property alias allowArtistNavigation: navigationBar.allowArtistNavigation
    property var delegateWidth: scrollBar.visible ? contentDirectoryView.width - scrollBar.width : contentDirectoryView.width
32
    property alias currentIndex: contentDirectoryView.currentIndex
33
    property alias enableSorting: navigationBar.enableSorting
34 35 36 37 38
    property alias sortRole: navigationBar.sortRole
    property alias sortRoles: navigationBar.sortRoles
    property alias sortRoleNames: navigationBar.sortRoleNames
    property alias sortOrderNames: navigationBar.sortOrderNames
    property alias sortOrder: navigationBar.sortOrder
39
    property var stackView
40 41
    property alias showEnqueueButton: navigationBar.showEnqueueButton
    property alias showCreateRadioButton: navigationBar.showCreateRadioButton
Jerome Guidon's avatar
Jerome Guidon committed
42
    property alias navigationBar: navigationBar
43
    property int depth: 1
44
    property alias viewManager: navigationBar.viewManager
45
    property bool suppressNoDataPlaceholderMessage: false
46

47
    signal goBackRequested()
48
    signal showArtist(var name)
49

50 51 52 53 54 55 56 57 58
    function goToBack() {
        if (haveTreeModel) {
            delegateModel.rootIndex = delegateModel.parentModelIndex()
            --depth
        } else {
            listView.goBackRequested()
        }
    }

59 60 61 62 63 64 65 66 67
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

    Theme {
        id: elisaTheme
    }

68 69
    DelegateModel {
        id: delegateModel
70 71

        model: listView.contentModel
72 73
    }

74 75 76 77
    ColumnLayout {
        anchors.fill: parent
        spacing: 0

78 79 80
        NavigationActionBar {
            id: navigationBar

81
            enableGoBack: listView.isSubPage || depth > 1
82

83
            Layout.fillWidth: true
84

85 86 87 88 89 90 91 92 93
            Loader {
                active: listView.contentModel

                sourceComponent: Binding {
                    target: listView.contentModel
                    property: 'filterText'
                    when: listView.contentModel
                    value: navigationBar.filterText
                }
94 95
            }

96 97 98 99 100 101 102 103 104
            Loader {
                active: listView.contentModel

                sourceComponent: Binding {
                    target: listView.contentModel
                    property: 'filterRating'
                    when: listView.contentModel
                    value: navigationBar.filterRating
                }
105 106
            }

107 108 109 110 111 112 113 114 115 116 117
            Loader {
                active: listView.contentModel && navigationBar.enableSorting

                sourceComponent: Binding {
                    target: listView.contentModel
                    property: 'sortRole'
                    when: listView.contentModel && navigationBar.enableSorting
                    value: navigationBar.sortRole
                }
            }

Matthieu Gallien's avatar
Matthieu Gallien committed
118
            onEnqueue: contentModel.enqueueToPlayList(delegateModel.rootIndex)
119

Matthieu Gallien's avatar
Matthieu Gallien committed
120
            onReplaceAndPlay: contentModel.replaceAndPlayOfPlayList(delegateModel.rootIndex)
121

122 123 124
            onGoBack: {
                listView.goToBack()
            }
125 126

            onShowArtist: listView.showArtist(listView.contentModel.sourceModel.author)
127

128 129 130 131 132 133 134 135 136 137
            onSortOrderChanged: {
                if (!contentModel || !navigationBar.enableSorting) {
                    return
                }

                if ((contentModel.sortedAscending && sortOrder !== Qt.AscendingOrder) ||
                        (!contentModel.sortedAscending && sortOrder !== Qt.DescendingOrder)) {
                    contentModel.sortModel(sortOrder)
                }
            }
138 139 140 141 142 143 144
        }

        Rectangle {
            color: myPalette.base

            Layout.fillHeight: true
            Layout.fillWidth: true
145
            Layout.margins: 2
146

147 148
            ListView {
                id: contentDirectoryView
149
                anchors.fill: parent
150

151 152 153 154
                Accessible.role: Accessible.List
                Accessible.name: mainTitle
                Accessible.description: mainTitle

155 156
                activeFocusOnTab: true
                keyNavigationEnabled: true
157

158 159
                model: delegateModel

160 161
                currentIndex: -1

162 163 164 165 166 167 168 169
                section.property: (showSection ? 'discNumber' : '')
                section.criteria: ViewSection.FullString
                section.labelPositioning: ViewSection.InlineLabels
                section.delegate: TracksDiscHeader {
                    discNumber: section
                    width: scrollBar.visible ? (!LayoutMirroring.enabled ? contentDirectoryView.width - scrollBar.width : contentDirectoryView.width) : contentDirectoryView.width
                }

170 171 172 173 174
                ScrollBar.vertical: ScrollBar {
                    id: scrollBar
                }
                boundsBehavior: Flickable.StopAtBounds
                clip: true
175 176 177 178 179 180

                ScrollHelper {
                    id: scrollHelper
                    flickable: contentDirectoryView
                    anchors.fill: contentDirectoryView
                }
181

182 183 184
                Kirigami.PlaceholderMessage {
                    anchors.centerIn: parent
                    width: parent.width - (Kirigami.Units.largeSpacing * 4)
185
                    visible: contentDirectoryView.count === 0 && !suppressNoDataPlaceholderMessage
186
                    text: i18n("Nothing to display")
187 188
                }

189 190 191
                onCountChanged: if (count === 0) {
                                    currentIndex = -1;
                                }
192 193 194 195
            }
        }
    }
}
196