bool QtPinchGestureRecognizer::update(const QTouchEvent::TouchPoint& point1, const QTouchEvent::TouchPoint& point2) { const qreal currentFingerDistance = QLineF(point1.screenPos(), point2.screenPos()).length(); switch (m_state) { case NoGesture: m_initialFingerDistance = currentFingerDistance; m_state = GestureRecognitionStarted; return false; case GestureRecognitionStarted: { const qreal pinchDistance = qAbs(currentFingerDistance - m_initialFingerDistance); if (pinchDistance < pinchInitialTriggerDistanceThreshold) return false; m_state = GestureRecognized; if (viewportController()) viewportController()->pinchGestureStarted(computePinchCenter(point1, point2)); // We reset the initial span distance to the current distance of the // touch points in order to avoid the jump caused by the events which // were skipped between the recognition start and the actual recognition. m_initialFingerDistance = currentFingerDistance; // fall through } case GestureRecognized: const qreal totalScaleFactor = currentFingerDistance / m_initialFingerDistance; const QPointF touchCenterInViewCoordinates = computePinchCenter(point1, point2); if (viewportController()) viewportController()->pinchGestureRequestUpdate(touchCenterInViewCoordinates, totalScaleFactor); return true; break; } ASSERT_NOT_REACHED(); return false; }
bool QtPanGestureRecognizer::update(const QTouchEvent::TouchPoint& touchPoint, qint64 eventTimestampMillis) { if (!viewportHandler()) return false; m_lastPosition = touchPoint.pos(); m_lastEventTimestampMillis = eventTimestampMillis; switch (m_state) { case NoGesture: m_state = GestureRecognitionStarted; m_firstScreenPosition = touchPoint.screenPos(); viewportHandler()->cancelScrollAnimation(); return false; case GestureRecognitionStarted: { // To start the gesture, the delta from start in screen coordinates // must be bigger than the trigger threshold. QPointF totalOffsetFromStart(touchPoint.screenPos() - m_firstScreenPosition); if (qAbs(totalOffsetFromStart.x()) < panningInitialTriggerDistanceThreshold && qAbs(totalOffsetFromStart.y()) < panningInitialTriggerDistanceThreshold) return false; m_state = GestureRecognized; viewportHandler()->panGestureStarted(touchPoint.pos(), eventTimestampMillis); return true; } case GestureRecognized: viewportHandler()->panGestureRequestUpdate(touchPoint.pos(), eventTimestampMillis); return true; default: ASSERT_NOT_REACHED(); } return false; }
bool PuzzleBoardItem::sceneEvent(QEvent *event) { if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) { QTouchEvent *te = static_cast<QTouchEvent*>(event); if (te->touchPoints().count() == 1) { QTouchEvent::TouchPoint tp = te->touchPoints().first(); QPointF diff = tp.screenPos() - this->game()->rotationGuideCoordinates(); if (abs(diff.x()) < 32 && abs(diff.y()) < 32) { event->ignore(); return false; } } event->accept(); _game->handleTouchEvent(te); if (!_autoRepainter->isActive()) update(); return true; } return QDeclarativeItem::sceneEvent(event); }
bool gpsp4Qt::event(QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: { QList<QTouchEvent::TouchPoint> touchPoints = (static_cast<QTouchEvent*>(event))->touchPoints(); m_softKeys = 0; for ( int i = 0; i < touchPoints.length(); i++ ) { QTouchEvent::TouchPoint tp = touchPoints[i]; if ( tp.state() == Qt::TouchPointPressed || tp.state() == Qt::TouchPointMoved || tp.state() == Qt::TouchPointStationary) { if ( tp.screenPos().x() < DPAD_WIDTH ) { m_softKeys |= m_dpad->getGpspKeys(tp.screenPos().x(), tp.screenPos().y()); } else if ( tp.screenPos().x() > BUTTON_LEFT_POS ) { m_softKeys |= m_rightButtons->getGpspKeys(tp.screenPos().x() - BUTTON_LEFT_POS, tp.screenPos().y()); } } } event->accept(); return true; } case QEvent::TouchEnd: { m_softKeys = 0; break; } case QEvent::FocusOut: { showAntSnesMenu(); } default: break; } return QWidget::event(event); }
WebGestureEvent WebEventFactory::createWebGestureEvent(const QTouchEvent::TouchPoint& point, const WebEvent::Type& gestureType, const QTransform& fromItemTransform) { WebEvent::Type type = gestureType; IntPoint position = fromItemTransform.map(point.pos()).toPoint(); IntPoint screenPosition = point.screenPos().toPoint(); WebEvent::Modifiers modifiers = WebEvent::Modifiers(0); double timestamp = 0; IntSize area = IntSize(point.rect().size().toSize()); FloatPoint delta = FloatPoint(0, 0); return WebGestureEvent(type, position, screenPosition, modifiers, timestamp, area, delta); }
PlatformTouchPoint::PlatformTouchPoint(const QTouchEvent::TouchPoint& point) { // The QTouchEvent::TouchPoint API states that ids will be >= 0. m_id = static_cast<unsigned>(point.id()); switch (point.state()) { case Qt::TouchPointReleased: m_state = TouchReleased; break; case Qt::TouchPointMoved: m_state = TouchMoved; break; case Qt::TouchPointPressed: m_state = TouchPressed; break; case Qt::TouchPointStationary: m_state = TouchStationary; break; } m_screenPos = point.screenPos().toPoint(); m_pos = point.pos().toPoint(); }
PlatformTouchPoint::PlatformTouchPoint(const QTouchEvent::TouchPoint& point, State state) // The QTouchEvent::TouchPoint API states that ids will be >= 0. : m_id(point.id()) , m_state(state) , m_screenPos(point.screenPos().toPoint()) , m_pos(point.pos().toPoint()) { // Qt reports touch point size as rectangles, but we will pretend it is an oval. QRect touchRect = point.rect().toAlignedRect(); if (touchRect.isValid()) { m_radiusX = point.rect().width() / 2; m_radiusY = point.rect().height() / 2; } else { // http://www.w3.org/TR/2011/WD-touch-events-20110505: 1 if no value is known. m_radiusX = 1; m_radiusY = 1; } m_force = point.pressure(); // FIXME: Support m_rotationAngle if QTouchEvent at some point supports it. }
QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { QTapGesture *q = static_cast<QTapGesture *>(state); QTapGesturePrivate *d = q->d_func(); const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture; switch (event->type()) { case QEvent::TouchBegin: { #ifndef QT_WEBOS // REBASE_CHECK_REQUIRED necessary? d->position = ev->touchPoints().at(0).pos(); q->setHotSpot(ev->touchPoints().at(0).screenPos()); #else // QT_WEBOS QTouchEvent::TouchPoint p = ev->touchPoints().at(0); d->position = p.pos(); d->hotSpot = p.screenPos(); d->isHotSpotSet = true; #endif // QT_WEBOS result = QGestureRecognizer::TriggerGesture; break; } case QEvent::TouchUpdate: case QEvent::TouchEnd: { if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) { QTouchEvent::TouchPoint p = ev->touchPoints().at(0); #ifdef QT_WEBOS // REBASE_CHECK_REQUIRED use setHotSpot? d->hotSpot = p.screenPos(); d->isHotSpotSet = true; #endif // QT_WEBOS QPoint delta = p.pos().toPoint() - p.startPos().toPoint(); enum { TapRadius = 40 }; if (delta.manhattanLength() <= TapRadius) { if (event->type() == QEvent::TouchEnd) result = QGestureRecognizer::FinishGesture; else result = QGestureRecognizer::TriggerGesture; } } break; } case QEvent::MouseButtonPress: case QEvent::MouseMove: case QEvent::MouseButtonRelease: result = QGestureRecognizer::Ignore; break; #ifdef QT_WEBOS case QEvent::Gesture: { QGesture* g = static_cast<QGestureEvent*>(event)->gesture(Qt::SysMgrGestureFlick); if (g && g->state() == Qt::GestureFinished && q->state() != Qt::NoGesture ) { result = QGestureRecognizer::CancelGesture; break; } g = static_cast<QGestureEvent*>(event)->gesture(Qt::SysMgrGestureScreenEdgeFlick); if (g && g->state() == Qt::GestureFinished && q->state() != Qt::NoGesture ) { result = QGestureRecognizer::CancelGesture; break; } } // fall through #endif // QT_WEBOS default: result = QGestureRecognizer::Ignore; break; } return result; }
void QtWebPageEventHandler::handleSingleTapEvent(const QTouchEvent::TouchPoint& point) { WebGestureEvent gesture(WebEvent::GestureSingleTap, point.pos().toPoint(), point.screenPos().toPoint(), WebEvent::Modifiers(0), 0); m_webPageProxy->handleGestureEvent(gesture); }
void QtWebPageEventHandler::handleSingleTapEvent(const QTouchEvent::TouchPoint& point) { m_postponeTextInputStateChanged = true; QTransform fromItemTransform = m_webPage->transformFromItem(); WebGestureEvent gesture(WebEvent::GestureSingleTap, fromItemTransform.map(point.pos()).toPoint(), point.screenPos().toPoint(), WebEvent::Modifiers(0), 0, IntSize(point.rect().size().toSize()), FloatPoint(0, 0)); m_webPageProxy->handleGestureEvent(gesture); }
bool QtTapGestureRecognizer::withinDistance(const QTouchEvent::TouchPoint& touchPoint, int distance) { return QLineF(touchPoint.screenPos(), m_lastTouchEvent->touchPoints().first().screenPos()).length() < distance; }
void MScenePrivate::touchPointCopyPosToLastPos(QTouchEvent::TouchPoint &point) { point.setLastPos(point.pos()); point.setLastScenePos(point.scenePos()); point.setLastScreenPos(point.screenPos()); }