From 15f5212fa09a940313c9ca8cd861b6fe90b9a0fa Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 14 Aug 2011 04:54:45 +0200 Subject: [PATCH] * Fixed TWK-375: TreeItemDelegate's painting for tracks was broken. --- src/libtomahawk/playlist/treeitemdelegate.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libtomahawk/playlist/treeitemdelegate.cpp b/src/libtomahawk/playlist/treeitemdelegate.cpp index ef63ca0e7..4d18f60d2 100644 --- a/src/libtomahawk/playlist/treeitemdelegate.cpp +++ b/src/libtomahawk/playlist/treeitemdelegate.cpp @@ -75,9 +75,11 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, opacity = qMax( (float)0.3, opacity ); QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity ); - if ( const QStyleOptionViewItem *vioption = qstyleoption_cast(&option)) { - QStyleOptionViewItemV4 o( *vioption ); + QStyleOptionViewItemV4 o = option; + initStyleOption( &o, QModelIndex() ); + + painter->save(); o.palette.setColor( QPalette::Text, textColor ); if ( o.state & QStyle::State_Selected && o.state & QStyle::State_Active ) @@ -93,14 +95,15 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, o.state |= QStyle::State_Selected; } -#ifdef Q_OS_MAC - int oldX = o.rect.x(); - o.rect.setX( 0 ); -#endif + int oldX = 0; + if ( m_view->header()->visualIndex( index.column() ) == 0 ) + { + oldX = o.rect.x(); + o.rect.setX( 0 ); + } qApp->style()->drawControl( QStyle::CE_ItemViewItem, &o, painter ); -#ifdef Q_OS_MAC - o.rect.setX( oldX ); -#endif + if ( oldX > 0 ) + o.rect.setX( oldX ); { QRect r = o.rect.adjusted( 3, 0, 0, 0 ); @@ -113,14 +116,15 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, r.adjust( 25, 0, 0, 3 ); } - painter->setPen( o.palette.text().color() ); QTextOption to( Qt::AlignVCenter ); QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 ); painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to ); } + painter->restore(); } + return; } else