1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-04 21:27:58 +02:00

* Use new model/view API.

This commit is contained in:
Christian Muehlhaeuser
2012-07-02 23:10:36 +02:00
parent bd629e6178
commit 01fb91ac59
15 changed files with 40 additions and 40 deletions

View File

@@ -35,7 +35,7 @@ RelatedArtistsContext::RelatedArtistsContext()
m_relatedView->setGuid( "RelatedArtistsContext" ); m_relatedView->setGuid( "RelatedArtistsContext" );
m_relatedView->setUpdatesContextView( false ); m_relatedView->setUpdatesContextView( false );
m_relatedModel = new TreeModel( m_relatedView ); m_relatedModel = new TreeModel( m_relatedView );
m_relatedModel->setStyle( TreeModel::Large ); m_relatedView->proxyModel()->setStyle( PlayableProxyModel::Large );
m_relatedView->setTreeModel( m_relatedModel ); m_relatedView->setTreeModel( m_relatedModel );
m_relatedView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_relatedView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
m_relatedView->setSortingEnabled( false ); m_relatedView->setSortingEnabled( false );

View File

@@ -33,7 +33,7 @@ TopTracksContext::TopTracksContext()
m_topHitsView->setGuid( "TopTracksContext" ); m_topHitsView->setGuid( "TopTracksContext" );
m_topHitsView->setUpdatesContextView( false ); m_topHitsView->setUpdatesContextView( false );
m_topHitsModel = new PlaylistModel( m_topHitsView ); m_topHitsModel = new PlaylistModel( m_topHitsView );
m_topHitsModel->setStyle( PlayableModel::Short ); m_topHitsView->proxyModel()->setStyle( PlayableProxyModel::Short );
m_topHitsView->setPlaylistModel( m_topHitsModel ); m_topHitsView->setPlaylistModel( m_topHitsModel );
m_topHitsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_topHitsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );

View File

