9
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU Lesser General Public License as published by
|
|
7 |
* the Free Software Foundation, version 2.1 of the License.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU Lesser General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Lesser General Public License
|
|
15 |
* along with this program. If not,
|
|
16 |
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
|
|
17 |
*
|
|
18 |
* Description:
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
|
|
22 |
/*
|
|
23 |
W A R N I N G
|
|
24 |
-------------
|
|
25 |
THIS IS A TEMPORARY GESTURE CODE. WOULD BE REPLACED WHEN BROWSER HAS ITS OWN GESTURE FRAMEWORK
|
|
26 |
*/
|
|
27 |
|
|
28 |
#ifndef GestureRecognizer_p_h
|
|
29 |
#define GestureRecognizer_p_h
|
|
30 |
|
|
31 |
#include "GestureEvent.h"
|
|
32 |
|
|
33 |
#include <QBasicTimer>
|
|
34 |
#include <QObject>
|
|
35 |
#include <QTime>
|
|
36 |
|
|
37 |
class QGraphicsSceneMouseEvent;
|
|
38 |
class QPoint;
|
|
39 |
class QPointF;
|
|
40 |
|
|
41 |
namespace GVA {
|
|
42 |
|
|
43 |
class GestureListener;
|
|
44 |
class GestureRecognizer;
|
|
45 |
|
|
46 |
class GestureRecognizerPrivate : public QObject {
|
|
47 |
Q_OBJECT
|
|
48 |
Q_DECLARE_PUBLIC(GestureRecognizer)
|
|
49 |
|
|
50 |
public:
|
|
51 |
//States of gesture recognizer
|
|
52 |
enum State {
|
|
53 |
Inactive,
|
|
54 |
Press,
|
|
55 |
Release,
|
|
56 |
Move,
|
|
57 |
DoublePress,
|
|
58 |
LongPress
|
|
59 |
};
|
|
60 |
|
|
61 |
GestureRecognizerPrivate(GestureListener*);
|
|
62 |
~GestureRecognizerPrivate();
|
|
63 |
|
|
64 |
bool mousePressEvent(QGraphicsSceneMouseEvent* event);
|
|
65 |
bool mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
|
66 |
bool mouseMoveEvent(QGraphicsSceneMouseEvent* event);
|
|
67 |
bool mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
|
|
68 |
|
|
69 |
protected:
|
|
70 |
void changeState(State state);
|
|
71 |
GestureEvent gestureEvent(const QPointF& pos, GestureEvent::Type type);
|
|
72 |
void timerEvent(QTimerEvent* event);
|
|
73 |
void resetTouchPositions();
|
|
74 |
QPointF calculateVelocity(const QPointF& delta, int time);
|
|
75 |
|
|
76 |
private:
|
|
77 |
GestureRecognizer* q_ptr;
|
|
78 |
GestureListener* m_gestureListener;
|
|
79 |
|
|
80 |
// state
|
|
81 |
State m_state;
|
|
82 |
|
|
83 |
//last moved time
|
|
84 |
QTime m_lastTime;
|
|
85 |
//time elapsed since last press
|
|
86 |
QTime m_delayedPressMoment;
|
|
87 |
//common timer for long tap or double tap recognition
|
|
88 |
QBasicTimer m_timer;
|
|
89 |
|
|
90 |
//Velocity factors
|
|
91 |
qreal m_dragInertia;
|
|
92 |
int m_directionErrorMargin;
|
|
93 |
qreal m_axisLockThreshold;
|
|
94 |
qreal m_maxVelocity;
|
|
95 |
qreal m_minVelocity;
|
|
96 |
int m_panningThreshold;
|
|
97 |
qreal m_fastVelocityFactor;
|
|
98 |
int m_scrollsPerSecond;
|
|
99 |
|
|
100 |
QPointF m_velocity;
|
|
101 |
|
|
102 |
//Touch positions
|
|
103 |
QPointF m_position;
|
|
104 |
QPointF m_initialPos;
|
|
105 |
|
|
106 |
QGraphicsSceneMouseEvent* m_delayedReleaseEvent;
|
|
107 |
}; //GestureRecognizerPrivate
|
|
108 |
|
|
109 |
} //namespace GVA
|
|
110 |
#endif //GestureRecognizer_p_h
|