qml: use RoundImage in artist view rather than local implementation
[vlc.git] / modules / gui / qt / medialibrary / qml / MusicArtistsDisplay.qml
blob5162489328f5da635c7b81767674169293eef4c1
1 /*****************************************************************************
2  * Copyright (C) 2019 VLC authors and VideoLAN
3  *
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.
8  *
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.
13  *
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
19 import QtQuick 2.11
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 {
30     id: root
31     property alias model: delegateModel.model
32     property var sortModel: [
33         { text: i18n.qtr("Alphabetic"),  criteria: "title" }
34     ]
36     property var artistId
38     Util.SelectableDelegateModel {
39         id: delegateModel
40         model: MLArtistModel {
41             ml: medialib
42         }
44         Component.onCompleted: {
45             artistId = items.get(0).model.id
46         }
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
59             }
61             line1: model.name || i18n.qtr("Unknown artist")
63             actionButtons: []
65             onItemClicked: {
66                 artistId = model.id
67                 delegateModel.updateSelection( modifier , artistList.currentIndex, index)
68                 artistList.currentIndex = index
69                 artistList.forceActiveFocus()
70             }
72             onItemDoubleClicked: {
73                 if (keys === Qt.RightButton)
74                     medialib.addAndPlay( model.id )
75                 else
76                     view.forceActiveFocus()
77             }
78         }
80         function actionAtIndex(index) {
81             view.forceActiveFocus()
82         }
83     }
85     /*
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
89      */
90     onActiveFocusChanged: {
91         if (activeFocus && delegateModel.items.count > 0 && delegateModel.selectedGroup.count === 0) {
92             var initialIndex = 0
93             if (view.currentIndex !== -1)
94                 initialIndex = view.currentIndex
95             delegateModel.items.get(initialIndex).inSelected = true
96             view.currentIndex = initialIndex
97         }
98     }
100     Row {
101         anchors.fill: parent
102         visible: delegateModel.items.count > 0
104         Widgets.KeyNavigableListView {
105             width: parent.width * 0.25
106             height: parent.height
108             id: artistList
109             spacing: 4
110             model: delegateModel
111             modelCount: delegateModel.items.count
113             focus: true
115             onSelectAll: delegateModel.selectAll()
116             onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
117             onCurrentIndexChanged: {
118                 root.artistId = delegateModel.items.get(artistList.currentIndex).model.id
119             }
121             navigationParent: root
122             navigationRightItem: view
123             navigationCancel: function() {
124                 if (artistList.currentIndex <= 0)
125                     defaultNavigationCancel()
126                 else
127                     artistList.currentIndex = 0;
128             }
130         }
132         FocusScope {
133             id: view
134             width: parent.width * 0.75
135             height: parent.height
137             property alias currentIndex: albumSubView.currentIndex
139             MusicAlbumsDisplay {
140                 id: albumSubView
141                 anchors.fill: parent
143                 header: ArtistTopBanner {
144                     id: artistBanner
145                     width: albumSubView.width
146                     artist: (artistList.currentIndex >= 0)
147                             ? delegateModel.items.get(artistList.currentIndex).model
148                             : ({})
149                     navigationParent: root
150                     navigationLeftItem: artistList
151                     navigationDown: function() {
152                         artistBanner.focus = false
153                         view.forceActiveFocus()
154                     }
155                 }
157                 focus: true
158                 parentId: artistId
160                 navigationParent: root
161                 navigationUpItem: albumSubView.headerItem
162                 navigationLeftItem: artistList
163             }
165         }
166     }
168     Label {
169         anchors.fill: parent
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")
177     }