diff --git a/src/sourcetree/items/groupitem.cpp b/src/sourcetree/items/groupitem.cpp index 57e8b56cd..01804c0ba 100644 --- a/src/sourcetree/items/groupitem.cpp +++ b/src/sourcetree/items/groupitem.cpp @@ -32,7 +32,8 @@ GroupItem::GroupItem( SourcesModel* model, SourceTreeItem* parent, const QString , m_text( text ) , m_peerSortValue( peerSortValue ) { - connect( this, SIGNAL( toggleExpandRequest( SourceTreeItem* ) ), model, SLOT( itemToggleExpandRequest( SourceTreeItem* ) ) ); + // expand by default + QTimer::singleShot( 0, this, SLOT( requestExpanding() ) ); } @@ -48,6 +49,13 @@ GroupItem::activate() } +void +GroupItem::requestExpanding() +{ + emit expandRequest( this ); +} + + QString GroupItem::text() const { diff --git a/src/sourcetree/items/groupitem.h b/src/sourcetree/items/groupitem.h index ae129b773..5f173ac0b 100644 --- a/src/sourcetree/items/groupitem.h +++ b/src/sourcetree/items/groupitem.h @@ -25,7 +25,6 @@ #include "boost/function.hpp" #include "boost/bind.hpp" -// generic item that has some name, some text, and calls a certain slot when activated. badabing! class GroupItem : public SourceTreeItem { Q_OBJECT @@ -35,15 +34,19 @@ public: virtual ~GroupItem(); virtual QString text() const; - virtual void activate(); virtual bool willAcceptDrag( const QMimeData* data ) const { Q_UNUSED( data ); return false; } virtual QIcon icon() const { return QIcon(); } virtual int peerSortValue() const { return m_peerSortValue; } virtual bool isBeingPlayed() const { return false; } +public slots: + virtual void activate(); + signals: void activated(); - void toggleExpandRequest( SourceTreeItem* ); + +private slots: + void requestExpanding(); private: QString m_text; diff --git a/src/sourcetree/items/historyitem.h b/src/sourcetree/items/historyitem.h index d3dd23449..7406d4e84 100644 --- a/src/sourcetree/items/historyitem.h +++ b/src/sourcetree/items/historyitem.h @@ -38,11 +38,11 @@ public: HistoryItem( SourcesModel* model, SourceTreeItem* parent, const QString& text, int peerSortValue = 0 ); virtual ~HistoryItem(); +public slots: virtual void activate(); signals: void activated(); - void toggleExpandRequest( SourceTreeItem* ); private slots: void tempPageActivated( Tomahawk::ViewPage* ); diff --git a/src/sourcetree/items/sourceitem.cpp b/src/sourcetree/items/sourceitem.cpp index 5a78379ff..9eafeab36 100644 --- a/src/sourcetree/items/sourceitem.cpp +++ b/src/sourcetree/items/sourceitem.cpp @@ -158,7 +158,6 @@ SourceItem::activate() p = ViewManager::instance()->showSuperCollection(); else emit toggleExpandRequest( this ); -// p = ViewManager::instance()->show( source()->collection() ); model()->linkSourceItemToPage( this, p ); } diff --git a/src/sourcetree/items/sourceitem.h b/src/sourcetree/items/sourceitem.h index 7827721e3..0b9230a8e 100644 --- a/src/sourcetree/items/sourceitem.h +++ b/src/sourcetree/items/sourceitem.h @@ -37,7 +37,6 @@ public: SourceItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::source_ptr& source ); virtual QString text() const; - virtual void activate(); virtual QIcon icon() const; virtual int peerSortValue() const; virtual int IDValue() const; @@ -51,6 +50,9 @@ public: void setStationsCategory( CategoryItem* item ) { m_stations = item; } void setPlaylistsCategory( CategoryItem* item ) { m_playlists = item; } +public slots: + virtual void activate(); + private slots: void onPlaylistsAdded( const QList& playlists ); void onPlaylistDeleted( const Tomahawk::playlist_ptr& playlists ); diff --git a/src/sourcetree/items/sourcetreeitem.h b/src/sourcetree/items/sourcetreeitem.h index 4e17f7e35..7e174b789 100644 --- a/src/sourcetree/items/sourcetreeitem.h +++ b/src/sourcetree/items/sourcetreeitem.h @@ -59,7 +59,6 @@ public: // varies depending on the type of the item virtual QString text() const { return QString(); } virtual Qt::ItemFlags flags() const { return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } - virtual void activate() {} virtual QIcon icon() const { return QIcon(); } virtual bool willAcceptDrag( const QMimeData* ) const { return false; } virtual bool dropMimeData( const QMimeData*, Qt::DropAction ) { return false; } @@ -77,6 +76,9 @@ public: void beginRowsRemoved( int from, int to ) { emit beginChildRowsRemoved( from, to ); } void endRowsRemoved() { emit childRowsRemoved(); } +public slots: + virtual void activate() {} + signals: void updated(); void selectRequest( SourceTreeItem* ); diff --git a/src/sourcetree/sourcesmodel.cpp b/src/sourcetree/sourcesmodel.cpp index 4ddf6fa36..6e81995fc 100644 --- a/src/sourcetree/sourcesmodel.cpp +++ b/src/sourcetree/sourcesmodel.cpp @@ -256,8 +256,8 @@ SourcesModel::appendGroups() { beginInsertRows( QModelIndex(), rowCount(), rowCount() + 2 ); - SourceTreeItem* divider = new SourceTreeItem( this, m_rootItem, SourcesModel::Divider, 0 ); - HistoryItem* history = new HistoryItem( this, m_rootItem, tr( "History" ), 5 ); + new SourceTreeItem( this, m_rootItem, SourcesModel::Divider, 0 ); + new HistoryItem( this, m_rootItem, tr( "History" ), 5 ); GroupItem* browse = new GroupItem( this, m_rootItem, tr( "Browse" ), 10 ); // super collection @@ -611,7 +611,7 @@ SourcesModel::indexFromItem( SourceTreeItem* item ) const int SourcesModel::rowForItem( SourceTreeItem* item ) const { - if( !item || !item->parent() || !item->parent()->children().contains( item ) ) + if ( !item || !item->parent() || !item->parent()->children().contains( item ) ) return -1; return item->parent()->children().indexOf( item ); @@ -628,7 +628,6 @@ SourcesModel::itemSelectRequest( SourceTreeItem* item ) void SourcesModel::itemExpandRequest( SourceTreeItem *item ) { - qDebug() << "expanding source" << indexFromItem( item ) << item; emit expandRequest( QPersistentModelIndex( indexFromItem( item ) ) ); } diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 01ecd8995..abacd799b 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -84,8 +84,8 @@ SourceTreeView::SourceTreeView( QWidget* parent ) // setAnimated( true ); m_delegate = new SourceDelegate( this ); - connect( m_delegate, SIGNAL( latchOn( Tomahawk::source_ptr ) ), this, SLOT( latchOnOrCatchUp( Tomahawk::source_ptr ) ), Qt::QueuedConnection ); - connect( m_delegate, SIGNAL( latchOff( Tomahawk::source_ptr ) ), this, SLOT( latchOff( Tomahawk::source_ptr ) ), Qt::QueuedConnection ); + connect( m_delegate, SIGNAL( latchOn( Tomahawk::source_ptr ) ), SLOT( latchOnOrCatchUp( Tomahawk::source_ptr ) ), Qt::QueuedConnection ); + connect( m_delegate, SIGNAL( latchOff( Tomahawk::source_ptr ) ), SLOT( latchOff( Tomahawk::source_ptr ) ), Qt::QueuedConnection ); setItemDelegate( m_delegate ); @@ -94,9 +94,9 @@ SourceTreeView::SourceTreeView( QWidget* parent ) m_model = new SourcesModel( this ); m_proxyModel = new SourcesProxyModel( m_model, this ); - connect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequest( QPersistentModelIndex ) ) ); - connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequest( QPersistentModelIndex ) ) ); - connect( m_proxyModel, SIGNAL( toggleExpandRequest( QPersistentModelIndex ) ), this, SLOT( toggleExpandRequest( QPersistentModelIndex ) ) ); + connect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), SLOT( selectRequest( QPersistentModelIndex ) ) ); + connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expandRequest( QPersistentModelIndex ) ) ); + connect( m_proxyModel, SIGNAL( toggleExpandRequest( QPersistentModelIndex ) ), SLOT( toggleExpandRequest( QPersistentModelIndex ) ) ); setModel( m_proxyModel ); @@ -104,7 +104,7 @@ SourceTreeView::SourceTreeView( QWidget* parent ) header()->setResizeMode( 0, QHeaderView::Stretch ); connect( this, SIGNAL( clicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) ); - connect( this, SIGNAL( expanded( QModelIndex ) ), this, SLOT( onItemExpanded( QModelIndex ) ) ); + connect( this, SIGNAL( expanded( QModelIndex ) ), SLOT( onItemExpanded( QModelIndex ) ) ); // connect( selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( onSelectionChanged() ) ); showOfflineSources( TomahawkSettings::instance()->showOfflineSources() ); @@ -228,8 +228,10 @@ void SourceTreeView::onItemExpanded( const QModelIndex& idx ) { // make sure to expand children nodes for collections - if( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection ) { - for( int i = 0; i < model()->rowCount( idx ); i++ ) { + if( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection ) + { + for( int i = 0; i < model()->rowCount( idx ); i++ ) + { setExpanded( model()->index( i, 0, idx ), true ); } }