ganeswidgets/src/hglongpressvisualizer.cpp
changeset 0 89c329efa980
child 5 4fa04caf0f43
equal deleted inserted replaced
-1:000000000000 0:89c329efa980
       
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QGesture>
       
    19 #include <QPainter>
       
    20 #include <QTimer>
       
    21 #include <hblabel.h>
       
    22 #include <hbgridviewitem>
       
    23 #include <hbmainwindow>
       
    24 #include "hglongpressvisualizer.h"
       
    25 
       
    26 HgLongPressVisualizer::HgLongPressVisualizer(QGraphicsItem* parent) : HbWidget(parent),
       
    27     active(false),
       
    28     spanAngle(0)
       
    29 {
       
    30 
       
    31 }
       
    32 
       
    33 HgLongPressVisualizer::~HgLongPressVisualizer()
       
    34 {
       
    35     
       
    36 }
       
    37 
       
    38 
       
    39 void HgLongPressVisualizer::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
       
    40 {
       
    41     Q_UNUSED(option);
       
    42     Q_UNUSED(widget);
       
    43     
       
    44     if (active) {
       
    45         QPen pen( Qt::lightGray );
       
    46         pen.setWidth(5);
       
    47         painter->setPen(pen);
       
    48         painter->drawArc(rect, 90*16, -spanAngle*16);
       
    49     }
       
    50 }
       
    51 
       
    52 void HgLongPressVisualizer::start(const QPointF& scenePos)
       
    53 {
       
    54     prepareGeometryChange();
       
    55     rect = QRect( 0, 0, 30, 30);
       
    56 
       
    57     if (scenePos.y() < 60 ) {
       
    58         //Draw the animation below of the touch point
       
    59         rect.moveCenter( QPointF(scenePos.x(), scenePos.y()+50));
       
    60     }
       
    61     else {
       
    62         //Draw the animation above of the touch point
       
    63         rect.moveCenter( QPointF(scenePos.x(), scenePos.y()-50));
       
    64     }
       
    65 
       
    66     setFrame(0);
       
    67     active = true;
       
    68 }
       
    69 
       
    70 void HgLongPressVisualizer::stop()
       
    71 {
       
    72     active = false;
       
    73     update();
       
    74 }
       
    75 
       
    76 void HgLongPressVisualizer::setFrame(int frame)
       
    77 {
       
    78     spanAngle = frame*360/100;
       
    79     update();
       
    80 }
       
    81 
       
    82 QRectF HgLongPressVisualizer::boundingRect() const 
       
    83 {
       
    84     return rect;
       
    85 }