From 744f31bb45dd0b24653b51ab157b1307d59c6a94 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 12 Aug 2011 03:17:36 +0200 Subject: [PATCH] Added almost-finished AlbumInfoWidget. --- src/libtomahawk/CMakeLists.txt | 3 + src/libtomahawk/viewmanager.cpp | 21 +-- src/libtomahawk/viewmanager.h | 3 +- .../widgets/infowidgets/AlbumInfoWidget.cpp | 171 ++++++++++++++++++ .../widgets/infowidgets/AlbumInfoWidget.h | 108 +++++++++++ .../widgets/infowidgets/AlbumInfoWidget.ui | 55 ++++++ .../widgets/infowidgets/ArtistInfoWidget.cpp | 15 +- .../widgets/infowidgets/ArtistInfoWidget.h | 3 +- src/libtomahawk/widgets/welcomewidget.cpp | 1 + 9 files changed, 351 insertions(+), 29 deletions(-) create mode 100644 src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp create mode 100644 src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h create mode 100644 src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.ui diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index b9b740b97..907be5b56 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -186,6 +186,7 @@ set( libSources widgets/SocialPlaylistWidget.cpp widgets/infowidgets/sourceinfowidget.cpp widgets/infowidgets/ArtistInfoWidget.cpp + widgets/infowidgets/AlbumInfoWidget.cpp kdsingleapplicationguard/kdsingleapplicationguard.cpp kdsingleapplicationguard/kdsharedmemorylocker.cpp @@ -366,6 +367,7 @@ set( libHeaders widgets/SocialPlaylistWidget.h widgets/infowidgets/sourceinfowidget.h widgets/infowidgets/ArtistInfoWidget.h + widgets/infowidgets/AlbumInfoWidget.h kdsingleapplicationguard/kdsingleapplicationguard.h ) @@ -389,6 +391,7 @@ set( libUI ${libUI} widgets/SocialPlaylistWidget.ui widgets/infowidgets/sourceinfowidget.ui widgets/infowidgets/ArtistInfoWidget.ui + widgets/infowidgets/AlbumInfoWidget.ui playlist/topbar/topbar.ui playlist/infobar/infobar.ui ) diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 54fdd54ce..b50a6ada9 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -46,6 +46,7 @@ #include "widgets/welcomewidget.h" #include "widgets/infowidgets/sourceinfowidget.h" #include "widgets/infowidgets/ArtistInfoWidget.h" +#include "widgets/infowidgets/AlbumInfoWidget.h" #include "widgets/newplaylistwidget.h" #include "utils/logger.h" @@ -237,27 +238,19 @@ ViewManager::show( const Tomahawk::artist_ptr& artist ) Tomahawk::ViewPage* ViewManager::show( const Tomahawk::album_ptr& album ) { - PlaylistView* view; + AlbumInfoWidget* swidget; if ( !m_albumViews.contains( album ) ) { - view = new PlaylistView(); - PlaylistModel* model = new PlaylistModel(); - model->append( album ); - view->setPlaylistModel( model ); - view->setFrameShape( QFrame::NoFrame ); - view->setAttribute( Qt::WA_MacShowFocusRect, 0 ); - - m_albumViews.insert( album, view ); + swidget = new AlbumInfoWidget( album ); + m_albumViews.insert( album, swidget ); } else { - view = m_albumViews.value( album ); + swidget = m_albumViews.value( album ); } - setPage( view ); - emit numSourcesChanged( 1 ); - - return view; + setPage( swidget ); + return swidget; } diff --git a/src/libtomahawk/viewmanager.h b/src/libtomahawk/viewmanager.h index 2321265cb..8d597d610 100644 --- a/src/libtomahawk/viewmanager.h +++ b/src/libtomahawk/viewmanager.h @@ -33,6 +33,7 @@ class AnimatedSplitter; class AlbumModel; class AlbumView; +class AlbumInfoWidget; class ArtistInfoWidget; class ArtistView; class CollectionModel; @@ -188,7 +189,7 @@ private: QHash< Tomahawk::collection_ptr, ArtistView* > m_treeViews; QHash< Tomahawk::collection_ptr, AlbumView* > m_collectionAlbumViews; QHash< Tomahawk::artist_ptr, ArtistInfoWidget* > m_artistViews; - QHash< Tomahawk::album_ptr, PlaylistView* > m_albumViews; + QHash< Tomahawk::album_ptr, AlbumInfoWidget* > m_albumViews; QHash< Tomahawk::playlist_ptr, PlaylistView* > m_playlistViews; QHash< Tomahawk::source_ptr, SourceInfoWidget* > m_sourceViews; diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp new file mode 100644 index 000000000..3454e47b2 --- /dev/null +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -0,0 +1,171 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "AlbumInfoWidget.h" +#include "ui_AlbumInfoWidget.h" + +#include "viewmanager.h" +#include "playlist/treemodel.h" +#include "playlist/albummodel.h" + +#include "database/databasecommand_alltracks.h" +#include "database/databasecommand_allalbums.h" + +#include "utils/tomahawkutils.h" +#include "utils/logger.h" + +#include "widgets/overlaywidget.h" + +static QString s_aiInfoIdentifier = QString( "AlbumInfoWidget" ); + +using namespace Tomahawk; + + +AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* parent ) + : QWidget( parent ) + , ui( new Ui::AlbumInfoWidget ) + , m_album( album ) +{ + ui->setupUi( this ); + + ui->albumsView->setFrameShape( QFrame::NoFrame ); + ui->albumsView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); + ui->tracksView->setFrameShape( QFrame::NoFrame ); + ui->tracksView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); + + TomahawkUtils::unmarginLayout( layout() ); + + m_albumsModel = new AlbumModel( ui->albumsView ); + ui->albumsView->setAlbumModel( m_albumsModel ); + + m_tracksModel = new TreeModel( ui->tracksView ); + ui->tracksView->setTreeModel( m_tracksModel ); + + m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation ); + + connect( Tomahawk::InfoSystem::InfoSystem::instance(), + SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), + SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); + + connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); + + // Apparently headers can only be removed when it's already visible / layed-out + QTimer::singleShot( 0, this, SLOT( removeHeaders() ) ); + + load( album ); +} + + +AlbumInfoWidget::~AlbumInfoWidget() +{ + delete ui; +} + + +void +AlbumInfoWidget::load( const album_ptr& album ) +{ + m_title = album->name(); + m_description = album->artist()->name(); + m_tracksModel->addTracks( album, QModelIndex() ); + + QList al; + al << album; + m_albumsModel->addAlbums( al ); + + Tomahawk::InfoSystem::InfoCriteriaHash trackInfo; + trackInfo["artist"] = album->artist()->name(); + trackInfo["album"] = album->name(); + + Tomahawk::InfoSystem::InfoRequestData requestData; + requestData.caller = s_aiInfoIdentifier; + requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt; + requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ); + requestData.customData = QVariantMap(); + + Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); +} + + +void +AlbumInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) +{ + if ( requestData.caller != s_aiInfoIdentifier ) + { + return; + } + + InfoSystem::InfoCriteriaHash trackInfo; + trackInfo = requestData.input.value< InfoSystem::InfoCriteriaHash >(); + + if ( output.canConvert< QVariantMap >() ) + { + if ( trackInfo["album"] != m_album->name() ) + { + qDebug() << "Returned info was for:" << trackInfo["album"] << "- was looking for:" << m_album->name(); + return; + } + } + + QVariantMap returnedData = output.value< QVariantMap >(); + switch ( requestData.type ) + { + case Tomahawk::InfoSystem::InfoAlbumCoverArt: + { + QVariantMap returnedData = output.value< QVariantMap >(); + const QByteArray ba = returnedData["imgbytes"].toByteArray(); + if ( ba.length() ) + { + m_pixmap.loadFromData( ba ); + emit pixmapChanged( m_pixmap ); + } + } + + default: + return; + } +} + + +void +AlbumInfoWidget::infoSystemFinished( QString target ) +{ + Q_UNUSED( target ); +} + + +void +AlbumInfoWidget::changeEvent( QEvent* e ) +{ + QWidget::changeEvent( e ); + switch ( e->type() ) + { + case QEvent::LanguageChange: + ui->retranslateUi( this ); + break; + + default: + break; + } +} + + +void +AlbumInfoWidget::removeHeaders() +{ +} diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h new file mode 100644 index 000000000..e88ec852a --- /dev/null +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h @@ -0,0 +1,108 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +/** + * \class AlbumInfoWidget + * \brief ViewPage, which displays an album for an artist and recommends others. + * + * This Tomahawk ViewPage displays the tracks of any given album + * It is our default ViewPage when showing an artist via ViewManager. + * + */ + +#ifndef ALBUMINFOWIDGET_H +#define ALBUMINFOWIDGET_H + +#include + +#include "artist.h" +#include "result.h" +#include "playlistinterface.h" +#include "viewpage.h" +#include "infosystem/infosystem.h" + +#include "dllmacro.h" + +class AlbumModel; +class TreeModel; + +namespace Ui +{ + class AlbumInfoWidget; +} + +class DLLEXPORT AlbumInfoWidget : public QWidget, public Tomahawk::ViewPage +{ +Q_OBJECT + +public: + AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* parent = 0 ); + ~AlbumInfoWidget(); + + /** \brief Loads information for a given album. + * \param album The album that you want to load information for. + * + * Calling this method will make AlbumInfoWidget load information about + * an album, and related other albums. This method will be automatically + * called by the constructor, but you can use it to load another album's + * information at any point. + */ + void load( const Tomahawk::album_ptr& album ); + + virtual QWidget* widget() { return this; } + virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + + virtual QString title() const { return m_title; } + virtual QString description() const { return m_description; } + virtual QString longDescription() const { return m_longDescription; } + virtual QPixmap pixmap() const { if ( m_pixmap.isNull() ) return Tomahawk::ViewPage::pixmap(); else return m_pixmap; } + + virtual bool isTemporaryPage() const { return true; } + virtual bool showStatsBar() const { return false; } + + virtual bool jumpToCurrentTrack() { return false; } + +signals: + void longDescriptionChanged( const QString& description ); + void descriptionChanged( const QString& description ); + void pixmapChanged( const QPixmap& pixmap ); + +protected: + void changeEvent( QEvent* e ); + +private slots: + void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); + void infoSystemFinished( QString target ); + + void removeHeaders(); + +private: + Ui::AlbumInfoWidget *ui; + + Tomahawk::album_ptr m_album; + + AlbumModel* m_albumsModel; + TreeModel* m_tracksModel; + + QString m_title; + QString m_description; + QString m_longDescription; + QPixmap m_pixmap; +}; + +#endif // ALBUMINFOWIDGET_H diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.ui b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.ui new file mode 100644 index 000000000..c06d89099 --- /dev/null +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.ui @@ -0,0 +1,55 @@ + + + AlbumInfoWidget + + + + 0 + 0 + 902 + 696 + + + + Form + + + + + + + + + + + Other Albums by Artist + + + + + + + + + + + + + HeaderLabel + QLabel +
widgets/HeaderLabel.h
+
+ + ArtistView + QTreeView +
artistview.h
+
+ + AlbumView + QListView +
playlist/albumview.h
+
+
+ + +
diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 39e41710c..e911033e6 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -59,6 +59,8 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* m_relatedModel = new TreeModel( ui->relatedArtists ); ui->relatedArtists->setTreeModel( m_relatedModel ); + ui->relatedArtists->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + ui->relatedArtists->header()->setVisible( false ); m_topHitsModel = new PlaylistModel( ui->topHits ); m_topHitsModel->setStyle( TrackModel::Short ); @@ -72,12 +74,10 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); - // Apparently headers can only be removed when it's already visible / layed-out - QTimer::singleShot( 0, this ,SLOT( removeHeaders() ) ); - load( artist ); } + ArtistInfoWidget::~ArtistInfoWidget() { delete ui; @@ -125,7 +125,6 @@ ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestD // qDebug() << "Info of wrong type or not with our identifier"; return; } - qDebug() << Q_FUNC_INFO << requestData.caller << requestData.type << s_aiInfoIdentifier; InfoSystem::InfoCriteriaHash trackInfo; trackInfo = requestData.input.value< InfoSystem::InfoCriteriaHash >(); @@ -207,7 +206,6 @@ void ArtistInfoWidget::infoSystemFinished( QString target ) { Q_UNUSED( target ); - qDebug() << Q_FUNC_INFO; } @@ -225,10 +223,3 @@ ArtistInfoWidget::changeEvent( QEvent* e ) break; } } - -void -ArtistInfoWidget::removeHeaders() -{ - for ( int i = 1; i < ui->relatedArtists->header()->count(); i++ ) - ui->relatedArtists->header()->hideSection( ui->relatedArtists->header()->logicalIndex( i ) ); -} diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h index 176adae95..155a3f2f7 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h @@ -90,7 +90,6 @@ private slots: void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemFinished( QString target ); - void removeHeaders(); private: Ui::ArtistInfoWidget *ui; @@ -106,4 +105,4 @@ private: QPixmap m_pixmap; }; -#endif // SOURCEINFOWIDGET_H +#endif // ARTISTINFOWIDGET_H diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index 44757c076..9f1af850a 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -190,6 +190,7 @@ WelcomeWidget::changeEvent( QEvent* e ) } } + QSize PlaylistDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const {