summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/kernel/qapplication.cpp6
-rw-r--r--src/gui/kernel/qapplication_win.cpp4
-rw-r--r--src/gui/kernel/qevent.cpp52
-rw-r--r--src/gui/kernel/qevent.h7
-rw-r--r--src/gui/kernel/qevent_p.h5
-rw-r--r--tests/auto/qtouchevent/tst_qtouchevent.cpp16
6 files changed, 88 insertions, 2 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index 5ef453d..4671ded 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -5331,6 +5331,8 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
d->widgetForTouchPointId[touchPoint.id()] = widget;
touchPoint.setStartScreenPos(touchPoint.screenPos());
touchPoint.setLastScreenPos(touchPoint.screenPos());
+ touchPoint.setStartNormalizedPos(touchPoint.normalizedPos());
+ touchPoint.setLastNormalizedPos(touchPoint.normalizedPos());
d->appCurrentTouchPoints.insert(touchPoint.id(), touchPoint);
break;
}
@@ -5343,6 +5345,8 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
QTouchEvent::TouchPoint previousTouchPoint = d->appCurrentTouchPoints.take(touchPoint.id());
touchPoint.setStartScreenPos(previousTouchPoint.startScreenPos());
touchPoint.setLastScreenPos(previousTouchPoint.screenPos());
+ touchPoint.setStartNormalizedPos(previousTouchPoint.startNormalizedPos());
+ touchPoint.setLastNormalizedPos(previousTouchPoint.normalizedPos());
break;
}
default:
@@ -5353,6 +5357,8 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
QTouchEvent::TouchPoint previousTouchPoint = d->appCurrentTouchPoints.value(touchPoint.id());
touchPoint.setStartScreenPos(previousTouchPoint.startScreenPos());
touchPoint.setLastScreenPos(previousTouchPoint.screenPos());
+ touchPoint.setStartNormalizedPos(previousTouchPoint.startNormalizedPos());
+ touchPoint.setLastNormalizedPos(previousTouchPoint.normalizedPos());
d->appCurrentTouchPoints[touchPoint.id()] = touchPoint;
break;
}
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index f8b1cbb..dd4aace 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -4023,6 +4023,8 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
if (!widgetForHwnd)
return false;
+ QRect screenGeometry = q->desktop()->screenGeometry(widgetForHwnd);
+
QList<QTouchEvent::TouchPoint> touchPoints;
QVector<TOUCHINPUT> winTouchInputs(msg.wParam);
@@ -4062,6 +4064,8 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
state |= Qt::TouchPointPrimary;
touchPoint.setState(state);
touchPoint.setScreenRect(screenRect);
+ touchPoint.setNormalizedPos(screenPos.x() / screenGeometry.width(),
+ screenPos.y() / screenGeometry.height());
allStates |= state;
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 9c990c3..759aeb9 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3873,6 +3873,15 @@ QPointF QTouchEvent::TouchPoint::screenPos() const
}
/*!
+ Returns the position of this touch point. The coordinates are normalized to size of the touch
+ device, i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
+*/
+QPointF QTouchEvent::TouchPoint::normalizedPos() const
+{
+ return d->normalizedPos;
+}
+
+/*!
Returns the starting position of this touch point, relative to the
widget that received the event.
*/
@@ -3898,6 +3907,15 @@ QPointF QTouchEvent::TouchPoint::startScreenPos() const
}
/*!
+ Returns the starting position of this touch point. The coordinates are normalized to size of
+ the touch device, i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
+*/
+QPointF QTouchEvent::TouchPoint::startNormalizedPos() const
+{
+ return d->startNormalizedPos;
+}
+
+/*!
Returns the position of this touch point from the previous touch
event, relative to the widget that received the event.
*/
@@ -3925,6 +3943,16 @@ QPointF QTouchEvent::TouchPoint::lastScreenPos() const
}
/*!
+ Returns the position of this touch point from the previous touch event. The coordinates are
+ normalized to size of the touch device, i.e. (0,0) is the top-left corner and (1,1) is the
+ bottom-right corner.
+*/
+QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
+{
+ return d->lastNormalizedPos;
+}
+
+/*!
Returns the rect for this touch point. The rect is centered around the point returned by pos().
Note this function returns an empty rect if the device does not report touch point sizes.
*/
@@ -3999,6 +4027,14 @@ void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
}
/*! \internal */
+void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
+{
+ if (d->ref != 1)
+ d = d->detach();
+ d->normalizedPos = normalizedPos;
+}
+
+/*! \internal */
void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
{
if (d->ref != 1)
@@ -4023,6 +4059,14 @@ void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
}
/*! \internal */
+void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
+{
+ if (d->ref != 1)
+ d = d->detach();
+ d->startNormalizedPos = startNormalizedPos;
+}
+
+/*! \internal */
void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
{
if (d->ref != 1)
@@ -4047,6 +4091,14 @@ void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
}
/*! \internal */
+void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
+{
+ if (d->ref != 1)
+ d = d->detach();
+ d->lastNormalizedPos = lastNormalizedPos;
+}
+
+/*! \internal */
void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
{
if (d->ref != 1)
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index ce3f0c0..04303fb 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -786,6 +786,10 @@ public:
QPointF startScreenPos() const;
QPointF lastScreenPos() const;
+ QPointF normalizedPos() const;
+ QPointF startNormalizedPos() const;
+ QPointF lastNormalizedPos() const;
+
QRectF rect() const;
QRectF sceneRect() const;
QRectF screenRect() const;
@@ -798,12 +802,15 @@ public:
void setPos(const QPointF &pos);
void setScenePos(const QPointF &scenePos);
void setScreenPos(const QPointF &screenPos);
+ void setNormalizedPos(const QPointF &normalizedPos);
void setStartPos(const QPointF &startPos);
void setStartScenePos(const QPointF &startScenePos);
void setStartScreenPos(const QPointF &startScreenPos);
+ void setStartNormalizedPos(const QPointF &startNormalizedPos);
void setLastPos(const QPointF &lastPos);
void setLastScenePos(const QPointF &lastScenePos);
void setLastScreenPos(const QPointF &lastScreenPos);
+ void setLastNormalizedPos(const QPointF &lastNormalizedPos);
void setRect(const QRectF &rect);
void setSceneRect(const QRectF &sceneRect);
void setScreenRect(const QRectF &screenRect);
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index 53d7a23..ba0159f 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -112,8 +112,9 @@ public:
int id;
Qt::TouchPointStates state;
QRectF rect, sceneRect, screenRect;
- QPointF startPos, startScenePos, startScreenPos;
- QPointF lastPos, lastScenePos, lastScreenPos;
+ QPointF normalizedPos,
+ startPos, startScenePos, startScreenPos, startNormalizedPos,
+ lastPos, lastScenePos, lastScreenPos, lastNormalizedPos;
qreal pressure;
};
diff --git a/tests/auto/qtouchevent/tst_qtouchevent.cpp b/tests/auto/qtouchevent/tst_qtouchevent.cpp
index 6885e8b..b21ba40 100644
--- a/tests/auto/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/qtouchevent/tst_qtouchevent.cpp
@@ -251,6 +251,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QPointF pos = touchWidget.rect().center();
QPointF screenPos = touchWidget.mapToGlobal(pos.toPoint());
QPointF delta(10, 10);
+ QRect screenGeometry = qApp->desktop()->screenGeometry(&touchWidget);
QTouchEvent::TouchPoint rawTouchPoint;
rawTouchPoint.setId(0);
@@ -258,6 +259,8 @@ void tst_QTouchEvent::basicRawEventTranslation()
// this should be translated to a TouchBegin
rawTouchPoint.setState(Qt::TouchPointPressed);
rawTouchPoint.setScreenPos(screenPos);
+ rawTouchPoint.setNormalizedPos(QPointF(rawTouchPoint.pos().x() / screenGeometry.width(),
+ rawTouchPoint.pos().y() / screenGeometry.height()));
qt_translateRawTouchEvent(QList<QTouchEvent::TouchPoint>() << rawTouchPoint, &touchWidget);
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
@@ -275,6 +278,9 @@ void tst_QTouchEvent::basicRawEventTranslation()
QCOMPARE(touchBeginPoint.screenPos(), rawTouchPoint.screenPos());
QCOMPARE(touchBeginPoint.startScreenPos(), rawTouchPoint.screenPos());
QCOMPARE(touchBeginPoint.lastScreenPos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchBeginPoint.normalizedPos(), rawTouchPoint.normalizedPos());
+ QCOMPARE(touchBeginPoint.startNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchBeginPoint.lastNormalizedPos(), touchBeginPoint.normalizedPos());
QCOMPARE(touchBeginPoint.rect(), QRectF(pos, QSizeF(0, 0)));
QCOMPARE(touchBeginPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0)));
QCOMPARE(touchBeginPoint.sceneRect(), touchBeginPoint.screenRect());
@@ -283,6 +289,8 @@ void tst_QTouchEvent::basicRawEventTranslation()
// moving the point should translate to TouchUpdate
rawTouchPoint.setState(Qt::TouchPointMoved);
rawTouchPoint.setScreenPos(screenPos + delta);
+ rawTouchPoint.setNormalizedPos(QPointF(rawTouchPoint.pos().x() / screenGeometry.width(),
+ rawTouchPoint.pos().y() / screenGeometry.height()));
qt_translateRawTouchEvent(QList<QTouchEvent::TouchPoint>() << rawTouchPoint, &touchWidget);
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
@@ -300,6 +308,9 @@ void tst_QTouchEvent::basicRawEventTranslation()
QCOMPARE(touchUpdatePoint.screenPos(), rawTouchPoint.screenPos());
QCOMPARE(touchUpdatePoint.startScreenPos(), screenPos);
QCOMPARE(touchUpdatePoint.lastScreenPos(), screenPos);
+ QCOMPARE(touchUpdatePoint.normalizedPos(), rawTouchPoint.normalizedPos());
+ QCOMPARE(touchUpdatePoint.startNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchUpdatePoint.lastNormalizedPos(), touchBeginPoint.normalizedPos());
QCOMPARE(touchUpdatePoint.rect(), QRectF(pos + delta, QSizeF(0, 0)));
QCOMPARE(touchUpdatePoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0)));
QCOMPARE(touchUpdatePoint.sceneRect(), touchUpdatePoint.screenRect());
@@ -308,6 +319,8 @@ void tst_QTouchEvent::basicRawEventTranslation()
// releasing the point translates to TouchEnd
rawTouchPoint.setState(Qt::TouchPointReleased);
rawTouchPoint.setScreenPos(screenPos + delta + delta);
+ rawTouchPoint.setNormalizedPos(QPointF(rawTouchPoint.pos().x() / screenGeometry.width(),
+ rawTouchPoint.pos().y() / screenGeometry.height()));
qt_translateRawTouchEvent(QList<QTouchEvent::TouchPoint>() << rawTouchPoint, &touchWidget);
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
@@ -325,6 +338,9 @@ void tst_QTouchEvent::basicRawEventTranslation()
QCOMPARE(touchEndPoint.screenPos(), rawTouchPoint.screenPos());
QCOMPARE(touchEndPoint.startScreenPos(), screenPos);
QCOMPARE(touchEndPoint.lastScreenPos(), screenPos + delta);
+ QCOMPARE(touchEndPoint.normalizedPos(), rawTouchPoint.normalizedPos());
+ QCOMPARE(touchEndPoint.startNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchEndPoint.lastNormalizedPos(), touchUpdatePoint.normalizedPos());
QCOMPARE(touchEndPoint.rect(), QRectF(pos + delta + delta, QSizeF(0, 0)));
QCOMPARE(touchEndPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0)));
QCOMPARE(touchEndPoint.sceneRect(), touchEndPoint.screenRect());