1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Improved AlbumView and cover fetching in Artist / Album-Model.

This commit is contained in:
Christian Muehlhaeuser
2011-07-11 16:52:09 +02:00
parent 6f14277821
commit 15805aa32c
10 changed files with 58 additions and 30 deletions

View File

@@ -38,6 +38,8 @@ AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel
, m_model( proxy ) , m_model( proxy )
{ {
m_shadowPixmap = QPixmap( RESPATH "images/cover-shadow.png" ); m_shadowPixmap = QPixmap( RESPATH "images/cover-shadow.png" );
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
} }
@@ -66,22 +68,44 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
} }
painter->save(); painter->save();
// painter->setRenderHint( QPainter::Antialiasing ); // painter->setRenderHint( QPainter::Antialiasing );
// painter->drawPixmap( option.rect.adjusted( 4, 4, -4, -38 ), m_shadowPixmap );
QPixmap cover = item->cover.isNull() ? m_defaultCover : item->cover;
painter->drawPixmap( option.rect.adjusted( 6, 4, -6, -41 ), cover );
painter->setPen( opt.palette.color( QPalette::Text ) ); painter->setPen( opt.palette.color( QPalette::Text ) );
// painter->drawPixmap( option.rect.adjusted( 4, 4, -4, -38 ), m_shadowPixmap );
painter->drawPixmap( option.rect.adjusted( 6, 4, -6, -41 ), item->cover );
QTextOption to; QTextOption to;
to.setAlignment( Qt::AlignHCenter ); to.setWrapMode( QTextOption::NoWrap );
QString text;
QFont font = opt.font; QFont font = opt.font;
QFont boldFont = opt.font; QFont boldFont = opt.font;
boldFont.setBold( true ); boldFont.setBold( true );
painter->drawText( option.rect.adjusted( 0, option.rect.height() - 16, 0, -2 ), item->album()->artist()->name(), to ); QRect textRect = option.rect.adjusted( 0, option.rect.height() - 32, 0, -2 );
painter->setFont( boldFont ); bool oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() ||
painter->drawText( option.rect.adjusted( 0, option.rect.height() - 32, 0, -18 ), item->album()->name(), to ); textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->artist()->name() ).height() );
if ( oneLiner )
{
to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
text = painter->fontMetrics().elidedText( item->album()->name(), Qt::ElideRight, textRect.width() - 3 );
painter->drawText( textRect, text, to );
}
else
{
to.setAlignment( Qt::AlignHCenter | Qt::AlignTop );
text = painter->fontMetrics().elidedText( item->album()->name(), Qt::ElideRight, textRect.width() - 3 );
painter->drawText( textRect, text, to );
painter->setFont( boldFont );
to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
text = painter->fontMetrics().elidedText( item->album()->artist()->name(), Qt::ElideRight, textRect.width() - 3 );
painter->drawText( textRect, text, to );
}
painter->restore(); painter->restore();
} }

View File

@@ -43,6 +43,7 @@ private:
AlbumProxyModel* m_model; AlbumProxyModel* m_model;
QPixmap m_shadowPixmap; QPixmap m_shadowPixmap;
QPixmap m_defaultCover;
}; };
#endif // ALBUMITEMDELEGATE_H #endif // ALBUMITEMDELEGATE_H

View File

@@ -27,8 +27,6 @@
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#define LASTFM_DEFAULT_COVER "http://cdn.last.fm/flatness/catalogue/noimage"
static QString s_tmInfoIdentifier = QString( "ALBUMMODEL" ); static QString s_tmInfoIdentifier = QString( "ALBUMMODEL" );
using namespace Tomahawk; using namespace Tomahawk;
@@ -40,9 +38,6 @@ AlbumModel::AlbumModel( QObject* parent )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
@@ -299,7 +294,6 @@ AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums )
foreach( const album_ptr& album, albums ) foreach( const album_ptr& album, albums )
{ {
albumitem = new AlbumItem( album, m_rootItem ); albumitem = new AlbumItem( album, m_rootItem );
albumitem->cover = m_defaultCover;
albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem ); albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem );
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
@@ -340,9 +334,7 @@ AlbumModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, Q
qlonglong p = pptr["pptr"].toLongLong( &ok ); qlonglong p = pptr["pptr"].toLongLong( &ok );
AlbumItem* ai = reinterpret_cast<AlbumItem*>(p); AlbumItem* ai = reinterpret_cast<AlbumItem*>(p);
if ( pm.isNull() ) if ( !pm.isNull() )
ai->cover = m_defaultCover;
else
ai->cover = pm; ai->cover = pm;
emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) ); emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) );

View File

@@ -103,7 +103,6 @@ private slots:
private: private:
QPersistentModelIndex m_currentIndex; QPersistentModelIndex m_currentIndex;
AlbumItem* m_rootItem; AlbumItem* m_rootItem;
QPixmap m_defaultCover;
QString m_title; QString m_title;
QString m_description; QString m_description;

View File

