From 7b5f16355d863b65dc5013311a2143655cad0ed5 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 7 Dec 2010 11:25:00 +0100 Subject: [PATCH] * AlbumViews are now sorted by Artist - Album. * Tweaked mode switching. * Hide stats & mode buttons for certain view types. --- src/audio/audioengine.cpp | 3 +- src/playlist/albumproxymodel.cpp | 22 ++++++++++++ src/playlist/albumproxymodel.h | 1 + src/playlist/albumview.cpp | 4 ++- src/playlist/playlistmanager.cpp | 57 ++++++++++++++++++++++++++++---- src/playlist/playlistmanager.h | 10 ++++++ src/playlist/trackmodel.cpp | 1 - src/tomahawkwindow.cpp | 6 ++++ src/topbar/topbar.cpp | 23 +++++++++++-- src/topbar/topbar.h | 3 ++ src/topbar/topbar.ui | 2 +- src/utils/animatedcounterlabel.h | 28 ++++++++++------ src/utils/animatedsplitter.cpp | 2 -- 13 files changed, 137 insertions(+), 25 deletions(-) diff --git a/src/audio/audioengine.cpp b/src/audio/audioengine.cpp index 7e164b8d6..92048f98b 100644 --- a/src/audio/audioengine.cpp +++ b/src/audio/audioengine.cpp @@ -40,10 +40,9 @@ AudioEngine::AudioEngine() AudioEngine::~AudioEngine() { - qDebug() << Q_FUNC_INFO << "waiting for event loop to finish.."; + qDebug() << Q_FUNC_INFO << "waiting for event loop to finish..."; quit(); wait( 1000 ); - qDebug() << Q_FUNC_INFO << "ok"; m_input.clear(); delete m_audio; diff --git a/src/playlist/albumproxymodel.cpp b/src/playlist/albumproxymodel.cpp index 8e8780019..f880a01a8 100644 --- a/src/playlist/albumproxymodel.cpp +++ b/src/playlist/albumproxymodel.cpp @@ -11,6 +11,8 @@ AlbumProxyModel::AlbumProxyModel( QObject* parent ) : QSortFilterProxyModel( parent ) , PlaylistInterface( this ) , m_model( 0 ) + , m_repeatMode( PlaylistInterface::NoRepeat ) + , m_shuffled( false ) { qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) ); @@ -71,6 +73,26 @@ AlbumProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParen } +bool +AlbumProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) const +{ + AlbumItem* p1 = sourceModel()->itemFromIndex( left ); + AlbumItem* p2 = sourceModel()->itemFromIndex( right ); + + if ( !p1 ) + return true; + if ( !p2 ) + return false; + + if ( p1->album()->artist()->name() == p2->album()->artist()->name() ) + { + return QString::localeAwareCompare( p1->album()->name(), p2->album()->name() ) < 0; + } + + return QString::localeAwareCompare( p1->album()->artist()->name(), p2->album()->artist()->name() ) < 0; +} + + void AlbumProxyModel::removeIndex( const QModelIndex& index ) { diff --git a/src/playlist/albumproxymodel.h b/src/playlist/albumproxymodel.h index 15e78552f..598dbaa08 100644 --- a/src/playlist/albumproxymodel.h +++ b/src/playlist/albumproxymodel.h @@ -45,6 +45,7 @@ public slots: protected: bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; + bool lessThan( const QModelIndex& left, const QModelIndex& right ) const; private: AlbumModel* m_model; diff --git a/src/playlist/albumview.cpp b/src/playlist/albumview.cpp index 1ef44376d..a10a86b5a 100644 --- a/src/playlist/albumview.cpp +++ b/src/playlist/albumview.cpp @@ -33,7 +33,6 @@ AlbumView::AlbumView( QWidget* parent ) setResizeMode( Adjust ); setViewMode( IconMode ); setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); -// setIconSize( QSize( 64, 64 ) ); setProxyModel( new AlbumProxyModel( this ) ); @@ -63,7 +62,10 @@ AlbumView::setModel( AlbumModel* model ) m_model = model; if ( m_proxyModel ) + { m_proxyModel->setSourceModel( model ); + m_proxyModel->sort( 0 ); + } connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) ); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index c87ec2ab7..981952907 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -28,6 +28,8 @@ PlaylistManager::PlaylistManager( QObject* parent ) , m_currentInterface( 0 ) , m_currentMode( 0 ) , m_superCollectionVisible( true ) + , m_statsAvailable( false ) + , m_modesAvailable( false ) { m_stack = new QStackedWidget(); @@ -54,7 +56,12 @@ PlaylistManager::PlaylistManager( QObject* parent ) m_superCollectionFlatModel = new CollectionFlatModel( m_superCollectionView ); m_superCollectionView->setModel( m_superCollectionFlatModel ); + m_superAlbumView = new AlbumView(); + m_superAlbumModel = new AlbumModel( m_superAlbumView ); + m_superAlbumView->setModel( m_superAlbumModel ); + m_stack->addWidget( m_superCollectionView ); + m_stack->addWidget( m_superAlbumView ); m_currentInterface = m_superCollectionView->proxyModel(); connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) ); @@ -102,6 +109,8 @@ PlaylistManager::show( const Tomahawk::playlist_ptr& playlist ) } m_superCollectionVisible = false; + m_statsAvailable = true; + m_modesAvailable = false; linkPlaylist(); emit numSourcesChanged( APP->sourcelist().count() ); @@ -136,6 +145,8 @@ PlaylistManager::show( const Tomahawk::album_ptr& album ) } m_superCollectionVisible = false; + m_statsAvailable = false; + m_modesAvailable = false; linkPlaylist(); emit numSourcesChanged( 1 ); @@ -148,6 +159,7 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection ) { unlinkPlaylist(); + m_currentCollection = collection; if ( m_currentMode == 0 ) { if ( !m_collectionViews.contains( collection ) ) @@ -195,6 +207,8 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection ) } m_superCollectionVisible = false; + m_statsAvailable = ( m_currentMode == 0 ); + m_modesAvailable = true; linkPlaylist(); emit numSourcesChanged( 1 ); @@ -223,6 +237,10 @@ PlaylistManager::show( const Tomahawk::source_ptr& source ) m_stack->setCurrentWidget( m_currentInfoWidget ); m_superCollectionVisible = false; + m_statsAvailable = false; + m_modesAvailable = false; + + linkPlaylist(); emit numSourcesChanged( 1 ); return true; @@ -238,13 +256,24 @@ PlaylistManager::showSuperCollection() { m_superCollections.append( source->collection() ); m_superCollectionFlatModel->addCollection( source->collection() ); + m_superAlbumModel->addCollection( source->collection() ); } } - m_stack->setCurrentWidget( m_superCollectionView ); - m_currentInterface = m_superCollectionView->proxyModel(); + if ( m_currentMode == 0 ) + { + m_stack->setCurrentWidget( m_superCollectionView ); + m_currentInterface = m_superCollectionView->proxyModel(); + } + else if ( m_currentMode == 2 ) + { + m_stack->setCurrentWidget( m_superAlbumView ); + m_currentInterface = m_superAlbumView->proxyModel(); + } m_superCollectionVisible = true; + m_statsAvailable = ( m_currentMode == 0 ); + m_modesAvailable = true; linkPlaylist(); emit numSourcesChanged( m_superCollections.count() ); @@ -258,7 +287,11 @@ PlaylistManager::setTableMode() qDebug() << Q_FUNC_INFO; m_currentMode = 0; - m_stack->setCurrentWidget( m_superCollectionView ); + + if ( m_superCollectionVisible ) + showSuperCollection(); + else + show( m_currentCollection ); } @@ -270,7 +303,11 @@ PlaylistManager::setTreeMode() qDebug() << Q_FUNC_INFO; m_currentMode = 1; - m_stack->setCurrentWidget( m_superCollectionView ); + + if ( m_superCollectionVisible ) + showSuperCollection(); + else + show( m_currentCollection ); } @@ -280,7 +317,11 @@ PlaylistManager::setAlbumMode() qDebug() << Q_FUNC_INFO; m_currentMode = 2; - m_stack->setCurrentWidget( m_superCollectionView ); + + if ( m_superCollectionVisible ) + showSuperCollection(); + else + show( m_currentCollection ); } @@ -377,13 +418,17 @@ PlaylistManager::linkPlaylist() applyFilter(); APP->audioEngine()->setPlaylist( m_currentInterface ); - if ( m_currentInterface ) + if ( m_currentInterface && m_statsAvailable ) { emit numTracksChanged( m_currentInterface->unfilteredTrackCount() ); emit numShownChanged( m_currentInterface->trackCount() ); emit repeatModeChanged( m_currentInterface->repeatMode() ); emit shuffleModeChanged( m_currentInterface->shuffled() ); + } + + emit statsAvailable( m_statsAvailable ); + emit modesAvailable( m_modesAvailable ); } diff --git a/src/playlist/playlistmanager.h b/src/playlist/playlistmanager.h index 56ed09e23..278551e6e 100644 --- a/src/playlist/playlistmanager.h +++ b/src/playlist/playlistmanager.h @@ -9,6 +9,7 @@ #include "tomahawk/playlistinterface.h" class AnimatedSplitter; +class AlbumModel; class AlbumView; class CollectionModel; class CollectionFlatModel; @@ -51,6 +52,9 @@ signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); + void statsAvailable( bool b ); + void modesAvailable( bool b ); + public slots: void setTreeMode(); void setTableMode(); @@ -78,6 +82,8 @@ private: PlaylistModel* m_queueModel; QueueView* m_queueView; + AlbumModel* m_superAlbumModel; + AlbumView* m_superAlbumView; CollectionFlatModel* m_superCollectionFlatModel; CollectionView* m_superCollectionView; @@ -94,8 +100,12 @@ private: QWidget* m_currentInfoWidget; + Tomahawk::collection_ptr m_currentCollection; + int m_currentMode; bool m_superCollectionVisible; + bool m_statsAvailable; + bool m_modesAvailable; QTimer m_filterTimer; QString m_filter; diff --git a/src/playlist/trackmodel.cpp b/src/playlist/trackmodel.cpp index 3da2238ec..25bcd2fc4 100644 --- a/src/playlist/trackmodel.cpp +++ b/src/playlist/trackmodel.cpp @@ -337,7 +337,6 @@ void TrackModel::onPlaybackFinished( const Tomahawk::result_ptr& result ) { PlItem* oldEntry = itemFromIndex( m_currentIndex ); - qDebug() << oldEntry->query(); if ( oldEntry && !oldEntry->query().isNull() && oldEntry->query()->results().contains( result ) ) { oldEntry->setIsPlaying( false ); diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index b41f32203..580f0f5c5 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -142,6 +142,12 @@ TomahawkWindow::setupSignals() connect( m_topbar, SIGNAL( albumMode() ), playlistManager(), SLOT( setAlbumMode() ) ); + connect( playlistManager(), SIGNAL( statsAvailable( bool ) ), + m_topbar, SLOT( setStatsVisible( bool ) ) ); + + connect( playlistManager(), SIGNAL( modesAvailable( bool ) ), + m_topbar, SLOT( setModesVisible( bool ) ) ); + // connect( playlistManager(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ), m_audioControls, SLOT( onRepeatModeChanged( PlaylistInterface::RepeatMode ) ) ); diff --git a/src/topbar/topbar.cpp b/src/topbar/topbar.cpp index 665e9b6c7..9b41878ac 100644 --- a/src/topbar/topbar.cpp +++ b/src/topbar/topbar.cpp @@ -171,7 +171,6 @@ void TopBar::setNumTracks( unsigned int i ) { m_tracks = i; - ui->statsLabelNumTracks->setVisible( m_tracks > 0 ); ui->statsLabelNumTracks->setVal( i ); } @@ -189,7 +188,7 @@ void TopBar::setNumShown( unsigned int i ) { m_shown = i; - ui->statsLabelNumShown->setVisible( m_shown != m_tracks ); + ui->statsLabelNumShown->setVisible( m_shown != m_tracks && ui->statsLabelNumTracks->isVisible() ); ui->statsLabelNumShown->setText( QString( "%L1 %2" ).arg( i ).arg( tr( "Shown" ) ) ); } @@ -209,3 +208,23 @@ TopBar::removeSource() Q_ASSERT( m_sources > 0 ); setNumSources( m_sources - 1 ); } + + +void +TopBar::setStatsVisible( bool b ) +{ + foreach( QLabel* dude, m_dudes ) + dude->setVisible( b ); + +// ui->statsLabelNumArtists->setVisible( b ); +// ui->statsLabelNumShown->setVisible( b ); + ui->statsLabelNumSources->setVisible( b ); + ui->statsLabelNumTracks->setVisible( b ); +} + + +void +TopBar::setModesVisible( bool b ) +{ + ui->widgetRadio->setVisible( b ); +} diff --git a/src/topbar/topbar.h b/src/topbar/topbar.h index 8571cd1d2..eccdcf886 100644 --- a/src/topbar/topbar.h +++ b/src/topbar/topbar.h @@ -33,6 +33,9 @@ public slots: void setNumArtists( unsigned int ); void setNumShown( unsigned int ); + void setStatsVisible( bool b ); + void setModesVisible( bool b ); + void addSource(); void removeSource(); diff --git a/src/topbar/topbar.ui b/src/topbar/topbar.ui index c609d1c70..4a2c6d41c 100644 --- a/src/topbar/topbar.ui +++ b/src/topbar/topbar.ui @@ -19,7 +19,7 @@ 0 - 27 + 38 diff --git a/src/utils/animatedcounterlabel.h b/src/utils/animatedcounterlabel.h index 040f3e9ee..3cf22c8da 100644 --- a/src/utils/animatedcounterlabel.h +++ b/src/utils/animatedcounterlabel.h @@ -31,6 +31,13 @@ public: } public slots: + void setVisible( bool b ) + { + QLabel::setVisible( b ); + if ( !m_diff.isNull() ) + m_diff.data()->setVisible( b ); + } + void frame( int f ) { m_displayed = f; @@ -65,24 +72,25 @@ public slots: void showDiff() { int differ = m_val - m_oldval; - QLabel* diff = new QLabel( QString("%1 %L2" ).arg( differ > 0 ? "+" : "" ) + m_diff = new QLabel( QString("%1 %L2" ).arg( differ > 0 ? "+" : "" ) .arg( (int)m_val - (int)m_oldval ), this->parentWidget() ); - diff->setStyleSheet( "font-size:9px; color:grey;" ); - diff->move( QPoint( this->pos().x(), this->pos().y() ) ); - QPropertyAnimation* a = new QPropertyAnimation( diff, "pos" ); + m_diff.data()->setStyleSheet( "font-size:9px; color:grey;" ); + m_diff.data()->move( QPoint( this->pos().x(), this->pos().y() ) ); + QPropertyAnimation* a = new QPropertyAnimation( m_diff.data(), "pos" ); a->setEasingCurve( QEasingCurve( QEasingCurve::InQuad ) ); - a->setStartValue( diff->pos() + QPoint( 0, -10 ) ); - a->setEndValue( QPoint( diff->pos().x(), diff->pos().y() - 25 ) ); + a->setStartValue( m_diff.data()->pos() + QPoint( 0, -10 ) ); + a->setEndValue( QPoint( m_diff.data()->pos().x(), m_diff.data()->pos().y() - 25 ) ); a->setDuration( 1000 ); // qDebug() << "ANIMATING DIFF:" << a->startValue() << a->endValue(); - connect( a, SIGNAL( finished() ), diff, SLOT( hide() ) ); - connect( a, SIGNAL( finished() ), diff, SLOT( deleteLater() ) ); + connect( a, SIGNAL( finished() ), m_diff.data(), SLOT( hide() ) ); + connect( a, SIGNAL( finished() ), m_diff.data(), SLOT( deleteLater() ) ); connect( a, SIGNAL( finished() ), a, SLOT( deleteLater() ) ); - diff->show(); + m_diff.data()->show(); + m_diff.data()->setVisible( this->isVisible() ); a->start(); } @@ -96,7 +104,7 @@ private: unsigned int m_val, m_oldval; QString m_format; - + QWeakPointer m_diff; }; #endif // ANIMATEDCOUNTERLABEL_H diff --git a/src/utils/animatedsplitter.cpp b/src/utils/animatedsplitter.cpp index 10a56b5a2..60fd68448 100644 --- a/src/utils/animatedsplitter.cpp +++ b/src/utils/animatedsplitter.cpp @@ -98,8 +98,6 @@ AnimatedSplitter::addWidget( AnimatedWidget* widget ) QSplitter::addWidget( widget ); m_sizes << widget->hiddenSize(); - qDebug() << m_sizes.count(); - connect( widget, SIGNAL( showWidget() ), SLOT( onShowRequest() ) ); connect( widget, SIGNAL( hideWidget() ), SLOT( onHideRequest() ) ); connect( widget, SIGNAL( hiddenSizeChanged() ), SLOT( onHiddenSizeChanged() ) );