mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-31 06:02:27 +02:00
* Improved AlbumView and cover fetching in Artist / Album-Model.
This commit is contained in:
parent
6f14277821
commit
15805aa32c
@ -38,6 +38,8 @@ AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel
|
||||
, m_model( proxy )
|
||||
{
|
||||
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->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->drawPixmap( option.rect.adjusted( 4, 4, -4, -38 ), m_shadowPixmap );
|
||||
painter->drawPixmap( option.rect.adjusted( 6, 4, -6, -41 ), item->cover );
|
||||
|
||||
QTextOption to;
|
||||
to.setAlignment( Qt::AlignHCenter );
|
||||
to.setWrapMode( QTextOption::NoWrap );
|
||||
|
||||
QString text;
|
||||
QFont font = opt.font;
|
||||
QFont boldFont = opt.font;
|
||||
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 );
|
||||
painter->drawText( option.rect.adjusted( 0, option.rect.height() - 32, 0, -18 ), item->album()->name(), to );
|
||||
bool oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() ||
|
||||
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();
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ private:
|
||||
AlbumProxyModel* m_model;
|
||||
|
||||
QPixmap m_shadowPixmap;
|
||||
QPixmap m_defaultCover;
|
||||
};
|
||||
|
||||
#endif // ALBUMITEMDELEGATE_H
|
||||
|
@ -27,8 +27,6 @@
|
||||
|
||||
#include "utils/tomahawkutils.h"
|
||||
|
||||
#define LASTFM_DEFAULT_COVER "http://cdn.last.fm/flatness/catalogue/noimage"
|
||||
|
||||
static QString s_tmInfoIdentifier = QString( "ALBUMMODEL" );
|
||||
|
||||
using namespace Tomahawk;
|
||||
@ -40,9 +38,6 @@ AlbumModel::AlbumModel( QObject* parent )
|
||||
{
|
||||
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(),
|
||||
SIGNAL( info( 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 )
|
||||
{
|
||||
albumitem = new AlbumItem( album, m_rootItem );
|
||||
albumitem->cover = m_defaultCover;
|
||||
albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem );
|
||||
|
||||
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
||||
@ -340,9 +334,7 @@ AlbumModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, Q
|
||||
qlonglong p = pptr["pptr"].toLongLong( &ok );
|
||||
AlbumItem* ai = reinterpret_cast<AlbumItem*>(p);
|
||||
|
||||
if ( pm.isNull() )
|
||||
ai->cover = m_defaultCover;
|
||||
else
|
||||
if ( !pm.isNull() )
|
||||
ai->cover = pm;
|
||||
|
||||
emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) );
|
||||
|
@ -103,7 +103,6 @@ private slots:
|
||||
private:
|
||||
QPersistentModelIndex m_currentIndex;
|
||||
AlbumItem* m_rootItem;
|
||||
QPixmap m_defaultCover;
|
||||
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
|
@ -145,18 +145,32 @@ AlbumView::onScrollTimeout()
|
||||
int rowHeight = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize().height();
|
||||
viewRect.adjust( 0, -rowHeight, 0, rowHeight );
|
||||
|
||||
bool started = false;
|
||||
bool done = false;
|
||||
for ( int i = 0; i < m_proxyModel->rowCount(); i++ )
|
||||
{
|
||||
if ( started && done )
|
||||
break;
|
||||
|
||||
for ( int j = 0; j < m_proxyModel->columnCount(); j++ )
|
||||
{
|
||||
QModelIndex idx = m_proxyModel->index( i, j );
|
||||
if ( !viewRect.contains( visualRect( idx ) ) )
|
||||
{
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
started = true;
|
||||
done = false;
|
||||
|
||||
AlbumItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( idx ) );
|
||||
if ( !item )
|
||||
break;
|
||||
if ( !item->cover.isNull() )
|
||||
break;
|
||||
|
||||
qDebug() << "Need cover for:" << item->album()->artist()->name() << item->album()->name();
|
||||
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
|
||||
trackInfo["artist"] = item->album()->artist()->name();
|
||||
trackInfo["album"] = item->album()->name();
|
||||
@ -167,7 +181,7 @@ AlbumView::onScrollTimeout()
|
||||
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
|
||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
|
||||
requestData.customData = QVariantMap();
|
||||
|
||||
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
}
|
||||
}
|
||||
|
@ -244,6 +244,8 @@ ArtistView::onScrollTimeout()
|
||||
TreeModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) );
|
||||
if ( item->artist().isNull() )
|
||||
continue;
|
||||
if ( !item->cover.isNull() )
|
||||
continue;
|
||||
|
||||
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
|
||||
trackInfo["artist"] = item->artist()->name();
|
||||
|
@ -40,6 +40,8 @@ TreeItemDelegate::TreeItemDelegate( ArtistView* parent, TreeProxyModel* proxy )
|
||||
, m_model( proxy )
|
||||
{
|
||||
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 );
|
||||
// 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;
|
||||
to.setAlignment( Qt::AlignVCenter );
|
||||
|
@ -44,6 +44,7 @@ private:
|
||||
TreeProxyModel* m_model;
|
||||
|
||||
QPixmap m_nowPlayingIcon;
|
||||
QPixmap m_defaultCover;
|
||||
};
|
||||
|
||||
#endif // TREEITEMDELEGATE_H
|
||||
|
@ -40,9 +40,6 @@ TreeModel::TreeModel( QObject* parent )
|
||||
{
|
||||
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( stopped() ), SLOT( onPlaybackStopped() ), Qt::DirectConnection );
|
||||
|
||||
@ -496,7 +493,6 @@ TreeModel::onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists )
|
||||
foreach( const artist_ptr& artist, artists )
|
||||
{
|
||||
artistitem = new TreeModelItem( artist, m_rootItem );
|
||||
artistitem->cover = m_defaultCover;
|
||||
artistitem->index = createIndex( m_rootItem->children.count() - 1, 0, artistitem );
|
||||
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 )
|
||||
{
|
||||
albumitem = new TreeModelItem( album, parentItem );
|
||||
albumitem->cover = m_defaultCover;
|
||||
albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem );
|
||||
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.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
|
||||
requestData.customData = QVariantMap();
|
||||
|
||||
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
}
|
||||
|
||||
@ -587,7 +582,6 @@ TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QVaria
|
||||
{
|
||||
qDebug() << query->toString();
|
||||
item = new TreeModelItem( query->results().first(), parentItem );
|
||||
item->cover = m_defaultCover;
|
||||
item->index = createIndex( parentItem->children.count() - 1, 0, item );
|
||||
|
||||
connect( item, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
||||
@ -633,9 +627,7 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
|
||||
qlonglong p = pptr["pptr"].toLongLong( &ok );
|
||||
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p);
|
||||
|
||||
if ( pm.isNull() )
|
||||
ai->cover = m_defaultCover;
|
||||
else
|
||||
if ( !pm.isNull() )
|
||||
ai->cover = pm;
|
||||
|
||||
emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) );
|
||||
|
@ -136,7 +136,6 @@ private slots:
|
||||
private:
|
||||
QPersistentModelIndex m_currentIndex;
|
||||
TreeModelItem* m_rootItem;
|
||||
QPixmap m_defaultCover;
|
||||
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
|
Loading…
x
Reference in New Issue
Block a user