// Copied with minor modifications from qtdeclarative/src/quick/items/qquickwindow.cpp
QMouseEvent *TouchDispatcher::touchToMouseEvent(
        QEvent::Type type, const QTouchEvent::TouchPoint &p,
        ulong timestamp, Qt::KeyboardModifiers modifiers,
        bool transformNeeded)
{
    QQuickItem *item = m_targetItem.data();

    // The touch point local position and velocity are not yet transformed.
    QMouseEvent *me = new QMouseEvent(type, transformNeeded ? item->mapFromScene(p.scenePos()) : p.pos(),
                                      p.scenePos(), p.screenPos(), Qt::LeftButton,
                                      (type == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton),
                                      modifiers);
    me->setAccepted(true);
    me->setTimestamp(timestamp);
    QVector2D transformedVelocity = p.velocity();
    if (transformNeeded) {
        QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
        QMatrix4x4 transformMatrix(itemPrivate->windowToItemTransform());
        transformedVelocity = transformMatrix.mapVector(p.velocity()).toVector2D();
    }

    // Add these later if needed:
    //QGuiApplicationPrivate::setMouseEventCapsAndVelocity(me, event->device()->capabilities(), transformedVelocity);
    //QGuiApplicationPrivate::setMouseEventSource(me, Qt::MouseEventSynthesizedByQt);
    return me;
}
Example #2
0
bool MouseEventFilter::eventFilter(QObject * obj, QEvent * evnt)
{
    if (evnt->type() == QEvent::MouseButtonPress)
    {
        QMouseEvent* m = static_cast<QMouseEvent*>(evnt);
        qDebug() << "X: " << m->x() << "Y: " << m->y();
        m->setAccepted(true);
        return true;
    }
    return false;
}