mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-27 07:44:34 +02:00
* Fixed PlaylistLargeItemDelegate.
This commit is contained in:
@@ -40,10 +40,11 @@
|
|||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
PlaylistLargeItemDelegate::PlaylistLargeItemDelegate( TrackView* parent, TrackProxyModel* proxy )
|
PlaylistLargeItemDelegate::PlaylistLargeItemDelegate( DisplayMode mode, TrackView* parent, TrackProxyModel* proxy )
|
||||||
: QStyledItemDelegate( (QObject*)parent )
|
: QStyledItemDelegate( (QObject*)parent )
|
||||||
, m_view( parent )
|
, m_view( parent )
|
||||||
, m_model( proxy )
|
, m_model( proxy )
|
||||||
|
, m_mode( mode )
|
||||||
{
|
{
|
||||||
m_topOption = QTextOption( Qt::AlignTop );
|
m_topOption = QTextOption( Qt::AlignTop );
|
||||||
m_topOption.setWrapMode( QTextOption::NoWrap );
|
m_topOption.setWrapMode( QTextOption::NoWrap );
|
||||||
@@ -149,8 +150,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QPixmap pixmap, avatar;
|
QPixmap pixmap, avatar;
|
||||||
QString artist, track, upperText, lowerText;
|
QString artist, track, lowerText;
|
||||||
source_ptr source = item->query()->playedBy().first;
|
|
||||||
unsigned int duration = 0;
|
unsigned int duration = 0;
|
||||||
|
|
||||||
if ( item->query()->results().count() )
|
if ( item->query()->results().count() )
|
||||||
@@ -165,14 +165,11 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
track = item->query()->track();
|
track = item->query()->track();
|
||||||
}
|
}
|
||||||
|
|
||||||
lowerText = item->query()->socialActionDescription( "Love", Query::Detailed );
|
QSize avatarSize( 32, 32 );
|
||||||
|
source_ptr source = item->query()->playedBy().first;
|
||||||
if ( source.isNull() )
|
if ( m_mode == RecentlyPlayed && !source.isNull() )
|
||||||
{
|
{
|
||||||
}
|
avatar = source->avatar( Source::FancyStyle, avatarSize );
|
||||||
else
|
|
||||||
{
|
|
||||||
upperText = QString( "%1 - %2" ).arg( artist ).arg( track );
|
|
||||||
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true );
|
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true );
|
||||||
|
|
||||||
if ( source == SourceList::instance()->getLocal() )
|
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() );
|
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();
|
painter->save();
|
||||||
{
|
{
|
||||||
QRect r = opt.rect.adjusted( 3, 6, 0, -6 );
|
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() );
|
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 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 );
|
QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 );
|
||||||
avatarRect.setSize( avatarSize );
|
avatarRect.setSize( avatarSize );
|
||||||
|
|
||||||
if ( source )
|
|
||||||
avatar = source->avatar( Source::FancyStyle, avatarRect.size() );
|
|
||||||
|
|
||||||
pixmap = item->query()->cover( pixmapRect.size(), false );
|
pixmap = item->query()->cover( pixmapRect.size(), false );
|
||||||
if ( !pixmap )
|
if ( !pixmap )
|
||||||
{
|
{
|
||||||
|
@@ -35,7 +35,10 @@ class DLLEXPORT PlaylistLargeItemDelegate : public QStyledItemDelegate
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlaylistLargeItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 );
|
enum DisplayMode
|
||||||
|
{ LovedTracks, RecentlyPlayed, LatestAdditions };
|
||||||
|
|
||||||
|
PlaylistLargeItemDelegate( DisplayMode mode, TrackView* parent = 0, TrackProxyModel* proxy = 0 );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
@@ -52,6 +55,7 @@ private:
|
|||||||
|
|
||||||
TrackView* m_view;
|
TrackView* m_view;
|
||||||
TrackProxyModel* m_model;
|
TrackProxyModel* m_model;
|
||||||
|
DisplayMode m_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLISTLARGEITEMDELEGATE_H
|
#endif // PLAYLISTLARGEITEMDELEGATE_H
|
||||||
|
@@ -441,7 +441,7 @@ ViewManager::showTopLovedPage()
|
|||||||
if ( !m_topLovedWidget )
|
if ( !m_topLovedWidget )
|
||||||
{
|
{
|
||||||
CustomPlaylistView* view = new CustomPlaylistView( CustomPlaylistView::TopLovedTracks, source_ptr(), m_widget );
|
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;
|
m_topLovedWidget = view;
|
||||||
}
|
}
|
||||||
|
@@ -504,7 +504,7 @@ SourceItem::lovedTracksClicked()
|
|||||||
if ( !m_lovedTracksPage )
|
if ( !m_lovedTracksPage )
|
||||||
{
|
{
|
||||||
CustomPlaylistView* view = new CustomPlaylistView( m_source.isNull() ? CustomPlaylistView::TopLovedTracks : CustomPlaylistView::SourceLovedTracks, m_source, ViewManager::instance()->widget() );
|
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;
|
m_lovedTracksPage = view;
|
||||||
}
|
}
|
||||||
@@ -533,7 +533,7 @@ SourceItem::latestAdditionsClicked()
|
|||||||
RecentlyAddedModel* raModel = new RecentlyAddedModel( m_source, cv );
|
RecentlyAddedModel* raModel = new RecentlyAddedModel( m_source, cv );
|
||||||
raModel->setStyle( TrackModel::Large );
|
raModel->setStyle( TrackModel::Large );
|
||||||
|
|
||||||
cv->setItemDelegate( new PlaylistLargeItemDelegate( cv, cv->proxyModel() ) );
|
cv->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LatestAdditions, cv, cv->proxyModel() ) );
|
||||||
cv->setTrackModel( raModel );
|
cv->setTrackModel( raModel );
|
||||||
cv->sortByColumn( TrackModel::Age, Qt::DescendingOrder );
|
cv->sortByColumn( TrackModel::Age, Qt::DescendingOrder );
|
||||||
|
|
||||||
@@ -564,7 +564,7 @@ SourceItem::recentPlaysClicked()
|
|||||||
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( m_source, pv );
|
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( m_source, pv );
|
||||||
raModel->setStyle( TrackModel::Large );
|
raModel->setStyle( TrackModel::Large );
|
||||||
|
|
||||||
pv->setItemDelegate( new PlaylistLargeItemDelegate( pv, pv->proxyModel() ) );
|
pv->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::RecentlyPlayed, pv, pv->proxyModel() ) );
|
||||||
pv->setPlaylistModel( raModel );
|
pv->setPlaylistModel( raModel );
|
||||||
|
|
||||||
m_recentPlaysPage = pv;
|
m_recentPlaysPage = pv;
|
||||||
|
Reference in New Issue
Block a user