[amarok] /: Now It's possible to use formated strings for prefix and suffix in Playlist's layout items.

Bart Cerneels bart.cerneels at kde.org
Tue Nov 29 07:50:14 UTC 2011


This feature should have waited until after 2.5 release is opened
again for new features. New code creates an additional risk of
regressions we can do without.

If this is just a minimal feature I would like to see it reverted.

Bart

On Sun, Nov 27, 2011 at 05:57, Sergey Ivanov <123kash at gmail.com> wrote:
> Git commit 284292a985f5cd7b6a6518893a8b3318e898e855 by Sergey Ivanov.
> Committed on 27/11/2011 at 05:56.
> Pushed by ivanov into branch 'master'.
>
> Now It's possible to use formated strings for prefix and suffix in Playlist's layout items.
>
> M  +4    -0    ChangeLog
> M  +52   -1    src/playlist/view/listview/PrettyItemDelegate.cpp
> M  +3    -0    src/playlist/view/listview/PrettyItemDelegate.h
>
> http://commits.kde.org/amarok/284292a985f5cd7b6a6518893a8b3318e898e855
>
> diff --git a/ChangeLog b/ChangeLog
> index 41c4843..a7d544d 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -3,6 +3,10 @@ Amarok ChangeLog
>  (C) 2002-2011 the Amarok authors.
>
>  Version 2.5
> +  FEATURES:
> +    * Now It's possible to use formated strings for prefix and suffix in
> +      Playlist's layout items.
> +
>   BUGFIXES:
>     * Fix volume control from within Amarok.
>     * Fix slow startup because of imported playlists. (BR 284761)
> diff --git a/src/playlist/view/listview/PrettyItemDelegate.cpp b/src/playlist/view/listview/PrettyItemDelegate.cpp
> index 01e489b..80f579f 100644
> --- a/src/playlist/view/listview/PrettyItemDelegate.cpp
> +++ b/src/playlist/view/listview/PrettyItemDelegate.cpp
> @@ -37,6 +37,7 @@
>  #include "playlist/proxymodels/GroupingProxy.h"
>  #include "playlist/PlaylistModel.h"
>  #include "playlist/layouts/LayoutManager.h"
> +#include "QStringx.h"
>
>  #include "kratingpainter.h"
>
> @@ -380,6 +381,11 @@ void Playlist::PrettyItemDelegate::paintItem( const LayoutItemConfig &config,
>     }
>     int markersWidth = rowOffsetX - rowOffsetXBeforeMarkers;
>
> +    Meta::TrackPtr trackPtr = index.data( TrackRole ).value<Meta::TrackPtr>();
> +    QMap<QString, QString> trackArgs;
> +    if( trackPtr )
> +        trackArgs = buildTrackArgsMap( trackPtr );
> +
>     // --- paint all the rows
>     for ( int i = 0; i < rowCount; i++ )
>     {
> @@ -510,7 +516,9 @@ void Playlist::PrettyItemDelegate::paintItem( const LayoutItemConfig &config,
>                 //TODO: get rid of passing TrackPtr as data, use custom role instead
>                 Meta::TrackPtr track = index.data( TrackRole ).value<Meta::TrackPtr>();
>                 QString text = textIndex.data( Qt::DisplayRole ).toString();
> -                text = element.prefix() + text + element.suffix();
> +                QStringx prefix( element.prefix() );
> +                QStringx suffix( element.suffix() );
> +                text = prefix.namedOptArgs( trackArgs ) + text + suffix.namedOptArgs( trackArgs );
>                 text = QFontMetricsF( font ).elidedText( text, Qt::ElideRight, itemWidth );
>
>                 //if the track can't be played, it should be grayed out to show that it is unavailable
> @@ -828,4 +836,47 @@ Playlist::PrettyItemDelegate::editorDone( InlineEditorWidget * editor )
>     emit commitData( editor );
>  }
>
> +QMap<QString, QString>
> +Playlist::PrettyItemDelegate::buildTrackArgsMap( const Meta::TrackPtr track ) const
> +{
> +    QMap<QString, QString> args;
> +    QString artist = track->artist() ? track->artist()->name() : QString();
> +    QString albumartist;
> +    if( track->album() && track->album()->hasAlbumArtist() )
> +        albumartist = track->album()->albumArtist()->name();
> +    else
> +        albumartist = artist;
> +
> +
> +    args["title"] = track->name();
> +    args["composer"] = track->composer() ? track->composer()->name() : QString();
> +
> +    // if year == 0 then we don't want include it
> +    QString year = track->year() ? track->year()->name() : QString();
> +    args["year"] = year.localeAwareCompare( "0" ) == 0 ? QString() : year;
> +    args["album"] = track->album() ? track->album()->name() : QString();
> +
> +    if( track->discNumber() )
> +        args["discnumber"] = QString::number( track->discNumber() );
> +
> +    args["genre"] = track->genre() ? track->genre()->name() : QString();
> +    args["comment"] = track->comment();
> +    args["artist"] = artist;
> +    args["albumartist"] = albumartist;
> +    args["initial"] = albumartist.mid( 0, 1 ).toUpper();    //artists starting with The are already handled above
> +    args["filetype"] = track->type();
> +
> +    args["rating"] = track->rating();
> +    args["filesize"] = track->filesize();
> +    args["length"] = track->length() / 1000;
> +
> +    if ( track->trackNumber() )
> +    {
> +        QString trackNum = QString( "%1" ).arg( track->trackNumber(), 2, 10, QChar('0') );
> +        args["track"] = trackNum;
> +    }
> +
> +    return args;
> +}
> +
>  #include "PrettyItemDelegate.moc"
> diff --git a/src/playlist/view/listview/PrettyItemDelegate.h b/src/playlist/view/listview/PrettyItemDelegate.h
> index 8e00e29..7e1ecea 100644
> --- a/src/playlist/view/listview/PrettyItemDelegate.h
> +++ b/src/playlist/view/listview/PrettyItemDelegate.h
> @@ -20,6 +20,7 @@
>  #ifndef PRETTYITEMDELEGATE_H
>  #define PRETTYITEMDELEGATE_H
>
> +#include "core/meta/Meta.h"
>  #include "playlist/layouts/LayoutItemConfig.h"
>
>  #include <QModelIndex>
> @@ -92,6 +93,8 @@ private:
>
>     static int getGroupMode( const QModelIndex &index);
>
> +    QMap<QString, QString> buildTrackArgsMap( const Meta::TrackPtr track ) const;
> +
>     static QFontMetricsF* s_nfm; //normal
>     static QFontMetricsF* s_ufm; //underline
>     static QFontMetricsF* s_ifm; //italic
>


More information about the Amarok-devel mailing list