ListBrowserView.qml 4.79 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
13
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0

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
    property var stackView
35
36
    property alias showEnqueueButton: navigationBar.showEnqueueButton
    property alias showCreateRadioButton: navigationBar.showCreateRadioButton
Jerome Guidon's avatar
Jerome Guidon committed
37
    property alias navigationBar: navigationBar
38
    property int depth: 1
39

40
    signal goBackRequested()
41
    signal showArtist(var name)
42

43
44
45
46
47
48
49
50
51
    function goToBack() {
        if (haveTreeModel) {
            delegateModel.rootIndex = delegateModel.parentModelIndex()
            --depth
        } else {
            listView.goBackRequested()
        }
    }

52
53
54
55
56
57
58
59
60
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

    Theme {
        id: elisaTheme
    }

61
62
    DelegateModel {
        id: delegateModel
63
64

        model: listView.contentModel
65
66
    }

67
68
69
70
    ColumnLayout {
        anchors.fill: parent
        spacing: 0

71
72
73
        NavigationActionBar {
            id: navigationBar

74
            enableGoBack: listView.isSubPage || depth > 1
75
76
            sortOrder: contentModel.sortedAscending

77
            Layout.fillWidth: true
78

79
80
81
82
83
84
85
86
87
            Loader {
                active: listView.contentModel

                sourceComponent: Binding {
                    target: listView.contentModel
                    property: 'filterText'
                    when: listView.contentModel
                    value: navigationBar.filterText
                }
88
89
            }

90
91
92
93
94
95
96
97
98
            Loader {
                active: listView.contentModel

                sourceComponent: Binding {
                    target: listView.contentModel
                    property: 'filterRating'
                    when: listView.contentModel
                    value: navigationBar.filterRating
                }
99
100
            }

Matthieu Gallien's avatar
Matthieu Gallien committed
101
            onEnqueue: contentModel.enqueueToPlayList(delegateModel.rootIndex)
102

Matthieu Gallien's avatar
Matthieu Gallien committed
103
            onReplaceAndPlay: contentModel.replaceAndPlayOfPlayList(delegateModel.rootIndex)
104

105
106
107
            onGoBack: {
                listView.goToBack()
            }
108
109

            onShowArtist: listView.showArtist(listView.contentModel.sourceModel.author)
110
111

            onSort: contentModel.sortModel(order)
112
113
114
115
116
117
118
        }

        Rectangle {
            color: myPalette.base

            Layout.fillHeight: true
            Layout.fillWidth: true
119
            Layout.margins: 2
120

121
122
            ListView {
                id: contentDirectoryView
123
                anchors.fill: parent
124

125
126
127
128
                Accessible.role: Accessible.List
                Accessible.name: mainTitle
                Accessible.description: mainTitle

129
130
                activeFocusOnTab: true
                keyNavigationEnabled: true
131

132
133
                model: delegateModel

134
135
                currentIndex: -1

136
137
138
139
140
141
142
143
                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
                }

144
145
146
147
148
                ScrollBar.vertical: ScrollBar {
                    id: scrollBar
                }
                boundsBehavior: Flickable.StopAtBounds
                clip: true
149
150
151
152
153
154

                ScrollHelper {
                    id: scrollHelper
                    flickable: contentDirectoryView
                    anchors.fill: contentDirectoryView
                }
155
156
157
158

                onCountChanged: if (count === 0) {
                                    currentIndex = -1;
                                }
159
160
161
162
            }
        }
    }
}
163