Browse Source

qml: refactor MusicAllArtists view in separate file

pull/127/head
Prince Gupta 5 years ago
committed by Hugo Beauzée-Luyssen
parent
commit
6bdc64f40e
  1. 1
      modules/gui/qt/Makefile.am
  2. 253
      modules/gui/qt/medialibrary/qml/MusicAllArtists.qml
  3. 234
      modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
  4. 1
      modules/gui/qt/vlc.qrc
  5. 1
      po/POTFILES.in

1
modules/gui/qt/Makefile.am

@ -690,6 +690,7 @@ libqt_plugin_la_QML = \
gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml \
gui/qt/medialibrary/qml/MusicArtist.qml \
gui/qt/medialibrary/qml/MusicArtistsAlbums.qml \
gui/qt/medialibrary/qml/MusicAllArtists.qml \
gui/qt/medialibrary/qml/MusicArtistsDisplay.qml \
gui/qt/medialibrary/qml/MusicDisplay.qml \
gui/qt/medialibrary/qml/MusicGenres.qml \

253
modules/gui/qt/medialibrary/qml/MusicAllArtists.qml

@ -0,0 +1,253 @@
/*****************************************************************************
* Copyright (C) 2021 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.Controls 2.4
import QtQuick 2.11
import QtQml.Models 2.2
import QtQuick.Layouts 1.3
import org.videolan.medialib 0.1
import org.videolan.vlc 0.1
import "qrc:///util/" as Util
import "qrc:///widgets/" as Widgets
import "qrc:///main/" as MainInterface
import "qrc:///style/"
FocusScope {
id: root
readonly property int currentIndex: view.currentItem.currentIndex
property int initialIndex: 0
property alias model: artistModel
onInitialIndexChanged: resetFocus()
function requestArtistAlbumView() {
console.assert(false, "must be reimplemented")
}
function resetFocus() {
if (artistModel.count === 0)
return
var initialIndex = root.initialIndex
if (initialIndex >= artistModel.count)
initialIndex = 0
selectionModel.select(artistModel.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
if (view.currentItem) {
view.currentItem.currentIndex = initialIndex
view.currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
}
}
function _onNavigationCancel() {
if (view.currentItem.currentIndex <= 0) {
root.Navigation.defaultNavigationCancel()
} else {
view.currentItem.currentIndex = 0;
view.currentItem.positionViewAtIndex(0, ItemView.Contain);
}
}
MLArtistModel {
id: artistModel
ml: medialib
onCountChanged: {
if (artistModel.count > 0 && !selectionModel.hasSelection) {
root.resetFocus()
}
}
}
Util.SelectableDelegateModel {
id: selectionModel
model: artistModel
}
ArtistContextMenu {
id: contextMenu
model: artistModel
}
Widgets.DragItem {
id: artistsDragItem
function updateComponents(maxCovers) {
var items = selectionModel.selectedIndexes.slice(0, maxCovers).map(function (x){
return artistModel.getDataAt(x.row)
})
var title = items.map(function (item){ return item.name}).join(", ")
var covers = items.map(function (item) { return {artwork: item.cover || VLCStyle.noArtArtistSmall}})
return {
covers: covers,
title: title,
count: selectionModel.selectedIndexes.length
}
}
function getSelectedInputItem() {
return artistModel.getItemsForIndexes(selectionModel.selectedIndexes);
}
}
Component {
id: gridComponent
MainInterface.MainGridView {
id: artistGrid
anchors.fill: parent
topMargin: VLCStyle.margin_large
delegateModel: selectionModel
model: artistModel
focus: true
cellWidth: VLCStyle.colWidth(1)
cellHeight: VLCStyle.gridItem_music_height
Navigation.parentItem: root
Navigation.cancelAction: root._onNavigationCancel
onSelectAll: selectionModel.selectAll()
onSelectionUpdated: selectionModel.updateSelection( keyModifiers, oldIndex, newIndex )
onActionAtIndex: {
if (selectionModel.selectedIndexes.length > 1) {
medialib.addAndPlay( artistModel.getIdsForIndexes( selectionModel.selectedIndexes ) )
} else {
view.currentItem.currentIndex = index
requestArtistAlbumView()
medialib.addAndPlay( artistModel.getIdForIndex(index) )
}
}
Widgets.GridShadows {
id: shadows
leftPadding: (VLCStyle.colWidth(1) - shadows.coverWidth) / 2 // GridItem's rect is horizontally centered
coverWidth: VLCStyle.artistGridCover_radius
coverHeight: VLCStyle.artistGridCover_radius
coverRadius: VLCStyle.artistGridCover_radius
}
delegate: AudioGridItem {
id: gridItem
title: model.name || i18n.qtr("Unknown artist")
subtitle: model.nb_tracks > 1 ? i18n.qtr("%1 songs").arg(model.nb_tracks) : i18n.qtr("%1 song").arg(model.nb_tracks)
pictureRadius: VLCStyle.artistGridCover_radius
pictureHeight: VLCStyle.artistGridCover_radius
pictureWidth: VLCStyle.artistGridCover_radius
playCoverBorderWidth: VLCStyle.dp(3, VLCStyle.scale)
titleMargin: VLCStyle.margin_xlarge
playIconSize: VLCStyle.play_cover_small
textAlignHCenter: true
width: VLCStyle.colWidth(1)
dragItem: artistsDragItem
unselectedUnderlay: shadows.unselected
selectedUnderlay: shadows.selected
onItemClicked: artistGrid.leftClickOnItem(modifier, index)
onItemDoubleClicked: root.requestArtistAlbumView(model)
onContextMenuButtonClicked: {
artistGrid.rightClickOnItem(index)
contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
}
}
}
}
Component {
id: tableComponent
MainInterface.MainTableView {
id: artistTable
readonly property int _nbCols: VLCStyle.gridColumnsForWidth(artistTable.availableRowWidth)
anchors.fill: parent
selectionDelegateModel: selectionModel
model: artistModel
focus: true
headerColor: VLCStyle.colors.bg
dragItem: artistsDragItem
rowHeight: VLCStyle.tableCoverRow_height
headerTopPadding: VLCStyle.margin_normal
Navigation.parentItem: root
Navigation.cancelAction: root._onNavigationCancel
onActionForSelection: {
if (selection.length > 1) {
medialib.addAndPlay( artistModel.getIdsForIndexes( selection ) )
} else if ( selection.length === 1) {
requestArtistAlbumView()
medialib.addAndPlay( artistModel.getIdForIndex( selection[0] ) )
}
}
sortModel: [
{ isPrimary: true, criteria: "name", width: VLCStyle.colWidth(Math.max(artistTable._nbCols - 1, 1)), text: i18n.qtr("Name"), headerDelegate: tableColumns.titleHeaderDelegate, colDelegate: tableColumns.titleDelegate },
{ criteria: "nb_tracks", width: VLCStyle.colWidth(1), text: i18n.qtr("Tracks") }
]
onItemDoubleClicked: {
root.requestArtistAlbumView(model)
}
onContextMenuButtonClicked: contextMenu.popup(selectionModel.selectedIndexes, menuParent.mapToGlobal(0,0))
onRightClick: contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
Widgets.TableColumns {
id: tableColumns
}
}
}
Widgets.StackViewExt {
id: view
anchors.fill: parent
visible: artistModel.count > 0
focus: artistModel.count > 0
initialItem: mainInterface.gridView ? gridComponent : tableComponent
}
Connections {
target: mainInterface
onGridViewChanged: {
if (mainInterface.gridView) {
view.replace(gridComponent)
} else {
view.replace(tableComponent)
}
}
}
EmptyLabel {
anchors.fill: parent
visible: artistModel.count === 0
focus: artistModel.count === 0
text: i18n.qtr("No artists found\nPlease try adding sources, by going to the Network tab")
Navigation.parentItem: root
cover: VLCStyle.noArtArtistCover
}
}

234
modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml

@ -37,7 +37,7 @@ Widgets.PageLoader {
defaultPage: "all"
pageModel: [{
name: "all",
component: artistGridComponent
component: allArtistsComponent
}, {
name: "albums",
component: artistAlbumsComponent
@ -59,240 +59,20 @@ Widgets.PageLoader {
}
Component {
id: artistGridComponent
id: allArtistsComponent
FocusScope {
id: artistAllView
MusicAllArtists {
onCurrentIndexChanged: _updateArtistsAllHistory(currentIndex)
readonly property int currentIndex: view.currentItem.currentIndex
property int initialIndex: 0
property alias model: artistModel
onCurrentIndexChanged: {
_updateArtistsAllHistory(currentIndex)
}
onInitialIndexChanged: resetFocus()
function showAlbumView() {
history.push([ "mc", "music", "artists", "albums", { initialIndex: artistAllView.currentIndex } ])
}
function resetFocus() {
if (artistModel.count === 0) {
return
}
var initialIndex = artistAllView.initialIndex
if (initialIndex >= artistModel.count)
initialIndex = 0
selectionModel.select(artistModel.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
if (view.currentItem) {
view.currentItem.currentIndex = initialIndex
view.currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
}
}
function _onNavigationCancel() {
if (view.currentItem.currentIndex <= 0) {
artistAllView.Navigation.defaultNavigationCancel()
} else {
view.currentItem.currentIndex = 0;
view.currentItem.positionViewAtIndex(0, ItemView.Contain);
}
}
MLArtistModel {
id: artistModel
ml: medialib
onCountChanged: {
if (artistModel.count > 0 && !selectionModel.hasSelection) {
artistAllView.resetFocus()
}
}
}
Util.SelectableDelegateModel {
id: selectionModel
model: artistModel
}
Widgets.DragItem {
id: artistsDragItem
function updateComponents(maxCovers) {
var items = selectionModel.selectedIndexes.slice(0, maxCovers).map(function (x){
return artistModel.getDataAt(x.row)
})
var title = items.map(function (item){ return item.name}).join(", ")
var covers = items.map(function (item) { return {artwork: item.cover || VLCStyle.noArtArtistSmall}})
return {
covers: covers,
title: title,
count: selectionModel.selectedIndexes.length
}
}
function getSelectedInputItem() {
return artistModel.getItemsForIndexes(selectionModel.selectedIndexes);
}
}
ArtistContextMenu {
id: contextMenu
model: artistModel
}
Component {
id: gridComponent
MainInterface.MainGridView {
id: artistGrid
anchors.fill: parent
topMargin: VLCStyle.margin_large
delegateModel: selectionModel
model: artistModel
focus: true
cellWidth: VLCStyle.colWidth(1)
cellHeight: VLCStyle.gridItem_music_height
Navigation.parentItem: root
Navigation.cancelAction: artistAllView._onNavigationCancel
onSelectAll: selectionModel.selectAll()
onSelectionUpdated: selectionModel.updateSelection( keyModifiers, oldIndex, newIndex )
onActionAtIndex: {
if (selectionModel.selectedIndexes.length > 1) {
medialib.addAndPlay( artistModel.getIdsForIndexes( selectionModel.selectedIndexes ) )
} else {
view.currentItem.currentIndex = index
showAlbumView()
medialib.addAndPlay( artistModel.getIdForIndex(index) )
}
}
Widgets.GridShadows {
id: shadows
leftPadding: (VLCStyle.colWidth(1) - shadows.coverWidth) / 2 // GridItem's rect is horizontally centered
coverWidth: VLCStyle.artistGridCover_radius
coverHeight: VLCStyle.artistGridCover_radius
coverRadius: VLCStyle.artistGridCover_radius
}
delegate: AudioGridItem {
id: gridItem
title: model.name || i18n.qtr("Unknown artist")
subtitle: model.nb_tracks > 1 ? i18n.qtr("%1 songs").arg(model.nb_tracks) : i18n.qtr("%1 song").arg(model.nb_tracks)
pictureRadius: VLCStyle.artistGridCover_radius
pictureHeight: VLCStyle.artistGridCover_radius
pictureWidth: VLCStyle.artistGridCover_radius
playCoverBorderWidth: VLCStyle.dp(3, VLCStyle.scale)
titleMargin: VLCStyle.margin_xlarge
playIconSize: VLCStyle.play_cover_small
textAlignHCenter: true
width: VLCStyle.colWidth(1)
dragItem: artistsDragItem
unselectedUnderlay: shadows.unselected
selectedUnderlay: shadows.selected
onItemClicked: artistGrid.leftClickOnItem(modifier, index)
onItemDoubleClicked: artistAllView.showAlbumView(model)
onContextMenuButtonClicked: {
artistGrid.rightClickOnItem(index)
contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
}
}
}
}
Component {
id: tableComponent
MainInterface.MainTableView {
id: artistTable
readonly property int _nbCols: VLCStyle.gridColumnsForWidth(artistTable.availableRowWidth)
anchors.fill: parent
selectionDelegateModel: selectionModel
model: artistModel
focus: true
headerColor: VLCStyle.colors.bg
dragItem: artistsDragItem
rowHeight: VLCStyle.tableCoverRow_height
headerTopPadding: VLCStyle.margin_normal
Navigation.parentItem: root
Navigation.cancelAction: artistAllView._onNavigationCancel
onActionForSelection: {
if (selection.length > 1) {
medialib.addAndPlay( artistModel.getIdsForIndexes( selection ) )
} else {
showAlbumView()
medialib.addAndPlay( artistModel.getIdForIndex(index) )
}
}
sortModel: [
{ isPrimary: true, criteria: "name", width: VLCStyle.colWidth(Math.max(artistTable._nbCols - 1, 1)), text: i18n.qtr("Name"), headerDelegate: tableColumns.titleHeaderDelegate, colDelegate: tableColumns.titleDelegate },
{ criteria: "nb_tracks", width: VLCStyle.colWidth(1), text: i18n.qtr("Tracks") }
]
onItemDoubleClicked: {
artistAllView.showAlbumView(model)
}
onContextMenuButtonClicked: contextMenu.popup(selectionModel.selectedIndexes, menuParent.mapToGlobal(0,0))
onRightClick: contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
Widgets.TableColumns {
id: tableColumns
}
}
}
Widgets.StackViewExt {
id: view
anchors.fill: parent
visible: artistModel.count > 0
focus: artistModel.count > 0
initialItem: mainInterface.gridView ? gridComponent : tableComponent
}
Connections {
target: mainInterface
onGridViewChanged: {
if (mainInterface.gridView) {
view.replace(gridComponent)
} else {
view.replace(tableComponent)
}
}
}
EmptyLabel {
anchors.fill: parent
visible: artistModel.count === 0
focus: artistModel.count === 0
text: i18n.qtr("No artists found\nPlease try adding sources, by going to the Network tab")
Navigation.parentItem: root
cover: VLCStyle.noArtArtistCover
function requestArtistAlbumView() /* override */ {
history.push([ "mc", "music", "artists", "albums", { initialIndex: currentIndex } ])
}
}
}
Component {
id: artistAlbumsComponent
/* List View */
MusicArtistsAlbums {
Navigation.parentItem: root

1
modules/gui/qt/vlc.qrc

@ -290,6 +290,7 @@
<file alias="MusicAlbumsGridExpandDelegate.qml">medialibrary/qml/MusicAlbumsGridExpandDelegate.qml</file>
<file alias="MusicArtist.qml">medialibrary/qml/MusicArtist.qml</file>
<file alias="MusicArtistsAlbums.qml">medialibrary/qml/MusicArtistsAlbums.qml</file>
<file alias="MusicAllArtists.qml">medialibrary/qml/MusicAllArtists.qml</file>
<file alias="MusicArtistsDisplay.qml">medialibrary/qml/MusicArtistsDisplay.qml</file>
<file alias="MusicGenresDisplay.qml">medialibrary/qml/MusicGenresDisplay.qml</file>
<file alias="MusicPlaylistsDisplay.qml">medialibrary/qml/MusicPlaylistsDisplay.qml</file>

1
po/POTFILES.in

@ -828,6 +828,7 @@ modules/gui/qt/medialibrary/qml/MusicAlbums.qml
modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml
modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml
modules/gui/qt/medialibrary/qml/MusicArtist.qml
modules/gui/qt/medialibrary/qml/MusicAllArtists.qml
modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
modules/gui/qt/medialibrary/qml/MusicDisplay.qml

Loading…
Cancel
Save