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);
}
Example #2
0
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);
}
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);
}
Example #4
0
QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state,
                                                            QObject *,
                                                            QEvent *event)
{
    QTapGesture *q = static_cast<QTapGesture *>(state);
    QTapGesturePrivate *d = q->d_func();

    const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);

    QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;

    switch (event->type()) {
    case QEvent::TouchBegin: {
#ifndef QT_WEBOS // REBASE_CHECK_REQUIRED necessary?
        d->position = ev->touchPoints().at(0).pos();
        q->setHotSpot(ev->touchPoints().at(0).screenPos());
#else // QT_WEBOS
        QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
        d->position = p.pos();
        d->hotSpot = p.screenPos();
        d->isHotSpotSet = true;
#endif // QT_WEBOS
        result = QGestureRecognizer::TriggerGesture;
        break;
    }
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd: {
        if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) {
            QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
#ifdef QT_WEBOS // REBASE_CHECK_REQUIRED use setHotSpot?
            d->hotSpot = p.screenPos();
            d->isHotSpotSet = true;
#endif // QT_WEBOS
            QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
            enum { TapRadius = 40 };
            if (delta.manhattanLength() <= TapRadius) {
                if (event->type() == QEvent::TouchEnd)
                    result = QGestureRecognizer::FinishGesture;
                else
                    result = QGestureRecognizer::TriggerGesture;
            }
        }
        break;
    }
    case QEvent::MouseButtonPress:
    case QEvent::MouseMove:
    case QEvent::MouseButtonRelease:
        result = QGestureRecognizer::Ignore;
        break;
#ifdef QT_WEBOS
    case QEvent::Gesture:
    {
    	QGesture* g = static_cast<QGestureEvent*>(event)->gesture(Qt::SysMgrGestureFlick);
		if (g && g->state() == Qt::GestureFinished && q->state() != Qt::NoGesture ) {
			result = QGestureRecognizer::CancelGesture;
			break;
		}
        g = static_cast<QGestureEvent*>(event)->gesture(Qt::SysMgrGestureScreenEdgeFlick);
        if (g && g->state() == Qt::GestureFinished && q->state() != Qt::NoGesture ) {
            result = QGestureRecognizer::CancelGesture;
            break;
        }
    }
    // fall through
#endif // QT_WEBOS
    default:
        result = QGestureRecognizer::Ignore;
        break;
    }
    return result;
}
Example #5
0
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);
}