From b9c61952a6c6e8e4122badbdc7c681ec3d6eac43 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 31 Mar 2012 05:48:15 +0200 Subject: [PATCH] * Fixed PlaylistLargeItemDelegate. --- .../playlist/PlaylistLargeItemDelegate.cpp | 24 ++++++++----------- .../playlist/PlaylistLargeItemDelegate.h | 6 ++++- src/libtomahawk/viewmanager.cpp | 2 +- src/sourcetree/items/sourceitem.cpp | 6 ++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp index 404fb1bf7..21824caec 100644 --- a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp @@ -40,10 +40,11 @@ using namespace Tomahawk; -PlaylistLargeItemDelegate::PlaylistLargeItemDelegate( TrackView* parent, TrackProxyModel* proxy ) +PlaylistLargeItemDelegate::PlaylistLargeItemDelegate( DisplayMode mode, TrackView* parent, TrackProxyModel* proxy ) : QStyledItemDelegate( (QObject*)parent ) , m_view( parent ) , m_model( proxy ) + , m_mode( mode ) { m_topOption = QTextOption( Qt::AlignTop ); m_topOption.setWrapMode( QTextOption::NoWrap ); @@ -149,8 +150,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& return; QPixmap pixmap, avatar; - QString artist, track, upperText, lowerText; - source_ptr source = item->query()->playedBy().first; + QString artist, track, lowerText; unsigned int duration = 0; if ( item->query()->results().count() ) @@ -165,14 +165,11 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& track = item->query()->track(); } - lowerText = item->query()->socialActionDescription( "Love", Query::Detailed ); - - if ( source.isNull() ) + QSize avatarSize( 32, 32 ); + source_ptr source = item->query()->playedBy().first; + if ( m_mode == RecentlyPlayed && !source.isNull() ) { - } - else - { - upperText = QString( "%1 - %2" ).arg( artist ).arg( track ); + avatar = source->avatar( Source::FancyStyle, avatarSize ); QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true ); if ( source == SourceList::instance()->getLocal() ) @@ -181,6 +178,9 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& lowerText = QString( tr( "played %1 by %2" ) ).arg( playtime ).arg( source->friendlyName() ); } + if ( m_mode == LovedTracks ) + lowerText = item->query()->socialActionDescription( "Love", Query::Detailed ); + painter->save(); { QRect r = opt.rect.adjusted( 3, 6, 0, -6 ); @@ -197,14 +197,10 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& painter->setPen( opt.palette.text().color() ); - QSize avatarSize( 32, 32 ); QRect pixmapRect = r.adjusted( 6, 0, -option.rect.width() + option.rect.height() - 6 + r.left(), 0 ); QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 ); avatarRect.setSize( avatarSize ); - if ( source ) - avatar = source->avatar( Source::FancyStyle, avatarRect.size() ); - pixmap = item->query()->cover( pixmapRect.size(), false ); if ( !pixmap ) { diff --git a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h index 56ea64a57..ad2210a75 100644 --- a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h +++ b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h @@ -35,7 +35,10 @@ class DLLEXPORT PlaylistLargeItemDelegate : public QStyledItemDelegate Q_OBJECT public: - PlaylistLargeItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 ); + enum DisplayMode + { LovedTracks, RecentlyPlayed, LatestAdditions }; + + PlaylistLargeItemDelegate( DisplayMode mode, TrackView* parent = 0, TrackProxyModel* proxy = 0 ); protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; @@ -52,6 +55,7 @@ private: TrackView* m_view; TrackProxyModel* m_model; + DisplayMode m_mode; }; #endif // PLAYLISTLARGEITEMDELEGATE_H diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 2d06796d5..d0c8aa88c 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -441,7 +441,7 @@ ViewManager::showTopLovedPage() if ( !m_topLovedWidget ) { CustomPlaylistView* view = new CustomPlaylistView( CustomPlaylistView::TopLovedTracks, source_ptr(), m_widget ); - view->setItemDelegate( new PlaylistLargeItemDelegate( view, view->proxyModel() ) ); + view->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, view, view->proxyModel() ) ); m_topLovedWidget = view; } diff --git a/src/sourcetree/items/sourceitem.cpp b/src/sourcetree/items/sourceitem.cpp index 42327f565..c1767734f 100644 --- a/src/sourcetree/items/sourceitem.cpp +++ b/src/sourcetree/items/sourceitem.cpp @@ -504,7 +504,7 @@ SourceItem::lovedTracksClicked() if ( !m_lovedTracksPage ) { CustomPlaylistView* view = new CustomPlaylistView( m_source.isNull() ? CustomPlaylistView::TopLovedTracks : CustomPlaylistView::SourceLovedTracks, m_source, ViewManager::instance()->widget() ); - view->setItemDelegate( new PlaylistLargeItemDelegate( view, view->proxyModel() ) ); + view->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, view, view->proxyModel() ) ); m_lovedTracksPage = view; } @@ -533,7 +533,7 @@ SourceItem::latestAdditionsClicked() RecentlyAddedModel* raModel = new RecentlyAddedModel( m_source, cv ); raModel->setStyle( TrackModel::Large ); - cv->setItemDelegate( new PlaylistLargeItemDelegate( cv, cv->proxyModel() ) ); + cv->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LatestAdditions, cv, cv->proxyModel() ) ); cv->setTrackModel( raModel ); cv->sortByColumn( TrackModel::Age, Qt::DescendingOrder ); @@ -564,7 +564,7 @@ SourceItem::recentPlaysClicked() RecentlyPlayedModel* raModel = new RecentlyPlayedModel( m_source, pv ); raModel->setStyle( TrackModel::Large ); - pv->setItemDelegate( new PlaylistLargeItemDelegate( pv, pv->proxyModel() ) ); + pv->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::RecentlyPlayed, pv, pv->proxyModel() ) ); pv->setPlaylistModel( raModel ); m_recentPlaysPage = pv;