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

also adjust the PlaylistDelegate

This commit is contained in:
Michael Zanetti
2012-07-17 23:10:43 +02:00
parent 2a7fabf633
commit ea497de3c4

View File

@@ -187,7 +187,18 @@ PlaylistDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelInde
{
Q_UNUSED( option );
Q_UNUSED( index );
return QSize( 0, 64 );
// Calculates the size for the bold line + 3 normal lines + margins
int height = 2 * 6; // margins
QFont font = option.font;
QFontMetrics fm1( font );
font.setPointSize( 8 );
height += fm1.height() * 3;
font.setPointSize( 9 );
QFontMetrics fm2( font );
height += fm2.height();
return QSize( 0, height );
}
@@ -210,14 +221,17 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
QTextOption to;
to.setAlignment( Qt::AlignCenter );
QFont font = opt.font;
font.setPixelSize( 10 );
font.setPointSize( 8 );
QFontMetrics fontMetrics( font );
QFont boldFont = font;
boldFont.setBold( true );
boldFont.setPixelSize( 11 );
boldFont.setPointSize( 9 );
QFontMetrics boldFontMetrics( boldFont );
QFont figFont = boldFont;
figFont.setPixelSize( 10 );
figFont.setPointSize( 8 );
QFontMetrics figFontMetrics( figFont );
QPixmap icon;
RecentlyPlayedPlaylistsModel::PlaylistTypes type = (RecentlyPlayedPlaylistsModel::PlaylistTypes)index.data( RecentlyPlayedPlaylistsModel::PlaylistTypeRole ).toInt();
@@ -228,7 +242,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
else if( type == RecentlyPlayedPlaylistsModel::Station )
icon = m_stationIcon;
QRect pixmapRect = option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 );
QRect pixmapRect = option.rect.adjusted( 10, 13, -option.rect.width() + option.rect.height() - 26, -13 );
icon = icon.scaled( pixmapRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
painter->drawPixmap( pixmapRect, icon );
@@ -258,7 +272,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
QPixmap avatar = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar( Source::FancyStyle );
if ( avatar.isNull() )
avatar = m_defaultAvatar;
QRect r( option.rect.width() - avatar.width() - 10, option.rect.top() + option.rect.height()/2 - avatar.height()/2, avatar.width(), avatar.height() );
QRect r( option.rect.width() - option.fontMetrics.height() * 2.5 - 10, option.rect.top() + option.rect.height()/2.25 - option.fontMetrics.height(), option.fontMetrics.height() * 2.5, option.fontMetrics.height() * 2.2 );
painter->drawPixmap( r, avatar );
painter->setFont( font );
@@ -287,7 +301,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setPen( QColor( Qt::gray ).darker() );
}
QRect rectText = option.rect.adjusted( 66, 20, -leftEdge - 10, -8 );
QRect rectText = option.rect.adjusted( option.fontMetrics.height() * 4.5, boldFontMetrics.height() + 6, -leftEdge - 10, -8 );
#ifdef Q_WS_MAC
rectText.adjust( 0, 1, 0, 0 );
#elif defined Q_WS_WIN
@@ -299,7 +313,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setFont( font );
painter->setFont( boldFont );
painter->drawText( option.rect.adjusted( 56, 6, -100, -option.rect.height() + 20 ), index.data().toString() );
painter->drawText( option.rect.adjusted( option.fontMetrics.height() * 4, 6, -100, -option.rect.height() + boldFontMetrics.height() + 6 ), index.data().toString() );
painter->restore();
}