1 /*****************************************************************************
2 * Copyright (C) 2019 VLC authors and VideoLAN
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * ( at your option ) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17 *****************************************************************************/
18 import QtQuick.Controls 2.4
20 import QtQml.Models 2.2
21 import QtQuick.Layouts 1.3
23 import org.videolan.medialib 0.1
25 import "qrc:///util/" as Util
26 import "qrc:///widgets/" as Widgets
27 import "qrc:///style/"
29 Widgets.NavigableFocusScope {
31 property alias model: delegateModel.model
32 property var sortModel: [
33 { text: i18n.qtr("Alphabetic"), criteria: "title" }
38 Util.SelectableDelegateModel {
40 model: MLArtistModel {
44 Component.onCompleted: {
45 artistId = items.get(0).model.id
48 delegate: Widgets.ListItem {
49 height: VLCStyle.icon_normal + VLCStyle.margin_small
50 width: artistList.width
52 color: VLCStyle.colors.getBgColor(delegateModel.inSelected, this.hovered, this.activeFocus)
54 cover: Widgets.RoundImage {
55 source: model.cover || VLCStyle.noArtArtistSmall
56 height: VLCStyle.icon_normal
57 width: VLCStyle.icon_normal
58 radius: VLCStyle.icon_normal
61 line1: model.name || i18n.qtr("Unknown artist")
67 delegateModel.updateSelection( modifier , artistList.currentIndex, index)
68 artistList.currentIndex = index
69 artistList.forceActiveFocus()
72 onItemDoubleClicked: {
73 if (keys === Qt.RightButton)
74 medialib.addAndPlay( model.id )
76 view.forceActiveFocus()
80 function actionAtIndex(index) {
81 view.forceActiveFocus()
86 *define the intial position/selection
87 * This is done on activeFocus rather than Component.onCompleted because delegateModel.
88 * selectedGroup update itself after this event
90 onActiveFocusChanged: {
91 if (activeFocus && delegateModel.items.count > 0 && delegateModel.selectedGroup.count === 0) {
93 if (view.currentIndex !== -1)
94 initialIndex = view.currentIndex
95 delegateModel.items.get(initialIndex).inSelected = true
96 view.currentIndex = initialIndex
102 visible: delegateModel.items.count > 0
104 Widgets.KeyNavigableListView {
105 width: parent.width * 0.25
106 height: parent.height
111 modelCount: delegateModel.items.count
115 onSelectAll: delegateModel.selectAll()
116 onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
117 onCurrentIndexChanged: {
118 root.artistId = delegateModel.items.get(artistList.currentIndex).model.id
121 navigationParent: root
122 navigationRightItem: view
123 navigationCancel: function() {
124 if (artistList.currentIndex <= 0)
125 defaultNavigationCancel()
127 artistList.currentIndex = 0;
134 width: parent.width * 0.75
135 height: parent.height
137 property alias currentIndex: albumSubView.currentIndex
143 header: ArtistTopBanner {
145 width: albumSubView.width
146 artist: (artistList.currentIndex >= 0)
147 ? delegateModel.items.get(artistList.currentIndex).model
149 navigationParent: root
150 navigationLeftItem: artistList
151 navigationDown: function() {
152 artistBanner.focus = false
153 view.forceActiveFocus()
160 navigationParent: root
161 navigationUpItem: albumSubView.headerItem
162 navigationLeftItem: artistList
170 horizontalAlignment: Text.AlignHCenter
171 verticalAlignment: Text.AlignVCenter
172 visible: delegateModel.items.count === 0
173 font.pixelSize: VLCStyle.fontHeight_xxlarge
174 color: root.activeFocus ? VLCStyle.colors.accent : VLCStyle.colors.text
175 wrapMode: Text.WordWrap
176 text: i18n.qtr("No artists found\nPlease try adding sources, by going to the Network tab")