|
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. |
|
15 * |
|
16 */ |
|
17 #include <QPainter> |
|
18 #include <QGraphicsSceneMouseEvent> |
|
19 |
|
20 |
|
21 #include "mpalbumcoverwidget.h" |
|
22 |
|
23 /*! |
|
24 \class MpAlbumCoverWidget |
|
25 \brief Album Cover Widget. |
|
26 This widget provides up scaled rendering of images and SVG rendering. |
|
27 |
|
28 This widget can be used instead of HbLabel or HbIconItem when up scaling |
|
29 and downscaling during painting is desired, there is no need to preprocess |
|
30 images to the target size, this is taken care of during paint in a more |
|
31 efficient manor; this widget renders images flush with the geometry. |
|
32 Default icon placeholder is also supported. |
|
33 |
|
34 */ |
|
35 |
|
36 /*! |
|
37 \fn void clicked( ) |
|
38 |
|
39 This signal is emitted when the item is clicked. |
|
40 */ |
|
41 |
|
42 /*! |
|
43 Constructs the album cover widget |
|
44 */ |
|
45 MpAlbumCoverWidget::MpAlbumCoverWidget( QGraphicsItem *parent ) : |
|
46 HbWidget( parent ) |
|
47 { |
|
48 setFlag( QGraphicsItem::ItemHasNoContents, false ); |
|
49 grabGesture(Qt::TapGesture); |
|
50 } |
|
51 |
|
52 /*! |
|
53 Destructs the album cover widget. |
|
54 */ |
|
55 MpAlbumCoverWidget::~MpAlbumCoverWidget() |
|
56 { |
|
57 } |
|
58 |
|
59 /*! |
|
60 Sets the \a icon as current album cover. |
|
61 */ |
|
62 void MpAlbumCoverWidget::setIcon( const HbIcon &icon ) |
|
63 { |
|
64 if (icon != mIcon) { |
|
65 mIcon = icon; |
|
66 mPixmap = QPixmap(); |
|
67 update(); |
|
68 } |
|
69 } |
|
70 |
|
71 /*! |
|
72 Sets the \a icon as default cover, to be used in case the album cover is null icon. |
|
73 */ |
|
74 void MpAlbumCoverWidget::setDefaultIcon( const HbIcon &icon ) |
|
75 { |
|
76 mDefaultIcon = icon; |
|
77 update(); |
|
78 } |
|
79 |
|
80 /*! |
|
81 \reimp |
|
82 */ |
|
83 void MpAlbumCoverWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) |
|
84 { |
|
85 Q_UNUSED( widget ) |
|
86 Q_UNUSED( option ) |
|
87 if ( isEnabled() ){ |
|
88 if ( !mIcon.isNull() ) { |
|
89 if ( mPixmap.isNull() ) { |
|
90 mPixmap = mIcon.qicon().pixmap( size().toSize() ); |
|
91 } |
|
92 //We paint directly to stretch up/down if necesary. |
|
93 painter->drawPixmap( rect(), mPixmap, QRectF() ); |
|
94 } |
|
95 else { |
|
96 //We use HbIcon paint to render vector graphics. |
|
97 mDefaultIcon.setSize(size()); |
|
98 mDefaultIcon.paint(painter,rect()); |
|
99 } |
|
100 } |
|
101 } |
|
102 |
|
103 /*! |
|
104 \reimp |
|
105 */ |
|
106 void MpAlbumCoverWidget::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
|
107 { |
|
108 if ( event->button() == Qt::LeftButton ) { |
|
109 event->accept(); |
|
110 } |
|
111 else { |
|
112 event->ignore(); |
|
113 } |
|
114 } |
|
115 |
|
116 /*! |
|
117 \reimp |
|
118 */ |
|
119 void MpAlbumCoverWidget::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
|
120 { |
|
121 if ( event->button() == Qt::LeftButton ) { |
|
122 emit clicked(); |
|
123 event->accept(); |
|
124 } |
|
125 else { |
|
126 event->ignore(); |
|
127 } |
|
128 } |
|
129 |
|
130 /*! |
|
131 \reimp |
|
132 */ |
|
133 void MpAlbumCoverWidget::gestureEvent(QGestureEvent *event) |
|
134 { |
|
135 QGesture* gesture = event->gesture(Qt::TapGesture); |
|
136 if (gesture) { |
|
137 event->accept(Qt::TapGesture); |
|
138 } |
|
139 } |
|
140 |
|
141 //EOF |