[vlc-devel] [PATCH 05/33] QML: add sections to the MusicTrackListDisplay
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Wed Jun 12 15:01:35 CEST 2019
On Wed, Jun 12, 2019, at 2:02 PM, Adrien Maglo wrote:
> ---
> .../mediacenter/mlalbumtrackmodel.cpp | 12 +++++++
> .../mediacenter/mlalbumtrackmodel.hpp | 2 ++
> .../MusicAlbumsGridExpandDelegate.qml | 2 ++
> .../qml/mediacenter/MusicTrackListDisplay.qml | 2 ++
> .../gui/qt/qml/utils/KeyNavigableListView.qml | 32 +++++++++++++++++++
> .../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..d9587e5fda 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;
> +}
Can't this be achieved in JS/qml without exposing an additional property?
> diff --git
> a/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.hpp
> b/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.hpp
> index 4314ff229a..179fb1a383 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 );
(And in case you need the property, you probably meant "const QString& str" here!)
> };
> #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
>
> --
> 2.20.1
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
--
Hugo Beauzée-Luyssen
hugo at beauzee.fr
More information about the vlc-devel
mailing list