PageRenderTime 185ms CodeModel.GetById 70ms app.highlight 72ms RepoModel.GetById 39ms app.codeStats 0ms

/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 269 lines | 179 code | 66 blank | 24 comment | 14 complexity | 51e98e4a5b87464cfd6644360d070bc4 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-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  6 *
  7 *   Tomahawk is free software: you can redistribute it and/or modify
  8 *   it under the terms of the GNU General Public License as published by
  9 *   the Free Software Foundation, either version 3 of the License, or
 10 *   (at your option) any later version.
 11 *
 12 *   Tomahawk is distributed in the hope that it will be useful,
 13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *   GNU General Public License for more details.
 16 *
 17 *   You should have received a copy of the GNU General Public License
 18 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21#include "AlbumInfoWidget.h"
 22#include "ui_AlbumInfoWidget.h"
 23#include "AlbumInfoWidget_p.h"
 24
 25#include "audio/AudioEngine.h"
 26#include "ViewManager.h"
 27#include "database/Database.h"
 28#include "playlist/TreeModel.h"
 29#include "playlist/PlayableModel.h"
 30#include "playlist/GridItemDelegate.h"
 31#include "Source.h"
 32
 33#include "database/DatabaseCommand_AllTracks.h"
 34#include "database/DatabaseCommand_AllAlbums.h"
 35
 36#include "utils/TomahawkUtilsGui.h"
 37#include "utils/Logger.h"
 38
 39#include <QScrollArea>
 40#include <QScrollBar>
 41
 42using namespace Tomahawk;
 43
 44
 45AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* parent )
 46    : QWidget( parent )
 47    , ui( new Ui::AlbumInfoWidget )
 48{
 49    QWidget* widget = new QWidget;
 50    ui->setupUi( widget );
 51
 52    QPalette pal = palette();
 53    pal.setColor( QPalette::Window, QColor( "#454e59" ) );
 54
 55    widget->setPalette( pal );
 56    widget->setAutoFillBackground( true );
 57
 58    m_albumsModel = new PlayableModel( ui->albums );
 59    ui->albums->setPlayableModel( m_albumsModel );
 60    ui->albums->setEmptyTip( tr( "Sorry, we could not find any other albums for this artist!" ) );
 61
 62    m_tracksModel = new TreeModel( ui->tracks );
 63    m_tracksModel->setMode( Mixed );
 64    ui->tracks->setTreeModel( m_tracksModel );
 65    ui->tracks->setRootIsDecorated( false );
 66    ui->tracks->setEmptyTip( tr( "Sorry, we could not find any tracks for this album!" ) );
 67    ui->tracks->proxyModel()->setStyle( PlayableProxyModel::Collection );
 68
 69    ui->albums->setAutoFitItems( false );
 70    ui->albums->setWrapping( false );
 71    ui->albums->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 72    ui->albums->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
 73    ui->albums->delegate()->setItemSize( QSize( 170, 170 ) );
 74    ui->albums->proxyModel()->setHideDupeItems( true );
 75
 76    ui->tracks->setFrameShape( QFrame::StyledPanel );
 77    ui->tracks->setAttribute( Qt::WA_MacShowFocusRect, 0 );
 78
 79    m_pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, QSize( 48, 48 ) );
 80    ui->cover->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::ScaledCover, QSize( ui->cover->sizeHint() ) ) );
 81
 82    ui->biography->setFrameShape( QFrame::NoFrame );
 83    ui->biography->setAttribute( Qt::WA_MacShowFocusRect, 0 );
 84    TomahawkUtils::styleScrollBar( ui->biography->verticalScrollBar() );
 85
 86    QFont f = font();
 87    f.setBold( true );
 88    f.setPointSize( TomahawkUtils::defaultFontSize() + 7 );
 89    ui->albumLabel->setFont( f );
 90//    ui->similarTracksLabel->setFont( f );
 91
 92    f.setPointSize( TomahawkUtils::defaultFontSize() + 4 );
 93    ui->artistLabel->setFont( f );
 94
 95    QPalette p = ui->biography->palette();
 96    p.setColor( QPalette::Foreground, Qt::white );
 97    p.setColor( QPalette::Text, Qt::white );
 98
 99    ui->albumLabel->setPalette( p );
