src/hbcore/gestures/hbmousepangesturerecognizer.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 
       
    27 #include "hbmousepangesturerecognizer_p.h"
       
    28 
       
    29 #include <QEvent>
       
    30 #include <QGraphicsSceneMouseEvent>
       
    31 #include <QGesture>
       
    32 #include <QVariant>
       
    33 
       
    34 HbMousePanGestureRecognizer::HbMousePanGestureRecognizer()
       
    35 {
       
    36 }
       
    37 
       
    38 HbMousePanGestureRecognizer::~HbMousePanGestureRecognizer()
       
    39 {
       
    40 }
       
    41 
       
    42 QGesture* HbMousePanGestureRecognizer::create(QObject *)
       
    43 {
       
    44     return new QPanGesture;
       
    45 }
       
    46 
       
    47 QGestureRecognizer::Result HbMousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
       
    48 {
       
    49     QPanGesture *g = static_cast<QPanGesture *>(state);
       
    50     QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
       
    51     QPoint pos;
       
    52 
       
    53     switch(event->type()) {
       
    54     case QEvent::GraphicsSceneMousePress:
       
    55         g->setOffset(QPointF(0,0));
       
    56         g->setProperty("startPos", me->screenPos());
       
    57         g->setProperty("pressed", QVariant::fromValue<bool>(true));
       
    58     case QEvent::GraphicsSceneMouseMove:
       
    59     case QEvent::GraphicsSceneMouseRelease:
       
    60         pos = me->screenPos();
       
    61         g->setHotSpot(pos);
       
    62         g->setLastOffset(g->offset());
       
    63         break;
       
    64     default:
       
    65         return QGestureRecognizer::Ignore;
       
    66     }
       
    67 
       
    68     if (event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
       
    69         return QGestureRecognizer::MayBeGesture;
       
    70     } else if (event->type() == QEvent::GraphicsSceneMouseMove) {
       
    71         if (g->property("pressed").toBool()) {
       
    72             QPoint offset = pos - g->property("startPos").toPoint();
       
    73             g->setOffset(offset);
       
    74             return QGestureRecognizer::TriggerGesture;
       
    75         }
       
    76         return QGestureRecognizer::CancelGesture;
       
    77     } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
       
    78         if(g->state() >= Qt::GestureStarted) {
       
    79             QPoint offset = pos - g->property("startPos").toPoint();
       
    80             g->setOffset(offset);
       
    81             g->setProperty("pressed", QVariant::fromValue<bool>(false));
       
    82             return QGestureRecognizer::FinishGesture;
       
    83         } else {
       
    84             return QGestureRecognizer::CancelGesture;
       
    85         }
       
    86 
       
    87     }
       
    88     return QGestureRecognizer::Ignore;
       
    89 }
       
    90 
       
    91 void HbMousePanGestureRecognizer::reset(QGesture *state)
       
    92 {
       
    93     QPanGesture *g = static_cast<QPanGesture *>(state);
       
    94     g->setLastOffset(QPointF());
       
    95     g->setOffset(QPointF(0,0));
       
    96     g->setAcceleration(0);
       
    97     g->setProperty("startPos", QVariant());
       
    98     g->setProperty("pressed", QVariant::fromValue<bool>(false));
       
    99     QGestureRecognizer::reset(state);
       
   100 }