mpviewplugins/mpcollectionviewplugin/src/mpsnapshotwidget.cpp
changeset 19 4e84c994a771
child 29 8192e5b5c935
equal deleted inserted replaced
5:2a40e88564c8 19:4e84c994a771
       
     1 /*
       
     2 * Copyright (c) 2009 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: Music Player now playing widget.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QPainter>
       
    19 #include <QImage>
       
    20 #include <qgraphicsview.h>
       
    21 
       
    22 #include "mpsnapshotwidget.h"
       
    23 #include "mptrace.h"
       
    24 
       
    25 /*!
       
    26     \class MpSnapshotWidget
       
    27     \brief Custom HB widget that grabs a snapshot of the graphics view.
       
    28 
       
    29     This widget grabs a snapshot of the graphics view so it can be drawn as 
       
    30     a decoy for transitios or fast ui response simulation.
       
    31 */
       
    32 
       
    33 
       
    34 /*!
       
    35  Constructs the snapshot widget.
       
    36  */
       
    37 MpSnapshotWidget::MpSnapshotWidget( QGraphicsItem *parent )
       
    38     : HbWidget(parent),
       
    39       mSnapshot(0)
       
    40 {
       
    41     TX_ENTRY_ARGS( " Parent=" << (void *)parent )
       
    42     TX_EXIT
       
    43 }
       
    44 
       
    45 /*!
       
    46  Destructs the snapshot widget.
       
    47  */
       
    48 MpSnapshotWidget::~MpSnapshotWidget()
       
    49 {
       
    50     TX_ENTRY
       
    51     if (mSnapshot)
       
    52      delete mSnapshot;
       
    53     TX_EXIT
       
    54 }
       
    55 
       
    56 /*!
       
    57  Takes a snapshot of an \a item within \a graphicsView, also sets its position
       
    58   and geometry so it can be used as a decoy for that itme.
       
    59  */
       
    60 void MpSnapshotWidget::capture(QGraphicsView *graphicsView, QGraphicsItem *item)
       
    61 {
       
    62     TX_ENTRY
       
    63     if (mSnapshot){
       
    64         delete mSnapshot;
       
    65         mSnapshot = 0;
       
    66     }
       
    67     setGeometry(QRect(QPoint(0,0),item->sceneBoundingRect().toRect().size()));
       
    68     setPos(item->sceneBoundingRect().toRect().topLeft());
       
    69     mSnapshot = new QImage(
       
    70             item->sceneBoundingRect().toRect().size() , 
       
    71             QImage::Format_ARGB32_Premultiplied);
       
    72     QPainter p( mSnapshot);
       
    73     graphicsView->render( &p, rect(), item->sceneBoundingRect().toRect());
       
    74     TX_EXIT
       
    75 }
       
    76 
       
    77 /*!
       
    78     \reimp
       
    79  */
       
    80 void MpSnapshotWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
       
    81 {
       
    82     TX_ENTRY
       
    83     Q_UNUSED(widget)
       
    84     Q_UNUSED(option)
       
    85     if (mSnapshot) {
       
    86         painter->drawImage( rect(), *mSnapshot );
       
    87     }
       
    88     TX_EXIT
       
    89 }