PageRenderTime 31ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  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. #include "AlbumInfoWidget.h"
  21. #include "ui_AlbumInfoWidget.h"
  22. #include "AlbumInfoWidget_p.h"
  23. #include "audio/AudioEngine.h"
  24. #include "ViewManager.h"
  25. #include "database/Database.h"
  26. #include "playlist/TreeModel.h"
  27. #include "playlist/PlayableModel.h"
  28. #include "playlist/GridItemDelegate.h"
  29. #include "Source.h"
  30. #include "database/DatabaseCommand_AllTracks.h"
  31. #include "database/DatabaseCommand_AllAlbums.h"
  32. #include "utils/TomahawkUtilsGui.h"
  33. #include "utils/Logger.h"
  34. #include <QScrollArea>
  35. #include <QScrollBar>
  36. using namespace Tomahawk;
  37. AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* parent )
  38. : QWidget( parent )
  39. , ui( new Ui::AlbumInfoWidget )
  40. {
  41. QWidget* widget = new QWidget;
  42. ui->setupUi( widget );
  43. QPalette pal = palette();
  44. pal.setColor( QPalette::Window, QColor( "#454e59" ) );
  45. widget->setPalette( pal );
  46. widget->setAutoFillBackground( true );
  47. m_albumsModel = new PlayableModel( ui->albums );
  48. ui->albums->setPlayableModel( m_albumsModel );
  49. ui->albums->setEmptyTip( tr( "Sorry, we could not find any other albums for this artist!" ) );
  50. m_tracksModel = new TreeModel( ui->tracks );
  51. m_tracksModel->setMode( Mixed );
  52. ui->tracks->setTreeModel( m_tracksModel );
  53. ui->tracks->setRootIsDecorated( false );
  54. ui->tracks->setEmptyTip( tr( "Sorry, we could not find any tracks for this album!" ) );
  55. ui->tracks->proxyModel()->setStyle( PlayableProxyModel::Collection );
  56. ui->albums->setAutoFitItems( false );
  57. ui->albums->setWrapping( false );
  58. ui->albums->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  59. ui->albums->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
  60. ui->albums->delegate()->setItemSize( QSize( 170, 170 ) );
  61. ui->albums->proxyModel()->setHideDupeItems( true );
  62. ui->tracks->setFrameShape( QFrame::StyledPanel );
  63. ui->tracks->setAttribute( Qt::WA_MacShowFocusRect, 0 );
  64. m_pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, QSize( 48, 48 ) );
  65. ui->cover->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::ScaledCover, QSize( ui->cover->sizeHint() ) ) );
  66. ui->biography->setFrameShape( QFrame::NoFrame );
  67. ui->biography->setAttribute( Qt::WA_MacShowFocusRect, 0 );
  68. TomahawkUtils::styleScrollBar( ui->biography->verticalScrollBar() );
  69. QFont f = font();
  70. f.setBold( true );
  71. f.setPointSize( TomahawkUtils::defaultFontSize() + 7 );
  72. ui->albumLabel->setFont( f );
  73. // ui->similarTracksLabel->setFont( f );
  74. f.setPointSize( TomahawkUtils::defaultFontSize() + 4 );
  75. ui->artistLabel->setFont( f );
  76. QPalette p = ui->biography->palette();
  77. p.setColor( QPalette::Foreground, Qt::white );
  78. p.setColor( QPalette::Text, Qt::white );
  79. ui->albumLabel->setPalette( p );
  80. ui->artistLabel->setPalette( p );
  81. ui->biography->setPalette( p );
  82. ui->label->setPalette( p );
  83. ui->label_2->setPalette( p );
  84. ui->artistLabel->setType( QueryLabel::Artist );
  85. QScrollArea* area = new QScrollArea();
  86. area->setWidgetResizable( true );
  87. area->setWidget( widget );
  88. area->setStyleSheet( "QScrollArea { background-color: #454e59; }" );
  89. area->setFrameShape( QFrame::NoFrame );
  90. area->setAttribute( Qt::WA_MacShowFocusRect, 0 );
  91. QVBoxLayout* layout = new QVBoxLayout();
  92. layout->addWidget( area );
  93. setLayout( layout );
  94. TomahawkUtils::unmarginLayout( layout );
  95. TomahawkUtils::styleScrollBar( ui->tracks->horizontalScrollBar() );
  96. TomahawkUtils::styleScrollBar( ui->albums->horizontalScrollBar() );
  97. ui->biography->setStyleSheet( "QTextBrowser#biography { background-color: transparent; }" );
  98. ui->albums->setStyleSheet( "QListView { background-color: transparent; }" );
  99. ui->albumFrame->setStyleSheet( "QFrame#albumFrame { background-color: transparent; }"
  100. "QFrame#albumFrame { "
  101. "border-image: url(" RESPATH "images/scrollbar-vertical-handle.png) 3 3 3 3 stretch stretch;"
  102. "border-top: 3px transparent; border-bottom: 3px transparent; border-right: 3px transparent; border-left: 3px transparent; }" );
  103. // ui->topHits->setStyleSheet( "QTreeView#topHits { background-color: transparent; }" );
  104. ui->trackFrame->setStyleSheet( "QFrame#trackFrame { background-color: transparent; }"
  105. "QFrame#trackFrame { "
  106. "border-image: url(" RESPATH "images/scrollbar-vertical-handle.png) 3 3 3 3 stretch stretch;"
  107. "border-top: 3px transparent; border-bottom: 3px transparent; border-right: 3px transparent; border-left: 3px transparent; }" );
  108. m_playlistInterface = playlistinterface_ptr( new MetaAlbumInfoInterface( this ) );
  109. load( album );
  110. connect( ui->artistLabel, SIGNAL( clickedArtist() ), SLOT( onArtistClicked() ) );
  111. }
  112. AlbumInfoWidget::~AlbumInfoWidget()
  113. {
  114. tDebug() << Q_FUNC_INFO;
  115. delete ui;
  116. }
  117. Tomahawk::playlistinterface_ptr
  118. AlbumInfoWidget::playlistInterface() const
  119. {
  120. return m_playlistInterface;
  121. }
  122. bool
  123. AlbumInfoWidget::isBeingPlayed() const
  124. {
  125. //tDebug() << Q_FUNC_INFO << "audioengine playlistInterface = " << AudioEngine::instance()->currentTrackPlaylist()->id();
  126. //tDebug() << Q_FUNC_INFO << "albumsView playlistInterface = " << ui->albumsView->playlistInterface()->id();
  127. //tDebug() << Q_FUNC_INFO << "tracksView playlistInterface = " << ui->tracksView->playlistInterface()->id();
  128. if ( ui->albums && ui->albums->isBeingPlayed() )
  129. return true;
  130. if ( ui->albums && ui->albums->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
  131. return true;
  132. if ( ui->tracks && ui->tracks->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
  133. return true;
  134. return false;
  135. }
  136. bool
  137. AlbumInfoWidget::jumpToCurrentTrack()
  138. {
  139. return ui->albums && ui->albums->jumpToCurrentTrack();
  140. }
  141. void
  142. AlbumInfoWidget::load( const album_ptr& album )
  143. {
  144. if ( !m_album.isNull() )
  145. {
  146. disconnect( m_album.data(), SIGNAL( updated() ), this, SLOT( onAlbumImageUpdated() ) );
  147. }
  148. m_album = album;
  149. m_title = album->name();
  150. connect( m_album.data(), SIGNAL( updated() ), SLOT( onArtistImageUpdated() ) );
  151. ui->artistLabel->setArtist( album->artist() );
  152. ui->albumLabel->setText( album->name() );
  153. ui->label_2->setText( tr( "Other Albums by %1" ).arg( album->artist()->name() ) );
  154. m_tracksModel->startLoading();
  155. m_tracksModel->addTracks( album, QModelIndex(), true );
  156. loadAlbums( true );
  157. onAlbumImageUpdated();
  158. }
  159. void
  160. AlbumInfoWidget::loadAlbums( bool autoRefetch )
  161. {
  162. Q_UNUSED( autoRefetch );
  163. m_albumsModel->clear();
  164. connect( m_album->artist().data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
  165. SLOT( gotAlbums( QList<Tomahawk::album_ptr> ) ) );
  166. if ( !m_album->artist()->albums( Mixed ).isEmpty() )
  167. gotAlbums( m_album->artist()->albums( Mixed ) );
  168. }
  169. void
  170. AlbumInfoWidget::onAlbumImageUpdated()
  171. {
  172. if ( m_album->cover( QSize( 0, 0 ) ).isNull() )
  173. return;
  174. m_pixmap = m_album->cover( QSize( 0, 0 ) );
  175. emit pixmapChanged( m_pixmap );
  176. ui->cover->setPixmap( TomahawkUtils::createRoundedImage( m_album->cover( ui->cover->sizeHint() ), QSize( 0, 0 ) ) );
  177. }
  178. void
  179. AlbumInfoWidget::gotAlbums( const QList<Tomahawk::album_ptr>& albums )
  180. {
  181. QList<Tomahawk::album_ptr> al = albums;
  182. if ( al.contains( m_album ) )
  183. al.removeAll( m_album );
  184. m_albumsModel->appendAlbums( al );
  185. }
  186. void
  187. AlbumInfoWidget::onArtistClicked()
  188. {
  189. ViewManager::instance()->show( m_album->artist() );
  190. }
  191. void
  192. AlbumInfoWidget::changeEvent( QEvent* e )
  193. {
  194. QWidget::changeEvent( e );
  195. switch ( e->type() )
  196. {
  197. case QEvent::LanguageChange:
  198. ui->retranslateUi( this );
  199. break;
  200. default:
  201. break;
  202. }
  203. }