1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-19 07:27:59 +01:00

* Auto-select first track in list to prevent default cover showing up in contextual view.

This commit is contained in:
Christian Muehlhaeuser 2014-08-19 04:52:09 +02:00
parent 3f1e97bb43
commit b8ded4fde2
7 changed files with 60 additions and 1 deletions

View File

@ -712,7 +712,10 @@ PlayableModel::insertInternal( const QList< T >& items, int row, const QList< To
emit endInsertRows(); emit endInsertRows();
emit itemCountChanged( rowCount( QModelIndex() ) ); emit itemCountChanged( rowCount( QModelIndex() ) );
if ( parent.isValid() ) if ( parent.isValid() )
{
emit selectRequest( index( 0, 0, parent ) );
emit expandRequest( parent ); emit expandRequest( parent );
}
finishLoading(); finishLoading();
} }

View File

@ -148,6 +148,7 @@ signals:
void currentIndexChanged(); void currentIndexChanged();
void expandRequest( const QPersistentModelIndex& index ); void expandRequest( const QPersistentModelIndex& index );
void selectRequest( const QPersistentModelIndex& index );
public slots: public slots:
virtual void setCurrentIndex( const QModelIndex& index ); virtual void setCurrentIndex( const QModelIndex& index );

View File

@ -113,6 +113,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
disconnect( m_model, SIGNAL( indexResolved( QModelIndex ) ), this, SLOT( onIndexResolved( QModelIndex ) ) ); disconnect( m_model, SIGNAL( indexResolved( QModelIndex ) ), this, SLOT( onIndexResolved( QModelIndex ) ) );
disconnect( m_model, SIGNAL( currentIndexChanged() ), this, SIGNAL( currentIndexChanged() ) ); disconnect( m_model, SIGNAL( currentIndexChanged() ), this, SIGNAL( currentIndexChanged() ) );
disconnect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequested( QPersistentModelIndex ) ) ); disconnect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequested( QPersistentModelIndex ) ) );
disconnect( m_model, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequested( QPersistentModelIndex ) ) );
} }
m_model = sourceModel; m_model = sourceModel;
@ -126,6 +127,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
connect( m_model, SIGNAL( indexResolved( QModelIndex ) ), SLOT( onIndexResolved( QModelIndex ) ) ); connect( m_model, SIGNAL( indexResolved( QModelIndex ) ), SLOT( onIndexResolved( QModelIndex ) ) );
connect( m_model, SIGNAL( currentIndexChanged() ), SIGNAL( currentIndexChanged() ) ); connect( m_model, SIGNAL( currentIndexChanged() ), SIGNAL( currentIndexChanged() ) );
connect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expandRequested( QPersistentModelIndex ) ) ); connect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expandRequested( QPersistentModelIndex ) ) );
connect( m_model, SIGNAL( selectRequest( QPersistentModelIndex ) ), SLOT( selectRequested( QPersistentModelIndex ) ) );
} }
QSortFilterProxyModel::setSourceModel( m_model ); QSortFilterProxyModel::setSourceModel( m_model );
@ -669,3 +671,10 @@ PlayableProxyModel::expandRequested( const QPersistentModelIndex& idx )
{ {
emit expandRequest( QPersistentModelIndex( mapFromSource( idx ) ) ); emit expandRequest( QPersistentModelIndex( mapFromSource( idx ) ) );
} }
void
PlayableProxyModel::selectRequested( const QPersistentModelIndex& idx )
{
emit selectRequest( QPersistentModelIndex( mapFromSource( idx ) ) );
}

View File

@ -100,6 +100,7 @@ signals:
void itemCountChanged( unsigned int items ); void itemCountChanged( unsigned int items );
void expandRequest( const QPersistentModelIndex& index ); void expandRequest( const QPersistentModelIndex& index );
void selectRequest( const QPersistentModelIndex& index );
protected: protected:
virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
@ -112,6 +113,7 @@ private slots:
void onIndexResolved( const QModelIndex& index ); void onIndexResolved( const QModelIndex& index );
void expandRequested( const QPersistentModelIndex& index ); void expandRequested( const QPersistentModelIndex& index );
void selectRequested( const QPersistentModelIndex& index );
private: private:
virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const; virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const;

View File

@ -331,8 +331,11 @@ PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int
emit endInsertRows(); emit endInsertRows();
emit itemCountChanged( rowCount( QModelIndex() ) ); emit itemCountChanged( rowCount( QModelIndex() ) );
emit selectRequest( index( 0, 0, parent ) );
if ( parent.isValid() ) if ( parent.isValid() )
{
emit expandRequest( parent ); emit expandRequest( parent );
}
} }

View File

@ -164,6 +164,7 @@ TrackView::setProxyModel( PlayableProxyModel* model )
disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( verifySize() ) ); 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( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( verifySize() ) );
disconnect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expand( QPersistentModelIndex ) ) ); disconnect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expand( QPersistentModelIndex ) ) );
disconnect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( select( QPersistentModelIndex ) ) );
} }
m_proxyModel = model; 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( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) );
connect( m_proxyModel, SIGNAL( rowsRemoved( 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( expandRequest( QPersistentModelIndex ) ), SLOT( expand( QPersistentModelIndex ) ) );
connect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), SLOT( select( QPersistentModelIndex ) ) );
m_delegate = new PlaylistItemDelegate( this, m_proxyModel ); m_delegate = new PlaylistItemDelegate( this, m_proxyModel );
QTreeView::setItemDelegate( m_delegate ); QTreeView::setItemDelegate( m_delegate );
@ -207,7 +209,8 @@ TrackView::setPlaylistItemDelegate( PlaylistItemDelegate* delegate )
void void
TrackView::setPlayableModel( PlayableModel* model ) TrackView::setPlayableModel( PlayableModel* model )
{ {
if ( m_model ) { if ( m_model )
{
disconnect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) ); disconnect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) );
disconnect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) ); disconnect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
} }
@ -242,6 +245,7 @@ TrackView::setPlayableModel( PlayableModel* model )
if ( m_autoExpanding ) if ( m_autoExpanding )
{ {
expandAll(); expandAll();
selectFirstTrack();
} }
onViewChanged(); onViewChanged();
@ -852,3 +856,38 @@ TrackView::expand( const QPersistentModelIndex& idx )
{ {
QTreeView::expand( 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() );
}
}

View File

@ -102,6 +102,8 @@ public slots:
void onScrollTimeout(); void onScrollTimeout();
void expand( const QPersistentModelIndex& idx ); void expand( const QPersistentModelIndex& idx );
void select( const QPersistentModelIndex& idx );
void selectFirstTrack();
signals: signals:
void itemActivated( const QModelIndex& index ); void itemActivated( const QModelIndex& index );