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 *****************************************************************************/
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 {
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 },
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 },
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: "" },
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
61 spacing: VLCStyle.margin_normal
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
72 iconSize: VLCStyle.play_cover_small
73 visible: currentlyFocused || containsMouse
75 onIconClicked: medialib.addAndPlay( rowModel.id )
80 text: !rowModel ? "" : (rowModel[model.criteria] || "")
82 Layout.fillHeight: true
83 Layout.fillWidth: true
87 property Component titleHeaderDelegate: Row {
88 spacing: VLCStyle.margin_normal
91 width: VLCStyle.heightAlbumCover_xsmall
92 horizontalAlignment: Text.AlignHCenter
93 text: VLCIcons.album_cover
94 color: VLCStyle.colors.caption
97 Widgets.CaptionLabel {
98 text: model.text || ""
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 {
111 onSortCriteriaChanged: {
112 switch (rootmodel.sortCriteria) {
116 section.property = rootmodel.sortCriteria + "_first_symbol"
119 section.property = ""
124 property alias parentId: rootmodel.parentId
129 property var rowModel: parent.rowModel
130 property var model: parent.colModel
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
142 leftMargin: VLCStyle.margin_xsmall
143 rightMargin: VLCStyle.margin_xsmall
145 verticalAlignment: Text.AlignVCenter
146 horizontalAlignment: Text.AlignLeft
150 onActionForSelection: medialib.addAndPlay(model.getIdsForIndexes( selection ))
152 Widgets.TableColumns {