diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index 96f0567aa..dbfaa287a 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -41,6 +41,7 @@ #include #include +#include using namespace Tomahawk; @@ -280,7 +281,7 @@ Source::friendlyNamesLessThan( const QString& first, const QString& second ) QPixmap -Source::avatar( TomahawkUtils::ImageMode style, const QSize& size ) +Source::avatar( TomahawkUtils::ImageMode style, const QSize& size, bool defaultAvatarFallback ) { Q_D( Source ); @@ -315,7 +316,20 @@ Source::avatar( TomahawkUtils::ImageMode style, const QSize& size ) return d->avatar->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } - return QPixmap(); + if ( defaultAvatarFallback ) + { + QPixmap px = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, style, size ); + QPainter p( &px ); + p.setRenderHint( QPainter::Antialiasing ); + QFont f = p.font(); + f.setPixelSize( px.size().height() - 8 ); + p.setFont( f ); + p.setPen( Qt::white ); + p.drawText( px.rect().adjusted( 0, 2, 0, 0 ), friendlyName().left( 1 ).toUpper(), QTextOption( Qt::AlignCenter ) ); + return px; + } + else + return QPixmap(); } diff --git a/src/libtomahawk/Source.h b/src/libtomahawk/Source.h index 4c3196f3d..9f71027e2 100644 --- a/src/libtomahawk/Source.h +++ b/src/libtomahawk/Source.h @@ -80,7 +80,7 @@ public: QString dbFriendlyName() const; void setDbFriendlyName( const QString& dbFriendlyName ); - QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() ); + QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize(), bool defaultAvatarFallback = false ); collection_ptr dbCollection() const; QList< Tomahawk::collection_ptr > collections() const;