bool QGraphicsMozView::event(QEvent* event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent* touch = static_cast<QTouchEvent*>(event); if (!mUseQmlMouse || touch->touchPoints().size() > 1) { d->touchEvent(touch); } return true; } case QEvent::Show: { LOGT("Event Show: curCtx:%p", (void*)QGLContext::currentContext()); break; } case QEvent::Hide: { LOGT("Event Hide"); break; } default: break; } // Here so that it can be reimplemented without breaking ABI. return QGraphicsWidget::event(event); }
void TestHsDomainModel::testWidgetTouchAreaSceneEvent() { HsWidgetHost *widget = new HsWidgetHost(-1); HsWidgetTouchArea *widgetTouchArea = new HsWidgetTouchArea(widget->visual()); HsScene *scene = HsScene::instance(); // test shape fetch QPainterPath *path = new QPainterPath(widgetTouchArea->shape()); QVERIFY(path); delete path; QSignalSpy widgetTapStartedSpy(scene, SIGNAL(widgetTapStarted(QPointF,HsWidgetHost*))); QSignalSpy widgetMoveFinishedSpy(scene, SIGNAL(widgetMoveFinished(const QPointF &, HsWidgetHost*))); // test touch begin QTouchEvent::TouchPoint touchPoint; QList<QTouchEvent::TouchPoint> touchPoints; touchPoints.append(touchPoint); QTouchEvent *touchEvent = new QTouchEvent(QEvent::TouchBegin); touchEvent->setTouchPoints(touchPoints); widgetTouchArea->sceneEvent(touchEvent); QCOMPARE(widgetTapStartedSpy.count(), 1); delete widgetTouchArea; delete widget; }
bool QDeclarativePinchArea::event(QEvent *event) { Q_D(QDeclarativePinchArea); if (!d->absorb || !isVisible()) return QDeclarativeItem::event(event); switch (event->type()) { case QEvent::TouchBegin: d->touchEventsActive = true; // No break, continue to next case. case QEvent::TouchUpdate: if (d->touchEventsActive) { QTouchEvent *touch = static_cast<QTouchEvent*>(event); d->touchPoints.clear(); for (int i = 0; i < touch->touchPoints().count(); ++i) { if (!(touch->touchPoints().at(i).state() & Qt::TouchPointReleased)) { d->touchPoints << touch->touchPoints().at(i); } } updatePinch(); return true; } break; case QEvent::WindowDeactivate: // No break, continue to next case. case QEvent::TouchEnd: d->touchEventsActive = false; d->touchPoints.clear(); updatePinch(); break; default: return QDeclarativeItem::event(event); } return QDeclarativeItem::event(event); }
bool QDeclarativePinchArea::sceneEventFilter(QGraphicsItem *i, QEvent *e) { Q_D(QDeclarativePinchArea); if (!d->absorb || !isVisible()) return QDeclarativeItem::sceneEventFilter(i, e); switch (e->type()) { case QEvent::GraphicsSceneMousePress: case QEvent::GraphicsSceneMouseMove: case QEvent::GraphicsSceneMouseRelease: return sendMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e)); break; case QEvent::TouchBegin: case QEvent::TouchUpdate: { QTouchEvent *touch = static_cast<QTouchEvent*>(e); d->touchPoints.clear(); for (int i = 0; i < touch->touchPoints().count(); ++i) if (!(touch->touchPoints().at(i).state() & Qt::TouchPointReleased)) d->touchPoints << touch->touchPoints().at(i); updatePinch(); } return d->inPinch; case QEvent::TouchEnd: d->touchPoints.clear(); updatePinch(); break; default: break; } return QDeclarativeItem::sceneEventFilter(i, e); }
bool QQuickPinchArea::childMouseEventFilter(QQuickItem *i, QEvent *e) { Q_D(QQuickPinchArea); if (!d->enabled || !isVisible()) return QQuickItem::childMouseEventFilter(i, e); switch (e->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: { QTouchEvent *touch = static_cast<QTouchEvent*>(e); if (touch->touchPoints().count() > 1) { touchEvent(touch); } else { d->touchPoints.clear(); for (int i = 0; i < touch->touchPoints().count(); ++i) if (!(touch->touchPoints().at(i).state() & Qt::TouchPointReleased)) d->touchPoints << touch->touchPoints().at(i); updatePinch(); } } return d->inPinch; case QEvent::TouchEnd: d->touchPoints.clear(); updatePinch(); break; default: break; } return QQuickItem::childMouseEventFilter(i, e); }
bool Knob::sceneEvent(QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); if (touchEvent->touchPoints().count() == 2) { const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first(); const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last(); QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos()); QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos()); rotate(line2.angleTo(line1)); } break; } default: return QGraphicsItem::sceneEvent(event); } return true; }
bool StelSkyItem::event(QEvent * e) { switch (e->type()){ case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e); QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); if (touchPoints.count() == 1) setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton); return true; break; } case QEvent::Gesture: setAcceptedMouseButtons(0); return gestureEvent(static_cast<QGestureEvent*>(e)); break; default: return QGraphicsWidget::event(e); } }
bool GraphicsView::viewportEvent(QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); if (touchPoints.count() == 2) { // determine scale factor const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); qreal currentScaleFactor = QLineF(touchPoint0.pos(), touchPoint1.pos()).length() / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).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)); } return true; } default: break; } return QGraphicsView::viewportEvent(event); }
bool Knob::sceneEvent(QEvent *event) { switch (event->type()) { case QEvent::TouchBegin:{ qDebug("start!!! ") ; // emit startTouch(); break; } case QEvent::TouchUpdate:{ qDebug("UPDATE!!! ") ; QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first(); qDebug()<< touchPoint1.scenePos().x()<< " + " <<touchPoint1.scenePos().y(); leftItem->setPos(touchPoint1.scenePos().x()-140,touchPoint1.scenePos().y()-140 ); // emit sendPos(touchPoint1.scenePos().x()-140,touchPoint1.scenePos().y()-140); break; } case QEvent::TouchEnd: { // emit stopTouch(); break; } default: return QGraphicsItem::sceneEvent(event); } return true; }
bool QDeclarativePinchArea::event(QEvent *event) { Q_D(QDeclarativePinchArea); if (!d->absorb || !isVisible()) return QDeclarativeItem::event(event); switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: { QTouchEvent *touch = static_cast<QTouchEvent*>(event); d->touchPoints.clear(); for (int i = 0; i < touch->touchPoints().count(); ++i) { if (!(touch->touchPoints().at(i).state() & Qt::TouchPointReleased)) { d->touchPoints << touch->touchPoints().at(i); } } updatePinch(); } return true; case QEvent::TouchEnd: d->touchPoints.clear(); updatePinch(); break; default: return QDeclarativeItem::event(event); } return QDeclarativeItem::event(event); }
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 ReticleHandler::eventFilter(QObject *, QEvent *event) { static bool show = true; switch (event->type()) { case QEvent::TouchBegin: show = true; break; case QEvent::TouchUpdate: show = false; break; case QEvent::TouchCancel: show = false; break; case QEvent::TouchEnd: { if (show) { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); QPointF fpoint = touchPoint.pos(); int x = static_cast<int>(fpoint.x()); int y = static_cast<int>(fpoint.y()); QScreen *primaryScreen = QGuiApplication::primaryScreen(); QTransform lOrientationTranform = primaryScreen->transformBetween(primaryScreen->orientation(), primaryScreen->primaryOrientation(), primaryScreen->geometry()).inverted(); emit reticleEvent(lOrientationTranform.map(QPoint(x,y))); }; show = false; } break; } return false; }
bool ReticleHandler::eventFilter(QObject *, QEvent *event) { static bool show = true; switch (event->type()) { case QEvent::TouchBegin: show = true; break; case QEvent::TouchUpdate: show = false; break; case QEvent::TouchCancel: show = false; break; case QEvent::TouchEnd: { if (show) { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); QPointF fpoint = touchPoint.pos(); int x = static_cast<int>(fpoint.x()); int y = static_cast<int>(fpoint.y()); QPoint point(x,y); emit reticleEvent(point); }; show = false; } break; } return false; }
bool ScrollArea::viewportEvent(QEvent *e) { if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) { QTouchEvent *ev = static_cast<QTouchEvent*>(e); if (_touchEnabled && ev->device()->type() == QTouchDevice::TouchScreen) { touchEvent(ev); return true; } } return QScrollArea::viewportEvent(e); }
bool FlatLabel::event(QEvent *e) { if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) { QTouchEvent *ev = static_cast<QTouchEvent*>(e); if (ev->device()->type() == QTouchDevice::TouchScreen) { touchEvent(ev); return true; } } return QWidget::event(e); }
bool InputField::InputFieldInner::viewportEvent(QEvent *e) { if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) { QTouchEvent *ev = static_cast<QTouchEvent*>(e); if (ev->device()->type() == QTouchDevice::TouchScreen) { qobject_cast<InputField*>(parentWidget())->touchEvent(ev); return QTextEdit::viewportEvent(e); } } return QTextEdit::viewportEvent(e); }
bool FlatTextarea::viewportEvent(QEvent *e) { if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) { QTouchEvent *ev = static_cast<QTouchEvent*>(e); if (ev->device()->type() == QTouchDevice::TouchScreen) { touchEvent(ev); return QTextEdit::viewportEvent(e); } } return QTextEdit::viewportEvent(e); }
QTouchEvent *TouchDispatcher::createQTouchEvent(QEvent::Type eventType, QTouchDevice *device, Qt::KeyboardModifiers modifiers, const QList<QTouchEvent::TouchPoint> &touchPoints, QWindow *window, ulong timestamp) { Qt::TouchPointStates eventStates = 0; for (int i = 0; i < touchPoints.count(); i++) eventStates |= touchPoints[i].state(); // if all points have the same state, set the event type accordingly switch (eventStates) { case Qt::TouchPointPressed: eventType = QEvent::TouchBegin; break; case Qt::TouchPointReleased: eventType = QEvent::TouchEnd; break; default: eventType = QEvent::TouchUpdate; break; } QTouchEvent *touchEvent = new QTouchEvent(eventType); touchEvent->setWindow(window); touchEvent->setTarget(m_targetItem.data()); touchEvent->setDevice(device); touchEvent->setModifiers(modifiers); touchEvent->setTouchPoints(touchPoints); touchEvent->setTouchPointStates(eventStates); touchEvent->setTimestamp(timestamp); touchEvent->accept(); return touchEvent; }
bool WWidget::event(QEvent* e) { if (e->type() == QEvent::ToolTip) { updateTooltip(); } else if (isEnabled()) { switch(e->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent* touchEvent = dynamic_cast<QTouchEvent*>(e); if (touchEvent->deviceType() != QTouchEvent::TouchScreen) { break; } // fake a mouse event! QEvent::Type eventType = QEvent::None; switch (touchEvent->type()) { case QEvent::TouchBegin: eventType = QEvent::MouseButtonPress; if (touchIsRightButton()) { // touch is right click m_activeTouchButton = Qt::RightButton; } else { m_activeTouchButton = Qt::LeftButton; } break; case QEvent::TouchUpdate: eventType = QEvent::MouseMove; break; case QEvent::TouchEnd: eventType = QEvent::MouseButtonRelease; break; default: DEBUG_ASSERT(false); break; } const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); QMouseEvent mouseEvent(eventType, touchPoint.pos().toPoint(), touchPoint.screenPos().toPoint(), m_activeTouchButton, // Button that causes the event Qt::NoButton, // Not used, so no need to fake a proper value. touchEvent->modifiers()); return QWidget::event(&mouseEvent); } default: break; } } return QWidget::event(e); }
bool LipstickCompositorWindow::eventFilter(QObject *obj, QEvent *event) { #if QT_VERSION >= 0x050202 if (obj == window() && m_interceptingTouch) { switch (event->type()) { case QEvent::TouchUpdate: { QTouchEvent *te = static_cast<QTouchEvent *>(event); // If we get press/release, don't intercept the event, but send it through QQuickWindow. // These are sent through to QQuickWindow so that the integrity of the touch // handling is maintained. if (te->touchPointStates() & (Qt::TouchPointPressed | Qt::TouchPointReleased)) return false; handleTouchEvent(static_cast<QTouchEvent *>(event)); return true; } case QEvent::TouchEnd: // Intentional fall through... case QEvent::TouchCancel: obj->removeEventFilter(this); m_interceptingTouch = false; default: break; } return false; } #else Q_UNUSED(obj); #endif if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { QKeyEvent *ke = static_cast<QKeyEvent *>(event); QWaylandSurface *m_surface = surface(); if (m_surface && (m_grabbedKeys.contains(ke->key()) || m_pressedGrabbedKeys.keys.contains(ke->key())) && !ke->isAutoRepeat()) { QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); if (event->type() == QEvent::KeyPress) { if (m_pressedGrabbedKeys.keys.isEmpty()) { QWaylandSurface *old = inputDevice->keyboardFocus(); m_pressedGrabbedKeys.oldFocus = old; inputDevice->setKeyboardFocus(m_surface); } m_pressedGrabbedKeys.keys << ke->key(); } inputDevice->sendFullKeyEvent(ke); if (event->type() == QEvent::KeyRelease) { m_pressedGrabbedKeys.keys.removeOne(ke->key()); if (m_pressedGrabbedKeys.keys.isEmpty()) { inputDevice->setKeyboardFocus(m_pressedGrabbedKeys.oldFocus); if (m_grabbedKeys.isEmpty()) qApp->removeEventFilter(this); } } return true; } } return false; }
bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent, QTabletEvent *lastTabletEvent, const QPoint &canvasOriginWorkaround) { bool retval = true; QTabletEvent *tabletEvent = dynamic_cast<QTabletEvent*>(event); QTouchEvent *touchEvent = dynamic_cast<QTouchEvent*>(event); QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event); if (tabletEvent) { QPointF docPoint = tabletToDocument(tabletEvent->hiResGlobalPos(), canvasOriginWorkaround); tabletEvent->accept(); this->tabletEvent(tabletEvent, docPoint); forwardToTool(state, action, tabletEvent, docPoint); retval = tabletEvent->isAccepted(); } else if (touchEvent) { if (state == END && touchEvent->type() != QEvent::TouchEnd) { //Fake a touch end if we are "upgrading" a single-touch gesture to a multi-touch gesture. QTouchEvent fakeEvent(QEvent::TouchEnd, touchEvent->deviceType(), touchEvent->modifiers(), touchEvent->touchPointStates(), touchEvent->touchPoints()); this->touchEvent(&fakeEvent); } else { this->touchEvent(touchEvent); } } else if (mouseEvent) { if (lastTabletEvent) { QPointF docPoint = tabletToDocument(lastTabletEvent->hiResGlobalPos(), canvasOriginWorkaround); lastTabletEvent->accept(); this->tabletEvent(lastTabletEvent, docPoint); forwardToTool(state, action, lastTabletEvent, docPoint); retval = lastTabletEvent->isAccepted(); } else { QPointF docPoint = widgetToDocument(mouseEvent->posF()); mouseEvent->accept(); if (mouseEvent->type() == QEvent::MouseButtonPress) { mousePressEvent(mouseEvent, docPoint); } else if (mouseEvent->type() == QEvent::MouseButtonDblClick) { mouseDoubleClickEvent(mouseEvent, docPoint); } else if (mouseEvent->type() == QEvent::MouseButtonRelease) { mouseReleaseEvent(mouseEvent, docPoint); } else if (mouseEvent->type() == QEvent::MouseMove) { mouseMoveEvent(mouseEvent, docPoint); } forwardToTool(state, action, originalEvent, docPoint); retval = mouseEvent->isAccepted(); } } else if(event->type() == QEvent::KeyPress) { QKeyEvent* kevent = static_cast<QKeyEvent*>(event); keyPressEvent(kevent); } else if(event->type() == QEvent::KeyRelease) { QKeyEvent* kevent = static_cast<QKeyEvent*>(event); keyReleaseEvent(kevent); } return retval; }
bool ScrollArea::viewportEvent(QEvent *e) { if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) { QTouchEvent *ev = static_cast<QTouchEvent*>(e); if (_touchEnabled && ev->device()->type() == QTouchDevice::TouchScreen) { if (ev->type() != QEvent::TouchBegin || ev->touchPoints().isEmpty() || !widget() || !widget()->childAt(widget()->mapFromGlobal(ev->touchPoints().cbegin()->screenPos().toPoint()))) { touchEvent(ev); return true; } } } return QScrollArea::viewportEvent(e); }
bool ScrollArea::eventFilter(QObject *obj, QEvent *e) { bool res = QScrollArea::eventFilter(obj, e); if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) { QTouchEvent *ev = static_cast<QTouchEvent*>(e); if (_touchEnabled && ev->device()->type() == QTouchDevice::TouchScreen) { if (obj == widget()) { touchEvent(ev); return true; } } } return res; }
bool eventFilter(QObject *, QEvent *event) { if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchCancel || event->type() == QEvent::TouchEnd) { QTouchEvent *touch = static_cast<QTouchEvent*>(event); eventList.append(Event(event->type(), touch->touchPoints())); if (filterTouch) event->accept(); return true; } return false; }
bool PhotoKitView::viewportEvent(QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { //only do these in picture wall mode QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); if (touchPoints.count() == 2) {//TODO: next/pre in PlayPage // determine scale factor const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); qreal currentScaleFactor = QLineF(touchPoint0.pos(), touchPoint1.pos()).length() / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length(); if (touchEvent->touchPointStates() & Qt::TouchPointMoved || touchEvent->touchPointStates() & Qt::TouchPointReleased) { BaseItem* item = UiManager::instance()->currentPageRootItem(); if (UiManager::page == UiManager::ThumbPage || UiManager::page == UiManager::SearchPage) { qreal scale0 = item->mScale; if (currentScaleFactor > 1) { item->mScale += 0.12; item->mScale = qMin(kScaleMax, item->mScale); } else { item->mScale -= 0.12; item->mScale = qMax(kScaleMin, item->mScale); } setAnimationDuration(kAniDuration); smartTransform(item->mX, item->mY, scale0, item->mScale, 0, 0, 0, 0, 0); //both thumbpage and playpage works } else if (UiManager::page == UiManager::PlayPage) { //qreal s0 = item->transform().m11(); qreal s = currentScaleFactor > 1 ? 1.1:0.9; //TODO: smooth and slow QRectF r = item->boundingRect(); //TODO: why translate? item->setTransform(QTransform().translate(r.width()/2, r.height()/2) .scale(s, s).translate(-r.width()/2, -r.height()/2), true); } } } return true; } default: break; } return QGraphicsView::viewportEvent(event); }
bool AndroidRotationControl::sceneEvent(QEvent *e){ switch(e->type()){ case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd:{ QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e); QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); m_shuttle->setRotation((qAtan2(points.first().pos().y(),points.first().pos().x()) * 180/M_PI) + 90); break; } default: return false; break; } return true; }
bool PianoScene::event(QEvent *event) { switch(event->type()) { case QEvent::TouchBegin: case QEvent::TouchEnd: case QEvent::TouchUpdate: { QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event); QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); foreach(const QTouchEvent::TouchPoint& touchPoint, touchPoints) { switch (touchPoint.state()) { case Qt::TouchPointReleased: { PianoKey* key = getKeyForPos(touchPoint.scenePos()); if (key != NULL && key->isPressed()) { keyOff(key, touchPoint.pressure()); } break; } case Qt::TouchPointPressed: { PianoKey* key = getKeyForPos(touchPoint.scenePos()); if (key != NULL && !key->isPressed()) { keyOn(key, touchPoint.pressure()); } break; } case Qt::TouchPointMoved: { PianoKey* key = getKeyForPos(touchPoint.scenePos()); PianoKey* lastkey = getKeyForPos(touchPoint.lastScenePos()); if ((lastkey != NULL) && (lastkey != key) && lastkey->isPressed()) { keyOff(lastkey, touchPoint.pressure()); } if ((key != NULL) && !key->isPressed()) { keyOn(key, touchPoint.pressure()); } break; } default: break; } } break; } default: return QGraphicsScene::event(event); } event->accept(); return true; }
QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { ThreeFingerSlideGesture *d = static_cast<ThreeFingerSlideGesture *>(state); QGestureRecognizer::Result result; switch (event->type()) { case QEvent::TouchBegin: result = QGestureRecognizer::MayBeGesture; case QEvent::TouchEnd: if (d->gestureFired) result = QGestureRecognizer::FinishGesture; else result = QGestureRecognizer::CancelGesture; case QEvent::TouchUpdate: if (d->state() != Qt::NoGesture) { QTouchEvent *ev = static_cast<QTouchEvent*>(event); if (ev->touchPoints().size() == 3) { d->gestureFired = true; result = QGestureRecognizer::TriggerGesture; } else { result = QGestureRecognizer::MayBeGesture; for (int i = 0; i < ev->touchPoints().size(); ++i) { const QTouchEvent::TouchPoint &pt = ev->touchPoints().at(i); const int distance = (pt.pos().toPoint() - pt.startPos().toPoint()).manhattanLength(); if (distance > 20) { result = QGestureRecognizer::CancelGesture; } } } } else { result = QGestureRecognizer::CancelGesture; } break; case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: if (d->state() != Qt::NoGesture) result = QGestureRecognizer::Ignore; else result = QGestureRecognizer::CancelGesture; break; default: result = QGestureRecognizer::Ignore; break; } return result; }
bool controlGraph::viewportEvent(QEvent *event) { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); switch (event->type()) { case QEvent::TouchBegin: { qDebug() << "touch TouchBegin"; return true; } case QEvent::TouchUpdate: { if(touchEvent->touchPoints().size() < 2) { // emit touchMove(0, 0); return(true); } qDebug() << "touch TouchUpdate"; const QTouchEvent::TouchPoint &touchPoint0 = touchEvent->touchPoints().first(); int s = 1; if(touchEvent->touchPoints().size() == 3)s = 10; float deltaX = touchPoint0.normalizedPos().x() - touchPoint0.startNormalizedPos().x(); float deltaY = touchPoint0.normalizedPos().y() - touchPoint0.startNormalizedPos().y(); // if(deltaX > -0.01 && deltaX < 0.01)deltaX=0; // if(deltaY > -0.01 && deltaY < 0.01)deltaY=0; emit touchMove(deltaX/s, deltaY/s); return true; } case QEvent::TouchEnd: { emit touchMove(0, 0); return true; } case QEvent::TouchCancel: { emit touchMove(0, 0); return true; } default: break; } return QGraphicsView::viewportEvent(event); }
static PyObject *meth_QTouchEvent_widget(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QTouchEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QTouchEvent, &sipCpp)) { QWidget *sipRes; Py_BEGIN_ALLOW_THREADS sipRes = sipCpp->widget(); Py_END_ALLOW_THREADS return sipConvertFromType(sipRes,sipType_QWidget,NULL); } }