From: Jakob Leben Date: Wed, 3 Mar 2010 12:44:25 +0000 (+0100) Subject: Qt: ensure that item selection has visible effect in playlist views X-Git-Tag: 1.1.0-pre1~557 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=b5a14d4d7684f609e5fe071c01870694fa3cd812;p=vlc Qt: ensure that item selection has visible effect in playlist views Fix #3349. Unfortunately we can not use QStyle to handle selection generically across platforms. --- diff --git a/modules/gui/qt4/components/playlist/icon_view.cpp b/modules/gui/qt4/components/playlist/icon_view.cpp index 38f2f92db6..ebd8f77aee 100644 --- a/modules/gui/qt4/components/playlist/icon_view.cpp +++ b/modules/gui/qt4/components/playlist/icon_view.cpp @@ -48,12 +48,35 @@ QString AbstractPlViewItemDelegate::getMeta( const QModelIndex & index, int meta .data().toString(); } -void AbstractPlViewItemDelegate::paintPlayingItemBg( QPainter *painter, const QStyleOptionViewItem & option ) const +void AbstractPlViewItemDelegate::paintBackground( + QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { + /* FIXME: This does not indicate item selection in all QStyles, so for the time being we + have to draw it ourselves, to ensure visible effect of selection on all platforms */ + /* QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, + painter ); */ + painter->save(); - painter->setOpacity( 0.5 ); - painter->setBrush( QBrush( Qt::gray ) ); - painter->fillRect( option.rect, option.palette.color( QPalette::Dark ) ); + QRect r = option.rect.adjusted( 0, 0, -1, -1 ); + if( option.state & QStyle::State_Selected ) + { + painter->setBrush( option.palette.color( QPalette::Highlight ) ); + painter->setPen( option.palette.color( QPalette::Highlight ).darker( 150 ) ); + painter->drawRect( r ); + } + else if( index.data( PLModel::IsCurrentRole ).toBool() ) + { + painter->setBrush( QBrush( Qt::lightGray ) ); + painter->setPen( QColor( Qt::darkGray ) ); + painter->drawRect( r ); + } + if( option.state & QStyle::State_MouseOver ) + { + painter->setOpacity( 0.5 ); + painter->setPen( Qt::NoPen ); + painter->setBrush( option.palette.color( QPalette::Highlight ).lighter( 150 ) ); + painter->drawRect( option.rect ); + } painter->restore(); } @@ -108,20 +131,10 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt QPixmap artPix = getArtPixmap( index, QSize( ART_SIZE_W, ART_SIZE_H ) ); - QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, - painter ); + paintBackground( painter, option, index ); painter->save(); - if( index.data( PLModel::IsCurrentRole ).toBool() ) - { - painter->save(); - painter->setOpacity( 0.2 ); - painter->setBrush( QBrush( Qt::gray ) ); - painter->drawRoundedRect( option.rect.adjusted( 0, 0, -1, -1 ), ART_RADIUS, ART_RADIUS ); - painter->restore(); - } - QRect artRect( option.rect.x() + 5 + ( ART_SIZE_W - artPix.width() ) / 2, option.rect.y() + 5 + ( ART_SIZE_H - artPix.height() ) / 2, artPix.width(), artPix.height() ); @@ -209,12 +222,8 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt QPixmap artPix = getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) ); - //Draw selection rectangle - QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter ); - - //Paint background if item is playing - if( index.data( PLModel::IsCurrentRole ).toBool() ) - paintPlayingItemBg( painter, option ); + //Draw selection rectangle and current playing item indication + paintBackground( painter, option, index ); QRect artRect( artPix.rect() ); artRect.moveCenter( QPoint( artRect.center().x() + 3, diff --git a/modules/gui/qt4/components/playlist/icon_view.hpp b/modules/gui/qt4/components/playlist/icon_view.hpp index f300142dee..27b704f5e6 100644 --- a/modules/gui/qt4/components/playlist/icon_view.hpp +++ b/modules/gui/qt4/components/playlist/icon_view.hpp @@ -35,7 +35,7 @@ class AbstractPlViewItemDelegate : public QStyledItemDelegate public: AbstractPlViewItemDelegate( QWidget * parent = 0 ) : QStyledItemDelegate(parent) {} QString getMeta( const QModelIndex & index, int meta ) const; - void paintPlayingItemBg( QPainter *painter, const QStyleOptionViewItem & option ) const; + void paintBackground( QPainter *, const QStyleOptionViewItem &, const QModelIndex & ) const; QPixmap getArtPixmap( const QModelIndex & index, const QSize & size ) const; };