File indexing completed on 2025-01-05 04:25:25

0001 /****************************************************************************************
0002  * Copyright (c) 2011 Emmanuel Wagner <manu.wagner@sfr.fr>                              *
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 "AlbumItem.h"
0018 
0019 #include "playlist/PlaylistModelStack.h"
0020 #include "core/meta/Meta.h"
0021 #include "playlist/PlaylistController.h"
0022 
0023 #include <QGraphicsPixmapItem>
0024 #include <QStyleOptionGraphicsItem>
0025 #include <QPaintEvent>
0026 #include <QPainter>
0027 #include <QPalette>
0028 #include <QImage>
0029 
0030 #include <math.h>
0031 
0032 
0033 AlbumItem::AlbumItem( const QPixmap & pixmap, Meta::AlbumPtr album , QWidget * parent, Qt::WindowFlags f )
0034 
0035     : QLabel( parent, f )
0036 {
0037     m_album = album;
0038     m_pixmap = pixmap;
0039     setPixmap( pixmap );
0040     m_size = pixmap.height();
0041     setMouseTracking( true );
0042     setDisabled( false );
0043     if( album )
0044     {
0045         Meta::ArtistPtr artist = album->albumArtist();
0046         QString label = album->prettyName();
0047         if( artist ) label += " - " + artist->prettyName();
0048         setToolTip( label );
0049     }
0050 }
0051 
0052 AlbumItem::~AlbumItem()
0053 {
0054     // emit the destructor here where actual (non-forward) declaration of Meta::* is known
0055 }
0056 
0057 Meta::AlbumPtr
0058 AlbumItem::getAlbum()
0059 {
0060     return m_album;
0061 }
0062 
0063 void
0064 AlbumItem::mousePressEvent( QMouseEvent  *event )
0065 {
0066     Q_UNUSED( event )
0067 }
0068 
0069 void
0070 AlbumItem::mouseDoubleClickEvent( QMouseEvent *event )
0071 {
0072     Q_UNUSED( event )
0073     The::playlistController()->insertOptioned( m_album->tracks(), Playlist::OnDoubleClickOnSelectedItems );
0074 }
0075 
0076 void
0077 AlbumItem::leaveEvent( QEvent * )
0078 {
0079     setPixmap( m_pixmap );
0080 }
0081 
0082 void
0083 AlbumItem::enterEvent( QEvent *event )
0084 {
0085     Q_UNUSED( event )
0086     QImage image = m_pixmap.toImage();
0087     QPixmap transparent( image.size() );
0088     transparent.fill( Qt::transparent );
0089     QPainter p;
0090     p.begin( &transparent );
0091     p.setCompositionMode( QPainter::CompositionMode_Source );
0092     p.drawPixmap( 0, 0, QPixmap::fromImage( image ) );
0093     p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
0094     p.fillRect( transparent.rect(), QColor( 0, 0, 0, 150 ) );
0095     p.end();
0096     setPixmap( transparent );
0097 }