author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 29 Apr 2010 15:15:16 +0300 | |
branch | RCL_3 |
changeset 17 | 4b6ee5efea19 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "mousepangesturerecognizer.h" |
|
43 |
||
44 |
#include <QEvent> |
|
45 |
#include <QVariant> |
|
46 |
#include <QGraphicsSceneMouseEvent> |
|
47 |
#include <QMouseEvent> |
|
48 |
#include <QGesture> |
|
49 |
||
50 |
MousePanGestureRecognizer::MousePanGestureRecognizer() |
|
51 |
{ |
|
52 |
} |
|
53 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
QGesture* MousePanGestureRecognizer::create(QObject *) |
0 | 55 |
{ |
56 |
return new QPanGesture; |
|
57 |
} |
|
58 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) |
0 | 60 |
{ |
61 |
QPanGesture *g = static_cast<QPanGesture *>(state); |
|
62 |
QPoint globalPos; |
|
63 |
switch (event->type()) { |
|
64 |
case QEvent::GraphicsSceneMousePress: |
|
65 |
case QEvent::GraphicsSceneMouseDoubleClick: |
|
66 |
case QEvent::GraphicsSceneMouseMove: |
|
67 |
case QEvent::GraphicsSceneMouseRelease: |
|
68 |
globalPos = static_cast<QGraphicsSceneMouseEvent *>(event)->screenPos(); |
|
69 |
break; |
|
70 |
case QEvent::MouseButtonPress: |
|
71 |
case QEvent::MouseMove: |
|
72 |
case QEvent::MouseButtonRelease: |
|
73 |
globalPos = static_cast<QMouseEvent *>(event)->globalPos(); |
|
74 |
break; |
|
75 |
default: |
|
76 |
break; |
|
77 |
} |
|
78 |
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick |
|
79 |
|| event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) { |
|
80 |
g->setHotSpot(globalPos); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
g->setProperty("startPos", globalPos); |
0 | 82 |
g->setProperty("pressed", QVariant::fromValue<bool>(true)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; |
0 | 84 |
} else if (event->type() == QEvent::MouseMove || event->type() == QEvent::GraphicsSceneMouseMove) { |
85 |
if (g->property("pressed").toBool()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
QPoint offset = globalPos - g->property("startPos").toPoint(); |
0 | 87 |
g->setLastOffset(g->offset()); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
g->setOffset(QPointF(offset.x(), offset.y())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; |
0 | 90 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
return QGestureRecognizer::CancelGesture; |
0 | 92 |
} else if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::GraphicsSceneMouseRelease) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; |
0 | 94 |
} |
95 |
return QGestureRecognizer::Ignore; |
|
96 |
} |
|
97 |
||
98 |
void MousePanGestureRecognizer::reset(QGesture *state) |
|
99 |
{ |
|
100 |
QPanGesture *g = static_cast<QPanGesture *>(state); |
|
101 |
g->setLastOffset(QPointF()); |
|
102 |
g->setOffset(QPointF()); |
|
103 |
g->setAcceleration(0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
g->setProperty("startPos", QVariant()); |
0 | 105 |
g->setProperty("pressed", QVariant::fromValue<bool>(false)); |
106 |
QGestureRecognizer::reset(state); |
|
107 |
} |