mpviewplugins/mpcollectionviewplugin/src/mpsnapshotwidget.cpp
branchRCL_3
changeset 52 14979e23cb5e
equal deleted inserted replaced
50:26a1709b9fec 52:14979e23cb5e
       
     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>
       
    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     setFlag( QGraphicsItem::ItemHasNoContents, false );
       
    43     TX_EXIT
       
    44 }
       
    45 
       
    46 /*!
       
    47  Destructs the snapshot widget.
       
    48  */
       
    49 MpSnapshotWidget::~MpSnapshotWidget()
       
    50 {
       
    51     TX_ENTRY
       
    52     if (mSnapshot)
       
    53      delete mSnapshot;
       
    54     TX_EXIT
       
    55 }
       
    56 
       
    57 /*!
       
    58  Takes a snapshot of an \a item within \a graphicsView, also sets its position
       
    59   and geometry so it can be used as a decoy for that itme.
       
    60  */
       
    61 void MpSnapshotWidget::capture(QGraphicsView *graphicsView, QGraphicsItem *item)
       
    62 {
       
    63     TX_ENTRY
       
    64     if (mSnapshot){
       
    65         delete mSnapshot;
       
    66         mSnapshot = 0;
       
    67     }
       
    68     setGeometry(QRect(QPoint(0,0),item->sceneBoundingRect().toRect().size()));
       
    69     setPos(item->sceneBoundingRect().toRect().topLeft());
       
    70     mSnapshot = new QImage(
       
    71             item->sceneBoundingRect().toRect().size() , 
       
    72             QImage::Format_ARGB32_Premultiplied);
       
    73     QPainter p( mSnapshot);
       
    74     graphicsView->render( &p, rect(), item->sceneBoundingRect().toRect());
       
    75     TX_EXIT
       
    76 }
       
    77 
       
    78 /*!
       
    79     \reimp
       
    80  */
       
    81 void MpSnapshotWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
       
    82 {
       
    83     TX_ENTRY
       
    84     Q_UNUSED(widget)
       
    85     Q_UNUSED(option)
       
    86     if (mSnapshot) {
       
    87         painter->drawImage( rect(), *mSnapshot );
       
    88     }
       
    89     TX_EXIT
       
    90 }