100    ui->artistLabel->setPalette( p );
101    ui->biography->setPalette( p );
102    ui->label->setPalette( p );
103    ui->label_2->setPalette( p );
104
105    ui->artistLabel->setType( QueryLabel::Artist );
106
107    QScrollArea* area = new QScrollArea();
108    area->setWidgetResizable( true );
109    area->setWidget( widget );
110
111    area->setStyleSheet( "QScrollArea { background-color: #454e59; }" );
112    area->setFrameShape( QFrame::NoFrame );
113    area->setAttribute( Qt::WA_MacShowFocusRect, 0 );
114
115    QVBoxLayout* layout = new QVBoxLayout();
116    layout->addWidget( area );
117    setLayout( layout );
118    TomahawkUtils::unmarginLayout( layout );
119
120    TomahawkUtils::styleScrollBar( ui->tracks->horizontalScrollBar() );
121    TomahawkUtils::styleScrollBar( ui->albums->horizontalScrollBar() );
122
123    ui->biography->setStyleSheet( "QTextBrowser#biography { background-color: transparent; }" );
124
125    ui->albums->setStyleSheet( "QListView { background-color: transparent; }" );
126    ui->albumFrame->setStyleSheet( "QFrame#albumFrame { background-color: transparent; }"
127                               "QFrame#albumFrame { "
128                               "border-image: url(" RESPATH "images/scrollbar-vertical-handle.png) 3 3 3 3 stretch stretch;"
129                               "border-top: 3px transparent; border-bottom: 3px transparent; border-right: 3px transparent; border-left: 3px transparent; }" );
130
131//    ui->topHits->setStyleSheet( "QTreeView#topHits { background-color: transparent; }" );
132    ui->trackFrame->setStyleSheet( "QFrame#trackFrame { background-color: transparent; }"
133                               "QFrame#trackFrame { "
134                               "border-image: url(" RESPATH "images/scrollbar-vertical-handle.png) 3 3 3 3 stretch stretch;"
135                               "border-top: 3px transparent; border-bottom: 3px transparent; border-right: 3px transparent; border-left: 3px transparent; }" );
136
137    m_playlistInterface = playlistinterface_ptr( new MetaAlbumInfoInterface( this ) );
138    load( album );
139
140    connect( ui->artistLabel, SIGNAL( clickedArtist() ), SLOT( onArtistClicked() ) );
141}
142
143
144AlbumInfoWidget::~AlbumInfoWidget()
145{
146    tDebug() << Q_FUNC_INFO;
147    delete ui;
148}
149
150
151Tomahawk::playlistinterface_ptr
152AlbumInfoWidget::playlistInterface() const
153{
154    return m_playlistInterface;
155}
156
157
158bool
159AlbumInfoWidget::isBeingPlayed() const
160{
161    //tDebug() << Q_FUNC_INFO << "audioengine playlistInterface = " << AudioEngine::instance()->currentTrackPlaylist()->id();
162    //tDebug() << Q_FUNC_INFO << "albumsView playlistInterface = " << ui->albumsView->playlistInterface()->id();
163    //tDebug() << Q_FUNC_INFO << "tracksView playlistInterface = " << ui->tracksView->playlistInterface()->id();
164
165    if ( ui->albums && ui->albums->isBeingPlayed() )
166        return true;
167
168    if ( ui->albums && ui->albums->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
169        return true;
170
171    if ( ui->tracks && ui->tracks->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
172        return true;
173
174    return false;
175}
176
177
178bool
179AlbumInfoWidget::jumpToCurrentTrack()
180{
181    return  ui->albums && ui->albums->jumpToCurrentTrack();
182}
183
184
185void
186AlbumInfoWidget::load( const album_ptr& album )
187{
188    if ( !m_album.isNull() )
189    {
190        disconnect( m_album.data(), SIGNAL( updated() ), this, SLOT( onAlbumImageUpdated() ) );
191    }
192
193    m_album = album;
194    m_title = album->name();
195
196    connect( m_album.data(), SIGNAL( updated() ), SLOT( onArtistImageUpdated() ) );
197
198    ui->artistLabel->setArtist( album->artist() );
199    ui->albumLabel->setText( album->name() );
200    ui->label_2->setText( tr( "Other Albums by %1" ).arg( album->artist()->name() ) );
201
202    m_tracksModel->startLoading();
203    m_tracksModel->addTracks( album, QModelIndex(), true );
204    loadAlbums( true );
205
206    onAlbumImageUpdated();
207}
208
209
210void
211AlbumInfoWidget::loadAlbums( bool autoRefetch )
212{
213    Q_UNUSED( autoRefetch );
214
215    m_albumsModel->clear();
216
217    connect( m_album->artist().data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
218                                         SLOT( gotAlbums( QList<Tomahawk::album_ptr> ) ) );
219
220    if ( !m_album->artist()->albums( Mixed ).isEmpty() )
221        gotAlbums( m_album->artist()->albums( Mixed ) );
222}
223
224
225void
226AlbumInfoWidget::onAlbumImageUpdated()
227{
228    if ( m_album->cover( QSize( 0, 0 ) ).isNull() )
229        return;
230
231    m_pixmap = m_album->cover( QSize( 0, 0 ) );
232    emit pixmapChanged( m_pixmap );
233
234    ui->cover->setPixmap( TomahawkUtils::createRoundedImage( m_album->cover( ui->cover->sizeHint() ), QSize( 0, 0 ) ) );
235}
236
237
238void
239AlbumInfoWidget::gotAlbums( const QList<Tomahawk::album_ptr>& albums )
240{
241    QList<Tomahawk::album_ptr> al = albums;
242    if ( al.contains( m_album ) )
243        al.removeAll( m_album );
244
245    m_albumsModel->appendAlbums( al );
246}
247
248
249void
250AlbumInfoWidget::onArtistClicked()
251{
252    ViewManager::instance()->show( m_album->artist() );
253}
254
255
256void
257AlbumInfoWidget::changeEvent( QEvent* e )
258{
259    QWidget::changeEvent( e );
260    switch ( e->type() )
261    {
262        case QEvent::LanguageChange:
263            ui->retranslateUi( this );
264            break;
265
266        default:
267            break;
268    }
269}