51 |
51 |
52 QMacSwipeGestureRecognizer::QMacSwipeGestureRecognizer() |
52 QMacSwipeGestureRecognizer::QMacSwipeGestureRecognizer() |
53 { |
53 { |
54 } |
54 } |
55 |
55 |
56 QGesture *QMacSwipeGestureRecognizer::createGesture(QObject * /*target*/) |
56 QGesture *QMacSwipeGestureRecognizer::create(QObject * /*target*/) |
57 { |
57 { |
58 return new QSwipeGesture; |
58 return new QSwipeGesture; |
59 } |
59 } |
60 |
60 |
61 QGestureRecognizer::Result |
61 QGestureRecognizer::Result |
62 QMacSwipeGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent *event) |
62 QMacSwipeGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) |
63 { |
63 { |
64 if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { |
64 if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { |
65 QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); |
65 QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); |
66 switch (ev->gestureType) { |
66 switch (ev->gestureType) { |
67 case QNativeGestureEvent::Swipe: { |
67 case QNativeGestureEvent::Swipe: { |
68 QSwipeGesture *g = static_cast<QSwipeGesture *>(gesture); |
68 QSwipeGesture *g = static_cast<QSwipeGesture *>(gesture); |
69 g->setSwipeAngle(ev->angle); |
69 g->setSwipeAngle(ev->angle); |
70 return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; |
70 return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; |
71 break; } |
71 break; } |
72 default: |
72 default: |
73 break; |
73 break; |
74 } |
74 } |
75 } |
75 } |
88 |
88 |
89 QMacPinchGestureRecognizer::QMacPinchGestureRecognizer() |
89 QMacPinchGestureRecognizer::QMacPinchGestureRecognizer() |
90 { |
90 { |
91 } |
91 } |
92 |
92 |
93 QGesture *QMacPinchGestureRecognizer::createGesture(QObject * /*target*/) |
93 QGesture *QMacPinchGestureRecognizer::create(QObject * /*target*/) |
94 { |
94 { |
95 return new QPinchGesture; |
95 return new QPinchGesture; |
96 } |
96 } |
97 |
97 |
98 QGestureRecognizer::Result |
98 QGestureRecognizer::Result |
99 QMacPinchGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent *event) |
99 QMacPinchGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) |
100 { |
100 { |
101 if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { |
101 if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { |
102 QPinchGesture *g = static_cast<QPinchGesture *>(gesture); |
102 QPinchGesture *g = static_cast<QPinchGesture *>(gesture); |
103 QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); |
103 QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); |
104 switch(ev->gestureType) { |
104 switch(ev->gestureType) { |
105 case QNativeGestureEvent::GestureBegin: |
105 case QNativeGestureEvent::GestureBegin: |
106 reset(gesture); |
106 reset(gesture); |
107 g->setStartCenterPoint(static_cast<QWidget*>(obj)->mapFromGlobal(ev->position)); |
107 g->setStartCenterPoint(static_cast<QWidget*>(obj)->mapFromGlobal(ev->position)); |
108 g->setCenterPoint(g->startCenterPoint()); |
108 g->setCenterPoint(g->startCenterPoint()); |
109 g->setWhatChanged(QPinchGesture::CenterPointChanged); |
109 g->setChangeFlags(QPinchGesture::CenterPointChanged); |
110 return QGestureRecognizer::MaybeGesture | QGestureRecognizer::ConsumeEventHint; |
110 g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); |
|
111 return QGestureRecognizer::MayBeGesture | QGestureRecognizer::ConsumeEventHint; |
111 case QNativeGestureEvent::Rotate: { |
112 case QNativeGestureEvent::Rotate: { |
112 g->setLastScaleFactor(g->scaleFactor()); |
113 g->setLastScaleFactor(g->scaleFactor()); |
113 g->setLastRotationAngle(g->rotationAngle()); |
114 g->setLastRotationAngle(g->rotationAngle()); |
114 g->setRotationAngle(g->rotationAngle() + ev->percentage); |
115 g->setRotationAngle(g->rotationAngle() + ev->percentage); |
115 g->setWhatChanged(QPinchGesture::RotationAngleChanged); |
116 g->setChangeFlags(QPinchGesture::RotationAngleChanged); |
116 return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; |
117 g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); |
117 break; |
118 return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; |
118 } |
119 } |
119 case QNativeGestureEvent::Zoom: |
120 case QNativeGestureEvent::Zoom: |
120 g->setLastScaleFactor(g->scaleFactor()); |
121 g->setLastScaleFactor(g->scaleFactor()); |
121 g->setLastRotationAngle(g->rotationAngle()); |
122 g->setLastRotationAngle(g->rotationAngle()); |
122 g->setScaleFactor(g->scaleFactor() + ev->percentage); |
123 g->setScaleFactor(g->scaleFactor() * (1 + ev->percentage)); |
123 g->setWhatChanged(QPinchGesture::ScaleFactorChanged); |
124 g->setChangeFlags(QPinchGesture::ScaleFactorChanged); |
124 return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; |
125 g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); |
125 break; |
126 return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; |
126 case QNativeGestureEvent::GestureEnd: |
127 case QNativeGestureEvent::GestureEnd: |
127 return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; |
128 return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; |
128 break; |
|
129 default: |
129 default: |
130 break; |
130 break; |
131 } |
131 } |
132 } |
132 } |
133 |
133 |
135 } |
135 } |
136 |
136 |
137 void QMacPinchGestureRecognizer::reset(QGesture *gesture) |
137 void QMacPinchGestureRecognizer::reset(QGesture *gesture) |
138 { |
138 { |
139 QPinchGesture *g = static_cast<QPinchGesture *>(gesture); |
139 QPinchGesture *g = static_cast<QPinchGesture *>(gesture); |
140 g->setWhatChanged(0); |
140 g->setChangeFlags(0); |
|
141 g->setTotalChangeFlags(0); |
141 g->setScaleFactor(1.0f); |
142 g->setScaleFactor(1.0f); |
142 g->setTotalScaleFactor(1.0f); |
143 g->setTotalScaleFactor(1.0f); |
143 g->setLastScaleFactor(1.0f); |
144 g->setLastScaleFactor(1.0f); |
144 g->setRotationAngle(0.0f); |
145 g->setRotationAngle(0.0f); |
145 g->setTotalRotationAngle(0.0f); |
146 g->setTotalRotationAngle(0.0f); |
183 case QEvent::TouchBegin: { |
184 case QEvent::TouchBegin: { |
184 const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); |
185 const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); |
185 if (ev->touchPoints().size() == 1) { |
186 if (ev->touchPoints().size() == 1) { |
186 reset(gesture); |
187 reset(gesture); |
187 _startPos = QCursor::pos(); |
188 _startPos = QCursor::pos(); |
188 _lastPos = _startPos; |
|
189 _panTimer.start(panBeginDelay, target); |
189 _panTimer.start(panBeginDelay, target); |
190 _panCanceled = false; |
190 _panCanceled = false; |
191 return QGestureRecognizer::MaybeGesture; |
191 return QGestureRecognizer::MayBeGesture; |
192 } |
192 } |
193 break;} |
193 break;} |
194 case QEvent::TouchEnd: { |
194 case QEvent::TouchEnd: { |
195 if (_panCanceled) |
195 if (_panCanceled) |
196 break; |
196 break; |
197 |
197 |
198 const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); |
198 const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); |
199 if (ev->touchPoints().size() == 1) |
199 if (ev->touchPoints().size() == 1) |
200 return QGestureRecognizer::GestureFinished; |
200 return QGestureRecognizer::FinishGesture; |
201 break;} |
201 break;} |
202 case QEvent::TouchUpdate: { |
202 case QEvent::TouchUpdate: { |
203 if (_panCanceled) |
203 if (_panCanceled) |
204 break; |
204 break; |
205 |
205 |
210 // moved his finger so much that it makes sense to cancel the pan: |
210 // moved his finger so much that it makes sense to cancel the pan: |
211 const QPointF p = QCursor::pos(); |
211 const QPointF p = QCursor::pos(); |
212 if ((p - _startPos).manhattanLength() > panBeginRadius) { |
212 if ((p - _startPos).manhattanLength() > panBeginRadius) { |
213 _panCanceled = true; |
213 _panCanceled = true; |
214 _panTimer.stop(); |
214 _panTimer.stop(); |
215 return QGestureRecognizer::NotGesture; |
215 return QGestureRecognizer::CancelGesture; |
216 } |
216 } |
217 } else { |
217 } else { |
218 const QPointF p = QCursor::pos(); |
218 const QPointF p = QCursor::pos(); |
219 const QPointF posOffset = p - _lastPos; |
219 const QPointF posOffset = p - _startPos; |
220 g->setLastOffset(g->offset()); |
220 g->setLastOffset(g->offset()); |
221 g->setOffset(QPointF(posOffset.x(), posOffset.y())); |
221 g->setOffset(QPointF(posOffset.x(), posOffset.y())); |
222 g->setTotalOffset(g->lastOffset() + g->offset()); |
222 return QGestureRecognizer::TriggerGesture; |
223 _lastPos = p; |
|
224 return QGestureRecognizer::GestureTriggered; |
|
225 } |
223 } |
226 } else if (_panTimer.isActive()) { |
224 } else if (_panTimer.isActive()) { |
227 // I only want to cancel the pan if the user is pressing |
225 // I only want to cancel the pan if the user is pressing |
228 // more than one finger, and the pan hasn't started yet: |
226 // more than one finger, and the pan hasn't started yet: |
229 _panCanceled = true; |
227 _panCanceled = true; |
230 _panTimer.stop(); |
228 _panTimer.stop(); |
231 return QGestureRecognizer::NotGesture; |
229 return QGestureRecognizer::CancelGesture; |
232 } |
230 } |
233 break;} |
231 break;} |
234 case QEvent::Timer: { |
232 case QEvent::Timer: { |
235 QTimerEvent *ev = static_cast<QTimerEvent *>(event); |
233 QTimerEvent *ev = static_cast<QTimerEvent *>(event); |
236 if (ev->timerId() == _panTimer.timerId()) { |
234 if (ev->timerId() == _panTimer.timerId()) { |
237 _panTimer.stop(); |
235 _panTimer.stop(); |
238 if (_panCanceled) |
236 if (_panCanceled) |
239 break; |
237 break; |
240 // Begin new pan session! |
238 // Begin new pan session! |
241 _startPos = QCursor::pos(); |
239 _startPos = QCursor::pos(); |
242 _lastPos = _startPos; |
240 return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; |
243 return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; |
|
244 } |
241 } |
245 break; } |
242 break; } |
246 default: |
243 default: |
247 break; |
244 break; |
248 } |
245 } |
252 |
249 |
253 void QMacPanGestureRecognizer::reset(QGesture *gesture) |
250 void QMacPanGestureRecognizer::reset(QGesture *gesture) |
254 { |
251 { |
255 QPanGesture *g = static_cast<QPanGesture *>(gesture); |
252 QPanGesture *g = static_cast<QPanGesture *>(gesture); |
256 _startPos = QPointF(); |
253 _startPos = QPointF(); |
257 _lastPos = QPointF(); |
|
258 _panCanceled = true; |
254 _panCanceled = true; |
259 g->setOffset(QPointF(0, 0)); |
255 g->setOffset(QPointF(0, 0)); |
260 g->setLastOffset(QPointF(0, 0)); |
256 g->setLastOffset(QPointF(0, 0)); |
261 g->setTotalOffset(QPointF(0, 0)); |
|
262 g->setAcceleration(qreal(1)); |
257 g->setAcceleration(qreal(1)); |
263 QGestureRecognizer::reset(gesture); |
258 QGestureRecognizer::reset(gesture); |
264 } |
259 } |
265 #endif // QT_MAC_USE_COCOA |
260 #endif // QT_MAC_USE_COCOA |
266 |
261 |