mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
* Always select the current view-page in the SourceTreeView.
This commit is contained in:
@@ -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 )
|
||||||
{
|
{
|
||||||
@@ -271,7 +283,7 @@ void
|
|||||||
SourceTreeView::onItemExpanded( const QModelIndex& idx )
|
SourceTreeView::onItemExpanded( const QModelIndex& idx )
|
||||||
{
|
{
|
||||||
// make sure to expand children nodes for collections
|
// make sure to expand children nodes for collections
|
||||||
if( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection )
|
if ( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection )
|
||||||
{
|
{
|
||||||
for( int i = 0; i < model()->rowCount( idx ); i++ )
|
for( int i = 0; i < model()->rowCount( idx ); i++ )
|
||||||
{
|
{
|
||||||
@@ -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 );
|
||||||
@@ -357,7 +371,7 @@ SourceTreeView::deletePlaylist( const QModelIndex& idxIn )
|
|||||||
playlist_ptr playlist = item->playlist();
|
playlist_ptr playlist = item->playlist();
|
||||||
Playlist::remove( playlist );
|
Playlist::remove( playlist );
|
||||||
}
|
}
|
||||||
else if( type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station )
|
else if ( type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station )
|
||||||
{
|
{
|
||||||
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( idx );
|
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( idx );
|
||||||
dynplaylist_ptr playlist = item->dynPlaylist();
|
dynplaylist_ptr playlist = item->dynPlaylist();
|
||||||
@@ -374,7 +388,7 @@ SourceTreeView::copyPlaylistLink()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if( type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station )
|
if ( type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station )
|
||||||
{
|
{
|
||||||
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
||||||
dynplaylist_ptr playlist = item->dynPlaylist();
|
dynplaylist_ptr playlist = item->dynPlaylist();
|
||||||
@@ -409,7 +423,7 @@ SourceTreeView::addToLocal()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if( type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station )
|
if ( type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station )
|
||||||
{
|
{
|
||||||
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
||||||
dynplaylist_ptr playlist = item->dynPlaylist();
|
dynplaylist_ptr playlist = item->dynPlaylist();
|
||||||
@@ -442,7 +456,7 @@ SourceTreeView::latchOnOrCatchUp()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if( type != SourcesModel::Collection )
|
if ( type != SourcesModel::Collection )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
@@ -461,7 +475,7 @@ SourceTreeView::latchOff()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if( type != SourcesModel::Collection )
|
if ( type != SourcesModel::Collection )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
@@ -498,7 +512,7 @@ SourceTreeView::latchModeToggled( bool checked )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if( type != SourcesModel::Collection )
|
if ( type != SourcesModel::Collection )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
@@ -510,7 +524,7 @@ SourceTreeView::latchModeToggled( bool checked )
|
|||||||
void
|
void
|
||||||
SourceTreeView::renamePlaylist()
|
SourceTreeView::renamePlaylist()
|
||||||
{
|
{
|
||||||
if( !m_contextMenuIndex.isValid() && !selectionModel()->selectedIndexes().isEmpty() )
|
if ( !m_contextMenuIndex.isValid() && !selectionModel()->selectedIndexes().isEmpty() )
|
||||||
edit( selectionModel()->selectedIndexes().first() );
|
edit( selectionModel()->selectedIndexes().first() );
|
||||||
else
|
else
|
||||||
edit( m_contextMenuIndex );
|
edit( m_contextMenuIndex );
|
||||||
@@ -533,7 +547,7 @@ SourceTreeView::onCustomContextMenu( const QPoint& pos )
|
|||||||
model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Station )
|
model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Station )
|
||||||
{
|
{
|
||||||
PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
|
PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
|
||||||
if( item->playlist()->author()->isLocal() )
|
if ( item->playlist()->author()->isLocal() )
|
||||||
m_playlistMenu.exec( mapToGlobal( pos ) );
|
m_playlistMenu.exec( mapToGlobal( pos ) );
|
||||||
else
|
else
|
||||||
m_roPlaylistMenu.exec( mapToGlobal( pos ) );
|
m_roPlaylistMenu.exec( mapToGlobal( pos ) );
|
||||||
@@ -610,7 +624,7 @@ SourceTreeView::dragMoveEvent( QDragMoveEvent* event )
|
|||||||
m_dropRect = rect;
|
m_dropRect = rect;
|
||||||
|
|
||||||
SourceTreeItem* item = itemFromIndex< SourceTreeItem >( index );
|
SourceTreeItem* item = itemFromIndex< SourceTreeItem >( index );
|
||||||
if( item->willAcceptDrag( event->mimeData() ) )
|
if ( item->willAcceptDrag( event->mimeData() ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
accept = true;
|
accept = true;
|
||||||
@@ -698,7 +712,7 @@ SourceTreeView::dropEvent( QDropEvent* event )
|
|||||||
void
|
void
|
||||||
SourceTreeView::keyPressEvent( QKeyEvent *event )
|
SourceTreeView::keyPressEvent( QKeyEvent *event )
|
||||||
{
|
{
|
||||||
if( ( event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace ) && !selectionModel()->selectedIndexes().isEmpty() )
|
if ( ( event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace ) && !selectionModel()->selectedIndexes().isEmpty() )
|
||||||
{
|
{
|
||||||
QModelIndex idx = selectionModel()->selectedIndexes().first();
|
QModelIndex idx = selectionModel()->selectedIndexes().first();
|
||||||
if ( model()->data( idx, SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::StaticPlaylist ||
|
if ( model()->data( idx, SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::StaticPlaylist ||
|
||||||
@@ -708,9 +722,8 @@ 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();
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user