1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 05:37:29 +02:00

* Always select the current view-page in the SourceTreeView.

This commit is contained in:
Christian Muehlhaeuser
2012-05-28 14:19:33 +02:00
parent bea23d7dbe
commit 9d26f342d3
2 changed files with 30 additions and 14 deletions

View File

@@ -111,7 +111,7 @@ SourceTreeView::SourceTreeView( QWidget* parent )
header()->setResizeMode( 0, QHeaderView::Stretch ); header()->setResizeMode( 0, QHeaderView::Stretch );
connect( this, SIGNAL( expanded( QModelIndex ) ), SLOT( onItemExpanded( QModelIndex ) ) ); connect( this, SIGNAL( expanded( QModelIndex ) ), SLOT( onItemExpanded( QModelIndex ) ) );
// connect( selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( onSelectionChanged() ) ); connect( selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( onSelectionChanged() ) );
showOfflineSources( TomahawkSettings::instance()->showOfflineSources() ); showOfflineSources( TomahawkSettings::instance()->showOfflineSources() );
@@ -245,6 +245,18 @@ SourceTreeView::showOfflineSources( bool offlineSourcesShown )
} }
void
SourceTreeView::onSelectionChanged()
{
if ( currentIndex() != m_selectedIndex )
{
selectionModel()->blockSignals( true );
selectionModel()->select( m_selectedIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current );
selectionModel()->blockSignals( false );
}
}
void void
SourceTreeView::onItemActivated( const QModelIndex& index ) SourceTreeView::onItemActivated( const QModelIndex& index )
{ {
@@ -284,6 +296,8 @@ SourceTreeView::onItemExpanded( const QModelIndex& idx )
void void
SourceTreeView::selectRequest( const QPersistentModelIndex& idx ) SourceTreeView::selectRequest( const QPersistentModelIndex& idx )
{ {
m_selectedIndex = idx;
if ( !selectionModel()->selectedIndexes().contains( idx ) ) if ( !selectionModel()->selectedIndexes().contains( idx ) )
{ {
scrollTo( idx, QTreeView::EnsureVisible ); scrollTo( idx, QTreeView::EnsureVisible );
@@ -708,10 +722,9 @@ SourceTreeView::keyPressEvent( QKeyEvent *event )
PlaylistItem* item = itemFromIndex< PlaylistItem >( idx ); PlaylistItem* item = itemFromIndex< PlaylistItem >( idx );
Q_ASSERT( item ); Q_ASSERT( item );
if( item->playlist()->author()->isLocal() ) { if ( item->playlist()->author()->isLocal() )
deletePlaylist( idx ); deletePlaylist( idx );
} }
}
event->accept(); event->accept();
} }
else else

View File

@@ -81,6 +81,7 @@ private slots:
void latchModeToggled( bool checked ); void latchModeToggled( bool checked );
void onCustomContextMenu( const QPoint& pos ); void onCustomContextMenu( const QPoint& pos );
void onSelectionChanged();
protected: protected:
void drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; void drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
@@ -113,6 +114,8 @@ private:
bool m_dragging; bool m_dragging;
QRect m_dropRect; QRect m_dropRect;
QPersistentModelIndex m_dropIndex; QPersistentModelIndex m_dropIndex;
QPersistentModelIndex m_selectedIndex;
}; };
#endif // SOURCETREEVIEW_H #endif // SOURCETREEVIEW_H