telutils/dialpad/src/dialpadbackground.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 03 May 2010 13:01:45 +0300
changeset 15 d7fc66ccd6fb
parent 13 e32024264ebb
child 31 a2467631ae02
permissions -rw-r--r--
Revision: 201015 Kit: 201018

/*!
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: Background item to close dialpad when tapping outside.
*
*/

#include <QtGui>
#include "dialpadbackground.h"
#include "dialpad.h"

DialpadBackground::DialpadBackground(Dialpad& dialpad) :
    mDialpad(dialpad), mPressed(false)
{
    setFlag(QGraphicsItem::ItemIsFocusable,true);
}

DialpadBackground::~DialpadBackground()
{

}

void DialpadBackground::setRect(QRectF rect)
{
    mRect = rect;
}

QRectF DialpadBackground::boundingRect() const
{
    return mRect;
}

void DialpadBackground::paint(
    QPainter *painter,
    const QStyleOptionGraphicsItem *option,
    QWidget *widget)
{
    Q_UNUSED(painter);
    Q_UNUSED(option);
    Q_UNUSED(widget);
}

void DialpadBackground::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
    mPressed = true;
    event->accept();
}

void DialpadBackground::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if ( !boundingRect().contains(event->pos()) && mPressed ) {
        ungrabMouse();
        mPressed = false;
    }
}

void DialpadBackground::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
    if (mPressed) {
        mPressed = false;
        event->accept();
        mDialpad.startCloseAnimation();
    }
}