1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

Paint a selection rect around items in the config dialog on osx

This commit is contained in:
Leo Franchi
2011-08-13 17:13:05 -04:00
parent 29b0b4e431
commit 3b148c66ad

View File

@@ -19,14 +19,35 @@ void SettingsListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
initStyleOption( &opt, QModelIndex() ); initStyleOption( &opt, QModelIndex() );
qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
QRect iconRect = option.rect.adjusted( 23, 6, -option.rect.width() + option.decorationSize.width() + 7, -option.rect.height() + option.decorationSize.height() + 2 - 12 ); #ifdef Q_OS_MAC
QPixmap avatar = index.data( Qt::DecorationRole ).value<QIcon>().pixmap( iconRect.size() ); // On mac draw our own selection rect as we don't get one from osx (around the whole icon or around just text)
painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) ); if ( opt.state & QStyle::State_Selected )
{
painter->save();
painter->setRenderHint( QPainter::Antialiasing );
QPainterPath p;
p.addRoundedRect( opt.rect.adjusted( 2, 1, -1, -1 ), 5, 5 );
QColor c = opt.palette.color( QPalette::Highlight );
painter->setPen( c.darker( 150 ) );
painter->drawPath( p );
c.setAlpha( 200 );
painter->fillPath( p, c.lighter( 150 ) );
painter->restore();
}
#else
if ( ( option.state & QStyle::State_Selected ) == QStyle::State_Selected ) if ( ( option.state & QStyle::State_Selected ) == QStyle::State_Selected )
{ {
painter->setPen( option.palette.color( QPalette::HighlightedText ) ); painter->setPen( option.palette.color( QPalette::HighlightedText ) );
} }
#endif
QRect iconRect = option.rect.adjusted( 23, 6, -option.rect.width() + option.decorationSize.width() + 7, -option.rect.height() + option.decorationSize.height() + 2 - 12 );
QPixmap avatar = index.data( Qt::DecorationRole ).value<QIcon>().pixmap( iconRect.size() );
painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) );
QRect textRect = option.rect.adjusted( 6, iconRect.height() + 8, -6, 0 ); QRect textRect = option.rect.adjusted( 6, iconRect.height() + 8, -6, 0 );
QString text = painter->fontMetrics().elidedText( index.data( Qt::DisplayRole ).toString(), Qt::ElideRight, textRect.width() ); QString text = painter->fontMetrics().elidedText( index.data( Qt::DisplayRole ).toString(), Qt::ElideRight, textRect.width() );
QTextOption to( Qt::AlignHCenter ); QTextOption to( Qt::AlignHCenter );