bool Panto::event (QEvent *evt) { //qDebug () << PANTO_PRETTY_FUNCTION << evt; if (evt) { QEvent::Type tipo = evt->type (); if (tipo ==QEvent::Gesture ) { qDebug () << "GESTURE event in " << this; QGestureEvent * gev = dynamic_cast <QGestureEvent*> (evt); if (gev) { qDebug () << " gev " << gev; } return true; } else if (tipo == QEvent::GestureOverride) { QGestureEvent * gev = dynamic_cast <QGestureEvent*> (evt); if (gev) { QDeclarativeItem * dItem = qobject_cast<QDeclarativeItem*>(gev->widget()); qDebug () << " override what? gev " << gev << gev->widget() << dItem; if (dItem) { QVariant retVar; QMetaObject::invokeMethod (dItem,"handleLoopGesture", Q_RETURN_ARG(QVariant, retVar)); if (retVar.isValid()) { return retVar.toBool(); } } } } } bool handled = QDeclarativeView::event (evt); //qDebug () << PANTO_PRETTY_FUNCTION << " returning " << handled; return handled; }
bool UBBoardView::event (QEvent * e) { if (e->type () == QEvent::Gesture) { QGestureEvent *gestureEvent = dynamic_cast<QGestureEvent *> (e); if (gestureEvent) { QSwipeGesture* swipe = dynamic_cast<QSwipeGesture*> (gestureEvent->gesture (Qt::SwipeGesture)); if (swipe) { if (swipe->horizontalDirection () == QSwipeGesture::Left) { mController->previousScene (); gestureEvent->setAccepted (swipe, true); } if (swipe->horizontalDirection () == QSwipeGesture::Right) { mController->nextScene (); gestureEvent->setAccepted (swipe, true); } } } } return QGraphicsView::event (e); }
bool MapView::event(QEvent *e) { // Ignore space bar events since they're handled by the MainWindow if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) { if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Space) { e->ignore(); return false; } } else if (e->type() == QEvent::Gesture) { QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e); if (QGesture *gesture = gestureEvent->gesture(Qt::PinchGesture)) { QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture); if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) handlePinchGesture(pinch); } } else if (e->type() == QEvent::ShortcutOverride) { auto keyEvent = static_cast<QKeyEvent*>(e); if (Utils::isZoomInShortcut(keyEvent) || Utils::isZoomOutShortcut(keyEvent) || Utils::isResetZoomShortcut(keyEvent)) { e->accept(); return true; } } return QGraphicsView::event(e); }
bool EmulatedCardWindow::sceneEvent(QEvent* event) { if (isMaximized()) { if (event->type() == QEvent::GestureOverride) { event->accept(); } else if (event->type() == QEvent::Gesture) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); QGesture* g = ge->gesture(Qt::TapGesture); if (g && g->state() == Qt::GestureFinished) { QTapGesture* gt = static_cast<QTapGesture*>(g); QPoint touchPoint = mapFromScene(gt->position()).toPoint(); QRectF hitTarget = mapRectFromItem(m_keyboardButton, m_keyboardButton->boundingRect()); if (hitTarget.contains(touchPoint)) { //The tap coordinates landed on the keyboard button, so let them through //without adjusting them m_keyboardButton->simulateClick(); return true; } } } } return CardWindow::sceneEvent(event); }
bool QLCTextBrowser::event(QEvent* ev) { if (ev->type() == QEvent::Gesture) { QGestureEvent* gesture = static_cast<QGestureEvent*> (ev); QSwipeGesture* swipe = qobject_cast<QSwipeGesture*> ( gesture->gesture(Qt::SwipeGesture)); if (swipe == NULL) { /* NOP */ } else if (swipe->horizontalDirection() == QSwipeGesture::Left) { if (m_hysteresis.elapsed() > HYSTERESIS_MS) { backward(); ev->accept(); m_hysteresis.start(); } } else if (swipe->horizontalDirection() == QSwipeGesture::Right) { if (m_hysteresis.elapsed() > HYSTERESIS_MS) { forward(); ev->accept(); m_hysteresis.start(); } } } return QTextBrowser::event(ev); }
bool TilesetView::event(QEvent *event) { if (mZoomable && event->type() == QEvent::Gesture) { QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event); if (QGesture *gesture = gestureEvent->gesture(Qt::PinchGesture)) mZoomable->handlePinchGesture(static_cast<QPinchGesture *>(gesture)); } return QTableView::event(event); }
bool pvQWebView::event(QEvent *e) { #if QT_VERSION >= 0x040600 if(e->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent*>(e); if(ge->gesture(Qt::PinchGesture)) return false; } #endif return QWebView::event(e); }
bool DashboardWindowContainer::sceneEvent(QEvent* event) { if (event->type() == QEvent::GestureOverride) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); ge->accept(); return true; } else if (event->type() == QEvent::Gesture) { QGesture* g = static_cast<QGestureEvent*>(event)->gesture(Qt::TapGesture); if (g) { QTapGesture* tap = static_cast<QTapGesture*>(g); if (tap->state() == Qt::GestureFinished) { handleTap(mapFromScene(tap->position())); } return true; } if(!m_isMenu) { #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) g = static_cast<QGestureEvent*>(event)->gesture((Qt::GestureType) SysMgrGestureFlick); #else g = static_cast<QGestureEvent*>(event)->gesture(FlickGesture::gestureType()); #endif if (g) { FlickGesture* flick = static_cast<FlickGesture*>(g); if (flick->state() == Qt::GestureFinished) { bool flick_delete = abs(flick->velocity().x()) > abs(flick->velocity().y()); if (flick_delete) { if (DashboardWindow* w = m_draggedWindow.data()) { m_draggedWindow.clear(); if (!w->persistent()) { m_seenFlick = true; triggerItemDelete(w); } } } } return true; } } } else if (event->type() == QEvent::TouchBegin) { return true; } else if (event->type() == QEvent::TouchUpdate) { return true; } else if (event->type() == QEvent::TouchEnd){ return true; } return QGraphicsObject::sceneEvent(event); }
bool viewportEvent(QEvent *event) { if (event->type() == QEvent::Gesture) { gestureEvent(static_cast<QGestureEvent *>(event)); return true; } else if (event->type() == QEvent::GestureOverride) { QGestureEvent *ge = static_cast<QGestureEvent *>(event); if (QPanGesture *pan = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture))) if (pan->state() == Qt::GestureStarted) { outside = false; } } return QScrollArea::viewportEvent(event); }
bool MyScrollArea::event(QEvent *event) { #if QT_VERSION >= 0x040600 //for some reason the panning gesture is handled in qscrollarea //we add pinch gesture: static int ignore_gesture = 0; if(event->type() == QEvent::Gesture && ignore_gesture == 0 && mw->pvbtab[mw->currentTab].s != -1) { QGestureEvent *ge = static_cast<QGestureEvent*>(event); if(QGesture *ge_pinch = ge->gesture(Qt::PinchGesture)) { static int mod = 0; // only respond to every 5'th pinch gesture QPinchGesture *pinch=static_cast<QPinchGesture *>(ge_pinch); int percent = mw->pvbtab[mw->currentTab].interpreter.percentZoomMask; int old_percent = percent; if (pinch->scaleFactor() < 0.99f) percent -= 5; else if(pinch->scaleFactor() > 1.01f) percent += 5; if(percent<10) percent=10; else if(percent>250) percent=250; //char buf[1024]; //sprintf(buf,"percent=%d old_percent=%d scaleFactor=%f", percent, old_percent, pinch->scaleFactor()); //mw->statusBar()->showMessage(buf); mod++; if(percent != old_percent && (mod % 5) == 0 && ignore_gesture == 0) { ignore_gesture = 1; mod = 0; mw->pvbtab[mw->currentTab].interpreter.zoomMask(percent); // will set ...interpreter.percentZoomMask int width = (mw->pvbtab[mw->currentTab].w * percent) / 100; // these lines int height = (mw->pvbtab[mw->currentTab].h * percent) / 100; // should if(mw->pvbtab[mw->currentTab].rootWidget != NULL) // mw->pvbtab[mw->currentTab].rootWidget->resize(width, height); // resize QEvent resize_event(QEvent::Resize); // scrollbars QApplication::sendEvent(mw, &resize_event); // correctly qApp->processEvents(); ignore_gesture = 0; } ge->accept(); return true; } else if(ignore_gesture == 1) { ge->accept(); return true; } } #endif return QScrollArea::event(event); }
bool MyTextBrowser::event(QEvent *e) { #if QT_VERSION >= 0x040600 if(e->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent*>(e); if(ge->gesture(Qt::PinchGesture)) return false; } #endif #ifdef NO_WEBKIT return QTextBrowser::event(e); #else return QWebView::event(e); #endif }
const SoEvent* GesturesDevice::translateEvent(QEvent* event) { if (event->type() == QEvent::Gesture || event->type() == QEvent::GestureOverride) { QGestureEvent* gevent = static_cast<QGestureEvent*>(event); QPinchGesture* zg = static_cast<QPinchGesture*>(gevent->gesture(Qt::PinchGesture)); if(zg){ gevent->setAccepted(Qt::PinchGesture,true);//prefer it over pan return new SoGesturePinchEvent(zg,this->widget); } QPanGesture* pg = static_cast<QPanGesture*>(gevent->gesture(Qt::PanGesture)); if(pg){ gevent->setAccepted(Qt::PanGesture,true); return new SoGesturePanEvent(pg,this->widget); } QSwipeGesture* sg = static_cast<QSwipeGesture*>(gevent->gesture(Qt::SwipeGesture)); if(sg){ gevent->setAccepted(Qt::SwipeGesture,true); return new SoGesturePanEvent(pg,this->widget); } } return 0; }
bool SlidingStackedWidget::event(QEvent *event) { if (event->type() == QEvent::TouchBegin) { event->accept(); return true; } if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent*>(event); if (QGesture *gesture = ge->gesture(fingerSwipeGestureType)) { FingerSwipeGesture *swipe = static_cast<FingerSwipeGesture*>(gesture); if (swipe->state() == Qt::GestureFinished) { if (swipe->isLeftToRight()) { emit fingerGesture(LeftToRight); } else if (swipe->isRightToLeft()) { emit fingerGesture(RightToLeft); } else if (swipe->isBottomToTop()) { emit fingerGesture(BottomToTop); } else if (swipe->isTopToBottom()) { emit fingerGesture(TopToBottom); } } ge->setAccepted(gesture, true); return true; } } //for debug if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); if (keyEvent->modifiers() == Qt::ControlModifier) { if (keyEvent->key() == Qt::Key_Left) { emit fingerGesture(LeftToRight); } else if (keyEvent->key() == Qt::Key_Right) emit fingerGesture(RightToLeft); } } return QStackedWidget::event(event); }
bool TilesetView::event(QEvent *event) { if (event->type() == QEvent::Gesture) { QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event); if (QGesture *gesture = gestureEvent->gesture(Qt::PinchGesture)) mZoomable->handlePinchGesture(static_cast<QPinchGesture *>(gesture)); } else if (event->type() == QEvent::ShortcutOverride) { auto keyEvent = static_cast<QKeyEvent*>(event); if (Utils::isZoomInShortcut(keyEvent) || Utils::isZoomOutShortcut(keyEvent) || Utils::isResetZoomShortcut(keyEvent)) { event->accept(); return true; } } return QTableView::event(event); }
bool MapView::event(QEvent *e) { // Ignore space bar events since they're handled by the MainWindow if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) { if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Space) { e->ignore(); return false; } } else if (e->type() == QEvent::Gesture) { QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e); if (QGesture *gesture = gestureEvent->gesture(Qt::PinchGesture)) { QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture); if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) handlePinchGesture(pinch); } } return QGraphicsView::event(e); }
//virtual bool PixButton::sceneEvent(QEvent * event) { if (event->type() == QEvent::GestureOverride) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); ge->accept(); return true; } else if (event->type() == QEvent::Gesture) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); QGesture * g = 0; g = ge->gesture(Qt::TapGesture); if (g) { QTapGesture* tap = static_cast<QTapGesture*>(g); if (tap->state() == Qt::GestureFinished) { tapGesture(tap); } return true; } g = ge->gesture(Qt::TapAndHoldGesture); if (g) { QTapAndHoldGesture* hold = static_cast<QTapAndHoldGesture*>(g); if (hold->state() == Qt::GestureFinished) { tapAndHoldGesture(hold); } return true; } } else if (event->type() == QEvent::TouchBegin) { return touchStartEvent(static_cast<QTouchEvent *>(event)); } else if (event->type() == QEvent::TouchUpdate) { return touchUpdateEvent(static_cast<QTouchEvent *>(event)); } else if (event->type() == QEvent::TouchEnd) { return touchEndEvent(static_cast<QTouchEvent *>(event)); } return QGraphicsObject::sceneEvent(event); }
bool PageTabBar::sceneEvent(QEvent* event) { if (event->type() == QEvent::GestureOverride) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); ge->accept(); return true; } else if (event->type() == QEvent::Gesture) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); QGesture * g = 0; // QGesture* g = ge->gesture(Qt::TapGesture); // if (g) { // QTapGesture* tap = static_cast<QTapGesture*>(g); // if (tap->state() == Qt::GestureFinished) { // tapGestureEvent(tap); // } // return true; // } // g = ge->gesture(Qt::TapAndHoldGesture); // if (g) { // QTapAndHoldGesture* hold = static_cast<QTapAndHoldGesture*>(g); // if (hold->state() == Qt::GestureFinished) { // tapAndHoldGestureEvent(hold); // } // return true; // } #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) g = ge->gesture((Qt::GestureType) SysMgrGestureFlick); #else g = ge->gesture(FlickGesture::gestureType()); #endif if (g) { FlickGesture* flick = static_cast<FlickGesture*>(g); if (flick->state() == Qt::GestureFinished) { flickGesture(flick); } return true; } } return QGraphicsObject::sceneEvent(event); }
/*! \brief Filters pan gesture events. Filters events if this object has been installed as an event filter for the watched object. Handles horizontal pan gestures (ignores vertical). When moving scroll area all gesture events are blocked. \param obj Watched object \param event Event to be filtered \return Returns TRUE if event was handled. FALSE otherwise. */ bool CalenDayContentScrollArea::eventFilter(QObject *obj, QEvent *event) { Q_UNUSED(obj); bool handled = false; // Check if we get a gesture event if (event->type() == QEvent::Gesture) { // Blocks handling of gesture events if scrolling started by // pan gesture is in progress if (mIsMoving) { handled = true; } else { QGestureEvent* gesture = static_cast<QGestureEvent*> (event); QPanGesture *panGesture = qobject_cast<QPanGesture*>(gesture->gesture(Qt::PanGesture)); if (panGesture) { checkPanDirection(panGesture); if (mPanDayDirection == ECalenPanHorizontal) { gestureEvent(gesture); handled = true; } }else{ QSwipeGesture *swipeGesture = qobject_cast<QSwipeGesture*>(gesture->gesture(Qt::SwipeGesture)); if (swipeGesture) { gestureEvent(gesture); handled = true; } } } } return handled; }
bool viewportEvent(QEvent *event) { if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent *>(event); if (QPanGesture *pan = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture))) { switch (pan->state()) { case Qt::GestureStarted: qDebug("view: Pan: started"); break; case Qt::GestureFinished: qDebug("view: Pan: finished"); break; case Qt::GestureCanceled: qDebug("view: Pan: canceled"); break; case Qt::GestureUpdated: break; default: qDebug("view: Pan: <unknown state>"); break; } const QPointF delta = pan->delta(); QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); vbar->setValue(vbar->value() - delta.y()); hbar->setValue(hbar->value() - delta.x()); ge->accept(pan); return true; } } return QGraphicsView::viewportEvent(event); }
bool PageTab::sceneEvent(QEvent* event) { if (event->type() == QEvent::GestureOverride) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); ge->accept(); return true; } else if (event->type() == QEvent::Gesture) { QGestureEvent* ge = static_cast<QGestureEvent*>(event); QGesture* g = ge->gesture(Qt::TapGesture); if (g) { QTapGesture* tap = static_cast<QTapGesture*>(g); if (tap->state() == Qt::GestureFinished) { tapGesture(tap,ge); } return true; } g = ge->gesture(Qt::TapAndHoldGesture); if (g) { QTapAndHoldGesture* hold = static_cast<QTapAndHoldGesture*>(g); if (hold->state() == Qt::GestureFinished) { tapAndHoldGesture(hold,ge); } return true; } // g = ge->gesture((Qt::GestureType) SysMgrGestureFlick); // if (g) { // FlickGesture* flick = static_cast<FlickGesture*>(g); // if (flick->state() == Qt::GestureFinished) { // flickGesture(flick,ge); // } // return true; // } } return QGraphicsObject::sceneEvent(event); }
static PyObject *meth_QGestureEvent_setAccepted(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { bool a0; QGestureEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "Bb", &sipSelf, sipType_QGestureEvent, &sipCpp, &a0)) { sipCpp->setAccepted(a0); Py_INCREF(Py_None); return Py_None; } } { QGesture* a0; bool a1; QGestureEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ8b", &sipSelf, sipType_QGestureEvent, &sipCpp, sipType_QGesture, &a0, &a1)) { sipCpp->setAccepted(a0,a1); Py_INCREF(Py_None); return Py_None; } } { Qt::GestureType a0; bool a1; QGestureEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BEb", &sipSelf, sipType_QGestureEvent, &sipCpp, sipType_Qt_GestureType, &a0, &a1)) { sipCpp->setAccepted(a0,a1); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QGestureEvent, sipName_setAccepted, doc_QGestureEvent_setAccepted); return NULL; }
bool MenuWindowManager::sceneEvent(QEvent* event) { switch (event->type()) { case QEvent::GestureOverride: { QGestureEvent* ge = static_cast<QGestureEvent*>(event); QList<QGesture*> activeGestures = ge->activeGestures(); Q_FOREACH(QGesture* g, activeGestures) { if (g->hasHotSpot()) { QPointF pt = ge->mapToGraphicsScene(g->hotSpot()); if (m_systemMenuOpened || (!m_winArray.empty() && m_positiveSpace.contains(pt.x() - boundingRect().x(), pt.y() - boundingRect().y()))) { ge->accept(g); } else { ge->ignore(g); } } } break; } case QEvent::Gesture: { QGestureEvent* ge = static_cast<QGestureEvent*>(event); #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) QGesture* g = ge->gesture((Qt::GestureType) SysMgrGestureFlick); #else QGesture* g = ge->gesture(FlickGesture::gestureType()); #endif if (g && g->state() == Qt::GestureFinished) { flickGestureEvent(ge); return true; } } default: break; } return WindowManagerBase::sceneEvent(event); }
static PyObject *meth_QGestureEvent_ignore(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QGestureEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QGestureEvent, &sipCpp)) { sipCpp->ignore(); Py_INCREF(Py_None); return Py_None; } } { QGesture* a0; QGestureEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ8", &sipSelf, sipType_QGestureEvent, &sipCpp, sipType_QGesture, &a0)) { sipCpp->ignore(a0); Py_INCREF(Py_None); return Py_None; } } { Qt::GestureType a0; QGestureEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BE", &sipSelf, sipType_QGestureEvent, &sipCpp, sipType_Qt_GestureType, &a0)) { sipCpp->ignore(a0); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QGestureEvent, sipName_ignore, doc_QGestureEvent_ignore); return NULL; }
bool InputManager::eventFilter( QObject* object, QEvent* event ) { if( object != m_filteredObj.data() ) return false; // Emit a signal with the QEvent argument so that others can handle it emit eventFiltered( event ); switch( event->type() ) { case QEvent::KeyPress: { QKeyEvent* keyEvent = static_cast<QKeyEvent*>( event ); keyboard( 0 )->setButtonState( keyEvent->key(), 1 ); emit keyPressed( keyEvent->key() ); return true; } case QEvent::KeyRelease: { QKeyEvent* keyEvent = static_cast<QKeyEvent*>( event ); keyboard( 0 )->setButtonState( keyEvent->key(), 0 ); emit keyReleased( keyEvent->key() ); return true; } case QEvent::MouseMove: { QMouseEvent* mouseEvent = static_cast<QMouseEvent*>( event ); mouse( 0 )->setPosition( mouseEvent->pos( ) ); emit mouseMoved( mouseEvent->pos( ) ); return true; } case QEvent::Wheel: { QWheelEvent* wheelEvent = static_cast<QWheelEvent*>( event ); mouse( 0 )->setHWheelPosition( wheelEvent->x( ) ); mouse( 0 )->setHWheelPosition( wheelEvent->y( ) ); emit mouseWheeled( wheelEvent->x( ), wheelEvent->y( ) ); return true; } case QEvent::MouseButtonPress: { if( !m_filteredObj.isNull() && !qobject_cast<QWidget*>( filteredObject() )->hasFocus() ) qobject_cast<QWidget*>( filteredObject() )->setFocus(); QMouseEvent* mouseEvent = static_cast<QMouseEvent*>( event ); mouse( 0 )->setButtonState( mapMouseButton( mouseEvent->button() ), 1 ); emit keyPressed( mapMouseButton( mouseEvent->button() ) ); return true; } case QEvent::MouseButtonRelease: { QMouseEvent* mouseEvent = static_cast<QMouseEvent*>( event ); mouse( 0 )->setButtonState( mapMouseButton( mouseEvent->button() ), 0 ); emit keyReleased( mapMouseButton( mouseEvent->button() ) ); return true; } case QEvent::Gesture: { QGestureEvent* gestureEvent = static_cast<QGestureEvent*>( event ); if( QGesture* swipe = gestureEvent->gesture( Qt::SwipeGesture ) ) swipeTriggered( static_cast<QSwipeGesture*>( swipe ) ); else if( QGesture* pan = gestureEvent->gesture( Qt::PanGesture ) ) panTriggered( static_cast<QPanGesture*>( pan ) ); if( QGesture* pinch = gestureEvent->gesture( Qt::PinchGesture ) ) pinchTriggered( static_cast<QPinchGesture*>( pinch ) ); return true; } case QEvent::GestureOverride: { QGestureEvent* gestureEvent = static_cast<QGestureEvent*>( event ); if( QGesture* swipe = gestureEvent->gesture( Qt::SwipeGesture ) ) swipeTriggered( static_cast<QSwipeGesture*>( swipe ) ); else if( QGesture* pan = gestureEvent->gesture( Qt::PanGesture ) ) panTriggered( static_cast<QPanGesture*>( pan ) ); if( QGesture* pinch = gestureEvent->gesture( Qt::PinchGesture ) ) pinchTriggered( static_cast<QPinchGesture*>( pinch ) ); return true; } default: return false; } return false; }
bool IMEView::sceneEvent(QEvent* event) { switch (event->type()) { case QEvent::GestureOverride: { // consume all gestures if we are handling touches QGestureEvent* ge = static_cast<QGestureEvent*>(event); QGesture* g = 0; if ((g = ge->gesture(Qt::TapGesture))) { if (acceptPoint(mapFromScene(ge->mapToGraphicsScene(g->hotSpot())))) { event->accept(); return true; } } else if ((g = ge->gesture(Qt::TapAndHoldGesture))) { if (acceptPoint(mapFromScene(ge->mapToGraphicsScene(g->hotSpot())))) { event->accept(); return true; } } else if ((g = ge->gesture(Qt::PinchGesture))) { if (acceptPoint(mapFromScene(ge->mapToGraphicsScene(g->hotSpot())))) { event->accept(); return true; } } else if ((g = ge->gesture((Qt::GestureType) SysMgrGestureFlick))) { if (acceptPoint(mapFromScene(ge->mapToGraphicsScene(g->hotSpot())))) { event->accept(); return true; } } else if ((g = ge->gesture((Qt::GestureType) SysMgrGestureSingleClick))) { if (acceptPoint(mapFromScene(ge->mapToGraphicsScene(g->hotSpot())))) { event->accept(); return true; } } else if ((g = ge->gesture((Qt::GestureType) SysMgrGestureSingleClick))) { if (acceptPoint(mapFromScene(ge->mapToGraphicsScene(g->hotSpot())))) { event->accept(); return true; } } } break; case QEvent::Gesture: { QGestureEvent* ge = static_cast<QGestureEvent*>(event); QGesture* g = ge->gesture(Qt::TapGesture); if (g && g->state() == Qt::GestureFinished) { tapEvent(static_cast<QTapGesture*>(g)); return true; } if (!g) { QGesture* g = ge->gesture((Qt::GestureType) SysMgrGestureScreenEdgeFlick); if (g && g->state() == Qt::GestureFinished) { screenEdgeFlickEvent(static_cast<ScreenEdgeFlickGesture*>(g)); return true; } } } break; case QEvent::TouchBegin: touchBegin(static_cast<QTouchEvent*>(event)); return event->isAccepted(); case QEvent::TouchUpdate: touchUpdate(static_cast<QTouchEvent*>(event)); return event->isAccepted(); case QEvent::TouchEnd: touchEnd(static_cast<QTouchEvent*>(event)); return event->isAccepted(); default: break; } return QGraphicsObject::sceneEvent(event); }
//=============================================================== bool MousePanNZoomNavigator::eventFilter(QObject *widget, QEvent *e) { // according to Qt's doc, this constant has been defined by wheel mouse vendors // we need it to interpret the value of QWheelEvent->delta() #define WHEEL_DELTA 120 if (e->type() == QEvent::Wheel && (((QWheelEvent *) e)->orientation() == Qt::Vertical)) { GlMainWidget *g = (GlMainWidget *) widget; if(((QWheelEvent *) e)->delta() < 0 && g->getScene()->getCamera().getZoomFactor() < 0.5f) { return true; } g->getScene()->zoomXY(((QWheelEvent *) e)->delta() / WHEEL_DELTA, ((QWheelEvent *) e)->x(), ((QWheelEvent *) e)->y()); g->draw(false); return true; } if(e->type() == QEvent::Gesture) { GlMainWidget *g = (GlMainWidget *) widget; QGestureEvent* gesture = (QGestureEvent*)e; QPointF center; //swipe events and pan events are never fired, known Qt bug /*if(gesture->gesture(Qt::SwipeGesture)) { QSwipeGesture* swipe = (QSwipeGesture*)gesture->gesture(Qt::SwipeGesture); int x = cos(swipe->swipeAngle()) * swipe->property("velocity").toFloat(); int y = sin(swipe->swipeAngle()) * swipe->property("velocity").toFloat(); g->getScene()->translateCamera(x, y, 0); }*/ if(gesture->gesture(Qt::PinchGesture)) { QPinchGesture* pinch = (QPinchGesture*)gesture->gesture(Qt::PinchGesture); Camera& camera = g->getScene()->getCamera(); //store the camera scale factor when starting the gesture if(pinch->state() == Qt::GestureStarted) { cameraScaleFactor = camera.getZoomFactor(); isGesturing = true; } if(pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) { //only set the zoom factor if two events in a row were in the same direction (zoom in or out) to smooth a bit the effect. if((pinch->lastScaleFactor() > 1 && pinch->scaleFactor() > 1) || (pinch->lastScaleFactor() <= 1 && pinch->scaleFactor() <= 1)) { camera.setZoomFactor(cameraScaleFactor * pinch->totalScaleFactor()); } } if(pinch->changeFlags() & QPinchGesture::RotationAngleChanged) { /*//backup the current camera center Coord oldCenter = camera.getCenter(); Coord oldEye = camera.getEyes(); //sets the camera center to the center of the pich gesture Coord rotationCenter(g->mapFromGlobal(pinch->centerPoint().toPoint()).x(), g->mapFromGlobal(pinch->centerPoint().toPoint()).y(), oldCenter.getZ()); Coord rotationEye=camera.getEyes()+(rotationCenter-oldCenter); camera.setCenter(rotationCenter); camera.setEyes(rotationEye);*/ //rotates the camera camera.rotate((pinch->rotationAngle() - pinch->lastRotationAngle())/180*M_PI, 0, 0, 1); /* //restore old camera center and eyes camera.setCenter(oldCenter); camera.setEyes(oldEye); */ } if(pinch->state() == Qt::GestureFinished) { isGesturing = false; } if(gesture->gesture(Qt::PanGesture)) { QPanGesture* pan = (QPanGesture*)gesture->gesture(Qt::PanGesture); if(pan->state() == Qt::GestureStarted) { isGesturing = true; } if(pan->state() == Qt::GestureFinished) { isGesturing = false; } center = pan->delta(); g->getScene()->translateCamera(pan->delta().x(), -pan->delta().y(), 0); } } g->draw(false); return true; } return false; }
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); }