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);
}
Example #2
0
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);
}
Example #3
0
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);
}
Example #5
0
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;
}
Example #6
0
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);
}
Example #7
0
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);
	}
}
Example #8
0
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;
}
Example #9
0
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;
}
Example #10
0
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;
}
Example #11
0
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);
}
Example #12
0
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);
}
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;
}
Example #14
0
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);
}
Example #15
0
/**
 * Touch events are processed here and @p TscoreItem gets only @p touched() @p touchMove() and @p untouched()
 * with latest touch position in scene coordinates. To use them, TscoreItem subclass has to map it first.
 * When second finger touches screen, last touch event is canceled by putting null point as a parameter.
 * So far, only: @class TscoreNote, @class TscoreKeySignature and @class TscoreClef handles those methods.
 * Two fingers touch is used to scroll score
 */
bool TsimpleScore::viewportEvent(QEvent* event) {
  if (TscoreNote::touchEnabled()) {
    if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
      QTouchEvent *te = static_cast<QTouchEvent*>(event);
      if (te->touchPoints().count() == 1) {
        // Touch event is sent here with view coordinates points - their has to be mapped to score scene
        QPointF touchScenePos = mapToScene(te->touchPoints().first().pos().toPoint());
        switch(te->touchPoints().first().state()) {
          case Qt::TouchPointPressed: {
            TscoreItem *it = castItem(scene()->itemAt(touchScenePos, transform()));
            if (it) {
              it->touched(touchScenePos);
              m_currentIt = it;
            }
            break;
          }
          case Qt::TouchPointMoved: {
            if (m_currentIt)
              m_currentIt->touchMove(touchScenePos);
            break;
          }
          case Qt::TouchPointReleased: {
            if (m_currentIt) {
              m_currentIt->untouched(touchScenePos);
              m_currentIt = 0;
            }
            break;
          }
          default:
            break;
        }
        return m_currentIt ? true : false;
      } else if (te->touchPoints().count() == 2) {
        if (m_currentIt) { // cancel the last touch event
          m_currentIt->untouched(QPointF(0, 0));
          m_currentIt = 0;
        }
        verticalScrollBar()->setValue(verticalScrollBar()->value() + (te->touchPoints()[0].lastPos().y() - te->touchPoints()[0].pos().y()));
        return true;
      }
    }
  }
  return QGraphicsView::viewportEvent(event);
}
Example #16
0
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);
}
Example #17
0
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 DisplayGroupGraphicsScene::event(QEvent *evt)
{
    switch( evt->type())
    {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        if( g_configuration->getOptions()->getShowTouchPoints( ))
        {
            QTouchEvent* touchEvent = static_cast< QTouchEvent* >( evt );

            while( markers_.size() < size_t( touchEvent->touchPoints().size( )))
                markers_.push_back( displayGroup_->getNewMarker( ));

            for( int i = 0; i < touchEvent->touchPoints().size(); ++i )
            {
                markers_[i]->setPosition(touchEvent->touchPoints()[i].normalizedPos().x(),
                                         touchEvent->touchPoints()[i].normalizedPos().y());
            }
        }
        return QGraphicsScene::event(evt);
    }
    case QEvent::KeyPress:
    {
        QKeyEvent *k = static_cast<QKeyEvent*>(evt);

        // Override default behaviour to process TAB key events
        QGraphicsScene::keyPressEvent(k);

        if( k->key() == Qt::Key_Backtab ||
            k->key() == Qt::Key_Tab ||
           (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
        {
            evt->accept();
        }
        return true;
    }
    default:
        return QGraphicsScene::event(evt);
    }
}
Example #19
0
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 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;
 }
Example #21
0
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);
}
Example #22
0
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 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;
}
Example #24
0
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;
}
Example #25
0
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;
}
Example #26
0
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);
    }
