Example #1
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);
}
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 #3
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 #4
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);
}
void QSGPinchArea::touchEvent(QTouchEvent *event)
{
    Q_D(QSGPinchArea);
    if (!d->absorb || !isVisible()) {
        QSGItem::event(event);
        return;
    }

    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
        d->touchPoints.clear();
        for (int i = 0; i < event->touchPoints().count(); ++i) {
            if (!(event->touchPoints().at(i).state() & Qt::TouchPointReleased)) {
                d->touchPoints << event->touchPoints().at(i);
            }
        }
        updatePinch();
        break;
    case QEvent::TouchEnd:
        d->touchPoints.clear();
        updatePinch();
        break;
    default:
        QSGItem::event(event);
    }
}
/*!
    \internal
*/
void QDeclarativeGeoMapGestureArea::pinchStateMachine()
{
    PinchState lastState = pinchState_;
    // Transitions:
    switch (pinchState_) {
    case pinchInactive:
        if (canStartPinch()) {
            startPinch();
            setPinchActive(true);
        }
        break;
    case pinchActive:
        if (touchPoints_.count() <= 1) {
            endPinch();
            setPinchActive(false);
        }
        break;
    }
    // This line implements an exclusive state machine, where the transitions and updates don't
    // happen on the same frame
    if (pinchState_ != lastState)
         return;
    // Update
    switch (pinchState_) {
    case pinchInactive:
        break; // do nothing
    case pinchActive:
        updatePinch();
        break;
    }
}
void QQuickPinchArea::touchEvent(QTouchEvent *event)
{
    Q_D(QQuickPinchArea);
    if (!d->enabled || !isVisible()) {
        QQuickItem::touchEvent(event);
        return;
    }

    // A common non-trivial starting scenario is the user puts down one finger,
    // then that finger remains stationary while putting down a second one.
    // However QQuickWindow will not send TouchUpdates for TouchPoints which
    // were not initially accepted; that would be inefficient and noisy.
    // So even if there is only one touchpoint so far, it's important to accept it
    // in order to get updates later on (and it's accepted by default anyway).
    // If the user puts down one finger, we're waiting for the other finger to drop.
    // Therefore updatePinch() must do the right thing for any combination of
    // points and states that may occur, and there is no reason to ignore any event.
    // One consequence though is that if PinchArea is on top of something else,
    // it's always going to accept the touches, and that means the item underneath
    // will not get them (unless the PA's parent is doing parent filtering,
    // as the Flickable does, for example).

    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
        d->touchPoints.clear();
        for (int i = 0; i < event->touchPoints().count(); ++i) {
            if (!(event->touchPoints().at(i).state() & Qt::TouchPointReleased)) {
                d->touchPoints << event->touchPoints().at(i);
            }
        }
        updatePinch();
        break;
    case QEvent::TouchEnd:
        d->touchPoints.clear();
        updatePinch();
        break;
    default:
        QQuickItem::event(event);
    }
}