@@ -145,18 +145,32 @@ AlbumView::onScrollTimeout()
int rowHeight = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize().height(); int rowHeight = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize().height();
viewRect.adjust( 0, -rowHeight, 0, rowHeight ); viewRect.adjust( 0, -rowHeight, 0, rowHeight );
bool started = false;
bool done = false;
for ( int i = 0; i < m_proxyModel->rowCount(); i++ ) for ( int i = 0; i < m_proxyModel->rowCount(); i++ )
{ {
if ( started && done )
break;
for ( int j = 0; j < m_proxyModel->columnCount(); j++ ) for ( int j = 0; j < m_proxyModel->columnCount(); j++ )
{ {
QModelIndex idx = m_proxyModel->index( i, j ); QModelIndex idx = m_proxyModel->index( i, j );
if ( !viewRect.contains( visualRect( idx ) ) ) if ( !viewRect.contains( visualRect( idx ) ) )
{
done = true;
break; break;
}
started = true;
done = false;
AlbumItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( idx ) ); AlbumItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( idx ) );
if ( !item ) if ( !item )
break; break;
if ( !item->cover.isNull() )
break;
qDebug() << "Need cover for:" << item->album()->artist()->name() << item->album()->name();
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo; Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["artist"] = item->album()->artist()->name(); trackInfo["artist"] = item->album()->artist()->name();
trackInfo["album"] = item->album()->name(); trackInfo["album"] = item->album()->name();
@@ -167,7 +181,7 @@ AlbumView::onScrollTimeout()
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt; requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ); requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
requestData.customData = QVariantMap(); requestData.customData = QVariantMap();
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
} }
} }

View File

@@ -244,6 +244,8 @@ ArtistView::onScrollTimeout()
TreeModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) ); TreeModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) );
if ( item->artist().isNull() ) if ( item->artist().isNull() )
continue; continue;
if ( !item->cover.isNull() )
continue;
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo; Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["artist"] = item->artist()->name(); trackInfo["artist"] = item->artist()->name();

View File

@@ -40,6 +40,8 @@ TreeItemDelegate::TreeItemDelegate( ArtistView* parent, TreeProxyModel* proxy )
, m_model( proxy ) , m_model( proxy )
{ {
m_nowPlayingIcon = QPixmap( RESPATH "images/now-playing-speaker.png" ); m_nowPlayingIcon = QPixmap( RESPATH "images/now-playing-speaker.png" );
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
} }
@@ -131,7 +133,9 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 ); QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 );
// painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) ); // painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) );
painter->drawPixmap( r, item->cover );
QPixmap cover = item->cover.isNull() ? m_defaultCover : item->cover;
painter->drawPixmap( r, cover );
QTextOption to; QTextOption to;
to.setAlignment( Qt::AlignVCenter ); to.setAlignment( Qt::AlignVCenter );

View File

@@ -44,6 +44,7 @@ private:
TreeProxyModel* m_model; TreeProxyModel* m_model;
QPixmap m_nowPlayingIcon; QPixmap m_nowPlayingIcon;
QPixmap m_defaultCover;
}; };
#endif // TREEITEMDELEGATE_H #endif // TREEITEMDELEGATE_H

View File

@@ -40,9 +40,6 @@ TreeModel::TreeModel( QObject* parent )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
connect( AudioEngine::instance(), SIGNAL( finished( Tomahawk::result_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::result_ptr ) ), Qt::DirectConnection ); connect( AudioEngine::instance(), SIGNAL( finished( Tomahawk::result_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::result_ptr ) ), Qt::DirectConnection );
connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ), Qt::DirectConnection ); connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ), Qt::DirectConnection );
@@ -496,7 +493,6 @@ TreeModel::onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists )
foreach( const artist_ptr& artist, artists ) foreach( const artist_ptr& artist, artists )
{ {
artistitem = new TreeModelItem( artist, m_rootItem ); artistitem = new TreeModelItem( artist, m_rootItem );
artistitem->cover = m_defaultCover;
artistitem->index = createIndex( m_rootItem->children.count() - 1, 0, artistitem ); artistitem->index = createIndex( m_rootItem->children.count() - 1, 0, artistitem );
connect( artistitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); connect( artistitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
} }
@@ -533,7 +529,6 @@ TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVaria
foreach( const album_ptr& album, albums ) foreach( const album_ptr& album, albums )
{ {
albumitem = new TreeModelItem( album, parentItem ); albumitem = new TreeModelItem( album, parentItem );
albumitem->cover = m_defaultCover;
albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem ); albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem );
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
@@ -547,7 +542,7 @@ TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVaria
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt; requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ); requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
requestData.customData = QVariantMap(); requestData.customData = QVariantMap();
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
} }
@@ -587,7 +582,6 @@ TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QVaria
{ {
qDebug() << query->toString(); qDebug() << query->toString();
item = new TreeModelItem( query->results().first(), parentItem ); item = new TreeModelItem( query->results().first(), parentItem );
item->cover = m_defaultCover;
item->index = createIndex( parentItem->children.count() - 1, 0, item ); item->index = createIndex( parentItem->children.count() - 1, 0, item );
connect( item, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); connect( item, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
@@ -633,9 +627,7 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
qlonglong p = pptr["pptr"].toLongLong( &ok ); qlonglong p = pptr["pptr"].toLongLong( &ok );
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p); TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p);
if ( pm.isNull() ) if ( !pm.isNull() )
ai->cover = m_defaultCover;
else
ai->cover = pm; ai->cover = pm;
emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) ); emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) );

View File

@@ -136,7 +136,6 @@ private slots:
private: private:
QPersistentModelIndex m_currentIndex; QPersistentModelIndex m_currentIndex;
TreeModelItem* m_rootItem; TreeModelItem* m_rootItem;
QPixmap m_defaultCover;
QString m_title; QString m_title;
QString m_description; QString m_description;