[vlc-commits] Qt: PLTreeView: use delegate for emphasing font.

Francois Cartegnie git at videolan.org
Fri Jul 20 15:08:27 CEST 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Jul 20 14:27:11 2012 +0200| [c3581f43a9ee93181d8c41c10bf84cb8b52aefa9] | committer: Francois Cartegnie

Qt: PLTreeView: use delegate for emphasing font.

Also fixes a mistake in 229c807ce1cf5b5edebb7de9621a8191d78209b5
where isCurrent == isSelected

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c3581f43a9ee93181d8c41c10bf84cb8b52aefa9
---

 .../gui/qt4/components/playlist/standardpanel.cpp  |   20 +--------
 modules/gui/qt4/components/playlist/views.cpp      |   43 +++++++++++++++++++-
 modules/gui/qt4/components/playlist/views.hpp      |   12 ++++++
 3 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index 879c827..e831597 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -525,25 +525,7 @@ void StandardPLPanel::createCoverView()
 void StandardPLPanel::createTreeView()
 {
     /* Create and configure the QTreeView */
-    treeView = new PlTreeView;
-
-    treeView->setIconSize( QSize( 20, 20 ) );
-    treeView->setAlternatingRowColors( true );
-    treeView->setAnimated( true );
-    treeView->setUniformRowHeights( true );
-    treeView->setSortingEnabled( true );
-    treeView->setAttribute( Qt::WA_MacShowFocusRect, false );
-    treeView->header()->setSortIndicator( -1 , Qt::AscendingOrder );
-    treeView->header()->setSortIndicatorShown( true );
-    treeView->header()->setClickable( true );
-    treeView->header()->setContextMenuPolicy( Qt::CustomContextMenu );
-
-    treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
-    treeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
-    treeView->setDragEnabled( true );
-    treeView->setAcceptDrops( true );
-    treeView->setDropIndicatorShown( true );
-    treeView->setContextMenuPolicy( Qt::CustomContextMenu );
+    treeView = new PlTreeView( model, this );
 
     /* setModel after setSortingEnabled(true), or the model will sort immediately! */
 
diff --git a/modules/gui/qt4/components/playlist/views.cpp b/modules/gui/qt4/components/playlist/views.cpp
index 5512e05..d82b945 100644
--- a/modules/gui/qt4/components/playlist/views.cpp
+++ b/modules/gui/qt4/components/playlist/views.cpp
@@ -33,6 +33,7 @@
 #include <QDrag>
 #include <QDragMoveEvent>
 #include <QMetaType>
+#include <QHeaderView>
 
 #include "assert.h"
 
@@ -80,7 +81,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
 
     QFont font( index.data( Qt::FontRole ).value<QFont>() );
     font.setPointSize( __MAX( font.pointSize() + i_zoom, 4 ) );
-    font.setBold( option.state & QStyle::State_Selected );
+    font.setBold( index.data( PLModel::IsCurrentRole ).toBool() );
     painter->setFont( font );
     QFontMetrics fm = painter->fontMetrics();
 
@@ -221,7 +222,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
     //Draw title info
     f.setItalic( true );
     f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
-    f.setBold( option.state & QStyle::State_Selected );
+    f.setBold( index.data( PLModel::IsCurrentRole ).toBool() );
     painter->setFont( f );
     QFontMetrics fm( painter->fontMetrics() );
 
@@ -272,6 +273,21 @@ QSize PlListViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QMo
     return QSize( 0, height );
 }
 
+
+void PlTreeViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
+{
+    if ( index.data( PLModel::IsCurrentRole ).toBool() )
+    {
+        QStyleOptionViewItem myoptions = option;
+        myoptions.font.setBold( true );
+        AbstractPlViewItemDelegate::paint( painter, myoptions, index );
+    }
+    else
+    {
+        AbstractPlViewItemDelegate::paint( painter, option, index );
+    }
+}
+
 static inline void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & supportedActions )
 {
     QDrag *drag = new QDrag( view );
@@ -384,6 +400,29 @@ bool PlListView::viewportEvent ( QEvent * event )
     }
 }
 
+PlTreeView::PlTreeView( PLModel *, QWidget *parent ) : QTreeView( parent )
+{
+    setItemDelegate( new PlTreeViewItemDelegate( this ) );
+
+    setIconSize( QSize( 20, 20 ) );
+    setAlternatingRowColors( true );
+    setAnimated( true );
+    setUniformRowHeights( true );
+    setSortingEnabled( true );
+    setAttribute( Qt::WA_MacShowFocusRect, false );
+    header()->setSortIndicator( -1 , Qt::AscendingOrder );
+    header()->setSortIndicatorShown( true );
+    header()->setClickable( true );
+    header()->setContextMenuPolicy( Qt::CustomContextMenu );
+
+    setSelectionBehavior( QAbstractItemView::SelectRows );
+    setSelectionMode( QAbstractItemView::ExtendedSelection );
+    setDragEnabled( true );
+    setAcceptDrops( true );
+    setDropIndicatorShown( true );
+    setContextMenuPolicy( Qt::CustomContextMenu );
+}
+
 void PlTreeView::setModel( QAbstractItemModel * model )
 {
     QTreeView::setModel( model );
diff --git a/modules/gui/qt4/components/playlist/views.hpp b/modules/gui/qt4/components/playlist/views.hpp
index b6a263d..3466e95 100644
--- a/modules/gui/qt4/components/playlist/views.hpp
+++ b/modules/gui/qt4/components/playlist/views.hpp
@@ -69,6 +69,16 @@ public:
     virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
 };
 
+class PlTreeViewItemDelegate : public AbstractPlViewItemDelegate
+{
+    Q_OBJECT
+
+public:
+    PlTreeViewItemDelegate(QWidget *parent = 0) : AbstractPlViewItemDelegate(parent) {}
+
+    virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
+};
+
 class PlIconView : public QListView
 {
     Q_OBJECT
@@ -98,6 +108,8 @@ class PlTreeView : public QTreeView
 {
     Q_OBJECT
 
+public:
+    PlTreeView( PLModel *, QWidget *parent = 0 );
 protected:
     virtual void startDrag ( Qt::DropActions supportedActions );
     virtual void dragMoveEvent ( QDragMoveEvent * event );



More information about the vlc-commits mailing list