void GestureEngine::updateTouchPoint(QTouchEvent::TouchPoint e) { gwc::touchpoint updated_point; updated_point.init(e.id(), e.pos().x() / 1920, e.pos().y()/ 1080, 0, 1, 1); updated_point.status = gwc::TOUCHUPDATE; addEvent(updated_point); }
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 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); }
void GestureEngine::removeTouchPoint(QTouchEvent::TouchPoint e) { gwc::touchpoint removed_point; removed_point.init(e.id(), e.pos().x() / 1920, e.pos().y()/ 1080, 0, 1, 1); removed_point.status = gwc::TOUCHREMOVED; addEvent(removed_point); }
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; }
void GestureEngine::addTouchPoint(QTouchEvent::TouchPoint e) { gwc::touchpoint new_point; new_point.init(e.id(), e.pos().x() / 1920, e.pos().y() / 1080, 0, 1920, 1080); new_point.status = gwc::TOUCHADDED; addEvent(new_point); qDebug() << "Added to Gestureworks"; }
bool TreeViewTouch::event(QEvent *event) { #if QT_VERSION >= 0x050000 if (event->type() == QEvent::TouchBegin && ((QTouchEvent*)event)->device()->type()==QTouchDevice::TouchScreen) { #else if (event->type() == QEvent::TouchBegin && ((QTouchEvent*)event)->deviceType()==QTouchEvent::TouchScreen) { #endif // Register that we may be scrolling, set the scroll mode to scroll-per-pixel // and accept the event (return true) so that we will receive TouchUpdate and TouchEnd/TouchCancel _touchScrollInProgress = true; setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); return true; } if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) { QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0); if (!_firstTouchUpdateHappened) { // After the first movement of a Touch-Point, calculate the distance in both axis // and if the point moved more horizontally abort scroll. double dx = qAbs(p.lastPos().x() - p.pos().x()); double dy = qAbs(p.lastPos().y() - p.pos().y()); if (dx > dy) { _touchScrollInProgress = false; } _firstTouchUpdateHappened = true; } // Apply touch movement to scrollbar verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y())); return true; } #if QT_VERSION >= 0x050000 if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) { #else if (event->type() == QEvent::TouchEnd) { #endif // End scroll and reset variables _touchScrollInProgress = false; _firstTouchUpdateHappened = false; return true; } return QTreeView::event(event); } void TreeViewTouch::mousePressEvent(QMouseEvent *event) { if (!_touchScrollInProgress) QTreeView::mousePressEvent(event); } void TreeViewTouch::mouseMoveEvent(QMouseEvent *event) { if (!_touchScrollInProgress) QTreeView::mouseMoveEvent(event); };
void MainGraphicsView::processTouchEvent(QTouchEvent *touchEvent) { QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); //qDebug("touch event %d count %d", event->type(), touchPoints.count()); if( touchPoints.count() > 1 ) { this->has_kinetic_scroll = false; this->single_left_mouse_down = false; // can't trust last mouse position if more that one touch! this->has_last_mouse = false; } #if QT_VERSION >= 0x050000 #ifdef Q_OS_ANDROID // on Android with Qt 5, mouse events are never received, instead it's done purely via touch events if( touchPoints.count() == 1 ) { QTouchEvent::TouchPoint touchPoint = touchPoints.at(0); int m_x = touchPoint.pos().x(); int m_y = touchPoint.pos().y(); if( touchEvent->type() == QEvent::TouchBegin ) { this->mousePress(m_x, m_y); } else if( touchEvent->type() == QEvent::TouchEnd ) { this->mouseRelease(m_x, m_y); } else if( touchEvent->type() == QEvent::TouchUpdate ) { this->mouseMove(m_x, m_y); } } #endif #endif if( touchPoints.count() == 2 ) { // determine scale factor const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); /*float scale_factor = QLineF(touchPoint0.pos(), touchPoint1.pos()).length() / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();*/ QPointF touch_centre = (touchPoint0.pos() + touchPoint1.pos())*0.5; QPointF zoom_centre = this->mapToScene(QPoint(touch_centre.x(), touch_centre.y())); float scale_factor = QLineF(touchPoint0.pos(), touchPoint1.pos()).length() / QLineF(touchPoint0.lastPos(), touchPoint1.lastPos()).length(); /*if (touchEvent->touchPointStates() & Qt::TouchPointReleased) { // if one of the fingers is released, remember the current scale // factor so that adding another finger later will continue zooming // by adding new scale factor to the existing remembered value. totalScaleFactor *= currentScaleFactor; currentScaleFactor = 1; }*/ /*setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor, totalScaleFactor * currentScaleFactor));*/ float n_scale = c_scale *scale_factor; //LOG("multitouch scale: %f : %f\n", scale_factor, n_scale); this->setScale(zoom_centre, n_scale); } }
void QtWebPageEventHandler::activateTapHighlight(const QTouchEvent::TouchPoint& point) { #if ENABLE(TOUCH_EVENTS) ASSERT(!point.pos().toPoint().isNull()); ASSERT(!m_isTapHighlightActive); m_isTapHighlightActive = true; QTransform fromItemTransform = m_webPage->transformFromItem(); m_webPageProxy->handlePotentialActivation(IntPoint(fromItemTransform.map(point.pos()).toPoint()), IntSize(point.rect().size().toSize())); #else Q_UNUSED(point); #endif }
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); }
QGestureRecognizer::Result WebosTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, QEvent *event) { QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture; WebosTapAndHoldGesture *q = static_cast<WebosTapAndHoldGesture *>(state); if (object == state && event->type() == QEvent::Timer) { q->stopTapTimer(); if (q->state() != Qt::NoGesture && q->state() != Qt::GestureCanceled) { result = QGestureRecognizer::FinishGesture; } return result | QGestureRecognizer::ConsumeEventHint; } const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); //Todo Here use a const value to set up the timer interval but maybe need to use the Timeout value //enum { TimerInterval = 700 }; enum { TapRadius = 40 }; switch (event->type()) { case QEvent::TouchBegin: q->setPosition(ev->touchPoints().at(0).startScreenPos()); q->setHotSpot(q->position()); q->stopTapTimer(); q->startTapTimer(); return QGestureRecognizer::TriggerGesture; case QEvent::TouchEnd: result = QGestureRecognizer::CancelGesture; q->stopTapTimer(); break; case QEvent::TouchUpdate: if (q->tapTimerId() && ev->touchPoints().size() == 1) { QTouchEvent::TouchPoint p = ev->touchPoints().at(0); QPoint delta = p.pos().toPoint() - p.startPos().toPoint(); if (delta.manhattanLength() > TapRadius) { result = QGestureRecognizer::CancelGesture; q->stopTapTimer(); } else { result = QGestureRecognizer::Ignore; } } else if (ev->touchPoints().size() > 1) { result = QGestureRecognizer::CancelGesture; q->stopTapTimer(); } else { result = QGestureRecognizer::Ignore; } break; default: return QGestureRecognizer::Ignore; } return result; }
QGestureRecognizer::Result QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, QEvent *event) { QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state); QTapAndHoldGesturePrivate *d = q->d_func(); if (object == state && event->type() == QEvent::Timer) { q->killTimer(d->timerId); d->timerId = 0; return QGestureRecognizer::Ignore | QGestureRecognizer::ConsumeEventHint; } const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture; enum { TimerInterval = 2000 }; enum { TapRadius = 40 }; switch (event->type()) { case QEvent::TouchBegin: d->position = ev->touchPoints().at(0).pos(); if (d->timerId) q->killTimer(d->timerId); d->timerId = q->startTimer(TimerInterval); result = QGestureRecognizer::TriggerGesture; break; case QEvent::TouchEnd: if (d->timerId) result = QGestureRecognizer::CancelGesture; else result = QGestureRecognizer::FinishGesture; break; case QEvent::TouchUpdate: if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) { QTouchEvent::TouchPoint p = ev->touchPoints().at(0); QPoint delta = p.pos().toPoint() - p.startPos().toPoint(); if (delta.manhattanLength() <= TapRadius) result = QGestureRecognizer::TriggerGesture; } break; case QEvent::MouseButtonPress: case QEvent::MouseMove: case QEvent::MouseButtonRelease: result = QGestureRecognizer::Ignore; break; default: result = QGestureRecognizer::Ignore; break; } return result; }
QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &s) { dbg.nospace() << "\"TouchPoint\":" << "{ \"id\":" << s.id() #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) << ", \"primary\":\"" << (s.isPrimary() ? "true" : "false") << "\"" #endif << ", \"state\":" << touchStateToString(s.state()) << ", \"pos\":\"" << s.pos() << "\"" << ", \"pressure\":\"" << s.pressure() << "\"" << " }"; return dbg.space(); }
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(); }
static QTouchEvent::TouchPoint touchPoint(qreal x, qreal y) { QPointF localPos(x, y); QTouchEvent::TouchPoint point; point.setId(1); point.setLastPos(localPos); QRectF touchRect(0, 0, 40, 40); touchRect.moveCenter(localPos); point.setRect(touchRect); point.setPressure(1); return point; }
void QtWebPageEventHandler::handlePotentialSingleTapEvent(const QTouchEvent::TouchPoint& point) { #if ENABLE(TOUCH_EVENTS) if (point.pos() == QPointF()) { // An empty point deactivates the highlighting. m_webPageProxy->handlePotentialActivation(IntPoint(), IntSize()); } else { QTransform fromItemTransform = m_webPage->transformFromItem(); m_webPageProxy->handlePotentialActivation(IntPoint(fromItemTransform.map(point.pos()).toPoint()), IntSize(point.rect().size().toSize())); } #else Q_UNUSED(point); #endif }
bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) { if (_currentWebCount >= MAX_CONCURRENT_WEB_VIEWS) { qWarning() << "Too many concurrent web views to create new view"; return false; } qDebug() << "Building web surface"; ++_currentWebCount; // Save the original GL context, because creating a QML surface will create a new context QOpenGLContext * currentContext = QOpenGLContext::currentContext(); QSurface * currentSurface = currentContext->surface(); _webSurface = new OffscreenQmlSurface(); _webSurface->create(currentContext); _webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/controls/")); _webSurface->load("WebView.qml"); _webSurface->resume(); _webSurface->getRootItem()->setProperty("url", _sourceUrl); _webSurface->getRootContext()->setContextProperty("desktop", QVariant()); _connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) { _texture = textureId; }); // Restore the original GL context currentContext->makeCurrent(currentSurface); auto forwardPointerEvent = [=](const EntityItemID& entityItemID, const PointerEvent& event) { if (entityItemID == getID()) { handlePointerEvent(event); } }; _mousePressConnection = QObject::connect(renderer, &EntityTreeRenderer::mousePressOnEntity, forwardPointerEvent); _mouseReleaseConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseReleaseOnEntity, forwardPointerEvent); _mouseMoveConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseMoveOnEntity, forwardPointerEvent); _hoverLeaveConnection = QObject::connect(renderer, &EntityTreeRenderer::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const PointerEvent& event) { if (this->_pressed && this->getID() == entityItemID) { // If the user mouses off the entity while the button is down, simulate a touch end. QTouchEvent::TouchPoint point; point.setId(event.getID()); point.setState(Qt::TouchPointReleased); glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); QPointF windowPoint(windowPos.x, windowPos.y); point.setPos(windowPoint); QList<QTouchEvent::TouchPoint> touchPoints; touchPoints.push_back(point); QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, touchPoints); QCoreApplication::postEvent(_webSurface->getWindow(), touchEvent); } }); return true; }
void MScenePrivate::touchPointMirrorMousePosToPointStartPos(QTouchEvent::TouchPoint &point, const QGraphicsSceneMouseEvent *event) { Q_Q(MScene); if (q->views().size() > 0) { QPointF windowPos(q->views().at(0)->pos()); QSize resolution = MDeviceProfile::instance()->resolution(); QPointF centerPoint(resolution.width() / 2, resolution.height() / 2); QPointF mirrorPoint = centerPoint + (centerPoint - event->screenPos() + windowPos); point.setStartPos(mirrorPoint); point.setStartScenePos(mirrorPoint); point.setStartScreenPos(mirrorPoint + windowPos); } }
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); }
void QWindowSystemInterface::handleTouchEvent(QWidget *tlw, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList<struct TouchPoint> &points) { if (!points.size()) // Touch events must have at least one point return; QList<QTouchEvent::TouchPoint> touchPoints; Qt::TouchPointStates states; QTouchEvent::TouchPoint p; QList<struct TouchPoint>::const_iterator point = points.constBegin(); QList<struct TouchPoint>::const_iterator end = points.constEnd(); while (point != end) { p.setId(point->id); p.setPressure(point->pressure); states |= point->state; Qt::TouchPointStates state = point->state; if (point->isPrimary) { state |= Qt::TouchPointPrimary; } p.setState(state); p.setRect(point->area); p.setScreenPos(point->area.center()); p.setNormalizedPos(point->normalPosition); touchPoints.append(p); ++point; } QWindowSystemInterfacePrivate::TouchEvent *e = new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, devType, touchPoints); QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); }
void QtWebPageEventHandler::handleDoubleTapEvent(const QTouchEvent::TouchPoint& point) { if (!m_webView->isInteractive()) return; deactivateTapHighlight(); QTransform fromItemTransform = m_webPage->transformFromItem(); m_webPageProxy->findZoomableAreaForPoint(fromItemTransform.map(point.pos()).toPoint(), IntSize(point.rect().size().toSize())); }
void QtPanGestureRecognizer::finish(const QTouchEvent::TouchPoint& touchPoint, qint64 eventTimestampMillis) { if (m_state == NoGesture) return; ASSERT(viewportHandler()); viewportHandler()->panGestureEnded(touchPoint.pos(), eventTimestampMillis); reset(); }
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: { d->position = ev->touchPoints().at(0).pos(); q->setHotSpot(ev->touchPoints().at(0).screenPos()); 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); 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; default: result = QGestureRecognizer::Ignore; break; } return result; }
void TouchInputDevice::processTouch(QEvent *e) { m_numPoints = 0; QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e); QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); for (int i = 0; i < points.size(); i++) { QTouchEvent::TouchPoint point = points.at(i); if (point.state() & Qt::TouchPointReleased) continue; m_points[m_numPoints] = point.pos().toPoint(); m_numPoints++; if (m_numPoints >= MaxPoints) break; } m_converted = false; }
QTouchEvent::TouchPoint makeTouchPointFromMouseEvent(QMouseEvent *event, Qt::TouchPointState state) { QTouchEvent::TouchPoint newPoint; #if defined ( QT_4 ) newPoint.setPos(event->posF()); newPoint.setScenePos(event->globalPos()); newPoint.setScreenPos(event->globalPos()); #elif defined ( QT_5 ) newPoint.setPos(event->localPos()); newPoint.setScenePos(event->windowPos()); newPoint.setScreenPos(event->screenPos()); #endif newPoint.setState(state); newPoint.setId(0); return newPoint; }
/*! \internal */ QTouchEvent::TouchPoint makeTouchPointFromMouseEvent(QMouseEvent *event, Qt::TouchPointState state) { // this is only partially filled. But since it is only partially used it works // more robust would be to store a list of QPointFs rather than TouchPoints QTouchEvent::TouchPoint newPoint; newPoint.setPos(event->localPos()); newPoint.setScenePos(event->windowPos()); newPoint.setScreenPos(event->screenPos()); newPoint.setState(state); newPoint.setId(0); return newPoint; }
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); }
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. }
bool ModelSelectionPane::eventFilter(QObject *obj, QEvent *event) { bool flipAction = false; static float last_x = 0.0f; static float touchBeginLastX = 0.0f; int deltaX = 0; float acceleration = 0.0f; switch(event->type()) { #if 0 case QEvent::TouchBegin: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchBegin"; flipAction = true; m_time.start(); const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); last_x = touchPoint.pos().x(); touchBeginLastX = touchPoint.pos().x(); } break; case QEvent::TouchUpdate: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchUpdate"; flipAction = true; const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); deltaX = touchPoint.pos().x() - last_x; last_x = touchPoint.pos().x(); } break; case QEvent::TouchEnd: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchEnd"; flipAction = true; const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); int elapseTime = m_time.elapsed(); LogManagerInst << LogManager::LogDegreeType_Normal << "elapseTime" << QString::number(elapseTime); deltaX = touchPoint.pos().x() - last_x; acceleration = (touchPoint.pos().x() - touchBeginLastX) / elapseTime; } break; #else case QEvent::MouseButtonPress: { // LogManagerInst << LogManager::LogDegreeType_Normal << "TouchBegin"; flipAction = true; m_time.start(); const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); last_x = mouseEvent->x(); touchBeginLastX = mouseEvent->x(); } break; case QEvent::MouseMove: { // LogManagerInst << LogManager::LogDegreeType_Normal << "TouchUpdate"; flipAction = true; const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); deltaX = mouseEvent->x() - last_x; last_x = mouseEvent->x(); } break; case QEvent::MouseButtonRelease: { // LogManagerInst << LogManager::LogDegreeType_Normal << "TouchEnd"; flipAction = true; int elapseTime = m_time.elapsed(); // LogManagerInst << LogManager::LogDegreeType_Normal << "elapseTime" << QString::number(elapseTime); const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); deltaX = mouseEvent->x() - last_x; acceleration = (mouseEvent->x() - touchBeginLastX) / elapseTime; } break; #endif default: break; } if(flipAction) { // const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); // QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); // LogManagerInst << LogManager::LogDegreeType_Normal << "FlipInfo" // << "deltaX" << QString::number(deltaX) // << "acceleration" << QString::number(acceleration); // << "TouchPostion" << QString::number(touchPoint.pos().x()) // << "TouchPoints" << QString::number(touchEvent->touchPoints().size()); if(acceleration != 0) { if((acceleration > 1) || (deltaX > width()/2)) { FlipAnimationStart(deltaX > 0 ? FlipDirection_Right : FlipDirection_Left); } } else { // LogManagerInst << LogManager::LogDegreeType_Normal << "Position" << QString::number(ui->itemsetpane->x()); QPoint targetPos = ui->itemsetpane->pos()+QPoint(deltaX,0); if(targetPos.x() > width()/4) { targetPos.setX(width()/4); } else if(targetPos.x() < width() - m_itemSetPaneSize.width() - width()/4) { targetPos.setX(width() - m_itemSetPaneSize.width() - width()/4); } else { } qDebug() << ui->itemsetpane->pos(); ui->itemsetpane->move(targetPos); // ui->itemsetpane->update(); // this->move(targetPos); } } return obj->event(event); }
bool ModelSelectionPane::event(QEvent *event) { #if 0 if(event->type() == QEvent::Gesture) { LogManagerInst << LogManager::LogDegreeType_Normal << "QEvent::Gesture"; QGestureEvent* gestureEvent = static_cast<QGestureEvent*>(event); QGesture *gesture = gestureEvent->gesture(Qt::PanGesture); if(NULL == gestureEvent) { LogManagerInst << LogManager::LogDegreeType_Error << "QEvent::Gesture is NULL"; }else { QList<QGesture *> gestures = gestureEvent->gestures(); QList<QGesture *> activeGestures = gestureEvent->activeGestures(); LogManagerInst << "Gesture Value" << QString::number((int)gesture, 16); LogManagerInst << LogManager::LogDegreeType_Normal << "Gesture Count" << QString::number(gestures.count()) << "activeGestures Count" << QString::number(activeGestures.count()); LogManagerInst << LogManager::LogDegreeType_Normal << (gestureEvent->gesture(Qt::TapGesture) != NULL?"TapGesture":"") << (gestureEvent->gesture(Qt::TapAndHoldGesture) != NULL?"TapAndHoldGesture":"") << ((NULL != gesture)?"PanGesture":"") << (gestureEvent->gesture(Qt::PinchGesture) != NULL?"PinchGesture":"") << (gestureEvent->gesture(Qt::SwipeGesture) != NULL?"SwipeGesture":"") ; } LogManagerInst << (gesture == NULL?"PanGesture == NULL":"PanGesture != NULL"); if(gesture != NULL) { LogManagerInst << LogManager::LogDegreeType_Normal << "Handle Pan Gesture"; QPanGesture* panGesture = static_cast<QPanGesture*>(gesture); LogManagerInst << LogManager::LogDegreeType_Normal << "Acceleration" << QString::number(panGesture->acceleration()); LogManagerInst << LogManager::LogDegreeType_Normal << "delta" << QString::number(panGesture->delta().x()); LogManagerInst << LogManager::LogDegreeType_Normal << "State" << QString::number(gesture->state()); if(gesture->state() == Qt::GestureFinished) { if((panGesture->acceleration() > 2) || (panGesture->delta().x() > width()/2)) { FlipAnimationStart(panGesture->delta().x() > 0 ? FlipDirection_Right : FlipDirection_Left); } } else { LogManagerInst << LogManager::LogDegreeType_Normal << "Position" << QString::number(ui->itemsetpane->x()); QPoint targetPos = ui->itemsetpane->pos()+QPoint(panGesture->delta().x(),0); if(targetPos.x() > width()/4) { targetPos.setX(width()/4); } else if(targetPos.x() < width() - m_itemSetPaneSize.width() - width()/4) { targetPos.setX(width() - m_itemSetPaneSize.width() - width()/4); } else { } ui->itemsetpane->move(targetPos); } } } #endif #if 1 /***** * 外面是阴天,我也成了阴天 * 狗屎的Gesture * Document明明图示QPanGesture是一个手指 * 源码里却他妈的是3个 * 你他妈的逗我么 * 我就是个秀逗 * 明天dota只能用秀逗了 * 悲剧啊悲剧啊 * 我的时间 * 如同我的身体老去 *****/ bool flipAction = false; static float last_x = 0.0f; static float touchBeginLastX = 0.0f; int deltaX = 0; float acceleration = 0.0f; switch(event->type()) { #if 1 case QEvent::TouchBegin: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchBegin"; flipAction = true; m_time.start(); const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); last_x = touchPoint.pos().x(); touchBeginLastX = touchPoint.pos().x(); } break; case QEvent::TouchUpdate: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchUpdate"; flipAction = true; const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); deltaX = touchPoint.pos().x() - last_x; last_x = touchPoint.pos().x(); } break; case QEvent::TouchEnd: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchEnd"; flipAction = true; const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); int elapseTime = m_time.elapsed(); LogManagerInst << LogManager::LogDegreeType_Normal << "elapseTime" << QString::number(elapseTime); deltaX = touchPoint.pos().x() - last_x; acceleration = (touchPoint.pos().x() - touchBeginLastX) / elapseTime; } break; #else case QEvent::MouseButtonPress: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchBegin"; flipAction = true; m_time.start(); const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); last_x = mouseEvent->x(); touchBeginLastX = mouseEvent->x(); } break; case QEvent::MouseMove: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchUpdate"; flipAction = true; const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); deltaX = mouseEvent->x() - last_x; last_x = mouseEvent->x(); } break; case QEvent::MouseButtonRelease: { LogManagerInst << LogManager::LogDegreeType_Normal << "TouchEnd"; flipAction = true; int elapseTime = m_time.elapsed(); LogManagerInst << LogManager::LogDegreeType_Normal << "elapseTime" << QString::number(elapseTime); const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); deltaX = mouseEvent->x() - last_x; acceleration = (mouseEvent->x() - touchBeginLastX) / elapseTime; } break; #endif default: break; } if(flipAction) { // const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event); // QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first(); LogManagerInst << LogManager::LogDegreeType_Normal << "FlipInfo" << "deltaX" << QString::number(deltaX) << "acceleration" << QString::number(acceleration); // << "TouchPostion" << QString::number(touchPoint.pos().x()) // << "TouchPoints" << QString::number(touchEvent->touchPoints().size()); if(acceleration != 0) { if((acceleration > 1) || (deltaX > width()/2)) { FlipAnimationStart(deltaX > 0 ? FlipDirection_Right : FlipDirection_Left); } } else { LogManagerInst << LogManager::LogDegreeType_Normal << "Position" << QString::number(ui->itemsetpane->x()); QPoint targetPos = ui->itemsetpane->pos()+QPoint(deltaX,0); if(targetPos.x() > width()/4) { targetPos.setX(width()/4); } else if(targetPos.x() < width() - m_itemSetPaneSize.width() - width()/4) { targetPos.setX(width() - m_itemSetPaneSize.width() - width()/4); } else { } ui->itemsetpane->move(targetPos); ui->itemsetpane->update(); } } #endif return PaneBase::event(event); }