Add QEventPoint::normalizedPosition() to replace normalizedPos()
In 4e400369c08db251cd489fec1229398c224d02b4 we deprecated normalizedPos() because we suspect it's a legacy feature that few users will need. However Qt developers keep bringing up the continued usage in autotests over and over. (It's IMO not wrong to keep testing deprecated functions in autotests, but the warning keeps attracting attention.) Of course it will turn out that normalizedPos() has users; we just don't know how many. One way to look at it is: why should they copy a snippet of code to calculate it, when it costs us so little to continue to provide this accessor. It might also turn out that some users will complain that in Qt 5 it was passed through from the device driver (or at least from the window system API) to the application, and perhaps the replacement will not always work, for example if availableVirtualGeometry() ends up wrong, or there is some strange scenario that generates events that are out-of-bounds for the device that the event professes to come from, so that the "normalized" coordinates also go outside the [0..1] range. We reserve the right to put back the storage in QEventPointPrivate if the need arises; so that's why this function is not inline. We continue to hope that startNormalizedPos() and lastNormalizedPos() are used even less and won't be missed much, because it would be wasteful to store them all the time if only a few users need them. Change-Id: I23ed78843e3f9e16133c5b6f462884a3845f91b6 Reviewed-by: David Skoland <david.skoland@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
46dd4df4b9
commit
f6418343f1
@ -410,16 +410,21 @@ void QEventPoint::setAccepted(bool accepted)
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
Deprecated since Qt 6.0. Use globalPosition() instead.
|
||||
\fn QPointF QPointerEvent::normalizedPos() const
|
||||
|
||||
Deprecated since Qt 6.0. Use normalizedPosition() instead.
|
||||
*/
|
||||
|
||||
/*!
|
||||
Returns the normalized position of this point.
|
||||
|
||||
The coordinates are normalized to QInputDevice::availableVirtualGeometry(),
|
||||
i.e. (0, 0) is the top-left corner and (1, 1) is the bottom-right corner.
|
||||
The coordinates are calculated by transforming globalPosition() into the
|
||||
space of QInputDevice::availableVirtualGeometry(), i.e. \c (0, 0) is the
|
||||
top-left corner and \c (1, 1) is the bottom-right corner.
|
||||
|
||||
\sa startNormalizedPos(), lastNormalizedPos(), pos()
|
||||
\sa globalPosition()
|
||||
*/
|
||||
QPointF QEventPoint::normalizedPos() const
|
||||
QPointF QEventPoint::normalizedPosition() const
|
||||
{
|
||||
auto geom = d->device->availableVirtualGeometry();
|
||||
if (geom.isNull())
|
||||
@ -449,7 +454,7 @@ QPointF QEventPoint::startNormalizedPos() const
|
||||
move event.
|
||||
|
||||
The coordinates are normalized to QInputDevice::availableVirtualGeometry(),
|
||||
i.e. (0, 0) is the top-left corner and (1, 1) is the bottom-right corner.
|
||||
i.e. \c (0, 0) is the top-left corner and \c (1, 1) is the bottom-right corner.
|
||||
|
||||
\sa normalizedPos(), startNormalizedPos()
|
||||
*/
|
||||
|
@ -145,6 +145,7 @@ public:
|
||||
QPointF globalPressPosition() const;
|
||||
QPointF globalGrabPosition() const;
|
||||
QPointF globalLastPosition() const;
|
||||
QPointF normalizedPosition() const;
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 0)
|
||||
// QEventPoint replaces QTouchEvent::TouchPoint, so we need all its old accessors, for now
|
||||
@ -162,8 +163,8 @@ public:
|
||||
QPointF startScreenPos() const { return globalPressPosition(); }
|
||||
QT_DEPRECATED_VERSION_X_6_0("Use globalPressPosition()")
|
||||
QPointF startNormalizedPos() const;
|
||||
QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
|
||||
QPointF normalizedPos() const;
|
||||
QT_DEPRECATED_VERSION_X_6_0("Use normalizedPosition()")
|
||||
QPointF normalizedPos() const { return normalizedPosition(); }
|
||||
QT_DEPRECATED_VERSION_X_6_0("Use lastPosition()")
|
||||
QPointF lastPos() const { return lastPosition(); }
|
||||
QT_DEPRECATED_VERSION_X_6_0("Use sceneLastPosition()")
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
touchBeginPoints = touchEvent->points();
|
||||
Q_ASSERT(touchBeginPoints.first().device() == touchEvent->pointingDevice());
|
||||
for (const QEventPoint &pt : qAsConst(touchBeginPoints))
|
||||
lastNormalizedPositions << pt.normalizedPos();
|
||||
lastNormalizedPositions << pt.normalizedPosition();
|
||||
timestamp = touchEvent->timestamp();
|
||||
deviceFromEvent = touchEvent->pointingDevice();
|
||||
event->setAccepted(acceptTouchBegin);
|
||||
@ -97,7 +97,7 @@ public:
|
||||
auto touchEvent = static_cast<QTouchEvent *>(event);
|
||||
touchUpdatePoints = touchEvent->points();
|
||||
for (const QEventPoint &pt : qAsConst(touchUpdatePoints))
|
||||
lastNormalizedPositions << pt.normalizedPos();
|
||||
lastNormalizedPositions << pt.normalizedPosition();
|
||||
timestamp = touchEvent->timestamp();
|
||||
deviceFromEvent = touchEvent->pointingDevice();
|
||||
event->setAccepted(acceptTouchUpdate);
|
||||
@ -113,7 +113,7 @@ public:
|
||||
auto touchEvent = static_cast<QTouchEvent *>(event);
|
||||
touchEndPoints = touchEvent->points();
|
||||
for (const QEventPoint &pt : qAsConst(touchEndPoints))
|
||||
lastNormalizedPositions << pt.normalizedPos();
|
||||
lastNormalizedPositions << pt.normalizedPosition();
|
||||
timestamp = touchEvent->timestamp();
|
||||
deviceFromEvent = touchEvent->pointingDevice();
|
||||
event->setAccepted(acceptTouchEnd);
|
||||
@ -702,11 +702,6 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate()
|
||||
}
|
||||
}
|
||||
|
||||
QPointF normalized(const QPointF &pos, const QRectF &rect)
|
||||
{
|
||||
return QPointF(pos.x() / rect.width(), pos.y() / rect.height());
|
||||
}
|
||||
|
||||
void tst_QTouchEvent::basicRawEventTranslation()
|
||||
{
|
||||
tst_QTouchEventWidget touchWidget;
|
||||
|
Loading…
x
Reference in New Issue
Block a user