mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-25 15:01:11 +02:00
* Fixed PlaylistLargeItemDelegate.
This commit is contained in:
@@ -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 )
|
||||
{
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user