[Interest] Two single touch areas

Federico Brega charon.66 at gmail.com
Sat Apr 6 16:23:59 CEST 2013


Hello everyone,

I'd like to do a full screen application for multi-touch devices. It
splits the screen (window) vertically, each half should track the
position of a finger touching it.
I'm using Qt Quick 1 because my only multi-touch device runs Android.
The only way to do this, in my understanding, is exposing multi-touch
events by subclassing QDeclarativeItem.
I tried several ways:
- an item for each half, it simply mimics the behaviour of MouseArea
- a single item dispaching touch events to the appropriate side

None of them really worked. The worst scenario is when I start
touching the left side, then touch also the right side and finally
release the left side.
At this point the touch point on the right side isn't tracked anymore.

My last try appended at the end of this message

Is this achievable in Qt 4?
Are the new touch area in Qt5 useful for this purpose?

Regards
--
Federico

#include "singletoucharea.h"

#include <QEvent>
#include <QTouchEvent>
#include <QGraphicsSceneMouseEvent>

SingleTouchArea::SingleTouchArea(QDeclarativeItem *parent) :
    QDeclarativeItem(parent),
    m_saturationMargin(0)
{
    setAcceptTouchEvents(true);
    setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
}

bool SingleTouchArea::sceneEvent(QEvent *event)
{
//    qDebug () << event->type();
    switch (event->type ()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
        QPointF pos = touchEvent->touchPoints().first().pos();
        m_pos = QPointF(qBound(m_saturationMargin, pos.x(), width() -
m_saturationMargin),
                        qBound(m_saturationMargin, pos.y(), height() -
m_saturationMargin));
//        qDebug() << m_pos;
        emit positionChanged(m_pos);

        break;
    }

    case QEvent::GraphicsSceneMousePress:
    case QEvent::GraphicsSceneMouseMove:
    {
        QGraphicsSceneMouseEvent *mouseEvent =
static_cast<QGraphicsSceneMouseEvent *>(event);
        QPointF pos = mouseEvent->pos();
        m_pos = QPointF(qBound(m_saturationMargin, pos.x(), width() -
m_saturationMargin),
                        qBound(m_saturationMargin, pos.y(), height() -
m_saturationMargin));
//        qDebug() << m_pos;
        emit positionChanged (m_pos);

        break;
    }

    default:
        return QDeclarativeItem::sceneEvent(event);
    }

    return true;
}

void SingleTouchArea::setSaturationMargin(qreal margin)
{
    if (m_saturationMargin != margin) {
        m_saturationMargin = margin;
        emit saturationMarginChanged(m_saturationMargin);
    }
}



More information about the Interest mailing list