diff options
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 6 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_win.cpp | 4 | ||||
-rw-r--r-- | src/gui/kernel/qevent.cpp | 52 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 7 | ||||
-rw-r--r-- | src/gui/kernel/qevent_p.h | 5 |
5 files changed, 72 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; }; |