[vlc-commits] qml: distinct the "album" view from the album component used in other view
Pierre Lamot
git at videolan.org
Fri Feb 14 11:59:52 CET 2020
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Tue Jan 28 17:49:58 2020 +0100| [d381b92ef8e25d57472bb3f0cd11f4e7e326e3d5] | committer: Jean-Baptiste Kempf
qml: distinct the "album" view from the album component used in other view
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d381b92ef8e25d57472bb3f0cd11f4e7e326e3d5
---
modules/gui/qt/Makefile.am | 1 +
modules/gui/qt/medialibrary/qml/MusicAlbums.qml | 236 +++++++++++++++++++++
.../gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml | 219 +------------------
.../qt/medialibrary/qml/MusicArtistsDisplay.qml | 2 +-
modules/gui/qt/vlc.qrc | 1 +
5 files changed, 247 insertions(+), 212 deletions(-)
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index a527e81ad9..947c712fb5 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -556,6 +556,7 @@ libqt_plugin_la_QML = \
gui/qt/medialibrary/qml/ArtistTopBanner.qml \
gui/qt/medialibrary/qml/AudioGridItem.qml \
gui/qt/medialibrary/qml/MainDisplay.qml \
+ gui/qt/medialibrary/qml/MusicAlbums.qml \
gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml \
gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml \
gui/qt/medialibrary/qml/MusicArtistsDisplay.qml \
diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
new file mode 100644
index 0000000000..9f45d6bb75
--- /dev/null
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -0,0 +1,236 @@
+/*****************************************************************************
+ * 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
+import QtQml.Models 2.2
+import org.videolan.medialib 0.1
+
+
+import "qrc:///util/" as Util
+import "qrc:///widgets/" as Widgets
+import "qrc:///style/"
+
+Widgets.NavigableFocusScope {
+ id: root
+
+ property var sortModel: [
+ { text: i18n.qtr("Alphabetic"), criteria: "title"},
+ { text: i18n.qtr("Duration"), criteria: "duration" },
+ { text: i18n.qtr("Date"), criteria: "release_year" },
+ { text: i18n.qtr("Artist"), criteria: "main_artist" },
+ ]
+
+ property alias model: delegateModel.model
+ property alias parentId: delegateModel.parentId
+ property var currentIndex: view.currentItem.currentIndex
+
+
+ navigationCancel: function() {
+ if (view.currentItem.currentIndex <= 0)
+ defaultNavigationCancel()
+ else
+ view.currentItem.currentIndex = 0;
+ }
+
+ property Component header: Item{}
+ readonly property var headerItem: view.currentItem ? view.currentItem.headerItem : undefined
+
+ Util.SelectableDelegateModel {
+ id: delegateModel
+ property alias parentId: albumModelId.parentId
+
+ model: MLAlbumModel {
+ id: albumModelId
+ ml: medialib
+ }
+
+
+ delegate: Package {
+ id: element
+
+ Widgets.ListItem {
+ Package.name: "list"
+ width: root.width
+ height: VLCStyle.icon_normal + VLCStyle.margin_small
+
+ cover: Image {
+ id: cover_obj
+ fillMode: Image.PreserveAspectFit
+ source: model.cover || VLCStyle.noArtAlbum
+ sourceSize: Qt.size(width, height)
+ }
+ line1: (model.title || i18n.qtr("Unknown title"))+" ["+model.duration+"]"
+ line2: model.main_artist || i18n.qtr("Unknown artist")
+
+ onItemClicked : {
+ delegateModel.updateSelection( modifier, view.currentItem.currentIndex, index )
+ view.currentItem.currentIndex = index
+ this.forceActiveFocus()
+ }
+ onPlayClicked: medialib.addAndPlay( model.id )
+ onAddToPlaylistClicked : medialib.addToPlaylist( model.id )
+ }
+ }
+
+ function actionAtIndex(index) {
+ if (delegateModel.selectedGroup.count > 1) {
+ var list = []
+ for (var i = 0; i < delegateModel.selectedGroup.count; i++)
+ list.push(delegateModel.selectedGroup.get(i).model.id)
+ medialib.addAndPlay( list )
+ } else {
+ medialib.addAndPlay( delegateModel.items.get(index).model.id )
+ }
+ }
+ }
+
+ /*
+ *define the intial position/selection
+ * This is done on activeFocus rather than Component.onCompleted because delegateModel.
+ * selectedGroup update itself after this event
+ */
+ onActiveFocusChanged: {
+ if (activeFocus && delegateModel.items.count > 0 && delegateModel.selectedGroup.count === 0) {
+ var initialIndex = 0
+ if (view.currentItem.currentIndex !== -1)
+ initialIndex = view.currentItem.currentIndex
+ delegateModel.items.get(initialIndex).inSelected = true
+ view.currentItem.currentIndex = initialIndex
+ }
+ }
+
+ Component {
+ id: gridComponent
+
+ Widgets.ExpandGridView {
+ id: gridView_id
+
+ activeFocusOnTab:true
+
+ cellWidth: VLCStyle.gridItem_music_width
+ cellHeight: VLCStyle.gridItem_music_height
+
+ headerDelegate: root.header
+
+ delegate: AudioGridItem {
+ id: audioGridItem
+
+ onItemClicked : {
+ delegateModel.updateSelection( modifier , root.currentIndex, index)
+ gridView_id.currentIndex = index
+ gridView_id.forceActiveFocus()
+ }
+ }
+
+ expandDelegate: MusicAlbumsGridExpandDelegate {
+ id: expandDelegateId
+ width: root.width
+
+ implicitHeight: gridView_id.height - gridView_id.cellHeight
+
+ navigationParent: root
+ navigationCancel: function() { gridView_id.retract() }
+ navigationUp: function() { gridView_id.retract() }
+ navigationDown: function() {}
+
+ }
+
+ model: delegateModel
+ modelCount: delegateModel.items.count
+
+ onActionAtIndex: {
+ if (delegateModel.selectedGroup.count === 1) {
+ view._switchExpandItem(index)
+ } else {
+ delegateModel.actionAtIndex(index)
+ }
+ }
+ onSelectAll: delegateModel.selectAll()
+ onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
+
+ navigationParent: root
+ }
+ }
+
+ Component {
+ id: listComponent
+ /* ListView */
+ Widgets.KeyNavigableListView {
+ id: listView_id
+
+ header: root.header
+
+ spacing: VLCStyle.margin_xxxsmall
+
+ model: delegateModel.parts.list
+ modelCount: delegateModel.items.count
+
+ onActionAtIndex: delegateModel.actionAtIndex(index)
+ onSelectAll: delegateModel.selectAll()
+ onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
+
+ navigationParent: root
+ navigationCancel: function() {
+ if (listView_id.currentIndex <= 0)
+ defaultNavigationCancel()
+ else
+ listView_id.currentIndex = 0;
+ }
+ }
+ }
+
+ Widgets.StackViewExt {
+ id: view
+
+ anchors.fill: parent
+ focus: true
+
+ initialItem: medialib.gridView ? gridComponent : listComponent
+
+ Connections {
+ target: medialib
+ onGridViewChanged: {
+ if (medialib.gridView)
+ view.replace(gridComponent)
+ else
+ view.replace(listComponent)
+ }
+ }
+
+ function _switchExpandItem(index) {
+ view.currentItem.switchExpandItem(index)
+
+ /*if (view.currentItem.expandIndex === index)
+ view.currentItem.expandIndex = -1
+ else
+ view.currentItem.expandIndex = index*/
+ }
+ }
+
+ Label {
+ anchors.fill: parent
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ visible: delegateModel.items.count === 0
+ font.pixelSize: VLCStyle.fontHeight_xxlarge
+ color: root.activeFocus ? VLCStyle.colors.accent : VLCStyle.colors.text
+ wrapMode: Text.WordWrap
+ text: i18n.qtr("No albums found\nPlease try adding sources, by going to the Network tab")
+ }
+}
diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml
index 9f45d6bb75..f4653ca079 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (C) 2019 VLC authors and VideoLAN
+ * Copyright (C) 2020 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
@@ -15,222 +15,19 @@
* 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
-import QtQml.Models 2.2
-import org.videolan.medialib 0.1
+import org.videolan.vlc 0.1
-import "qrc:///util/" as Util
-import "qrc:///widgets/" as Widgets
import "qrc:///style/"
+import "qrc:///widgets/" as Widgets
-Widgets.NavigableFocusScope {
+MusicAlbums {
id: root
- property var sortModel: [
- { text: i18n.qtr("Alphabetic"), criteria: "title"},
- { text: i18n.qtr("Duration"), criteria: "duration" },
- { text: i18n.qtr("Date"), criteria: "release_year" },
- { text: i18n.qtr("Artist"), criteria: "main_artist" },
- ]
-
- property alias model: delegateModel.model
- property alias parentId: delegateModel.parentId
- property var currentIndex: view.currentItem.currentIndex
-
-
- navigationCancel: function() {
- if (view.currentItem.currentIndex <= 0)
- defaultNavigationCancel()
- else
- view.currentItem.currentIndex = 0;
- }
-
- property Component header: Item{}
- readonly property var headerItem: view.currentItem ? view.currentItem.headerItem : undefined
-
- Util.SelectableDelegateModel {
- id: delegateModel
- property alias parentId: albumModelId.parentId
-
- model: MLAlbumModel {
- id: albumModelId
- ml: medialib
- }
-
-
- delegate: Package {
- id: element
-
- Widgets.ListItem {
- Package.name: "list"
- width: root.width
- height: VLCStyle.icon_normal + VLCStyle.margin_small
-
- cover: Image {
- id: cover_obj
- fillMode: Image.PreserveAspectFit
- source: model.cover || VLCStyle.noArtAlbum
- sourceSize: Qt.size(width, height)
- }
- line1: (model.title || i18n.qtr("Unknown title"))+" ["+model.duration+"]"
- line2: model.main_artist || i18n.qtr("Unknown artist")
-
- onItemClicked : {
- delegateModel.updateSelection( modifier, view.currentItem.currentIndex, index )
- view.currentItem.currentIndex = index
- this.forceActiveFocus()
- }
- onPlayClicked: medialib.addAndPlay( model.id )
- onAddToPlaylistClicked : medialib.addToPlaylist( model.id )
- }
- }
-
- function actionAtIndex(index) {
- if (delegateModel.selectedGroup.count > 1) {
- var list = []
- for (var i = 0; i < delegateModel.selectedGroup.count; i++)
- list.push(delegateModel.selectedGroup.get(i).model.id)
- medialib.addAndPlay( list )
- } else {
- medialib.addAndPlay( delegateModel.items.get(index).model.id )
- }
- }
- }
-
- /*
- *define the intial position/selection
- * This is done on activeFocus rather than Component.onCompleted because delegateModel.
- * selectedGroup update itself after this event
- */
- onActiveFocusChanged: {
- if (activeFocus && delegateModel.items.count > 0 && delegateModel.selectedGroup.count === 0) {
- var initialIndex = 0
- if (view.currentItem.currentIndex !== -1)
- initialIndex = view.currentItem.currentIndex
- delegateModel.items.get(initialIndex).inSelected = true
- view.currentItem.currentIndex = initialIndex
- }
- }
-
- Component {
- id: gridComponent
-
- Widgets.ExpandGridView {
- id: gridView_id
-
- activeFocusOnTab:true
-
- cellWidth: VLCStyle.gridItem_music_width
- cellHeight: VLCStyle.gridItem_music_height
-
- headerDelegate: root.header
-
- delegate: AudioGridItem {
- id: audioGridItem
-
- onItemClicked : {
- delegateModel.updateSelection( modifier , root.currentIndex, index)
- gridView_id.currentIndex = index
- gridView_id.forceActiveFocus()
- }
- }
-
- expandDelegate: MusicAlbumsGridExpandDelegate {
- id: expandDelegateId
- width: root.width
-
- implicitHeight: gridView_id.height - gridView_id.cellHeight
-
- navigationParent: root
- navigationCancel: function() { gridView_id.retract() }
- navigationUp: function() { gridView_id.retract() }
- navigationDown: function() {}
-
- }
-
- model: delegateModel
- modelCount: delegateModel.items.count
-
- onActionAtIndex: {
- if (delegateModel.selectedGroup.count === 1) {
- view._switchExpandItem(index)
- } else {
- delegateModel.actionAtIndex(index)
- }
- }
- onSelectAll: delegateModel.selectAll()
- onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
-
- navigationParent: root
- }
- }
-
- Component {
- id: listComponent
- /* ListView */
- Widgets.KeyNavigableListView {
- id: listView_id
-
- header: root.header
-
- spacing: VLCStyle.margin_xxxsmall
-
- model: delegateModel.parts.list
- modelCount: delegateModel.items.count
-
- onActionAtIndex: delegateModel.actionAtIndex(index)
- onSelectAll: delegateModel.selectAll()
- onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
-
- navigationParent: root
- navigationCancel: function() {
- if (listView_id.currentIndex <= 0)
- defaultNavigationCancel()
- else
- listView_id.currentIndex = 0;
- }
- }
- }
-
- Widgets.StackViewExt {
- id: view
-
- anchors.fill: parent
- focus: true
-
- initialItem: medialib.gridView ? gridComponent : listComponent
-
- Connections {
- target: medialib
- onGridViewChanged: {
- if (medialib.gridView)
- view.replace(gridComponent)
- else
- view.replace(listComponent)
- }
- }
-
- function _switchExpandItem(index) {
- view.currentItem.switchExpandItem(index)
-
- /*if (view.currentItem.expandIndex === index)
- view.currentItem.expandIndex = -1
- else
- view.currentItem.expandIndex = index*/
- }
- }
-
- Label {
- anchors.fill: parent
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- visible: delegateModel.items.count === 0
- font.pixelSize: VLCStyle.fontHeight_xxlarge
- color: root.activeFocus ? VLCStyle.colors.accent : VLCStyle.colors.text
- wrapMode: Text.WordWrap
- text: i18n.qtr("No albums found\nPlease try adding sources, by going to the Network tab")
+ header: Widgets.LabelSeparator {
+ text: i18n.qtr("Albums")
+ width: root.width
}
}
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index 5162489328..440ea45724 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -136,7 +136,7 @@ Widgets.NavigableFocusScope {
property alias currentIndex: albumSubView.currentIndex
- MusicAlbumsDisplay {
+ MusicAlbums {
id: albumSubView
anchors.fill: parent
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 1b1ff3a47c..ec0b278d27 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -223,6 +223,7 @@
<file alias="NetworkListItem.qml">network/qml/NetworkListItem.qml</file>
</qresource>
<qresource prefix="/medialibrary">
+ <file alias="MusicAlbums.qml">medialibrary/qml/MusicAlbums.qml</file>
<file alias="MusicDisplay.qml">medialibrary/qml/MusicDisplay.qml</file>
<file alias="VideoDisplay.qml">medialibrary/qml/VideoDisplay.qml</file>
<file alias="MusicAlbumsDisplay.qml">medialibrary/qml/MusicAlbumsDisplay.qml</file>
More information about the vlc-commits
mailing list