|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Album Cover Widget for Music Player Media Wall. |
|
15 * |
|
16 */ |
|
17 #include <QPainter> |
|
18 #include <QGraphicsSceneMouseEvent> |
|
19 |
|
20 |
|
21 #include "mpalbumcoverwidget.h" |
|
22 #include "mpreflectioneffect.h" |
|
23 |
|
24 /*! |
|
25 \class MpAlbumCoverWidget |
|
26 \brief Album Cover Widget. |
|
27 |
|
28 This widget provides upscaled rendering of images and SVG rendering. |
|
29 Also there is a reflection effect. |
|
30 */ |
|
31 |
|
32 /*! |
|
33 \fn void clicked( ) |
|
34 |
|
35 This signal is emitted when the item is clicked. |
|
36 */ |
|
37 |
|
38 /*! |
|
39 Constructs the album cover widget |
|
40 */ |
|
41 MpAlbumCoverWidget::MpAlbumCoverWidget( QGraphicsItem *parent ) : |
|
42 HbWidget( parent ) |
|
43 { |
|
44 setFlag( QGraphicsItem::ItemHasNoContents, false ); |
|
45 grabGesture(Qt::TapGesture); |
|
46 |
|
47 MpReflectionEffect *effect = new MpReflectionEffect(this); |
|
48 setGraphicsEffect(effect); |
|
49 } |
|
50 |
|
51 /*! |
|
52 Destructs the album cover widget. |
|
53 */ |
|
54 MpAlbumCoverWidget::~MpAlbumCoverWidget() |
|
55 { |
|
56 } |
|
57 |
|
58 /*! |
|
59 Sets the \a icon as current album cover. |
|
60 */ |
|
61 void MpAlbumCoverWidget::setIcon( const HbIcon &icon ) |
|
62 { |
|
63 if (icon != mIcon) { |
|
64 mIcon = icon; |
|
65 mPixmap = QPixmap(); |
|
66 } |
|
67 } |
|
68 |
|
69 /*! |
|
70 Sets the \a icon as default cover, to be used in case the album cover is null icon. |
|
71 */ |
|
72 void MpAlbumCoverWidget::setDefaultIcon( const HbIcon &icon ) |
|
73 { |
|
74 mDefaultIcon = icon; |
|
75 } |
|
76 |
|
77 /*! |
|
78 \reimp |
|
79 */ |
|
80 void MpAlbumCoverWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) |
|
81 { |
|
82 Q_UNUSED( widget ) |
|
83 Q_UNUSED( option ) |
|
84 if ( !mIcon.isNull() ) { |
|
85 if ( mPixmap.isNull() ) { |
|
86 mPixmap = mIcon.qicon().pixmap( size().toSize() ); |
|
87 } |
|
88 //We paint directly to stretch up/down if necesary. |
|
89 painter->drawPixmap( rect(), mPixmap, QRectF() ); |
|
90 } |
|
91 else { |
|
92 //We use HbIcon paint to render vector graphics. |
|
93 mDefaultIcon.setSize(size()); |
|
94 mDefaultIcon.paint(painter,rect()); |
|
95 } |
|
96 } |
|
97 |
|
98 /*! |
|
99 \reimp |
|
100 */ |
|
101 void MpAlbumCoverWidget::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
|
102 { |
|
103 if ( event->button() == Qt::LeftButton ) { |
|
104 event->accept(); |
|
105 } |
|
106 else { |
|
107 event->ignore(); |
|
108 } |
|
109 } |
|
110 |
|
111 /*! |
|
112 \reimp |
|
113 */ |
|
114 void MpAlbumCoverWidget::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
|
115 { |
|
116 if ( event->button() == Qt::LeftButton ) { |
|
117 emit clicked(); |
|
118 event->accept(); |
|
119 } |
|
120 else { |
|
121 event->ignore(); |
|
122 } |
|
123 } |
|
124 |
|
125 /*! |
|
126 \reimp |
|
127 */ |
|
128 void MpAlbumCoverWidget::gestureEvent(QGestureEvent *event) |
|
129 { |
|
130 QGesture* gesture = event->gesture(Qt::TapGesture); |
|
131 if (gesture) { |
|
132 event->accept(Qt::TapGesture); |
|
133 } |
|
134 } |
|
135 |
|
136 //EOF |