]> git.sesse.net Git - vlc/commitdiff
Qt: ensure that item selection has visible effect in playlist views
authorJakob Leben <jleben@videolan.org>
Wed, 3 Mar 2010 12:44:25 +0000 (13:44 +0100)
committerJakob Leben <jleben@videolan.org>
Wed, 3 Mar 2010 12:50:38 +0000 (13:50 +0100)
Fix #3349.
Unfortunately we can not use QStyle to handle selection generically across platforms.

modules/gui/qt4/components/playlist/icon_view.cpp
modules/gui/qt4/components/playlist/icon_view.hpp

index 38f2f92db63ad43ababc75784334d9edc9482016..ebd8f77aeeb0aeab757d3dff090fac6e4c6e51e7 100644 (file)
@@ -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,
index f300142dee3c0247a12c44f60bf7f2e6182703c1..27b704f5e61751a34ec9af25673bac6b276904af 100644 (file)
@@ -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;
 };