PageRenderTime 45ms CodeModel.GetById 15ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 325 lines | 223 code | 79 blank | 23 comment | 30 complexity | dad6e6ae22283f0f9d294106ce4e30ad MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#include "ArtistInfoWidget.h"
 21#include "ArtistInfoWidget_p.h"
 22#include "ui_ArtistInfoWidget.h"
 23
 24#include <QScrollArea>
 25#include <QScrollBar>
 26
 27#include "audio/AudioEngine.h"
 28#include "playlist/GridItemDelegate.h"
 29#include "playlist/PlayableModel.h"
 30#include "playlist/TreeModel.h"
 31#include "playlist/PlaylistModel.h"
 32#include "playlist/TreeProxyModel.h"
 33#include "Source.h"
 34
 35#include "database/DatabaseCommand_AllTracks.h"
 36#include "database/DatabaseCommand_AllAlbums.h"
 37
 38#include "Pipeline.h"
 39#include "utils/StyleHelper.h"
 40#include "utils/TomahawkUtilsGui.h"
 41#include "utils/Logger.h"
 42
 43using namespace Tomahawk;
 44
 45
 46ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* parent )
 47    : QWidget( parent )
 48    , ui( new Ui::ArtistInfoWidget )
 49    , m_artist( artist )
 50{
 51    QWidget* widget = new QWidget;
 52    ui->setupUi( widget );
 53
 54    QPalette pal = palette();
 55    pal.setColor( QPalette::Window, QColor( "#454e59" ) );
 56
 57    widget->setPalette( pal );
 58    widget->setAutoFillBackground( true );
 59
 60    m_plInterface = Tomahawk::playlistinterface_ptr( new MetaArtistInfoInterface( this ) );
 61
 62/*    TomahawkUtils::unmarginLayout( ui->layoutWidget->layout() );
 63    TomahawkUtils::unmarginLayout( ui->layoutWidget1->layout() );
 64    TomahawkUtils::unmarginLayout( ui->layoutWidget2->layout() );
 65    TomahawkUtils::unmarginLayout( ui->albumHeader->layout() );*/
 66
 67    m_albumsModel = new PlayableModel( ui->albums );
 68    ui->albums->setPlayableModel( m_albumsModel );
 69    ui->albums->setEmptyTip( tr( "Sorry, we could not find any albums for this artist!" ) );
 70
 71    m_relatedModel = new PlayableModel( ui->relatedArtists );
 72    ui->relatedArtists->setPlayableModel( m_relatedModel );
 73    ui->relatedArtists->proxyModel()->sort( -1 );
 74    ui->relatedArtists->setEmptyTip( tr( "Sorry, we could not find any related artists!" ) );
 75
 76    m_topHitsModel = new PlaylistModel( ui->topHits );
 77    ui->topHits->proxyModel()->setStyle( PlayableProxyModel::Short );
 78    ui->topHits->setPlayableModel( m_topHitsModel );
 79    ui->topHits->setSortingEnabled( false );
 80    ui->topHits->setEmptyTip( tr( "Sorry, we could not find any top hits for this artist!" ) );
 81
 82    ui->relatedArtists->setAutoFitItems( false );
 83    ui->relatedArtists->setWrapping( false );
 84    ui->relatedArtists->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 85    ui->relatedArtists->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
 86    ui->relatedArtists->delegate()->setItemSize( QSize( 170, 170 ) );
 87
 88    ui->albums->setAutoFitItems( false );
 89    ui->albums->setWrapping( false );
 90    ui->albums->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 91    ui->albums->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
 92    ui->albums->delegate()->setItemSize( QSize( 170, 170 ) );
 93    ui->albums->proxyModel()->setHideDupeItems( true );
 94
 95    ui->topHits->setFrameShape( QFrame::StyledPanel );
 96    ui->topHits->setAttribute( Qt::WA_MacShowFocusRect, 0 );
 97
 98    m_pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, QSize( 48, 48 ) );
 99    ui->cover->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, QSize( ui->cover->sizeHint() ) ) );