Example #27
0
bool QQuickMultiPointTouchArea::shouldFilter(QEvent *event)
{
    QQuickWindow *c = window();
    QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
    bool disabledItem = grabber && !grabber->isEnabled();
    bool stealThisEvent = _stealMouse;
    bool containsPoint = false;
    if (!stealThisEvent) {
        switch (event->type()) {
        case QEvent::MouseButtonPress:
        case QEvent::MouseMove:
        case QEvent::MouseButtonRelease: {
                QMouseEvent *me = static_cast<QMouseEvent*>(event);
                containsPoint = contains(mapFromScene(me->windowPos()));
            }
            break;
        case QEvent::TouchBegin:
        case QEvent::TouchUpdate:
        case QEvent::TouchEnd: {
                QTouchEvent *te = static_cast<QTouchEvent*>(event);
                for (const QTouchEvent::TouchPoint &point : te->touchPoints()) {
                    if (contains(mapFromScene(point.scenePos()))) {
                        containsPoint = true;
                        break;
                    }
                }
            }
            break;
        default:
            break;
        }
    }
    if ((stealThisEvent || containsPoint) && (!grabber || !grabber->keepMouseGrab() || disabledItem)) {
        return true;
    }
    ungrab();
    return false;
}
Example #28
0
//=============================================================================
//	eControl::paintEvent
//-----------------------------------------------------------------------------
bool eControl::event(QEvent* event)
{
	switch(event->type())
	{
	case QEvent::MouseButtonPress:
	case QEvent::MouseButtonRelease:
	case QEvent::MouseMove:
		{
			QMouseEvent* me = (QMouseEvent*)event;
			bool ok = event->type() == QEvent::MouseMove ? ((me->buttons() & Qt::LeftButton) != 0) : (me->button() == Qt::LeftButton);
			if(ok)
			{
				float x = float(me->x())/width();
				float y = float(me->y())/height();
				OnTouch(x, y, event->type() != QEvent::MouseButtonRelease, 0);
				return true;
			}
		}
		return true;
	case QEvent::TouchBegin:
	case QEvent::TouchUpdate:
	case QEvent::TouchEnd:
		{
			QTouchEvent* te = (QTouchEvent*)event;
			foreach(const QTouchEvent::TouchPoint& p, te->touchPoints())
			{
				float x = p.pos().x()/width();
				float y = p.pos().x()/height();
				OnTouch(x, y, p.state() != Qt::TouchPointReleased, p.id());
			}
		}
		return true;
	default:
		return QWidget::event(event);
	}
}
Example #29
0
bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
{
    if (obj != m_window)
        return false;

    QWaylandInputDevice *input = defaultInputDevice();

    switch (event->type()) {
    case QEvent::Expose:
        m_renderScheduler.start(0);
        if (m_window->isExposed()) {
            // Alt-tabbing away normally results in the alt remaining in
            // pressed state in the clients xkb state. Prevent this by sending
            // a release. This is not an issue in a "real" compositor but
            // is very annoying when running in a regular window on xcb.
            Qt::KeyboardModifiers mods = QGuiApplication::queryKeyboardModifiers();
            if (m_modifiers != mods && input->keyboardFocus()) {
                Qt::KeyboardModifiers stuckMods = m_modifiers ^ mods;
                if (stuckMods & Qt::AltModifier)
                    input->sendKeyReleaseEvent(64); // native scancode for left alt
                m_modifiers = mods;
            }
        }
        break;
    case QEvent::MouseButtonPress: {
        QPointF local;
        QMouseEvent *me = static_cast<QMouseEvent *>(event);
        QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local);
        if (m_dragKeyIsPressed && targetSurface) {
            m_draggingWindow = targetSurface;
            m_drag_diff = local;
        } else {
            if (targetSurface && input->keyboardFocus() != targetSurface) {
                input->setKeyboardFocus(targetSurface);
                m_surfaces.removeOne(targetSurface);
                m_surfaces.append(targetSurface);
                m_renderScheduler.start(0);
            }
            input->sendMousePressEvent(me->button(), local, me->localPos());
        }
        return true;
    }
    case QEvent::MouseButtonRelease: {
        QWaylandSurface *targetSurface = input->mouseFocus();
        if (m_draggingWindow) {
            m_draggingWindow = 0;
            m_drag_diff = QPointF();
        } else {
            QMouseEvent *me = static_cast<QMouseEvent *>(event);
            QPointF localPos;
            if (targetSurface)
                localPos = toSurface(targetSurface, me->localPos());
            input->sendMouseReleaseEvent(me->button(), localPos, me->localPos());
        }
        return true;
    }
    case QEvent::MouseMove: {
        QMouseEvent *me = static_cast<QMouseEvent *>(event);
        if (m_draggingWindow) {
            m_draggingWindow->setPos(me->localPos() - m_drag_diff);
            m_renderScheduler.start(0);
        } else {
            QPointF local;
            QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local);
            input->sendMouseMoveEvent(targetSurface, local, me->localPos());
        }
        break;
    }
    case QEvent::Wheel: {
        QWheelEvent *we = static_cast<QWheelEvent *>(event);
        input->sendMouseWheelEvent(we->orientation(), we->delta());
        break;
    }
    case QEvent::KeyPress: {
        QKeyEvent *ke = static_cast<QKeyEvent *>(event);
        if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) {
            m_dragKeyIsPressed = true;
        }
        m_modifiers = ke->modifiers();
        QWaylandSurface *targetSurface = input->keyboardFocus();
        if (targetSurface)
            input->sendKeyPressEvent(ke->nativeScanCode());
        break;
    }
    case QEvent::KeyRelease: {
        QKeyEvent *ke = static_cast<QKeyEvent *>(event);
        if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) {
            m_dragKeyIsPressed = false;
        }
        m_modifiers = ke->modifiers();
        QWaylandSurface *targetSurface = input->keyboardFocus();
        if (targetSurface)
            input->sendKeyReleaseEvent(ke->nativeScanCode());
        break;
    }
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        QWaylandSurface *targetSurface = 0;
        QTouchEvent *te = static_cast<QTouchEvent *>(event);
        QList<QTouchEvent::TouchPoint> points = te->touchPoints();
        QPoint pointPos;
        if (!points.isEmpty()) {
            pointPos = points.at(0).pos().toPoint();
            targetSurface = surfaceAt(pointPos);
        }
        if (targetSurface && targetSurface != input->mouseFocus())
            input->setMouseFocus(targetSurface, pointPos, pointPos);
        if (input->mouseFocus())
            input->sendFullTouchEvent(te);
        break;
    }
    default:
        break;
    }
    return false;
}
Example #30
0
bool WindowServerLuna::sysmgrEventFilters(QEvent* event)
{
	QEvent::Type type = event->type();

	if (handleEvent(event)) {
		luna_log(kWindowSrvChnl, "event consumed by WindowServer: %d", type);
		return true;
	}

	if (m_displayMgr->handleEvent(event)) {
		luna_log(kWindowSrvChnl, "event consumed by DisplayMgr: %d", type);
		return true;
	}

	if (m_coreNaviMgr->handleEvent(event)) {
		luna_log(kWindowSrvChnl, "event consumed by CoreNaviMgr: %d", type);
		return true;
	}

	if (m_inputMgr->handleEvent(event)) {
		luna_log(kWindowSrvChnl, "event consumed by InputManager: %d", type);
		return true;
	}

	if (SystemService::instance()->brickMode() || m_runningProgress || m_bootingUp) {
		luna_log(kWindowSrvChnl, "event blocked due to brick mode/progress anim/boot up: %d", type);
		return true;
	}

	if (m_metaKeyMgr->handleEvent(event)) {
		luna_log(kWindowSrvChnl, "event consumed by MetaKeyManager: %d", type);
		return true;
	}

	if (
        type == QEvent::KeyPress ||
        type == QEvent::KeyRelease ||
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
        type == QEvent::MouseButtonPress ||
        type == QEvent::MouseButtonRelease ||
        type == QEvent::MouseMove ||
#else
        type == QEvent::TouchBegin ||
        type == QEvent::TouchEnd ||
        type == QEvent::TouchUpdate ||
#endif // QT_VERSION < 5.0.0
        type == QEvent::GestureOverride)
    {
		if(!SystemUiController::instance()->isInDockMode()) {
			if (m_topLevelMgr && ((TopLevelWindowManager*)m_topLevelMgr)->handleEvent(event)) {
				luna_log(kWindowSrvChnl, "event consumed by TopLevelWindowManager: %d", type);
				return true;
			}
		}
	}

	if (UiNavigationController::instance()->handleEvent(event)) {
		luna_log(kWindowSrvChnl, "event consumed by UiNavigationController: %d", type);
		return true;
	}

	if (SystemUiController::instance()->handleEvent(event)) {
		luna_log(kWindowSrvChnl, "event consumed by SystemUiController: %d", type);
		return true;
	}

    if(((type == QEvent::KeyPress) || (type == QEvent::KeyRelease)) && (((QKeyEvent*)event)->key() == KEYS::Key_CoreNavi_QuickLaunch))
	{
		// Quick Launch Key should go to Overlay WM
		if(!SystemUiController::instance()->isInDockMode() && !SystemUiController::instance()->isScreenLocked() && !SystemUiController::instance()->isInEmergencyMode()) {
			if (type == QEvent::KeyPress) {
				if (m_overlayMgr) {
					((OverlayWindowManager*)m_overlayMgr)->keyPressEvent((QKeyEvent*)event);
					luna_log(kWindowSrvChnl, "event consumed by OverlayWindowManager: %d", type);
					return true;
				}
			} else {
				if (m_overlayMgr) {
					((OverlayWindowManager*)m_overlayMgr)->keyReleaseEvent((QKeyEvent*)event);
					luna_log(kWindowSrvChnl, "event consumed by OverlayWindowManager: %d", type);
					return true;
				}
			}
		}
	}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    if (m_overlayMgr && (type == QEvent::TouchBegin ||
                         type == QEvent::TouchEnd ||
                         type == QEvent::TouchCancel ||
                         type == QEvent::TouchUpdate)) {
        QTouchEvent *te = static_cast<QTouchEvent *>(event);
        OverlayWindowManager *owm =
            static_cast<OverlayWindowManager *>(m_overlayMgr);

        if (!te->touchPoints().isEmpty() && owm->universalSearchState() ==
            OverlayWindowManager::StateUSearchVisible) {
            if (type == QEvent::TouchBegin) {
                return owm->handleTouchBegin(te);
            } else if (type == QEvent::TouchEnd || type == QEvent::TouchCancel) {
                return owm->handleTouchEnd(te);
            } else if (type == QEvent::TouchUpdate) {
                return owm->handleTouchUpdate(te);
            }
        }
    }
#endif

	return false;
}