From 3ed443456aac8ebb8fb7b016823a76850e9a70ed Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 28 Nov 2011 06:32:10 +0100 Subject: [PATCH] * Support Footnotes in TreeViews. --- src/libtomahawk/context/ContextPage.h | 4 +- src/libtomahawk/context/ContextWidget.cpp | 41 +++++++++++++ src/libtomahawk/context/ContextWidget.h | 4 ++ .../context/pages/RelatedArtistsContext.cpp | 35 +++++++++-- .../context/pages/RelatedArtistsContext.h | 6 +- .../context/pages/TopTracksContext.cpp | 36 ++++++++--- .../context/pages/TopTracksContext.h | 6 +- .../context/pages/WikipediaContext.cpp | 60 ++++++++++++++++--- .../context/pages/WikipediaContext.h | 10 +++- src/libtomahawk/playlist/artistview.cpp | 23 +++++++ src/libtomahawk/playlist/artistview.h | 8 +++ src/libtomahawk/playlist/trackview.cpp | 2 - 12 files changed, 208 insertions(+), 27 deletions(-) diff --git a/src/libtomahawk/context/ContextPage.h b/src/libtomahawk/context/ContextPage.h index c7e0e5449..6e19bf409 100644 --- a/src/libtomahawk/context/ContextPage.h +++ b/src/libtomahawk/context/ContextPage.h @@ -52,7 +52,9 @@ public: virtual bool jumpToCurrentTrack() = 0; public slots: - virtual void setQuery( const Tomahawk::query_ptr& query ) = 0; + virtual void setArtist( const Tomahawk::artist_ptr& artist ) { Q_UNUSED( artist ); } + virtual void setAlbum( const Tomahawk::album_ptr& album ) { Q_UNUSED( album ); } + virtual void setQuery( const Tomahawk::query_ptr& query ) { Q_UNUSED( query ); } signals: void nameChanged( const QString& ); diff --git a/src/libtomahawk/context/ContextWidget.cpp b/src/libtomahawk/context/ContextWidget.cpp index 4c20c91ca..a778dcaf7 100644 --- a/src/libtomahawk/context/ContextWidget.cpp +++ b/src/libtomahawk/context/ContextWidget.cpp @@ -94,6 +94,7 @@ ContextWidget::ContextWidget( QWidget* parent ) setAutoFillBackground( true ); setFixedHeight( m_minHeight ); + ensurePolished(); QPalette pal = palette(); pal.setBrush( QPalette::Window, StyleHelper::headerLowerColor() ); setPalette( pal ); @@ -229,6 +230,44 @@ ContextWidget::fadeOut( bool animate ) } +void +ContextWidget::setArtist( const Tomahawk::artist_ptr& artist ) +{ + if ( artist.isNull() ) + return; + + m_artist = artist; + if ( height() > m_minHeight ) + { + foreach ( ContextProxyPage* proxy, m_pages ) + { + proxy->page()->setArtist( artist ); + } + + layoutViews( true ); + } +} + + +void +ContextWidget::setAlbum( const Tomahawk::album_ptr& album ) +{ + if ( album.isNull() ) + return; + + m_album = album; + if ( height() > m_minHeight ) + { + foreach ( ContextProxyPage* proxy, m_pages ) + { + proxy->page()->setAlbum( album ); + } + + layoutViews( true ); + } +} + + void ContextWidget::setQuery( const Tomahawk::query_ptr& query, bool force ) { @@ -292,6 +331,8 @@ ContextWidget::onAnimationFinished() fadeOut( false ); m_scene->setSceneRect( ui->contextView->viewport()->rect() ); layoutViews( false ); + setArtist( m_artist ); + setAlbum( m_album ); setQuery( m_query, true ); ui->toggleButton->setText( tr( "Hide Footnotes" ) ); diff --git a/src/libtomahawk/context/ContextWidget.h b/src/libtomahawk/context/ContextWidget.h index e47a88da6..309839cd1 100644 --- a/src/libtomahawk/context/ContextWidget.h +++ b/src/libtomahawk/context/ContextWidget.h @@ -50,6 +50,8 @@ public: ~ContextWidget(); public slots: + void setArtist( const Tomahawk::artist_ptr& artist ); + void setAlbum( const Tomahawk::album_ptr& album ); void setQuery( const Tomahawk::query_ptr& query, bool force = false ); void toggleSize(); @@ -82,6 +84,8 @@ private: int m_currentView; + Tomahawk::artist_ptr m_artist; + Tomahawk::album_ptr m_album; Tomahawk::query_ptr m_query; bool m_visible; }; diff --git a/src/libtomahawk/context/pages/RelatedArtistsContext.cpp b/src/libtomahawk/context/pages/RelatedArtistsContext.cpp index c4620d697..1c403e5e0 100644 --- a/src/libtomahawk/context/pages/RelatedArtistsContext.cpp +++ b/src/libtomahawk/context/pages/RelatedArtistsContext.cpp @@ -32,6 +32,7 @@ RelatedArtistsContext::RelatedArtistsContext() { m_relatedView = new ArtistView(); m_relatedView->setGuid( "RelatedArtistsContext" ); + m_relatedView->setUpdatesContextView( false ); m_relatedModel = new TreeModel( m_relatedView ); m_relatedModel->setColumnStyle( TreeModel::TrackOnly ); m_relatedView->setTreeModel( m_relatedModel ); @@ -58,15 +59,17 @@ RelatedArtistsContext::~RelatedArtistsContext() void -RelatedArtistsContext::setQuery( const Tomahawk::query_ptr& query ) +RelatedArtistsContext::setArtist( const Tomahawk::artist_ptr& artist ) { - if ( !m_query.isNull() && query->artist() == m_query->artist() ) + if ( artist.isNull() ) + return; + if ( !m_artist.isNull() && m_artist->name() == artist->name() ) return; - m_query = query; + m_artist = artist; Tomahawk::InfoSystem::InfoStringHash artistInfo; - artistInfo["artist"] = query->artist(); + artistInfo["artist"] = artist->name(); Tomahawk::InfoSystem::InfoRequestData requestData; requestData.caller = m_infoId; @@ -78,6 +81,26 @@ RelatedArtistsContext::setQuery( const Tomahawk::query_ptr& query ) } +void +RelatedArtistsContext::setQuery( const Tomahawk::query_ptr& query ) +{ + if ( query.isNull() ) + return; + + setArtist( Artist::get( query->artist(), false ) ); +} + + +void +RelatedArtistsContext::setAlbum( const Tomahawk::album_ptr& album ) +{ + if ( album.isNull() ) + return; + + setArtist( album->artist() ); +} + + void RelatedArtistsContext::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) { @@ -89,9 +112,9 @@ RelatedArtistsContext::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData req if ( output.canConvert< QVariantMap >() ) { - if ( trackInfo["artist"] != m_query->artist() ) + if ( trackInfo["artist"] != m_artist->name() ) { - qDebug() << "Returned info was for:" << trackInfo["artist"] << "- was looking for:" << m_query->artist(); + qDebug() << "Returned info was for:" << trackInfo["artist"] << "- was looking for:" << m_artist->name(); return; } } diff --git a/src/libtomahawk/context/pages/RelatedArtistsContext.h b/src/libtomahawk/context/pages/RelatedArtistsContext.h index a079f0365..47f4ef138 100644 --- a/src/libtomahawk/context/pages/RelatedArtistsContext.h +++ b/src/libtomahawk/context/pages/RelatedArtistsContext.h @@ -23,6 +23,8 @@ #include "dllmacro.h" +#include "artist.h" +#include "album.h" #include "query.h" #include "context/ContextPage.h" #include "infosystem/infosystem.h" @@ -48,6 +50,8 @@ public: virtual bool jumpToCurrentTrack() { return false; } public slots: + virtual void setArtist( const Tomahawk::artist_ptr& artist ); + virtual void setAlbum( const Tomahawk::album_ptr& album ); virtual void setQuery( const Tomahawk::query_ptr& query ); private slots: @@ -61,7 +65,7 @@ private: QGraphicsProxyWidget* m_proxy; QString m_infoId; - Tomahawk::query_ptr m_query; + Tomahawk::artist_ptr m_artist; }; #endif // RELATEDARTISTSCONTEXT_H diff --git a/src/libtomahawk/context/pages/TopTracksContext.cpp b/src/libtomahawk/context/pages/TopTracksContext.cpp index 8f25e646c..ab78310a0 100644 --- a/src/libtomahawk/context/pages/TopTracksContext.cpp +++ b/src/libtomahawk/context/pages/TopTracksContext.cpp @@ -58,15 +58,17 @@ TopTracksContext::~TopTracksContext() void -TopTracksContext::setQuery( const Tomahawk::query_ptr& query ) +TopTracksContext::setArtist( const Tomahawk::artist_ptr& artist ) { - if ( !m_query.isNull() && query->artist() == m_query->artist() ) + if ( artist.isNull() ) + return; + if ( !m_artist.isNull() && m_artist->name() == artist->name() ) return; - m_query = query; + m_artist = artist; Tomahawk::InfoSystem::InfoStringHash artistInfo; - artistInfo["artist"] = query->artist(); + artistInfo["artist"] = artist->name(); Tomahawk::InfoSystem::InfoRequestData requestData; requestData.caller = m_infoId; @@ -78,6 +80,26 @@ TopTracksContext::setQuery( const Tomahawk::query_ptr& query ) } +void +TopTracksContext::setAlbum( const Tomahawk::album_ptr& album ) +{ + if ( album.isNull() ) + return; + + setArtist( album->artist() ); +} + + +void +TopTracksContext::setQuery( const Tomahawk::query_ptr& query ) +{ + if ( query.isNull() ) + return; + + setArtist( Artist::get( query->artist(), false ) ); +} + + void TopTracksContext::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) { @@ -89,9 +111,9 @@ TopTracksContext::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestD if ( output.canConvert< QVariantMap >() ) { - if ( trackInfo["artist"] != m_query->artist() ) + if ( trackInfo["artist"] != m_artist->name() ) { - qDebug() << "Returned info was for:" << trackInfo["artist"] << "- was looking for:" << m_query->artist(); + qDebug() << "Returned info was for:" << trackInfo["artist"] << "- was looking for:" << m_artist->name(); return; } } @@ -107,7 +129,7 @@ TopTracksContext::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestD int i = 0; foreach ( const QString& track, tracks ) { - query_ptr query = Query::get( m_query->artist(), track, QString(), uuid() ); + query_ptr query = Query::get( m_artist->name(), track, QString(), uuid() ); m_topHitsModel->append( query ); if ( ++i == 15 ) diff --git a/src/libtomahawk/context/pages/TopTracksContext.h b/src/libtomahawk/context/pages/TopTracksContext.h index 46db47f53..d74abda7c 100644 --- a/src/libtomahawk/context/pages/TopTracksContext.h +++ b/src/libtomahawk/context/pages/TopTracksContext.h @@ -23,6 +23,8 @@ #include "dllmacro.h" +#include "artist.h" +#include "album.h" #include "query.h" #include "context/ContextPage.h" #include "infosystem/infosystem.h" @@ -48,6 +50,8 @@ public: virtual bool jumpToCurrentTrack() { return false; } public slots: + virtual void setArtist( const Tomahawk::artist_ptr& artist ); + virtual void setAlbum( const Tomahawk::album_ptr& album ); virtual void setQuery( const Tomahawk::query_ptr& query ); private slots: @@ -61,7 +65,7 @@ private: QGraphicsProxyWidget* m_proxy; QString m_infoId; - Tomahawk::query_ptr m_query; + Tomahawk::artist_ptr m_artist; }; #endif // TOPTRACKSCONTEXT_H diff --git a/src/libtomahawk/context/pages/WikipediaContext.cpp b/src/libtomahawk/context/pages/WikipediaContext.cpp index f48bf22ee..1fe90f4a5 100644 --- a/src/libtomahawk/context/pages/WikipediaContext.cpp +++ b/src/libtomahawk/context/pages/WikipediaContext.cpp @@ -22,22 +22,68 @@ using namespace Tomahawk; void -WikipediaContext::setQuery( const Tomahawk::query_ptr& query ) +WikipediaContext::setArtist( const Tomahawk::artist_ptr& artist ) { - if ( !m_query.isNull() && query->artist() == m_query->artist() ) + if ( artist.isNull() ) + return; + if ( !m_artist.isNull() && m_artist->name() == artist->name() ) return; - m_query = query; - webView()->load( QString( "http://en.wikipedia.org/w/index.php?useformat=mobile&title=%1" ).arg( query->artist() ) ); + m_artist = artist; + + webView()->load( QString( "http://en.wikipedia.org/w/index.php?useformat=mobile&title=%1" ).arg( m_artist->name() ) ); +} + + +void +WikipediaContext::setAlbum( const Tomahawk::album_ptr& album ) +{ + if ( album.isNull() ) + return; + + setArtist( album->artist() ); +} + + +void +WikipediaContext::setQuery( const Tomahawk::query_ptr& query ) +{ + if ( query.isNull() ) + return; + + setArtist( Artist::get( query->artist(), false ) ); +} + + +void +LastfmContext::setArtist( const Tomahawk::artist_ptr& artist ) +{ + if ( artist.isNull() ) + return; + if ( !m_artist.isNull() && m_artist->name() == artist->name() ) + return; + + m_artist = artist; + + webView()->load( QString( "http://last.fm/music/%1" ).arg( m_artist->name() ) ); +} + + +void +LastfmContext::setAlbum( const Tomahawk::album_ptr& album ) +{ + if ( album.isNull() ) + return; + + setArtist( album->artist() ); } void LastfmContext::setQuery( const Tomahawk::query_ptr& query ) { - if ( !m_query.isNull() && query->artist() == m_query->artist() ) + if ( query.isNull() ) return; - m_query = query; - webView()->load( QString( "http://last.fm/music/%1" ).arg( query->artist() ) ); + setArtist( Artist::get( query->artist(), false ) ); } diff --git a/src/libtomahawk/context/pages/WikipediaContext.h b/src/libtomahawk/context/pages/WikipediaContext.h index 5c8d45c16..54fe011e6 100644 --- a/src/libtomahawk/context/pages/WikipediaContext.h +++ b/src/libtomahawk/context/pages/WikipediaContext.h @@ -23,6 +23,8 @@ #include "dllmacro.h" +#include "artist.h" +#include "album.h" #include "query.h" #include "WebContext.h" @@ -42,10 +44,12 @@ public: virtual bool jumpToCurrentTrack() { return false; } public slots: + virtual void setArtist( const Tomahawk::artist_ptr& artist ); + virtual void setAlbum( const Tomahawk::album_ptr& album ); virtual void setQuery( const Tomahawk::query_ptr& query ); private: - Tomahawk::query_ptr m_query; + Tomahawk::artist_ptr m_artist; }; @@ -65,10 +69,12 @@ public: virtual bool jumpToCurrentTrack() { return false; } public slots: + virtual void setArtist( const Tomahawk::artist_ptr& artist ); + virtual void setAlbum( const Tomahawk::album_ptr& album ); virtual void setQuery( const Tomahawk::query_ptr& query ); private: - Tomahawk::query_ptr m_query; + Tomahawk::artist_ptr m_artist; }; #endif // WIKIPEDIACONTEXT_H diff --git a/src/libtomahawk/playlist/artistview.cpp b/src/libtomahawk/playlist/artistview.cpp index 8927eb896..cd02c3266 100644 --- a/src/libtomahawk/playlist/artistview.cpp +++ b/src/libtomahawk/playlist/artistview.cpp @@ -24,6 +24,7 @@ #include #include "audio/audioengine.h" +#include "context/ContextWidget.h" #include "dynamic/widgets/LoadingSpinner.h" #include "widgets/overlaywidget.h" @@ -47,6 +48,7 @@ ArtistView::ArtistView( QWidget* parent ) , m_proxyModel( 0 ) // , m_delegate( 0 ) , m_loadingSpinner( new LoadingSpinner( this ) ) + , m_updateContextView( true ) , m_contextMenu( new ContextMenu( this ) ) , m_showModes( true ) { @@ -150,6 +152,27 @@ ArtistView::setTreeModel( TreeModel* model ) } +void +ArtistView::currentChanged( const QModelIndex& current, const QModelIndex& /* previous */ ) +{ + if ( !m_updateContextView ) + return; + + TreeModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( current ) ); + if ( item ) + { + if ( !item->result().isNull() ) + ViewManager::instance()->context()->setQuery( item->result()->toQuery() ); + else if ( !item->artist().isNull() ) + ViewManager::instance()->context()->setArtist( item->artist() ); + else if ( !item->album().isNull() ) + ViewManager::instance()->context()->setAlbum( item->album() ); + else if ( !item->query().isNull() ) + ViewManager::instance()->context()->setQuery( item->query() ); + } +} + + void ArtistView::onItemActivated( const QModelIndex& index ) { diff --git a/src/libtomahawk/playlist/artistview.h b/src/libtomahawk/playlist/artistview.h index f53026857..934edbea4 100644 --- a/src/libtomahawk/playlist/artistview.h +++ b/src/libtomahawk/playlist/artistview.h @@ -70,6 +70,9 @@ public: virtual bool jumpToCurrentTrack(); + bool updatesContextView() const { return m_updateContextView; } + void setUpdatesContextView( bool b ) { m_updateContextView = b; } + public slots: void onItemActivated( const QModelIndex& index ); @@ -80,6 +83,9 @@ protected: void paintEvent( QPaintEvent* event ); void keyPressEvent( QKeyEvent* event ); +protected slots: + virtual void currentChanged( const QModelIndex& current, const QModelIndex& previous ); + private slots: void onItemCountChanged( unsigned int items ); void onFilterChanged( const QString& filter ); @@ -98,6 +104,8 @@ private: // PlaylistItemDelegate* m_delegate; LoadingSpinner* m_loadingSpinner; + bool m_updateContextView; + QModelIndex m_contextMenuIndex; Tomahawk::ContextMenu* m_contextMenu; diff --git a/src/libtomahawk/playlist/trackview.cpp b/src/libtomahawk/playlist/trackview.cpp index 613b62c95..dc01fd980 100644 --- a/src/libtomahawk/playlist/trackview.cpp +++ b/src/libtomahawk/playlist/trackview.cpp @@ -90,8 +90,6 @@ TrackView::TrackView( QWidget* parent ) TrackView::~TrackView() { tDebug() << Q_FUNC_INFO; - - delete m_header; }