100
101    ui->biography->setFrameShape( QFrame::NoFrame );
102    ui->biography->setAttribute( Qt::WA_MacShowFocusRect, 0 );
103    TomahawkUtils::styleScrollBar( ui->biography->verticalScrollBar() );
104
105    QFont f = font();
106    f.setBold( true );
107    f.setPointSize( TomahawkUtils::defaultFontSize() + 5 );
108    ui->artistLabel->setFont( f );
109
110    QPalette p = ui->biography->palette();
111    p.setColor( QPalette::Foreground, Qt::white );
112    p.setColor( QPalette::Text, Qt::white );
113
114    ui->artistLabel->setPalette( p );
115    ui->biography->setPalette( p );
116    ui->label->setPalette( p );
117    ui->label_2->setPalette( p );
118    ui->label_3->setPalette( p );
119
120    QScrollArea* area = new QScrollArea();
121    area->setWidgetResizable( true );
122    area->setWidget( widget );
123
124    area->setStyleSheet( "QScrollArea { background-color: #454e59; }" );
125    area->setFrameShape( QFrame::NoFrame );
126    area->setAttribute( Qt::WA_MacShowFocusRect, 0 );
127
128    QVBoxLayout* layout = new QVBoxLayout();
129    layout->addWidget( area );
130    setLayout( layout );
131    TomahawkUtils::unmarginLayout( layout );
132
133    TomahawkUtils::styleScrollBar( ui->albums->horizontalScrollBar() );
134    TomahawkUtils::styleScrollBar( ui->relatedArtists->horizontalScrollBar() );
135
136    ui->biography->setStyleSheet( "QTextBrowser#biography { background-color: transparent; }" );
137
138    ui->albums->setStyleSheet( "QListView { background-color: transparent; }" );
139    ui->albumFrame->setStyleSheet( "QFrame#albumFrame { background-color: transparent; }"
140                               "QFrame#albumFrame { "
141                               "border-image: url(" RESPATH "images/scrollbar-vertical-handle.png) 3 3 3 3 stretch stretch;"
142                               "border-top: 3px transparent; border-bottom: 3px transparent; border-right: 3px transparent; border-left: 3px transparent; }" );
143
144    ui->relatedArtists->setStyleSheet( "QListView { background-color: transparent; }" );
145    ui->artistFrame->setStyleSheet( "QFrame#artistFrame { background-color: transparent; }"
146                               "QFrame#artistFrame { "
147                               "border-image: url(" RESPATH "images/scrollbar-vertical-handle.png) 3 3 3 3 stretch stretch;"
148                               "border-top: 3px transparent; border-bottom: 3px transparent; border-right: 3px transparent; border-left: 3px transparent; }" );
149
150//    ui->topHits->setStyleSheet( "QTreeView#topHits { background-color: transparent; }" );
151    ui->trackFrame->setStyleSheet( "QFrame#trackFrame { background-color: transparent; }"
152                               "QFrame#trackFrame { "
153                               "border-image: url(" RESPATH "images/scrollbar-vertical-handle.png) 3 3 3 3 stretch stretch;"
154                               "border-top: 3px transparent; border-bottom: 3px transparent; border-right: 3px transparent; border-left: 3px transparent; }" );
155
156    load( artist );
157}
158
159
160ArtistInfoWidget::~ArtistInfoWidget()
161{
162    tDebug() << Q_FUNC_INFO;
163    delete ui;
164}
165
166
167Tomahawk::playlistinterface_ptr
168ArtistInfoWidget::playlistInterface() const
169{
170    return m_plInterface;
171}
172
173
174bool
175ArtistInfoWidget::isBeingPlayed() const
176{
177    if ( ui->albums && ui->albums->isBeingPlayed() )
178        return true;
179
180    if ( ui->relatedArtists && ui->relatedArtists->isBeingPlayed() )
181        return true;
182
183    if ( ui->albums && ui->albums->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
184        return true;
185
186    if ( ui->relatedArtists && ui->relatedArtists->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
187        return true;
188
189    if ( ui->topHits && ui->topHits->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
190        return true;
191
192    return false;
193}
194
195
196bool
197ArtistInfoWidget::jumpToCurrentTrack()
198{
199    if ( ui->albums && ui->albums->jumpToCurrentTrack() )
200        return true;
201
202    if ( ui->relatedArtists && ui->relatedArtists->jumpToCurrentTrack() )
203        return true;
204
205    if ( ui->topHits && ui->topHits->jumpToCurrentTrack() )
206        return true;
207
208    if ( ui->albums && ui->albums->jumpToCurrentTrack() )
209        return true;
210
211    if ( ui->relatedArtists && ui->relatedArtists->jumpToCurrentTrack() )
212        return true;
213
214    return false;
215}
216
217
218void
219ArtistInfoWidget::load( const artist_ptr& artist )
220{
221    if ( !m_artist.isNull() )
222    {
223        disconnect( m_artist.data(), SIGNAL( updated() ), this, SLOT( onArtistImageUpdated() ) );
224        disconnect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), this, SLOT( onSimilarArtistsLoaded() ) );
225        disconnect( m_artist.data(), SIGNAL( biographyLoaded() ), this, SLOT( onBiographyLoaded() ) );
226        disconnect( m_artist.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
227                    this,              SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ) );
228        disconnect( m_artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
229                    this,              SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode ) ) );
230    }
231
232    m_artist = artist;
233    m_title = artist->name();
234
235    connect( m_artist.data(), SIGNAL( biographyLoaded() ), SLOT( onBiographyLoaded() ) );
236    connect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), SLOT( onSimilarArtistsLoaded() ) );
237    connect( m_artist.data(), SIGNAL( updated() ), SLOT( onArtistImageUpdated() ) );
238    connect( m_artist.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
239                                SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ) );
240    connect( m_artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
241                                SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode ) ) );
242
243    ui->artistLabel->setText( artist->name() );
244
245    m_topHitsModel->startLoading();
246
247    if ( !m_artist->albums( Mixed ).isEmpty() )
248        onAlbumsFound( m_artist->albums( Mixed ), Mixed );
249
250    if ( !m_artist->tracks().isEmpty() )
251        onTracksFound( m_artist->tracks(), Mixed );
252
253    if ( !m_artist->similarArtists().isEmpty() )
254        onSimilarArtistsLoaded();
255
256    if ( !m_artist->biography().isEmpty() )
257        onBiographyLoaded();
258
259    onArtistImageUpdated();
260}
261
262
263void
264ArtistInfoWidget::onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, ModelMode mode )
265{
266    Q_UNUSED( mode );
267
268    m_albumsModel->appendAlbums( albums );
269}
270
271
272void
273ArtistInfoWidget::onTracksFound( const QList<Tomahawk::query_ptr>& queries, ModelMode mode )
274{
275    Q_UNUSED( mode );
276
277    m_topHitsModel->finishLoading();
278    m_topHitsModel->appendQueries( queries );
279}
280
281
282void
283ArtistInfoWidget::onSimilarArtistsLoaded()
284{
285    m_relatedModel->appendArtists( m_artist->similarArtists() );
286}
287
288
289void
290ArtistInfoWidget::onBiographyLoaded()
291{
292    m_longDescription = m_artist->biography();
293    emit longDescriptionChanged( m_longDescription );
294
295    ui->biography->setHtml( m_artist->biography() );
296}
297
298
299void
300ArtistInfoWidget::onArtistImageUpdated()
301{
302    if ( m_artist->cover( QSize( 0, 0 ) ).isNull() )
303        return;
304
305    m_pixmap = m_artist->cover( QSize( 0, 0 ) );
306    emit pixmapChanged( m_pixmap );
307
308    ui->cover->setPixmap( TomahawkUtils::createRoundedImage( m_artist->cover( ui->cover->sizeHint() ), QSize( 0, 0 ) ) );
309}
310
311
312void
313ArtistInfoWidget::changeEvent( QEvent* e )
314{
315    QWidget::changeEvent( e );
316    switch ( e->type() )
317    {
318        case QEvent::LanguageChange:
319            ui->retranslateUi( this );
320            break;
321
322        default:
323            break;
324    }
325}