[vlc-commits] commit: Qt4: highlight nodepath to current item on icon_view ( Ilkka Ollakka )

git at videolan.org git at videolan.org
Wed Jun 23 11:52:45 CEST 2010


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Wed Jun 23 12:51:14 2010 +0300| [0d9ca0e07cdbe2903b8edc6126ee45cec815734b] | committer: Ilkka Ollakka 

Qt4: highlight nodepath to current item on icon_view

Shows user where the current input is on icon_view with tree-mode.

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

 modules/gui/qt4/components/playlist/icon_view.cpp  |    5 ++++-
 .../gui/qt4/components/playlist/playlist_model.cpp |   16 ++++++++++++++++
 .../gui/qt4/components/playlist/playlist_model.hpp |    4 +++-
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/icon_view.cpp b/modules/gui/qt4/components/playlist/icon_view.cpp
index 60e1ca5..6a01d6e 100644
--- a/modules/gui/qt4/components/playlist/icon_view.cpp
+++ b/modules/gui/qt4/components/playlist/icon_view.cpp
@@ -168,7 +168,10 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
         QRect r( option.rect );
         r.setSize( QSize( 25, 25 ) );
         r.translate( 5, 5 );
-        painter->fillRect( r, option.palette.color( QPalette::Mid ) );
+        if( index.data( PLModel::IsCurrentsParentNodeRole ).toBool() )
+            painter->fillRect( r, option.palette.color( QPalette::Highlight ) );
+        else
+            painter->fillRect( r, option.palette.color( QPalette::Mid ) );
         painter->setOpacity( 1.0 );
         QPixmap dirPix( ":/type/node" );
         QRect r2( dirPix.rect() );
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 756ee00..2c1fb76 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -378,9 +378,25 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
         PL_UNLOCK;
         return isLeaf;
     }
+    else if( role == IsCurrentsParentNodeRole )
+    {
+        return QVariant( isParent( index, current_index ) );
+    }
     return QVariant();
 }
 
+/* Seek from current index toward the top and see if index is one of parent nodes */
+bool PLModel::isParent( const QModelIndex &index, const QModelIndex &current ) const
+{
+    if( index == current )
+        return true;
+
+    if( !current.parent().isValid() )
+        return false;
+
+    return isParent( index, current.parent() );
+}
+
 bool PLModel::isCurrent( const QModelIndex &index ) const
 {
     return index == current_index;
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index 033cdc6..90dcf17 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -59,7 +59,8 @@ friend class PLSelector;
 public:
     enum {
       IsCurrentRole = Qt::UserRole,
-      IsLeafNodeRole
+      IsLeafNodeRole,
+      IsCurrentsParentNodeRole
     };
 
     PLModel( playlist_t *, intf_thread_t *,
@@ -92,6 +93,7 @@ public:
     QModelIndex index( PLItem *, int c ) const;
     QModelIndex index( int i_id, int c );
     QModelIndex currentIndex();
+    bool isParent( const QModelIndex &index, const QModelIndex &current) const;
     bool isCurrent( const QModelIndex &index ) const;
     int itemId( const QModelIndex &index ) const;
     static int columnFromMeta( int meta_column );



More information about the vlc-commits mailing list