From 67e30668dd19db37a5a9329e9b081a8b95c28176 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 30 May 2013 04:22:06 +0200 Subject: [PATCH] * Disable / enable alternate row colors when required. --- src/libtomahawk/playlist/TrackView.cpp | 20 +++++++++++++++++++- src/libtomahawk/playlist/TrackView.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index aedae4d89..19f440086 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -64,7 +64,6 @@ TrackView::TrackView( QWidget* parent ) setContentsMargins( 0, 0, 0, 0 ); setMouseTracking( true ); - setAlternatingRowColors( true ); setSelectionMode( QAbstractItemView::ExtendedSelection ); setSelectionBehavior( QAbstractItemView::SelectRows ); setDragEnabled( true ); @@ -147,6 +146,8 @@ TrackView::setProxyModel( PlayableProxyModel* model ) { if ( m_proxyModel ) { + disconnect( m_proxyModel, SIGNAL( rowsAboutToBeInserted( QModelIndex, int, int ) ), this, SLOT( onModelFilling() ) ); + disconnect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( onModelEmptyCheck() ) ); disconnect( m_proxyModel, SIGNAL( filterChanged( QString ) ), this, SLOT( onFilterChanged( QString ) ) ); disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( onViewChanged() ) ); disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( verifySize() ) ); @@ -155,6 +156,8 @@ TrackView::setProxyModel( PlayableProxyModel* model ) m_proxyModel = model; + connect( m_proxyModel, SIGNAL( rowsAboutToBeInserted( QModelIndex, int, int ) ), SLOT( onModelFilling() ) ); + connect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( onModelEmptyCheck() ) ); connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) ); connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) ); connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) ); @@ -227,6 +230,21 @@ TrackView::setEmptyTip( const QString& tip ) } +void +TrackView::onModelFilling() +{ + setAlternatingRowColors( true ); +} + + +void +TrackView::onModelEmptyCheck() +{ + if ( !m_proxyModel->rowCount( QModelIndex() ) ) + setAlternatingRowColors( false ); +} + + void TrackView::onViewChanged() { diff --git a/src/libtomahawk/playlist/TrackView.h b/src/libtomahawk/playlist/TrackView.h index 947da07fb..3549a06a9 100644 --- a/src/libtomahawk/playlist/TrackView.h +++ b/src/libtomahawk/playlist/TrackView.h @@ -121,6 +121,8 @@ protected slots: private slots: void onItemResized( const QModelIndex& index ); void onFilterChanged( const QString& filter ); + void onModelFilling(); + void onModelEmptyCheck(); void onCustomContextMenu( const QPoint& pos );