MusicAlbumsGridExpandDelegate.qml 8.74 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*****************************************************************************
 * Copyright (C) 2019 VLC authors and VideoLAN
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * ( at your option ) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
21
import QtQml.Models 2.11
22
23

import org.videolan.medialib 0.1
24
import org.videolan.controls 0.1
25

26
import "qrc:///widgets/" as Widgets
27
import "qrc:///util/Helpers.js" as Helpers
28
29
import "qrc:///style/"

30
Widgets.NavigableFocusScope {
31
    id: root
32

33
    property var model
34

35
    signal retract()
36

37
38
39
40
41
42
43
44
45
46
47
    implicitWidth: layout.implicitWidth

    implicitHeight: {
        var verticalMargins = layout.anchors.topMargin + layout.anchors.bottomMargin
        if (tracks.contentHeight < artAndControl.height)
            return artAndControl.height + verticalMargins
        return Math.min(tracks.contentHeight
                        , tracks.listView.headerItem.height + tracks.rowHeight * 6) // show a maximum of 6 rows
                + verticalMargins
    }

Prince Gupta's avatar
Prince Gupta committed
48
49
50
51
    // components should shrink with change of height, but it doesn't happen fast enough
    // causing expand and shrink animation bit laggy, so clip the delegate to fix it
    clip: true

52
53
54
    Rectangle {
        anchors.fill: parent
        color: VLCStyle.colors.bgAlt
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

        Rectangle {
            anchors {
                top: parent.top
                left: parent.left
                right: parent.right
            }
            color: VLCStyle.colors.buttonBorder
            height: VLCStyle.expandDelegate_border
        }

        Rectangle {
            anchors {
                bottom: parent.bottom
                left: parent.left
                right: parent.right
            }
            color: VLCStyle.colors.buttonBorder
            height: VLCStyle.expandDelegate_border
        }
75
76
    }

77
    RowLayout {
78
        id: layout
79
80

        anchors.fill: parent
81
82
83
84
85
        anchors.leftMargin: VLCStyle.margin_normal
        anchors.topMargin: VLCStyle.margin_large
        anchors.rightMargin: VLCStyle.margin_small
        anchors.bottomMargin: VLCStyle.margin_xxsmall
        spacing: VLCStyle.margin_large
86
87
88

        FocusScope {
            id: artAndControl
89
90
91
92

            Layout.preferredHeight: artAndControlLayout.implicitHeight
            Layout.preferredWidth: artAndControlLayout.implicitWidth
            Layout.alignment: Qt.AlignTop
93

94
95
            focus: true

96
97
            Column {
                id: artAndControlLayout
98

99
                spacing: VLCStyle.margin_normal
100
                bottomPadding: VLCStyle.margin_large
101
102

                /* A bigger cover for the album */
103
                Item {
104
105
                    height: VLCStyle.expandCover_music_height
                    width: VLCStyle.expandCover_music_width
106

107
                    RoundImage {
108
                        id: expand_cover_id
109

110
111
112
113
114
115
116
117
118
119
120
                        height: VLCStyle.expandCover_music_height
                        width: VLCStyle.expandCover_music_width
                        radius: VLCStyle.expandCover_music_radius
                        source: model.cover || VLCStyle.noArtAlbum
                        sourceSize: Qt.size(width, height)
                    }

                    Widgets.ListCoverShadow {
                        source: expand_cover_id
                        anchors.fill: parent
                    }
121
122
                }

123
                Widgets.NavigableRow {
124
                    id: actionButtons
125

126
127
                    focus: true
                    width: expand_cover_id.width
128
                    spacing: VLCStyle.margin_small
129

130
                    Layout.alignment: Qt.AlignCenter
131

132
133
134
                    model: ObjectModel {
                        Widgets.TabButtonExt {
                            id: playActionBtn
135

136
137
                            iconTxt: VLCIcons.play_outline
                            text: i18n.qtr("Play")
138
139
                            onClicked: medialib.addAndPlay( model.id )
                        }
140

141
142
                        Widgets.TabButtonExt {
                            id: enqueueActionBtn
143

144
145
                            iconTxt: VLCIcons.enqueue
                            text: i18n.qtr("Enqueue")
146
                            onClicked: medialib.addToPlaylist( model.id )
147
148
149
                        }
                    }

150
                    navigationParent: root
151
                    navigationRightItem: tracks
152
                }
153

154
155
156
            }
        }

157
158
159
        /* The list of the tracks available */
        MusicTrackListDisplay {
            id: tracks
160

161
            readonly property int _nbCols: VLCStyle.gridColumnsForWidth(tracks.availableRowWidth)
162

163
164
            property Component titleDelegate: RowLayout {
                property var rowModel: parent.rowModel
165

166
                anchors.fill: parent
167

168
169
170
171
                Widgets.ListLabel {
                    text: !!rowModel && !!rowModel.track_number ? rowModel.track_number : ""
                    color: foregroundColor
                    font.weight: Font.Normal
172

173
174
175
                    Layout.fillHeight: true
                    Layout.leftMargin: VLCStyle.margin_xxsmall
                    Layout.preferredWidth: VLCStyle.margin_large
176
177
                }

178
179
180
                Widgets.ListLabel {
                    text: !!rowModel && !!rowModel.title ? rowModel.title : ""
                    color: foregroundColor
181

182
183
                    Layout.fillHeight: true
                    Layout.fillWidth: true
184
                }
185
186
            }

187
            property Component titleHeaderDelegate: Row {
188

189
190
191
192
                Widgets.CaptionLabel {
                    text: "#"
                    width: VLCStyle.margin_large
                }
193

194
195
196
                Widgets.CaptionLabel {
                    text: i18n.qtr("Title")
                }
197
198
            }

199
200
201
202
            header: Column {
                width: tracks.width
                height: implicitHeight
                bottomPadding: VLCStyle.margin_large
203

204
205
                RowLayout {
                    width: parent.width
206

207
208
209
                    /* The title of the albums */
                    Widgets.SubtitleLabel {
                        id: expand_infos_title_id
210

211
                        text: model.title || i18n.qtr("Unknown title")
212

213
                        Layout.fillWidth: true
214
215
                    }

216
217
                    Widgets.IconLabel {
                        text: VLCIcons.close
218

219
220
221
222
223
224
                        Layout.rightMargin: VLCStyle.margin_small

                        MouseArea {
                            anchors.fill: parent
                            onClicked: root.retract()
                        }
225
226
227
                    }
                }

228
229
                Widgets.CaptionLabel {
                    id: expand_infos_subtitle_id
230

231
232
233
234
235
                    width: parent.width
                    text: i18n.qtr("%1 - %2 - %3")
                        .arg(model.main_artist || i18n.qtr("Unknown artist"))
                        .arg(model.release_year || "")
                        .arg(Helpers.msToString(model.duration) || "")
236
                }
237
            }
238

239
240
            headerPositioning: ListView.InlineHeader
            section.property: ""
241

242
243
            Layout.fillWidth: true
            Layout.fillHeight: true
244

245
246
            rowHeight: VLCStyle.tableRow_height
            headerColor: VLCStyle.colors.bgAlt
247

248
249
250
251
            parentId: root.model.id
            onParentIdChanged: {
                currentIndex = 0
            }
252

253
254
255
256
            sortModel: [
                { isPrimary: true, criteria: "title", width: VLCStyle.colWidth(Math.max(tracks._nbCols - 1, 1)), visible: true, text: i18n.qtr("Title"), showSection: "", colDelegate: titleDelegate, headerDelegate: titleHeaderDelegate },
                { criteria: "duration",               width: VLCStyle.colWidth(1), visible: true, showSection: "", colDelegate: tableColumns.timeColDelegate, headerDelegate: tableColumns.timeHeaderDelegate },
            ]
257

258
259
            navigationParent: root
            navigationLeftItem: actionButtons
260

261
262
            Widgets.TableColumns {
                id: tableColumns
263
264
265
266
267
268
269
270
            }
        }
    }


    Keys.priority:  KeyNavigation.AfterItem
    Keys.onPressed:  defaultKeyAction(event, 0)
}