[vlc-commits] commit: Qt: ensure that item selection has visible effect in playlist views ( Jakob Leben )
git version control
git at videolan.org
Wed Mar 3 14:01:00 CET 2010
vlc | branch: master | Jakob Leben <jleben at videolan.org> | Wed Mar 3 13:44:25 2010 +0100| [b5a14d4d7684f609e5fe071c01870694fa3cd812] | committer: Jakob Leben
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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b5a14d4d7684f609e5fe071c01870694fa3cd812
---
modules/gui/qt4/components/playlist/icon_view.cpp | 51 ++++++++++++---------
modules/gui/qt4/components/playlist/icon_view.hpp | 2 +-
2 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/icon_view.cpp b/modules/gui/qt4/components/playlist/icon_view.cpp
index 38f2f92..ebd8f77 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 f300142..27b704f 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;
};
More information about the vlc-commits
mailing list