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); }
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 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 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 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 KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent) { 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 = widgetToDocument(tabletEvent->posF()); 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->device(), touchEvent->modifiers(), touchEvent->touchPointStates(), touchEvent->touchPoints()); this->touchEvent(&fakeEvent); } else { this->touchEvent(touchEvent); } } else if (mouseEvent) { 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 MediaView::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) { if (!ev->touchPoints().isEmpty()) { QPoint p(mapFromGlobal(ev->touchPoints().cbegin()->screenPos().toPoint())); if ((!_close.isHidden() && _close.geometry().contains(p)) || (!_save.isHidden() && _save.geometry().contains(p)) || (!_forward.isHidden() && _forward.geometry().contains(p)) || (!_delete.isHidden() && _delete.geometry().contains(p))) { return QWidget::event(e); } } touchEvent(ev); return true; } } return QWidget::event(e); }
bool QtCanvas::event(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(); event->accept(); qint8 deviceType = touchEvent->device()->type(); std::deque<tgt::TouchPoint> tps; int states = 0; foreach (const QTouchEvent::TouchPoint &p, touchPoints) { int id = p.id(); tgt::vec2 pos(p.pos().x(), p.pos().y()); int state = p.state(); //bool primary = p.isPrimary(); bool primary = true; states = states | state; tgt::TouchPoint tp; tp.setId(id); tp.setPos(pos); tp.setState((tgt::TouchPoint::State)state); tp.setPrimary(primary); tps.push_back(tp); } tgt::TouchEvent * te = new tgt::TouchEvent(tgt::Event::MODIFIER_NONE, (tgt::TouchPoint::State)states, (tgt::TouchEvent::DeviceType)deviceType, tps); eventHandler_->broadcast(te); break; } default: return QGLWidget::event(event); }
// override QApplication::notify() for greatest control over event handling bool TouchApplication::notify(QObject* receiver, QEvent* event) { //DebugEventFilter::printEvent(receiver, event); QEvent::Type evtype = event->type(); // first, try to pass TabletPress/TouchBegin event and see if anyone accepts it // In Qt, events are first sent to a QWindow, which then figures out what widget they should be sent to. // Unfortunately, QWindow event handler always returns true and doesn't change accepted state of event (it // sends a copy of the event and discards the accepted state of the copy), so we must save result from // sending event to final widget (by incrementing acceptCount) // When faking mouse events, we must send them to the QWindow instead of a widget, since some of the // routing logic is there, e.g., for handling popup windows if((evtype == QEvent::TabletPress || evtype == QEvent::TouchBegin) && inputState == None) { if(receiver->isWindowType()) { int prevacceptcount = acceptCount; receiver = getRecvWindow(receiver); QApplication::notify(receiver, event); if(acceptCount > prevacceptcount) { acceptCount = prevacceptcount; inputState = PassThru; return true; } // else, fall through and resend as mouse event // we must send a tablet release to put QWidgetWindow in consistent state // doesn't appear to be necessary for TouchBegin if(evtype == QEvent::TabletPress) { QTabletEvent* tev = static_cast<QTabletEvent*>(event); QTabletEvent rlev(QEvent::TabletRelease, tev->posF(), tev->globalPosF(), tev->device(), tev->pointerType(), 0, 0, 0, 0, 0, 0, tev->modifiers(), tev->uniqueId()); QApplication::notify(receiver, &rlev); } } else { event->setAccepted(false); bool res = QApplication::notify(receiver, event); if(event->isAccepted()) acceptCount++; return res; } } switch(evtype) { // reject external mouse events if we are translating touch or tablet input case QEvent::MouseButtonRelease: case QEvent::MouseMove: case QEvent::MouseButtonPress: // QWidgetWindow always forwards mouse event to widget as spontaneous event (why?) if(inputState != None && event->spontaneous() && receiver->isWindowType()) return true; // qDebug("This event should be rejected!"); break; case QEvent::TabletRelease: if(inputState == PassThru) inputState = None; case QEvent::TabletMove: case QEvent::TabletPress: { // TODO: should this only be done if inputState == TabletInput? receiver = getRecvWindow(receiver); QTabletEvent* tabletevent = static_cast<QTabletEvent*>(event); QEvent::Type mevtype = QEvent::MouseMove; if(inputState == None && evtype == QEvent::TabletPress) { mevtype = QEvent::MouseButtonPress; inputState = TabletInput; } else if(inputState != TabletInput) // this covers PassThru break; if(evtype == QEvent::TabletRelease) { mevtype = QEvent::MouseButtonRelease; inputState = None; } return sendMouseEvent(receiver, mevtype, tabletevent->globalPos(), tabletevent->modifiers()); } #ifdef QT_5 case QEvent::TouchCancel: evtype = QEvent::TouchEnd; #endif case QEvent::TouchEnd: if(inputState == PassThru) // && touchPoints.count() == 1) inputState = None; case QEvent::TouchUpdate: case QEvent::TouchBegin: { receiver = getRecvWindow(receiver); QTouchEvent* touchevent = static_cast<QTouchEvent*>(event); QEvent::Type mevtype = QEvent::MouseMove; if(inputState == None && evtype == QEvent::TouchBegin && touchevent->touchPoints().size() == 1 && touchevent->device()->type() != QTouchDevice::TouchPad) { activeTouchId = touchevent->touchPoints().first().id(); mevtype = QEvent::MouseButtonPress; inputState = TouchInput; } else if(inputState != TouchInput) // this covers PassThru break; if(evtype == QEvent::TouchEnd) inputState = None; event->setAccepted(true); QList<QTouchEvent::TouchPoint> touchPoints = touchevent->touchPoints(); for(int ii = 0; ii < touchPoints.count(); ++ii) { const QTouchEvent::TouchPoint& touchpt = touchPoints.at(ii); if(touchpt.id() == activeTouchId) { if(touchpt.state() == Qt::TouchPointReleased) { mevtype = QEvent::MouseButtonRelease; activeTouchId = -1; } return sendMouseEvent(receiver, mevtype, touchpt.screenPos().toPoint(), touchevent->modifiers()); } } // swallow all touch events until TouchEnd // another option would be to propagate the touch event with the activeTouchId point removed, if >1 point return true; } default: break; } return QApplication::notify(receiver, event); }
bool QIGraphicsView::event(QEvent *pEvent) { /* Handle known event types: */ switch (pEvent->type()) { case QEvent::TouchBegin: { /* Parse the touch event: */ QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent); AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent)); /* For touch-screen event we have something special: */ #if QT_VERSION >= 0x050000 if (pTouchEvent->device()->type() == QTouchDevice::TouchScreen) #else /* QT_VERSION < 0x050000 */ if (pTouchEvent->deviceType() == QTouchEvent::TouchScreen) #endif /* QT_VERSION < 0x050000 */ { /* Remember where the scrolling was started: */ m_iVerticalScrollBarPosition = verticalScrollBar()->value(); /* Allow further touch events: */ pEvent->accept(); /* Mark event handled: */ return true; } break; } case QEvent::TouchUpdate: { /* Parse the touch-event: */ QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent); AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent)); /* For touch-screen event we have something special: */ #if QT_VERSION >= 0x050000 if (pTouchEvent->device()->type() == QTouchDevice::TouchScreen) #else /* QT_VERSION < 0x050000 */ if (pTouchEvent->deviceType() == QTouchEvent::TouchScreen) #endif /* QT_VERSION < 0x050000 */ { /* Determine vertical shift (inverted): */ const QTouchEvent::TouchPoint point = pTouchEvent->touchPoints().first(); const int iShift = (int)(point.startPos().y() - point.pos().y()); /* Calculate new scroll-bar value according calculated shift: */ int iNewScrollBarValue = m_iVerticalScrollBarPosition + iShift; /* Make sure new scroll-bar value is within the minimum/maximum bounds: */ iNewScrollBarValue = qMax(verticalScrollBar()->minimum(), iNewScrollBarValue); iNewScrollBarValue = qMin(verticalScrollBar()->maximum(), iNewScrollBarValue); /* Apply calculated scroll-bar shift finally: */ verticalScrollBar()->setValue(iNewScrollBarValue); /* Mark event handled: */ return true; } break; } case QEvent::TouchEnd: { /* Parse the touch event: */ QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent); AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent)); /* For touch-screen event we have something special: */ #if QT_VERSION >= 0x050000 if (pTouchEvent->device()->type() == QTouchDevice::TouchScreen) #else /* QT_VERSION < 0x050000 */ if (pTouchEvent->deviceType() == QTouchEvent::TouchScreen) #endif /* QT_VERSION < 0x050000 */ { /* Reset the scrolling start position: */ m_iVerticalScrollBarPosition = 0; /* Mark event handled: */ return true; } break; } default: break; } /* Call to base-class: */ return QGraphicsView::event(pEvent); }