[vlc-commits] qml: add sections to the MusicTrackListDisplay

Adrien Maglo git at videolan.org
Thu Jun 13 13:10:37 CEST 2019


vlc | branch: master | Adrien Maglo <magsoft at videolan.org> | Tue Apr 16 23:32:04 2019 +0200| [ec78cc6dfa48839c5b981c7249325a75af996f53] | committer: Thomas Guillem

qml: add sections to the MusicTrackListDisplay

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ec78cc6dfa48839c5b981c7249325a75af996f53
---

 .../components/mediacenter/mlalbumtrackmodel.cpp   | 12 ++++++++
 .../components/mediacenter/mlalbumtrackmodel.hpp   |  2 ++
 .../mediacenter/MusicAlbumsGridExpandDelegate.qml  |  2 ++
 .../qt/qml/mediacenter/MusicTrackListDisplay.qml   |  2 ++
 modules/gui/qt/qml/utils/KeyNavigableListView.qml  | 32 ++++++++++++++++++++++
 modules/gui/qt/qml/utils/KeyNavigableTableView.qml |  2 ++
 6 files changed, 52 insertions(+)

diff --git a/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp b/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp
index 2b5be88f01..7ef567aeef 100644
--- a/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp
+++ b/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp
@@ -29,6 +29,7 @@ enum Role {
     TRACK_DURATION,
     TRACK_ALBUM,
     TRACK_ARTIST,
+    TRACK_FIRST_SYMBOL,
 };
 
 }
@@ -76,6 +77,8 @@ QVariant MLAlbumTrackModel::data(const QModelIndex &index, int role) const
         return QVariant::fromValue( ml_track->getAlbumTitle() );
     case TRACK_ARTIST:
         return QVariant::fromValue( ml_track->getArtist() );
+    case TRACK_FIRST_SYMBOL:
+        return QVariant::fromValue( getFirstSymbol( ml_track->getTitle() ) );
     default :
         return QVariant();
     }
@@ -92,6 +95,7 @@ QHash<int, QByteArray> MLAlbumTrackModel::roleNames() const
         { TRACK_DURATION, "duration" },
         { TRACK_ALBUM, "album_title"},
         { TRACK_ARTIST, "main_artist"},
+        { TRACK_FIRST_SYMBOL, "first_symbol"},
     };
 }
 
@@ -177,3 +181,11 @@ void MLAlbumTrackModel::onVlcMlEvent(const vlc_ml_event_t* event)
     }
     MLBaseModel::onVlcMlEvent( event );
 }
+
+QString MLAlbumTrackModel::getFirstSymbol( const QString& str )
+{
+    QString ret("#");
+    if ( str.length() > 0 && str[0].isLetter() )
+        ret = str[0].toUpper();
+    return ret;
+}
diff --git a/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.hpp b/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.hpp
index 4314ff229a..bae6f42db9 100644
--- a/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.hpp
+++ b/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.hpp
@@ -49,5 +49,7 @@ private:
     virtual void onVlcMlEvent( const vlc_ml_event_t* event ) override;
 
     static QHash<QByteArray, vlc_ml_sorting_criteria_t> M_names_to_criteria;
+
+    static QString getFirstSymbol( const QString& str );
 };
 #endif // MLTRACKMODEL_HPP
diff --git a/modules/gui/qt/qml/mediacenter/MusicAlbumsGridExpandDelegate.qml b/modules/gui/qt/qml/mediacenter/MusicAlbumsGridExpandDelegate.qml
index 6e17b1e34f..b037bf6f49 100644
--- a/modules/gui/qt/qml/mediacenter/MusicAlbumsGridExpandDelegate.qml
+++ b/modules/gui/qt/qml/mediacenter/MusicAlbumsGridExpandDelegate.qml
@@ -165,6 +165,8 @@ Utils.NavigableFocusScope {
             MusicTrackListDisplay {
                 id: expand_track_id
 
+                section.property: ""
+
                 height: expand_track_id.contentHeight
                 anchors {
                     left: parent.left
diff --git a/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml b/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml
index a5034b94c0..f82e5e1299 100644
--- a/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml
+++ b/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml
@@ -37,6 +37,8 @@ Utils.KeyNavigableTableView {
         ListElement{ criteria: "disc_number"; width:0.05; text: qsTr("Disc");  showSection: "" }
     }
 
+    section.property: "first_symbol"
+
     model: MLAlbumTrackModel {
         id: rootmodel
         ml: medialib
diff --git a/modules/gui/qt/qml/utils/KeyNavigableListView.qml b/modules/gui/qt/qml/utils/KeyNavigableListView.qml
index 35b832647e..c5eb93d240 100644
--- a/modules/gui/qt/qml/utils/KeyNavigableListView.qml
+++ b/modules/gui/qt/qml/utils/KeyNavigableListView.qml
@@ -18,6 +18,8 @@
 import QtQuick 2.11
 import QtQuick.Controls 2.4
 
+import "qrc:///style/"
+
 NavigableFocusScope {
     id: listview_id
 
@@ -52,6 +54,32 @@ NavigableFocusScope {
 
     property alias highlightMoveVelocity: view.highlightMoveVelocity
 
+    property alias section: view.section
+
+    Component {
+        id: sectionHeading
+        Rectangle {
+            width: parent.width
+            height: childrenRect.height
+
+            Column {
+                width: parent.width
+
+                Text {
+                    text: section
+                    font.pixelSize: 20
+                    color: VLCStyle.colors.accent
+                }
+
+                Rectangle {
+                    width: parent.width
+                    height: 1
+                    color: VLCStyle.colors.textInactive
+                }
+            }
+        }
+    }
+
     ListView {
         id: view
         anchors.fill: parent
@@ -66,6 +94,10 @@ NavigableFocusScope {
         highlightMoveDuration: 300 //ms
         highlightMoveVelocity: 1000 //px/s
 
+        section.property: ""
+        section.criteria: ViewSection.FullString
+        section.delegate: sectionHeading
+
         Connections {
             target: view.currentItem
             ignoreUnknownSignals: true
diff --git a/modules/gui/qt/qml/utils/KeyNavigableTableView.qml b/modules/gui/qt/qml/utils/KeyNavigableTableView.qml
index 5a539367e3..d6d9d17f43 100644
--- a/modules/gui/qt/qml/utils/KeyNavigableTableView.qml
+++ b/modules/gui/qt/qml/utils/KeyNavigableTableView.qml
@@ -38,6 +38,8 @@ NavigableFocusScope {
 
     property alias interactive: view.interactive
 
+    property alias section: view.section
+
     Utils.SelectableDelegateModel {
         id: delegateModel
 



More information about the vlc-commits mailing list