1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-14 01:54:07 +02:00

* Try centering by using QFontMetricsF.

This commit is contained in:
Christian Muehlhaeuser
2014-09-01 05:24:30 +02:00
parent 9240e8d476
commit dce30cf718

View File

@@ -316,17 +316,18 @@ Source::avatar( TomahawkUtils::ImageMode style, const QSize& size, bool defaultA
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 );
#ifdef Q_OS_MAC
const QRect pxRect = px.rect();
#else
const QRect pxRect = px.rect().adjusted( 0, 2, 0, 0 );
#endif
p.drawText( pxRect, friendlyName().left( 1 ).toUpper(), QTextOption( Qt::AlignCenter ) );
const QString initial = friendlyName().left( 1 ).toUpper();
const QFontMetricsF fm( f );
const qreal w = fm.width( initial );
const QPointF pxp = QPointF( px.rect().topLeft() ) + QPointF( px.rect().width() / 2.0 - w / 2.0, px.rect().height() / 2.0 - fm.height() / 2.0 + fm.ascent() );
p.drawText( pxp, initial );
return px;
}
else