mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
* Create default avatar based on user's name.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QtAlgorithms>
|
#include <QtAlgorithms>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -280,7 +281,7 @@ Source::friendlyNamesLessThan( const QString& first, const QString& second )
|
|||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
Source::avatar( TomahawkUtils::ImageMode style, const QSize& size )
|
Source::avatar( TomahawkUtils::ImageMode style, const QSize& size, bool defaultAvatarFallback )
|
||||||
{
|
{
|
||||||
Q_D( Source );
|
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 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ public:
|
|||||||
QString dbFriendlyName() const;
|
QString dbFriendlyName() const;
|
||||||
void setDbFriendlyName( const QString& dbFriendlyName );
|
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;
|
collection_ptr dbCollection() const;
|
||||||
QList< Tomahawk::collection_ptr > collections() const;
|
QList< Tomahawk::collection_ptr > collections() const;
|
||||||
|
Reference in New Issue
Block a user