@@ -34,7 +34,7 @@ CustomPlaylistView::CustomPlaylistView( CustomPlaylistView::PlaylistType type, c
, m_model( new PlaylistModel( this ) ) , m_model( new PlaylistModel( this ) )
{ {
// Generate the tracks, add them to the playlist // Generate the tracks, add them to the playlist
m_model->setStyle( PlayableModel::Large ); proxyModel()->setStyle( PlayableProxyModel::Large );
setPlaylistModel( m_model ); setPlaylistModel( m_model );
generateTracks(); generateTracks();

View File

@@ -67,8 +67,8 @@ PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModel
if ( index.isValid() ) if ( index.isValid() )
{ {
int style = index.data( PlayableModel::StyleRole ).toInt(); int style = index.data( PlayableProxyModel::StyleRole ).toInt();
if ( style == PlayableModel::Short || style == PlayableModel::ShortWithAvatars ) if ( style == PlayableProxyModel::Short || style == PlayableProxyModel::ShortWithAvatars )
{ {
int rowHeight = option.fontMetrics.height() + 8; int rowHeight = option.fontMetrics.height() + 8;
size.setHeight( rowHeight * 2 ); size.setHeight( rowHeight * 2 );
@@ -101,17 +101,17 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const
void void
PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
int style = index.data( PlayableModel::StyleRole ).toInt(); int style = index.data( PlayableProxyModel::StyleRole ).toInt();
switch ( style ) switch ( style )
{ {
case PlayableModel::Detailed: case PlayableProxyModel::Detailed:
paintDetailed( painter, option, index ); paintDetailed( painter, option, index );
break; break;
case PlayableModel::Short: case PlayableProxyModel::Short:
paintShort( painter, option, index ); paintShort( painter, option, index );
break; break;
case PlayableModel::ShortWithAvatars: case PlayableProxyModel::ShortWithAvatars:
paintShort( painter, option, index, true ); paintShort( painter, option, index, true );
break; break;
} }

View File

@@ -62,15 +62,15 @@ PlaylistView::setPlaylistModel( PlaylistModel* model )
setColumnHidden( PlayableModel::Age, true ); // Hide age column per default setColumnHidden( PlayableModel::Age, true ); // Hide age column per default
setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default
if ( guid().isEmpty() ) if ( guid().isEmpty() && proxyModel()->columnCount() > 1 )
{ {
if ( !m_model->playlist().isNull() ) if ( !m_model->playlist().isNull() )
{ {
setGuid( QString( "playlistview/%1/%2" ).arg( m_model->columnCount() ).arg( m_model->playlist()->guid() ) ); setGuid( QString( "playlistview/%1/%2" ).arg( proxyModel()->columnCount() ).arg( m_model->playlist()->guid() ) );
} }
else else
{ {
setGuid( QString( "playlistview/%1" ).arg( m_model->columnCount() ) ); setGuid( QString( "playlistview/%1" ).arg( proxyModel()->columnCount() ) );
} }
} }

View File

@@ -47,7 +47,7 @@ QueueView::QueueView( AnimatedSplitter* parent )
ui->queue->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored ); ui->queue->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored );
PlaylistModel* queueModel = new PlaylistModel( this ); PlaylistModel* queueModel = new PlaylistModel( this );
queueModel->setStyle( PlaylistModel::Short ); ui->queue->proxyModel()->setStyle( PlayableProxyModel::Short );
queueModel->finishLoading(); queueModel->finishLoading();
ui->queue->setPlaylistModel( queueModel ); ui->queue->setPlaylistModel( queueModel );
queueModel->setReadOnly( false ); queueModel->setReadOnly( false );

View File

@@ -153,13 +153,13 @@ TrackView::setPlayableModel( PlayableModel* model )
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) ); connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) );
setAcceptDrops( true ); setAcceptDrops( true );
m_header->setDefaultColumnWeights( model->columnWeights() ); m_header->setDefaultColumnWeights( m_proxyModel->columnWeights() );
switch( model->style() ) switch( m_proxyModel->style() )
{ {
case PlayableModel::Short: case PlayableProxyModel::Short:
case PlayableModel::ShortWithAvatars: case PlayableProxyModel::ShortWithAvatars:
case PlayableModel::Large: case PlayableProxyModel::Large:
setHeaderHidden( true ); setHeaderHidden( true );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
break; break;
@@ -184,7 +184,7 @@ TrackView::setEmptyTip( const QString& tip )
void void
TrackView::onViewChanged() TrackView::onViewChanged()
{ {
if ( m_model->style() != PlayableModel::Short && m_model->style() != PlayableModel::Large ) // eventual FIXME? if ( m_proxyModel->style() != PlayableProxyModel::Short && m_proxyModel->style() != PlayableProxyModel::Large ) // eventual FIXME?
return; return;
if ( m_timer.isActive() ) if ( m_timer.isActive() )
@@ -217,7 +217,7 @@ TrackView::onScrollTimeout()
for ( int i = left.row(); i <= max; i++ ) for ( int i = left.row(); i <= max; i++ )
{ {
m_model->updateDetailedInfo( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) ); m_proxyModel->updateDetailedInfo( m_proxyModel->index( i, 0 ) );
} }
} }
@@ -621,7 +621,7 @@ TrackView::updateHoverIndex( const QPoint& pos )
repaint(); repaint();
} }
if ( !m_model || m_model->style() != PlayableModel::Detailed ) if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Detailed )
return; return;
if ( idx.column() == PlayableModel::Artist || idx.column() == PlayableModel::Album || idx.column() == PlayableModel::Track ) if ( idx.column() == PlayableModel::Artist || idx.column() == PlayableModel::Album || idx.column() == PlayableModel::Track )
@@ -673,7 +673,7 @@ TrackView::mousePressEvent( QMouseEvent* event )
{ {
QTreeView::mousePressEvent( event ); QTreeView::mousePressEvent( event );
if ( !m_model || m_model->style() != PlayableModel::Detailed ) if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Detailed )
return; return;
QModelIndex idx = indexAt( event->pos() ); QModelIndex idx = indexAt( event->pos() );

View File

@@ -41,7 +41,6 @@ TreeModel::TreeModel( QObject* parent )
: PlayableModel( parent ) : PlayableModel( parent )
, m_mode( DatabaseMode ) , m_mode( DatabaseMode )
{ {
setStyle( Collection );
setIcon( QPixmap( RESPATH "images/music-icon.png" ) ); setIcon( QPixmap( RESPATH "images/music-icon.png" ) );
connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection ); connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection );

View File

@@ -145,8 +145,8 @@ TreeView::setTreeModel( TreeModel* model )
guid(); // this will set the guid on the header guid(); // this will set the guid on the header
m_header->setDefaultColumnWeights( model->columnWeights() ); m_header->setDefaultColumnWeights( m_proxyModel->columnWeights() );
if ( model->style() == PlayableModel::Large ) if ( m_proxyModel->style() == PlayableProxyModel::Large )
{ {
setHeaderHidden( true ); setHeaderHidden( true );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
@@ -439,7 +439,7 @@ TreeView::updateHoverIndex( const QPoint& pos )
repaint(); repaint();
} }
if ( !m_model || m_model->style() != PlayableModel::Collection ) if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Collection )
return; return;
PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( idx ) ); PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( idx ) );
@@ -492,7 +492,7 @@ TreeView::mousePressEvent( QMouseEvent* event )
{ {
QTreeView::mousePressEvent( event ); QTreeView::mousePressEvent( event );
if ( !m_model || m_model->style() != PlayableModel::Collection ) if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Collection )
return; return;
QModelIndex idx = indexAt( event->pos() ); QModelIndex idx = indexAt( event->pos() );

View File

@@ -69,7 +69,7 @@ SocialPlaylistWidget::SocialPlaylistWidget ( QWidget* parent )
m_topForeignTracksModel = new PlaylistModel( ui->newTracksView ); m_topForeignTracksModel = new PlaylistModel( ui->newTracksView );
ui->newTracksView->setPlaylistModel( m_topForeignTracksModel ); ui->newTracksView->setPlaylistModel( m_topForeignTracksModel );
m_topForeignTracksModel->setStyle( PlayableModel::Short ); ui->newTracksView->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->newTracksView->overlay()->setEnabled( false ); ui->newTracksView->overlay()->setEnabled( false );
m_popularNewAlbumsModel = new PlayableModel( ui->newAlbumsView ); m_popularNewAlbumsModel = new PlayableModel( ui->newAlbumsView );

View File

@@ -69,7 +69,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
updatePlaylists(); updatePlaylists();
m_tracksModel = new RecentlyPlayedModel( ui->tracksView ); m_tracksModel = new RecentlyPlayedModel( ui->tracksView );
m_tracksModel->setStyle( PlayableModel::ShortWithAvatars ); ui->tracksView->proxyModel()->setStyle( PlayableProxyModel::ShortWithAvatars );
ui->tracksView->overlay()->setEnabled( false ); ui->tracksView->overlay()->setEnabled( false );
ui->tracksView->setPlaylistModel( m_tracksModel ); ui->tracksView->setPlaylistModel( m_tracksModel );
m_tracksModel->setSource( source_ptr() ); m_tracksModel->setSource( source_ptr() );

View File

@@ -262,7 +262,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft ); TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft );
artistsModel->setMode( InfoSystemMode ); artistsModel->setMode( InfoSystemMode );
artistsModel->setStyle( PlayableModel::Collection );
artistsModel->startLoading(); artistsModel->startLoading();
m_artistModels[ chartId ] = artistsModel; m_artistModels[ chartId ] = artistsModel;
@@ -293,7 +292,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
connect( loader, SIGNAL( tracks( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ), this, SLOT( chartTracksLoaded( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ) ); connect( loader, SIGNAL( tracks( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ), this, SLOT( chartTracksLoaded( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ) );
PlaylistModel* trackModel = new PlaylistModel( ui->tracksViewLeft ); PlaylistModel* trackModel = new PlaylistModel( ui->tracksViewLeft );
trackModel->setStyle( PlayableModel::Large );
trackModel->startLoading(); trackModel->startLoading();
m_trackModels[ chartId ] = trackModel; m_trackModels[ chartId ] = trackModel;
@@ -463,6 +461,7 @@ WhatsHotWidget::setLeftViewAlbums( PlayableModel* model )
void void
WhatsHotWidget::setLeftViewArtists( TreeModel* model ) WhatsHotWidget::setLeftViewArtists( TreeModel* model )
{ {
ui->artistsViewLeft->proxyModel()->setStyle( PlayableProxyModel::Collection );
ui->artistsViewLeft->setTreeModel( model ); ui->artistsViewLeft->setTreeModel( model );
ui->artistsViewLeft->proxyModel()->sort( -1 ); // disable sorting, must be called after artistsViewLeft->setTreeModel ui->artistsViewLeft->proxyModel()->sort( -1 ); // disable sorting, must be called after artistsViewLeft->setTreeModel
ui->stackLeft->setCurrentIndex( 1 ); ui->stackLeft->setCurrentIndex( 1 );
@@ -472,6 +471,7 @@ WhatsHotWidget::setLeftViewArtists( TreeModel* model )
void void
WhatsHotWidget::setLeftViewTracks( PlaylistModel* model ) WhatsHotWidget::setLeftViewTracks( PlaylistModel* model )
{ {
ui->tracksViewLeft->proxyModel()->setStyle( PlayableProxyModel::Large );
ui->tracksViewLeft->setPlaylistModel( model ); ui->tracksViewLeft->setPlaylistModel( model );
ui->tracksViewLeft->proxyModel()->sort( -1 ); ui->tracksViewLeft->proxyModel()->sort( -1 );
ui->stackLeft->setCurrentIndex( 0 ); ui->stackLeft->setCurrentIndex( 0 );

View File

@@ -25,6 +25,7 @@
#include <QScrollBar> #include <QScrollBar>
#include "audio/AudioEngine.h" #include "audio/AudioEngine.h"
#include "playlist/GridItemDelegate.h"
#include "playlist/PlayableModel.h" #include "playlist/PlayableModel.h"
#include "playlist/TreeModel.h" #include "playlist/TreeModel.h"
#include "playlist/PlaylistModel.h" #include "playlist/PlaylistModel.h"
@@ -73,7 +74,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->topHits->setEmptyTip( tr( "Sorry, we could not find any related artists!" ) ); ui->topHits->setEmptyTip( tr( "Sorry, we could not find any related artists!" ) );
m_topHitsModel = new PlaylistModel( ui->topHits ); m_topHitsModel = new PlaylistModel( ui->topHits );
m_topHitsModel->setStyle( PlayableModel::Short ); ui->topHits->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->topHits->setPlayableModel( m_topHitsModel ); ui->topHits->setPlayableModel( m_topHitsModel );
ui->topHits->setSortingEnabled( false ); ui->topHits->setSortingEnabled( false );
ui->topHits->setEmptyTip( tr( "Sorry, we could not find any top hits for this artist!" ) ); ui->topHits->setEmptyTip( tr( "Sorry, we could not find any top hits for this artist!" ) );
@@ -82,13 +83,13 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->relatedArtists->setWrapping( false ); ui->relatedArtists->setWrapping( false );
ui->relatedArtists->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->relatedArtists->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
ui->relatedArtists->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); ui->relatedArtists->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
m_relatedModel->setItemSize( QSize( 170, 170 ) ); ui->relatedArtists->delegate()->setItemSize( QSize( 170, 170 ) );
ui->albums->setAutoFitItems( false ); ui->albums->setAutoFitItems( false );
ui->albums->setWrapping( false ); ui->albums->setWrapping( false );
ui->albums->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->albums->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
ui->albums->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); ui->albums->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
m_albumsModel->setItemSize( QSize( 170, 170 ) ); ui->albums->delegate()->setItemSize( QSize( 170, 170 ) );
ui->albums->proxyModel()->setHideDupeItems( true ); ui->albums->proxyModel()->setHideDupeItems( true );
ui->topHits->setFrameShape( QFrame::StyledPanel ); ui->topHits->setFrameShape( QFrame::StyledPanel );

View File

@@ -50,13 +50,13 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
ui->splitter->setStretchFactor( 1, 1 ); ui->splitter->setStretchFactor( 1, 1 );
m_recentTracksModel = new RecentlyAddedModel( ui->recentCollectionView ); m_recentTracksModel = new RecentlyAddedModel( ui->recentCollectionView );
m_recentTracksModel->setStyle( PlayableModel::Short ); ui->recentCollectionView->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->recentCollectionView->setPlayableModel( m_recentTracksModel ); ui->recentCollectionView->setPlayableModel( m_recentTracksModel );
ui->recentCollectionView->sortByColumn( PlayableModel::Age, Qt::DescendingOrder ); ui->recentCollectionView->sortByColumn( PlayableModel::Age, Qt::DescendingOrder );
m_recentTracksModel->setSource( source ); m_recentTracksModel->setSource( source );
m_historyModel = new RecentlyPlayedModel( ui->historyView ); m_historyModel = new RecentlyPlayedModel( ui->historyView );
m_historyModel->setStyle( PlayableModel::Short ); ui->historyView->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->historyView->setPlaylistModel( m_historyModel ); ui->historyView->setPlaylistModel( m_historyModel );
m_historyModel->setSource( source ); m_historyModel->setSource( source );

View File

@@ -513,7 +513,7 @@ SourceItem::latestAdditionsClicked()
cv->setAttribute( Qt::WA_MacShowFocusRect, 0 ); cv->setAttribute( Qt::WA_MacShowFocusRect, 0 );
RecentlyAddedModel* raModel = new RecentlyAddedModel( cv ); RecentlyAddedModel* raModel = new RecentlyAddedModel( cv );
raModel->setStyle( PlayableModel::Large ); cv->proxyModel()->setStyle( PlayableProxyModel::Large );
raModel->setTitle( tr( "Latest Additions" ) ); raModel->setTitle( tr( "Latest Additions" ) );
if ( m_source->isLocal() ) if ( m_source->isLocal() )
@@ -556,7 +556,7 @@ SourceItem::recentPlaysClicked()
pv->setAttribute( Qt::WA_MacShowFocusRect, 0 ); pv->setAttribute( Qt::WA_MacShowFocusRect, 0 );
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( pv ); RecentlyPlayedModel* raModel = new RecentlyPlayedModel( pv );
raModel->setStyle( PlayableModel::Large ); pv->proxyModel()->setStyle( PlayableProxyModel::Large );
raModel->setTitle( tr( "Recently Played Tracks" ) ); raModel->setTitle( tr( "Recently Played Tracks" ) );
if ( m_source->isLocal() ) if ( m_source->isLocal() )