Fix finding the closest active touch point for the pressed touch point

Currently pressed touch point is added to the list of active touch
points in Gui module. It must be excluded from consideration when
we traverse the list.

Task-number: QTBUG-43255
Change-Id: Idddab093b1f6a79122cf18fad7f43bfc93ce7eea
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Alexander Volkov 2015-01-14 19:27:22 +03:00
parent f58e882b75
commit 0c28e1ab7a
3 changed files with 58 additions and 4 deletions

View File

@ -4275,15 +4275,16 @@ void QApplicationPrivate::cleanupMultitouch_sys()
{
}
QWidget *QApplicationPrivate::findClosestTouchPointTarget(QTouchDevice *device, const QPointF &screenPos)
QWidget *QApplicationPrivate::findClosestTouchPointTarget(QTouchDevice *device, const QTouchEvent::TouchPoint &touchPoint)
{
const QPointF screenPos = touchPoint.screenPos();
int closestTouchPointId = -1;
QObject *closestTarget = 0;
qreal closestDistance = qreal(0.);
QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it = activeTouchPoints.constBegin(),
ite = activeTouchPoints.constEnd();
while (it != ite) {
if (it.key().device == device) {
if (it.key().device == device && it.key().touchPointId != touchPoint.id()) {
const QTouchEvent::TouchPoint &touchPoint = it->touchPoint;
qreal dx = screenPos.x() - touchPoint.screenPos().x();
qreal dy = screenPos.y() - touchPoint.screenPos().y();
@ -4339,7 +4340,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
}
if (device->type() == QTouchDevice::TouchScreen) {
QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint.screenPos());
QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint);
QWidget *widget = static_cast<QWidget *>(target.data());
if (closestWidget
&& (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {

View File

@ -280,7 +280,7 @@ public:
void initializeMultitouch_sys();
void cleanupMultitouch();
void cleanupMultitouch_sys();
QWidget *findClosestTouchPointTarget(QTouchDevice *device, const QPointF &screenPos);
QWidget *findClosestTouchPointTarget(QTouchDevice *device, const QTouchEvent::TouchPoint &touchPoint);
void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint);
void removeTouchPoint(int touchPointId);
static bool translateRawTouchEvent(QWidget *widget,

View File

@ -435,6 +435,7 @@ private slots:
void grabKeyboard();
void touchEventSynthesizedMouseEvent();
void touchUpdateOnNewTouch();
void styleSheetPropagation();
@ -9763,6 +9764,9 @@ class TouchMouseWidget : public QWidget {
public:
explicit TouchMouseWidget(QWidget *parent = 0)
: QWidget(parent),
m_touchBeginCount(0),
m_touchUpdateCount(0),
m_touchEndCount(0),
m_touchEventCount(0),
m_acceptTouch(false),
m_mouseEventCount(0),
@ -9789,6 +9793,12 @@ protected:
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
if (e->type() == QEvent::TouchBegin)
++m_touchBeginCount;
else if (e->type() == QEvent::TouchUpdate)
++m_touchUpdateCount;
else if (e->type() == QEvent::TouchEnd)
++m_touchEndCount;
++m_touchEventCount;
if (m_acceptTouch)
e->accept();
@ -9813,6 +9823,9 @@ protected:
}
public:
int m_touchBeginCount;
int m_touchUpdateCount;
int m_touchEndCount;
int m_touchEventCount;
bool m_acceptTouch;
int m_mouseEventCount;
@ -9933,6 +9946,46 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
}
}
void tst_QWidget::touchUpdateOnNewTouch()
{
QTouchDevice *device = new QTouchDevice;
device->setType(QTouchDevice::TouchScreen);
QWindowSystemInterface::registerTouchDevice(device);
TouchMouseWidget widget;
widget.setAcceptTouch(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(new QWidget);
widget.setLayout(layout);
widget.show();
QWindow* window = widget.windowHandle();
QVERIFY(QTest::qWaitForWindowExposed(window));
QCOMPARE(widget.m_touchBeginCount, 0);
QCOMPARE(widget.m_touchUpdateCount, 0);
QCOMPARE(widget.m_touchEndCount, 0);
QTest::touchEvent(window, device).press(0, QPoint(20, 20), window);
QCOMPARE(widget.m_touchBeginCount, 1);
QCOMPARE(widget.m_touchUpdateCount, 0);
QCOMPARE(widget.m_touchEndCount, 0);
QTest::touchEvent(window, device).move(0, QPoint(25, 25), window);
QCOMPARE(widget.m_touchBeginCount, 1);
QCOMPARE(widget.m_touchUpdateCount, 1);
QCOMPARE(widget.m_touchEndCount, 0);
QTest::touchEvent(window, device).stationary(0).press(1, QPoint(40, 40), window);
QCOMPARE(widget.m_touchBeginCount, 1);
QCOMPARE(widget.m_touchUpdateCount, 2);
QCOMPARE(widget.m_touchEndCount, 0);
QTest::touchEvent(window, device).stationary(1).release(0, QPoint(25, 25), window);
QCOMPARE(widget.m_touchBeginCount, 1);
QCOMPARE(widget.m_touchUpdateCount, 3);
QCOMPARE(widget.m_touchEndCount, 0);
QTest::touchEvent(window, device).release(1, QPoint(40, 40), window);
QCOMPARE(widget.m_touchBeginCount, 1);
QCOMPARE(widget.m_touchUpdateCount, 3);
QCOMPARE(widget.m_touchEndCount, 1);
}
void tst_QWidget::styleSheetPropagation()
{
QTableView tw;