telutils/dialpad/src/dialpadbackground.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     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: Background item to close dialpad when tapping outside.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QGraphicsSceneMouseEvent>
       
    19 #include "dialpadbackground.h"
       
    20 #include "dialpad.h"
       
    21 
       
    22 DialpadBackground::DialpadBackground(Dialpad& dialpad) :
       
    23     mDialpad(dialpad), mPressed(false)
       
    24 {
       
    25     setFlag(QGraphicsItem::ItemIsFocusable,true);
       
    26 }
       
    27 
       
    28 DialpadBackground::~DialpadBackground()
       
    29 {
       
    30 
       
    31 }
       
    32 
       
    33 void DialpadBackground::setRect(QRectF rect)
       
    34 {
       
    35     mRect = rect;
       
    36 }
       
    37 
       
    38 QRectF DialpadBackground::boundingRect() const
       
    39 {
       
    40     return mRect;
       
    41 }
       
    42 
       
    43 void DialpadBackground::paint(
       
    44     QPainter *painter,
       
    45     const QStyleOptionGraphicsItem *option,
       
    46     QWidget *widget)
       
    47 {
       
    48     Q_UNUSED(painter);
       
    49     Q_UNUSED(option);
       
    50     Q_UNUSED(widget);
       
    51 }
       
    52 
       
    53 void DialpadBackground::mousePressEvent(QGraphicsSceneMouseEvent * event)
       
    54 {
       
    55     mPressed = true;
       
    56     event->accept();
       
    57 }
       
    58 
       
    59 void DialpadBackground::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
       
    60 {
       
    61     if ( !boundingRect().contains(event->pos()) && mPressed ) {
       
    62         ungrabMouse();
       
    63         mPressed = false;
       
    64     }
       
    65 }
       
    66 
       
    67 void DialpadBackground::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
       
    68 {
       
    69     if (mPressed) {
       
    70         mPressed = false;
       
    71         event->accept();
       
    72         mDialpad.startCloseAnimation();
       
    73     }
       
    74 }
       
    75 
       
    76 
       
    77