File indexing completed on 2024-05-05 04:49:24
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Rick W. Chen <stuffcorpse@archlinux.us> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "AlbumBreadcrumbWidget.h" 0018 0019 #include "core/meta/Meta.h" 0020 #include "widgets/BreadcrumbItemButton.h" 0021 0022 #include <QBoxLayout> 0023 #include <QIcon> 0024 0025 #include <KLocalizedString> 0026 0027 AlbumBreadcrumbWidget::AlbumBreadcrumbWidget( const Meta::AlbumPtr &album, QWidget *parent ) 0028 : BoxWidget( false, parent ) 0029 , m_album( album ) 0030 { 0031 const QIcon artistIcon = QIcon::fromTheme( "filename-artist-amarok" ); 0032 const QIcon albumIcon = QIcon::fromTheme( "filename-album-amarok" ); 0033 new BreadcrumbItemMenuButton( this ); 0034 m_artistButton = new BreadcrumbItemButton( artistIcon, QString(), this ); 0035 new BreadcrumbItemMenuButton( this ); 0036 m_albumButton = new BreadcrumbItemButton( albumIcon, QString(), this ); 0037 0038 QWidget *spacer = new QWidget( this ); 0039 0040 auto l = static_cast<QBoxLayout*>( layout() ); 0041 l->setStretchFactor( m_artistButton, 1 ); 0042 l->setStretchFactor( m_albumButton, 1 ); 0043 l->setStretchFactor( spacer, 1 ); 0044 0045 connect( m_artistButton, &BreadcrumbItemButton::clicked, this, &AlbumBreadcrumbWidget::slotArtistClicked ); 0046 connect( m_albumButton, &BreadcrumbItemButton::clicked, this, &AlbumBreadcrumbWidget::slotAlbumClicked ); 0047 0048 updateBreadcrumbs(); 0049 } 0050 0051 AlbumBreadcrumbWidget::~AlbumBreadcrumbWidget() 0052 { 0053 } 0054 0055 void AlbumBreadcrumbWidget::setAlbum(const Meta::AlbumPtr &album ) 0056 { 0057 m_album = album; 0058 updateBreadcrumbs(); 0059 } 0060 0061 void AlbumBreadcrumbWidget::updateBreadcrumbs() 0062 { 0063 const QString &album = m_album->prettyName(); 0064 const QString &artist = m_album->hasAlbumArtist() ? m_album->albumArtist()->prettyName() 0065 : i18n( "Various Artists" ); 0066 m_artistButton->setText( artist ); 0067 m_albumButton->setText( album ); 0068 } 0069 0070 void AlbumBreadcrumbWidget::slotArtistClicked() 0071 { 0072 if( m_album->hasAlbumArtist() ) 0073 Q_EMIT artistClicked( m_album->albumArtist()->name() ); 0074 } 0075 0076 void AlbumBreadcrumbWidget::slotAlbumClicked() 0077 { 0078 Q_EMIT albumClicked( m_album->name() ); 0079 } 0080