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 ); QPixmap px = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, style, size );
QPainter p( &px ); QPainter p( &px );
p.setRenderHint( QPainter::Antialiasing ); p.setRenderHint( QPainter::Antialiasing );
QFont f = p.font(); QFont f = p.font();
f.setPixelSize( px.size().height() - 8 ); f.setPixelSize( px.size().height() - 8 );
p.setFont( f ); p.setFont( f );
p.setPen( Qt::white ); p.setPen( Qt::white );
#ifdef Q_OS_MAC const QString initial = friendlyName().left( 1 ).toUpper();
const QRect pxRect = px.rect(); const QFontMetricsF fm( f );
#else const qreal w = fm.width( initial );
const QRect pxRect = px.rect().adjusted( 0, 2, 0, 0 ); 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() );
#endif
p.drawText( pxRect, friendlyName().left( 1 ).toUpper(), QTextOption( Qt::AlignCenter ) ); p.drawText( pxp, initial );
return px; return px;
} }
else else