1 /****************************************************************************************
2  * Copyright (c) 2011 Emmanuel Wagner <manu.wagner@sfr.fr>                              *
3  *                                                                                      *
4  * This program is free software; you can redistribute it and/or modify it under        *
5  * the terms of the GNU General Public License as published by the Free Software        *
6  * Foundation; either version 2 of the License, or (at your option) any later           *
7  * version.                                                                             *
8  *                                                                                      *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12  *                                                                                      *
13  * You should have received a copy of the GNU General Public License along with         *
14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15  ****************************************************************************************/
16 
17 #include "AlbumItem.h"
18 
19 #include "playlist/PlaylistModelStack.h"
20 #include "core/meta/Meta.h"
21 #include "playlist/PlaylistController.h"
22 
23 #include <QGraphicsPixmapItem>
24 #include <QStyleOptionGraphicsItem>
25 #include <QPaintEvent>
26 #include <QPainter>
27 #include <QPalette>
28 #include <QImage>
29 
30 #include <math.h>
31 
32 
AlbumItem(const QPixmap & pixmap,Meta::AlbumPtr album,QWidget * parent,Qt::WindowFlags f)33 AlbumItem::AlbumItem( const QPixmap & pixmap, Meta::AlbumPtr album , QWidget * parent, Qt::WindowFlags f )
34 
35     : QLabel( parent, f )
36 {
37     m_album = album;
38     m_pixmap = pixmap;
39     setPixmap( pixmap );
40     m_size = pixmap.height();
41     setMouseTracking( true );
42     setDisabled( false );
43     if( album )
44     {
45         Meta::ArtistPtr artist = album->albumArtist();
46         QString label = album->prettyName();
47         if( artist ) label += " - " + artist->prettyName();
48         setToolTip( label );
49     }
50 }
51 
~AlbumItem()52 AlbumItem::~AlbumItem()
53 {
54     // emit the destructor here where actual (non-forward) declaration of Meta::* is known
55 }
56 
57 Meta::AlbumPtr
getAlbum()58 AlbumItem::getAlbum()
59 {
60     return m_album;
61 }
62 
63 void
mousePressEvent(QMouseEvent * event)64 AlbumItem::mousePressEvent( QMouseEvent  *event )
65 {
66     Q_UNUSED( event )
67 }
68 
69 void
mouseDoubleClickEvent(QMouseEvent * event)70 AlbumItem::mouseDoubleClickEvent( QMouseEvent *event )
71 {
72     Q_UNUSED( event )
73     The::playlistController()->insertOptioned( m_album->tracks(), Playlist::OnDoubleClickOnSelectedItems );
74 }
75 
76 void
leaveEvent(QEvent *)77 AlbumItem::leaveEvent( QEvent * )
78 {
79     setPixmap( m_pixmap );
80 }
81 
82 void
enterEvent(QEvent * event)83 AlbumItem::enterEvent( QEvent *event )
84 {
85     Q_UNUSED( event )
86     QImage image = m_pixmap.toImage();
87     QPixmap transparent( image.size() );
88     transparent.fill( Qt::transparent );
89     QPainter p;
90     p.begin( &transparent );
91     p.setCompositionMode( QPainter::CompositionMode_Source );
92     p.drawPixmap( 0, 0, QPixmap::fromImage( image ) );
93     p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
94     p.fillRect( transparent.rect(), QColor( 0, 0, 0, 150 ) );
95     p.end();
96     setPixmap( transparent );
97 }
98