From b8ded4fde20d4003c702d3efdba282e184d5ed06 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 19 Aug 2014 04:52:09 +0200 Subject: [PATCH] * Auto-select first track in list to prevent default cover showing up in contextual view. --- src/libtomahawk/playlist/PlayableModel.cpp | 3 ++ src/libtomahawk/playlist/PlayableModel.h | 1 + .../playlist/PlayableProxyModel.cpp | 9 ++++ src/libtomahawk/playlist/PlayableProxyModel.h | 2 + src/libtomahawk/playlist/PlaylistModel.cpp | 3 ++ src/libtomahawk/playlist/TrackView.cpp | 41 ++++++++++++++++++- src/libtomahawk/playlist/TrackView.h | 2 + 7 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index ec878a232..6d08d4708 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -712,7 +712,10 @@ PlayableModel::insertInternal( const QList< T >& items, int row, const QList< To emit endInsertRows(); emit itemCountChanged( rowCount( QModelIndex() ) ); if ( parent.isValid() ) + { + emit selectRequest( index( 0, 0, parent ) ); emit expandRequest( parent ); + } finishLoading(); } diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 31c113911..e2a9bef92 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -148,6 +148,7 @@ signals: void currentIndexChanged(); void expandRequest( const QPersistentModelIndex& index ); + void selectRequest( const QPersistentModelIndex& index ); public slots: virtual void setCurrentIndex( const QModelIndex& index ); diff --git a/src/libtomahawk/playlist/PlayableProxyModel.cpp b/src/libtomahawk/playlist/PlayableProxyModel.cpp index fa4b90fb0..33ee7f884 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.cpp +++ b/src/libtomahawk/playlist/PlayableProxyModel.cpp @@ -113,6 +113,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel ) disconnect( m_model, SIGNAL( indexResolved( QModelIndex ) ), this, SLOT( onIndexResolved( QModelIndex ) ) ); disconnect( m_model, SIGNAL( currentIndexChanged() ), this, SIGNAL( currentIndexChanged() ) ); disconnect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequested( QPersistentModelIndex ) ) ); + disconnect( m_model, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequested( QPersistentModelIndex ) ) ); } m_model = sourceModel; @@ -126,6 +127,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel ) connect( m_model, SIGNAL( indexResolved( QModelIndex ) ), SLOT( onIndexResolved( QModelIndex ) ) ); connect( m_model, SIGNAL( currentIndexChanged() ), SIGNAL( currentIndexChanged() ) ); connect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expandRequested( QPersistentModelIndex ) ) ); + connect( m_model, SIGNAL( selectRequest( QPersistentModelIndex ) ), SLOT( selectRequested( QPersistentModelIndex ) ) ); } QSortFilterProxyModel::setSourceModel( m_model ); @@ -669,3 +671,10 @@ PlayableProxyModel::expandRequested( const QPersistentModelIndex& idx ) { emit expandRequest( QPersistentModelIndex( mapFromSource( idx ) ) ); } + + +void +PlayableProxyModel::selectRequested( const QPersistentModelIndex& idx ) +{ + emit selectRequest( QPersistentModelIndex( mapFromSource( idx ) ) ); +} diff --git a/src/libtomahawk/playlist/PlayableProxyModel.h b/src/libtomahawk/playlist/PlayableProxyModel.h index f92b3b520..121ad8f63 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.h +++ b/src/libtomahawk/playlist/PlayableProxyModel.h @@ -100,6 +100,7 @@ signals: void itemCountChanged( unsigned int items ); void expandRequest( const QPersistentModelIndex& index ); + void selectRequest( const QPersistentModelIndex& index ); protected: virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; @@ -112,6 +113,7 @@ private slots: void onIndexResolved( const QModelIndex& index ); void expandRequested( const QPersistentModelIndex& index ); + void selectRequested( const QPersistentModelIndex& index ); private: virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const; diff --git a/src/libtomahawk/playlist/PlaylistModel.cpp b/src/libtomahawk/playlist/PlaylistModel.cpp index 42212b1d8..2060fdbcd 100644 --- a/src/libtomahawk/playlist/PlaylistModel.cpp +++ b/src/libtomahawk/playlist/PlaylistModel.cpp @@ -331,8 +331,11 @@ PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int emit endInsertRows(); emit itemCountChanged( rowCount( QModelIndex() ) ); + emit selectRequest( index( 0, 0, parent ) ); if ( parent.isValid() ) + { emit expandRequest( parent ); + } } diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index b6ef8d57f..8fd707789 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -164,6 +164,7 @@ TrackView::setProxyModel( PlayableProxyModel* model ) disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( verifySize() ) ); disconnect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( verifySize() ) ); disconnect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expand( QPersistentModelIndex ) ) ); + disconnect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( select( QPersistentModelIndex ) ) ); } m_proxyModel = model; @@ -175,6 +176,7 @@ TrackView::setProxyModel( PlayableProxyModel* model ) connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) ); connect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( verifySize() ) ); connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expand( QPersistentModelIndex ) ) ); + connect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), SLOT( select( QPersistentModelIndex ) ) ); m_delegate = new PlaylistItemDelegate( this, m_proxyModel ); QTreeView::setItemDelegate( m_delegate ); @@ -207,7 +209,8 @@ TrackView::setPlaylistItemDelegate( PlaylistItemDelegate* delegate ) void TrackView::setPlayableModel( PlayableModel* model ) { - if ( m_model ) { + if ( m_model ) + { disconnect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) ); disconnect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) ); } @@ -242,6 +245,7 @@ TrackView::setPlayableModel( PlayableModel* model ) if ( m_autoExpanding ) { expandAll(); + selectFirstTrack(); } onViewChanged(); @@ -852,3 +856,38 @@ TrackView::expand( const QPersistentModelIndex& idx ) { QTreeView::expand( idx ); } + + +void +TrackView::select( const QPersistentModelIndex& idx ) +{ + if ( selectedIndexes().count() ) + return; + +// selectionModel()->select( idx, QItemSelectionModel::SelectCurrent ); + currentChanged( idx, QModelIndex() ); +} + + +void +TrackView::selectFirstTrack() +{ + if ( !m_proxyModel->rowCount() ) + return; + if ( selectedIndexes().count() ) + return; + + QModelIndex idx = m_proxyModel->index( 0, 0, QModelIndex() ); + PlayableItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( idx ) ); + if ( item->source() ) + { + idx = m_proxyModel->index( 0, 0, idx ); + item = m_model->itemFromIndex( m_proxyModel->mapToSource( idx ) ); + } + + if ( item->query() ) + { +// selectionModel()->select( idx, QItemSelectionModel::SelectCurrent ); + currentChanged( idx, QModelIndex() ); + } +} diff --git a/src/libtomahawk/playlist/TrackView.h b/src/libtomahawk/playlist/TrackView.h index 128220158..a18365966 100644 --- a/src/libtomahawk/playlist/TrackView.h +++ b/src/libtomahawk/playlist/TrackView.h @@ -102,6 +102,8 @@ public slots: void onScrollTimeout(); void expand( const QPersistentModelIndex& idx ); + void select( const QPersistentModelIndex& idx ); + void selectFirstTrack(); signals: void itemActivated( const QModelIndex& index );