From 3b148c66ad21a1cb37d6fe9a18a4c569a2a6055c Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sat, 13 Aug 2011 17:13:05 -0400 Subject: [PATCH] Paint a selection rect around items in the config dialog on osx --- src/settingslistdelegate.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/settingslistdelegate.cpp b/src/settingslistdelegate.cpp index cf952780b..195c8ef76 100644 --- a/src/settingslistdelegate.cpp +++ b/src/settingslistdelegate.cpp @@ -19,14 +19,35 @@ void SettingsListDelegate::paint(QPainter *painter, const QStyleOptionViewItem & initStyleOption( &opt, QModelIndex() ); 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 ); - QPixmap avatar = index.data( Qt::DecorationRole ).value().pixmap( iconRect.size() ); - painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) ); +#ifdef Q_OS_MAC + // On mac draw our own selection rect as we don't get one from osx (around the whole icon or around just text) + 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 ) { 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().pixmap( iconRect.size() ); + painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) ); + 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() ); QTextOption to( Qt::AlignHCenter );