Commit 41148b03 authored by Ilkka Ollakka's avatar Ilkka Ollakka

Qt4: scale iconview art related to fontsize

Scales whole view content related to fontsize we get from model.
parent 8526b9a3
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
#include "assert.h" #include "assert.h"
#define ART_SIZE_W 110 /* ICON_SCALER comes currently from harrison-stetson method, so good value */
#define ART_SIZE_H 80 #define ICON_SCALER 16
#define ART_RADIUS 5 #define ART_RADIUS 5
#define SPACER 5 #define SPACER 5
...@@ -131,14 +131,22 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -131,14 +131,22 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
QString title = getMeta( index, COLUMN_TITLE ); QString title = getMeta( index, COLUMN_TITLE );
QString artist = getMeta( index, COLUMN_ARTIST ); QString artist = getMeta( index, COLUMN_ARTIST );
QPixmap artPix = getArtPixmap( index, QSize( ART_SIZE_W, ART_SIZE_H ) ); QFont font( index.data( Qt::FontRole ).value<QFont>() );
painter->setFont( font );
QFontMetrics fm = painter->fontMetrics();
int averagewidth = fm.averageCharWidth();
int art_width = averagewidth * ICON_SCALER;
int art_height = averagewidth * ICON_SCALER;
QPixmap artPix = getArtPixmap( index, QSize( art_width, art_height) );
paintBackground( painter, option, index ); paintBackground( painter, option, index );
painter->save(); painter->save();
QRect artRect( option.rect.x() + 5 + ( ART_SIZE_W - artPix.width() ) / 2, QRect artRect( option.rect.x() + averagewidth*2 + ( art_width - artPix.width() ) / 2,
option.rect.y() + 5 + ( ART_SIZE_H - artPix.height() ) / 2, option.rect.y() + averagewidth + ( art_height - artPix.height() ) / 2,
artPix.width(), artPix.height() ); artPix.width(), artPix.height() );
// Draw the drop shadow // Draw the drop shadow
...@@ -159,7 +167,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -159,7 +167,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
if( option.state & QStyle::State_Selected ) if( option.state & QStyle::State_Selected )
painter->setPen( option.palette.color( QPalette::HighlightedText ) ); painter->setPen( option.palette.color( QPalette::HighlightedText ) );
QFont font( index.data( Qt::FontRole ).value<QFont>() );
//Draw children indicator //Draw children indicator
if( !index.data( PLModel::IsLeafNodeRole ).toBool() ) if( !index.data( PLModel::IsLeafNodeRole ).toBool() )
...@@ -183,10 +190,9 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -183,10 +190,9 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
// Draw title // Draw title
font.setItalic( true ); font.setItalic( true );
painter->setFont( font );
QFontMetrics fm = painter->fontMetrics(); fm = painter->fontMetrics();
QRect textRect = option.rect.adjusted( 1, ART_SIZE_H + 10, 0, -1 ); QRect textRect = option.rect.adjusted( 1, art_height + 10, 0, -1 );
textRect.setHeight( fm.height() ); textRect.setHeight( fm.height() );
painter->drawText( textRect, painter->drawText( textRect,
...@@ -214,8 +220,9 @@ QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem & option, co ...@@ -214,8 +220,9 @@ QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem & option, co
f.setBold( true ); f.setBold( true );
QFontMetrics fm( f ); QFontMetrics fm( f );
int textHeight = fm.height(); int textHeight = fm.height();
QSize sz ( ART_SIZE_W + 2 * SPACER, int averagewidth = fm.averageCharWidth();
ART_SIZE_H + 3 * SPACER + 2 * textHeight + 1 ); QSize sz ( averagewidth * ICON_SCALER + 4 * SPACER,
averagewidth * ICON_SCALER + 4 * SPACER + 2 * textHeight + 1 );
return sz; return sz;
} }
...@@ -341,7 +348,6 @@ PlIconView::PlIconView( PLModel *model, QWidget *parent ) : QListView( parent ) ...@@ -341,7 +348,6 @@ PlIconView::PlIconView( PLModel *model, QWidget *parent ) : QListView( parent )
setViewMode( QListView::IconMode ); setViewMode( QListView::IconMode );
setMovement( QListView::Static ); setMovement( QListView::Static );
setResizeMode( QListView::Adjust ); setResizeMode( QListView::Adjust );
setGridSize( delegate->sizeHint() );
setWrapping( true ); setWrapping( true );
setUniformItemSizes( true ); setUniformItemSizes( true );
setSelectionMode( QAbstractItemView::ExtendedSelection ); setSelectionMode( QAbstractItemView::ExtendedSelection );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment