qml: show icons as header and centre align text for duration column in MusicTrackList
[vlc.git] / modules / gui / qt / medialibrary / qml / MusicTrackListDisplay.qml
blob11b583120780cba8d6c31b38f986b946e02ebdc9
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 2.11
19 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:///widgets/" as Widgets
26 import "qrc:///style/"
28 Widgets.KeyNavigableTableView {
29     id: root
31     property var sortModelSmall: [
32         { isPrimary: true, criteria: "title",       width: VLCStyle.colWidth(1), text: i18n.qtr("Title"),    showSection: "title", colDelegate: titleDelegate, headerDelegate: titleHeaderDelegate },
33         { criteria: "album_title", width: VLCStyle.colWidth(1), text: i18n.qtr("Album"),    showSection: "album_title" },
34         { criteria: "main_artist", width: VLCStyle.colWidth(1), text: i18n.qtr("Artist"),   showSection: "main_artist" },
35         { criteria: "durationShort", width: VLCStyle.colWidth(1), showSection: "", colDelegate: tableColumns.timeColDelegate, headerDelegate: tableColumns.timeHeaderDelegate },
36     ]
38     property var sortModelMedium: [
39         { isPrimary: true, criteria: "title",       width: VLCStyle.colWidth(2), text: i18n.qtr("Title"),    showSection: "title", colDelegate: titleDelegate, headerDelegate: titleHeaderDelegate },
40         { criteria: "album_title", width: VLCStyle.colWidth(2), text: i18n.qtr("Album"),    showSection: "album_title" },
41         { criteria: "main_artist", width: VLCStyle.colWidth(1), text: i18n.qtr("Artist"),   showSection: "main_artist" },
42         { criteria: "durationShort", width: VLCStyle.colWidth(1), showSection: "", colDelegate: tableColumns.timeColDelegate, headerDelegate: tableColumns.timeHeaderDelegate },
43     ]
45     property var sortModelLarge: [
46         { isPrimary: true, criteria: "title",       width: VLCStyle.colWidth(2), text: i18n.qtr("Title"),    showSection: "title", colDelegate: titleDelegate, headerDelegate: titleHeaderDelegate },
47         { criteria: "album_title", width: VLCStyle.colWidth(2), text: i18n.qtr("Album"),    showSection: "album_title" },
48         { criteria: "main_artist", width: VLCStyle.colWidth(2), text: i18n.qtr("Artist"),   showSection: "main_artist" },
49         { criteria: "durationShort", width: VLCStyle.colWidth(1), showSection: "", colDelegate: tableColumns.timeColDelegate, headerDelegate: tableColumns.timeHeaderDelegate },
50         { criteria: "track_number",width: VLCStyle.colWidth(1), text: i18n.qtr("Track"), showSection: "" },
51         { criteria: "disc_number", width: VLCStyle.colWidth(1), text: i18n.qtr("Disc"),  showSection: "" },
52     ]
54     property Component titleDelegate: RowLayout {
55         property var rowModel: parent.rowModel
56         property var model: parent.colModel
57         readonly property bool containsMouse: parent.containsMouse
58         readonly property bool currentlyFocused: parent.currentlyFocused
60         anchors.fill: parent
61         spacing: VLCStyle.margin_normal
63         Image {
64             source: !rowModel ? VLCStyle.noArtCover : (rowModel.cover || VLCStyle.noArtCover)
65             mipmap: true // this widget can down scale the source a lot, so for better visuals we use mipmap
67             Layout.preferredHeight: VLCStyle.trackListAlbumCover_heigth
68             Layout.preferredWidth: VLCStyle.trackListAlbumCover_width
70             Widgets.PlayCover {
71                 anchors.fill: parent
72                 iconSize: VLCStyle.play_cover_small
73                 visible: currentlyFocused || containsMouse
75                 onIconClicked: medialib.addAndPlay( rowModel.id )
76             }
77         }
79         Widgets.ListLabel {
80             text: !rowModel ? "" : (rowModel[model.criteria] || "")
82             Layout.fillHeight: true
83             Layout.fillWidth: true
84         }
85     }
87     property Component titleHeaderDelegate: Row {
88         spacing: VLCStyle.margin_normal
90         Widgets.IconLabel {
91             width: VLCStyle.heightAlbumCover_xsmall
92             horizontalAlignment: Text.AlignHCenter
93             text: VLCIcons.album_cover
94             color: VLCStyle.colors.caption
95         }
97         Widgets.CaptionLabel {
98             text: model.text || ""
99         }
100     }
102     sortModel: ( width < VLCStyle.colWidth(6) ) ? sortModelSmall
103                                                 : ( width < VLCStyle.colWidth(9) ) ? sortModelMedium : sortModelLarge
104     section.property: "title_first_symbol"
106     headerColor: VLCStyle.colors.bg
108     model: MLAlbumTrackModel {
109         id: rootmodel
110         ml: medialib
111         onSortCriteriaChanged: {
112             switch (rootmodel.sortCriteria) {
113             case "title":
114             case "album_title":
115             case "main_artist":
116                 section.property = rootmodel.sortCriteria + "_first_symbol"
117                 break;
118             default:
119                 section.property = ""
120             }
121         }
122     }
124     property alias parentId: rootmodel.parentId
126     colDelegate: Item {
127         anchors.fill: parent
129         property var rowModel: parent.rowModel
130         property var model: parent.colModel
132         Text {
133             anchors.fill:parent
135             text: !rowModel ? "" : (rowModel[model.criteria] || "")
136             elide: Text.ElideRight
137             font.pixelSize: VLCStyle.fontSize_normal
138             color: (model.isPrimary)? VLCStyle.colors.text : VLCStyle.colors.textDisabled
140             anchors {
141                 fill: parent
142                 leftMargin: VLCStyle.margin_xsmall
143                 rightMargin: VLCStyle.margin_xsmall
144             }
145             verticalAlignment: Text.AlignVCenter
146             horizontalAlignment: Text.AlignLeft
147         }
148     }
150     onActionForSelection:  medialib.addAndPlay(model.getIdsForIndexes( selection ))
152     Widgets.TableColumns {
153         id: tableColumns
154     }