23 #include <QGraphicsWebView> |
23 #include <QGraphicsWebView> |
24 #include <QWebPage> |
24 #include <QWebPage> |
25 #include <QWebFrame> |
25 #include <QWebFrame> |
26 #include <QGraphicsScene> |
26 #include <QGraphicsScene> |
27 #include <QGraphicsView> |
27 #include <QGraphicsView> |
|
28 #include <QGraphicsSceneContextMenuEvent> |
|
29 #include <QApplication> |
28 |
30 |
29 #include "WebTouchNavigation.h" |
31 #include "WebTouchNavigation.h" |
30 #include "KineticHelper.h" |
32 #include "GWebContentViewWidget.h" |
31 |
33 #include "GWebContentView.h" |
|
34 #include "wrtperftracer.h" |
|
35 |
|
36 #ifndef NO_QSTM_GESTURE |
|
37 #include "qstmutils.h" |
|
38 #include "qstmgestureevent.h" |
|
39 #include "qstmfilelogger.h" |
|
40 #endif |
32 #define SCROLL_TIMEOUT 40 |
41 #define SCROLL_TIMEOUT 40 |
33 |
42 |
34 namespace GVA { |
43 namespace GVA { |
|
44 #ifndef NO_QSTM_GESTURE |
35 using namespace qstmGesture; |
45 using namespace qstmGesture; |
36 |
46 #endif |
37 |
|
38 |
|
39 |
|
40 DecelEdit::DecelEdit(WebTouchNavigation* nav) : QLineEdit(), m_nav(nav) |
|
41 { |
|
42 setMaxLength(6); |
|
43 connect(this, SIGNAL(editingFinished()), this, SLOT(setDecel())); |
|
44 // connect(this, SIGNAL(returnPressed ()), this, SLOT(setDecel())); |
|
45 } |
|
46 |
|
47 void DecelEdit::setDecel() |
|
48 { |
|
49 QString txt = text(); |
|
50 bool ok = false; |
|
51 int decel = txt.toInt(&ok); |
|
52 m_nav->m_kinetic->setDeceleration((qreal)decel); |
|
53 hide(); |
|
54 } |
|
55 |
47 |
56 |
48 |
57 WebTouchNavigation::WebTouchNavigation(QGraphicsWebView* view) : |
49 WebTouchNavigation::WebTouchNavigation(QGraphicsWebView* view) : |
58 m_view(view), |
50 m_view(view), |
59 m_scrollTimer(0) |
51 m_scrollHelper(0), |
|
52 m_frame(0) |
60 |
53 |
61 { |
54 { |
62 m_webPage = m_view->page(); |
55 m_webPage = m_view->page(); |
63 m_kinetic = new KineticHelper(this); |
|
64 m_decelEdit = new DecelEdit(this); |
|
65 } |
56 } |
66 |
57 |
67 WebTouchNavigation::~WebTouchNavigation() |
58 WebTouchNavigation::~WebTouchNavigation() |
68 { |
59 { |
69 disconnect(m_scrollTimer, SIGNAL(timeout()),this,SLOT(pan())); |
60 } |
70 delete m_scrollTimer; |
61 |
71 |
62 |
72 delete m_kinetic; |
63 bool WebTouchNavigation::eventFilter(QObject* obj, QEvent* event) |
73 } |
64 { |
74 |
65 if (obj != m_view) return false; |
75 |
66 #ifndef NO_QSTM_GESTURE |
|
67 if (event->type() == QEvent::Gesture) { |
|
68 QStm_Gesture* gesture = getQStmGesture(event); |
|
69 if (gesture) { |
|
70 handleQStmGesture(gesture); |
|
71 return true; |
|
72 } |
|
73 } |
|
74 #endif |
|
75 return false; |
|
76 } |
|
77 |
|
78 #ifndef NO_QSTM_GESTURE |
76 void WebTouchNavigation::handleQStmGesture(QStm_Gesture* gesture) |
79 void WebTouchNavigation::handleQStmGesture(QStm_Gesture* gesture) |
77 { |
80 { |
78 QStm_GestureType type = gesture->getGestureStmType(); |
81 QStm_GestureType type = gesture->getGestureStmType(); |
79 |
82 qstmDebug() << " WTN::handleQStmGesture - type=" << type << "\n"; |
|
83 |
80 switch (type) { |
84 switch (type) { |
81 case QStmTapGestureType: |
85 case QStmTapGestureType: |
82 { |
86 { |
83 doTap(gesture); |
87 doTap(gesture); |
|
88 //gesture->sendMouseEvents(); |
|
89 break; |
|
90 } |
|
91 case QStmLeftRightGestureType: |
|
92 { |
|
93 qstmDebug() << " handleQStmGesture LEFTRIGHT_begin: pos: " << gesture->position() << "\n"; |
|
94 //gesture->sendMouseEvents(); |
|
95 doPan(gesture); |
|
96 qstmDebug() << " handleQStmGesture LEFTRIGHT_end" << "\n"; |
|
97 break; |
|
98 } |
|
99 case QStmUpDownGestureType: |
|
100 { |
|
101 qstmDebug() << " handleQStmGesture UPDOWN_begin pos: " << gesture->position() << "\n"; |
|
102 //gesture->sendMouseEvents(); |
|
103 doPan(gesture); |
|
104 qstmDebug() << " handleQStmGesture UPDOWN_end"<< "\n"; |
84 break; |
105 break; |
85 } |
106 } |
86 case QStmPanGestureType: |
107 case QStmPanGestureType: |
87 { |
108 { |
|
109 // |
|
110 qstmDebug() << " handleQStmGesture PAN_begin pos: " << gesture->position() << "\n"; |
|
111 //gesture->sendMouseEvents(); |
88 doPan(gesture); |
112 doPan(gesture); |
|
113 qstmDebug() << " handleQStmGesture PAN_end" << "\n"; |
89 break; |
114 break; |
90 } |
115 } |
91 case QStmFlickGestureType: |
116 case QStmFlickGestureType: |
92 { |
117 { |
|
118 qstmDebug() << " handleQStmGesture FLICK_begin pos: " << gesture->position() << ", speed: " << gesture->getSpeedVec() << "\n"; |
93 doFlick(gesture); |
119 doFlick(gesture); |
|
120 //gesture->sendMouseEvents(); |
|
121 qstmDebug() << " handleQStmGesture FLICK_end" << "\n"; |
94 break; |
122 break; |
95 } |
123 } |
96 case QStmDoubleTapGestureType: |
124 case QStmDoubleTapGestureType: |
97 { |
125 { |
98 m_decelEdit->show(); |
126 //qstmDebug() << "WTN::handleQStmGesture doubletap"; |
|
127 //m_decelEdit->show(); |
|
128 //gesture->sendMouseEvents(); |
99 break; |
129 break; |
100 } |
130 } |
101 case QStmTouchGestureType: |
131 case QStmTouchGestureType: |
102 { |
132 { |
103 doTouch(gesture); |
133 qstmDebug() << " handleQStmGesture TOUCH_begin pos: " << gesture->position() << "\n"; |
104 break; |
134 //doTouch(gesture); |
|
135 //gesture->sendMouseEvents(m_view); |
|
136 qstmDebug() << " handleQStmGesture TOUCH_end" << "\n"; |
|
137 break; |
|
138 } |
|
139 case QStmReleaseGestureType: |
|
140 { |
|
141 qstmDebug() << " handleQStmGesture RELEASE_begin pos: " << gesture->position() << "\n"; |
|
142 //gesture->sendMouseEvents(m_view); |
|
143 m_scrollHelper->stopScroll(); |
|
144 qstmDebug() << " handleQStmGesture RELEASE_end" << "\n" << "\n"; |
|
145 break; |
|
146 } |
|
147 case QStmPinchGestureType: |
|
148 { |
|
149 qstmDebug() << " handleQStmGesture PINCH_begin" << "\n"; |
|
150 qstmDebug() << " handleQStmGesture PINCH_end" << "\n"; |
|
151 break; |
|
152 } |
|
153 case QStmLongPressGestureType: |
|
154 { |
|
155 qstmDebug() << " handleQStmGesture LONGPRESS_begin pos: " << gesture->position() << "\n"; |
|
156 QPoint gpos = gesture->position(); |
|
157 QPoint pos = mapFromGlobal(gpos).toPoint(); |
|
158 //QContextMenuEvent cmEvent(QContextMenuEvent::Mouse, pos, gpos); |
|
159 |
|
160 QGraphicsSceneContextMenuEvent cmEvent(QEvent::GraphicsSceneContextMenu); |
|
161 cmEvent.setPos(pos); |
|
162 cmEvent.setScenePos(gpos); |
|
163 cmEvent.setReason(QGraphicsSceneContextMenuEvent::Mouse); |
|
164 |
|
165 QApplication::sendEvent(m_view, &cmEvent); |
|
166 qstmDebug() << " handleQStmGesture LONGPRESS_end" << "\n"; |
|
167 } |
|
168 |
|
169 default: |
|
170 { |
|
171 // gesture->sendMouseEvents(); |
105 } |
172 } |
106 } |
173 } |
107 } |
174 } |
108 |
175 |
109 void WebTouchNavigation::doTouch(QStm_Gesture* gesture) |
176 void WebTouchNavigation::doTouch(QStm_Gesture* gesture) |
110 { |
177 { |
|
178 qstmDebug() << "WTN::doTouch IN"; |
111 stopScrolling(); |
179 stopScrolling(); |
112 if (m_kinetic->isScrolling()) { |
180 } |
113 m_kinetic->stopScrolling(); |
|
114 } |
|
115 } |
|
116 |
181 |
117 void WebTouchNavigation::stopScrolling() |
182 void WebTouchNavigation::stopScrolling() |
118 { |
183 { |
119 if (m_scrollTimer && m_scrollTimer->isActive()) { |
|
120 m_scrollTimer->stop(); |
|
121 m_scrollDelta = QPoint(0,0); |
|
122 } |
|
123 } |
184 } |
124 |
185 |
125 |
186 |
126 void WebTouchNavigation::doFlick(QStm_Gesture* gesture) |
187 void WebTouchNavigation::doFlick(QStm_Gesture* gesture) |
127 { |
188 { |
128 |
|
129 QPointF pos = mapFromGlobal(gesture->position()); |
|
130 m_kineticSpeed = gesture->getSpeedVec(); |
189 m_kineticSpeed = gesture->getSpeedVec(); |
131 QStm_GestureDirection direction = static_cast<QStm_GestureDirection>(gesture->getDirection()); |
190 m_scrollHelper->kineticScroll(m_kineticSpeed); |
132 |
|
133 if (direction == ENorth || direction == ESouth) { |
|
134 m_kineticSpeed.setY(0.0); |
|
135 } |
|
136 else if (direction == EEast || direction == EWest) { |
|
137 m_kineticSpeed.setX(0.0); |
|
138 } |
|
139 |
|
140 m_kineticSpeed *= -1.0; |
|
141 m_frame = m_webPage->frameAt(pos.toPoint()); |
|
142 m_kinetic->startScrolling(); |
|
143 } |
191 } |
144 |
192 |
145 void WebTouchNavigation::doPan(QStm_Gesture* gesture) |
193 void WebTouchNavigation::doPan(QStm_Gesture* gesture) |
146 { |
194 { |
147 if (gesture->gestureState() == Qt::GestureFinished) { |
195 m_scrollDelta = gesture->getLengthAndDirection(); |
148 stopScrolling(); |
196 #ifdef BEDROCK_TILED_BACKING_STORE |
149 } |
197 m_scrollDelta.setY(-1 * m_scrollDelta.y()); |
150 else { |
198 #endif |
151 m_scrollDelta += gesture->getLengthAndDirection(); |
199 QPointF p = QPointF(gesture->position()); |
152 Q_ASSERT(m_scrollDelta.x() != 0 || m_scrollDelta.y() != 0); |
200 // if (m_scrollDelta.x() != 0 || m_scrollDelta.y() != 0) { |
153 QPointF pos = mapFromGlobal(gesture->position()); |
201 m_scrollHelper->scroll(m_scrollDelta, p); |
154 m_frame = m_webPage->frameAt(pos.toPoint()); |
202 // } |
155 if (!m_scrollTimer) { |
203 } |
156 m_scrollTimer = new QTimer(this); |
204 |
157 m_scrollTimer->setSingleShot(false); |
|
158 QObject::connect(m_scrollTimer, SIGNAL(timeout()), this, SLOT(pan())); |
|
159 } |
|
160 |
|
161 if (!m_scrollTimer->isActive()) { |
|
162 m_scrollTimer->stop(); |
|
163 m_scrollTimer->start(SCROLL_TIMEOUT); |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 void WebTouchNavigation::pan() |
|
169 { |
|
170 if (m_scrollDelta.x() != 0 || m_scrollDelta.y() != 0) { |
|
171 m_frame->scroll(-m_scrollDelta.x(), m_scrollDelta.y()); |
|
172 m_scrollDelta = QPoint(0,0); |
|
173 } |
|
174 } |
|
175 |
205 |
176 void WebTouchNavigation::doTap(QStm_Gesture* gesture) |
206 void WebTouchNavigation::doTap(QStm_Gesture* gesture) |
177 { |
207 { |
|
208 qstmDebug() << "WTN::doTap IN"; |
178 QPoint gpos = gesture->position(); |
209 QPoint gpos = gesture->position(); |
179 QPoint pos = mapFromGlobal(gpos).toPoint(); |
210 QPoint pos = mapFromGlobal(gpos).toPoint(); |
180 Qt::MouseButtons buttons = Qt::LeftButton; |
211 Qt::MouseButtons buttons = Qt::LeftButton; |
181 buttons &= ~Qt::RightButton; |
212 buttons &= ~Qt::RightButton; |
182 buttons &= ~Qt::MidButton; |
213 buttons &= ~Qt::MidButton; |