mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
* Auto expand group items.
This commit is contained in:
parent
cf4d0fe465
commit
3875f0b693
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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* );
|
||||
|
@ -158,7 +158,6 @@ SourceItem::activate()
|
||||
p = ViewManager::instance()->showSuperCollection();
|
||||
else
|
||||
emit toggleExpandRequest( this );
|
||||
// p = ViewManager::instance()->show( source()->collection() );
|
||||
|
||||
model()->linkSourceItemToPage( this, p );
|
||||
}
|
||||
|
@ -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<Tomahawk::playlist_ptr>& playlists );
|
||||
void onPlaylistDeleted( const Tomahawk::playlist_ptr& playlists );
|
||||
|
@ -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* );
|
||||
|
@ -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 ) ) );
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user