mpviewplugins/mpmediawallviewplugin/src/mpalbumcoverwidget.cpp
changeset 29 8192e5b5c935
child 37 eb79a7c355bf
equal deleted inserted replaced
25:3ec52facab4d 29:8192e5b5c935
       
     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 #include <hbinstantfeedback.h>
       
    21 
       
    22 #include "mpalbumcoverwidget.h"
       
    23 
       
    24 
       
    25 /*!
       
    26     Constructs the album cover widget
       
    27  */
       
    28 MpAlbumCoverWidget::MpAlbumCoverWidget( QGraphicsItem *parent ) : 
       
    29     QGraphicsWidget( parent )
       
    30 {
       
    31     grabGesture(Qt::TapGesture);
       
    32     grabGesture(Qt::SwipeGesture);
       
    33 }
       
    34 
       
    35 /*!
       
    36     Sets the \a icon as current album cover.
       
    37  */
       
    38 void MpAlbumCoverWidget::setIcon( const HbIcon &icon )
       
    39 {
       
    40     if (icon != mIcon) {
       
    41         mIcon = icon;
       
    42         mPixmap = QPixmap();
       
    43     }
       
    44 }
       
    45 
       
    46 /*!
       
    47     Sets the \a icon as default cover, to be used in case the album cover is null icon.
       
    48  */
       
    49 void MpAlbumCoverWidget::setDefaultIcon( const HbIcon &icon )
       
    50 {
       
    51     mDefaultIcon = icon;
       
    52 }
       
    53 
       
    54 /*!
       
    55     \reimp
       
    56  */
       
    57 void MpAlbumCoverWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
       
    58 {
       
    59     Q_UNUSED( widget )
       
    60     Q_UNUSED( option )
       
    61     //TODO: add a function to set default album art ,and use default when qicon is NULL,
       
    62     if ( !mIcon.isNull() ) {
       
    63         if ( mPixmap.isNull() ) {
       
    64             mPixmap = mIcon.qicon().pixmap( size().toSize() );
       
    65         }
       
    66         //We paint directly to stretch up/down if necesary.
       
    67         painter->drawPixmap( rect(), mPixmap, QRectF() );
       
    68     }
       
    69     else {
       
    70         //We use HbIcon paint to render vector graphics.
       
    71         mDefaultIcon.setSize(size());
       
    72         mDefaultIcon.paint(painter,rect());
       
    73     }
       
    74 }
       
    75 
       
    76 /*!
       
    77     \reimp
       
    78  */
       
    79 void MpAlbumCoverWidget::mousePressEvent( QGraphicsSceneMouseEvent *event )
       
    80 {
       
    81     if ( event->button() == Qt::LeftButton ) {
       
    82         HbInstantFeedback::play( HbFeedback::Basic );
       
    83         event->accept();
       
    84     }
       
    85     else {
       
    86         event->ignore();
       
    87     }
       
    88 }
       
    89 
       
    90 /*!
       
    91     \reimp
       
    92  */
       
    93 void MpAlbumCoverWidget::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
       
    94 {
       
    95     if ( event->button() == Qt::LeftButton ) {
       
    96         emit clicked();
       
    97         event->accept();
       
    98     }
       
    99     else {
       
   100         event->ignore();
       
   101     }
       
   102 }
       
   103 
       
   104 //EOF