qwinrtcursor: Use QPointF as much as possible in pos/setPos
Using QPoint for calculations can lead to rounding errors which can result in a situation where "QCursor::setPos(somePos); QCOMPARE(pos, somePos)" fails. Change-Id: Iaba499f67abcf5ec66adfe93bfbd79ef0102e6d0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
fdcbf0b2a2
commit
7b00eab593
@ -179,14 +179,15 @@ QPoint QWinRTCursor::pos() const
|
|||||||
return hr;
|
return hr;
|
||||||
});
|
});
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
QPoint position = QPoint(int(point.X), int(point.Y));
|
QPointF position(qreal(point.X), qreal(point.Y));
|
||||||
// If no cursor get_PointerPosition returns SHRT_MIN for x and y
|
// If no cursor get_PointerPosition returns SHRT_MIN for x and y
|
||||||
if ((position.x() == SHRT_MIN && position.y() == SHRT_MIN) || FAILED(hr))
|
if ((int(position.x()) == SHRT_MIN && int(position.y()) == SHRT_MIN)
|
||||||
|
|| FAILED(hr))
|
||||||
return QPointF(Q_INFINITY, Q_INFINITY).toPoint();
|
return QPointF(Q_INFINITY, Q_INFINITY).toPoint();
|
||||||
position.rx() -= bounds.X;
|
position.rx() -= qreal(bounds.X);
|
||||||
position.ry() -= bounds.Y;
|
position.ry() -= qreal(bounds.Y);
|
||||||
position *= screen->scaleFactor();
|
position *= screen->scaleFactor();
|
||||||
return position;
|
return position.toPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWinRTCursor::setPos(const QPoint &pos)
|
void QWinRTCursor::setPos(const QPoint &pos)
|
||||||
@ -195,7 +196,7 @@ void QWinRTCursor::setPos(const QPoint &pos)
|
|||||||
Q_ASSERT(screen);
|
Q_ASSERT(screen);
|
||||||
ComPtr<ICoreWindow> coreWindow = screen->coreWindow();
|
ComPtr<ICoreWindow> coreWindow = screen->coreWindow();
|
||||||
Q_ASSERT(coreWindow);
|
Q_ASSERT(coreWindow);
|
||||||
const QPointF scaledPos = pos / screen->scaleFactor();
|
const QPointF scaledPos = QPointF(pos) / screen->scaleFactor();
|
||||||
QWinRTScreen::MousePositionTransition t;
|
QWinRTScreen::MousePositionTransition t;
|
||||||
HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, scaledPos, &t]() {
|
HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, scaledPos, &t]() {
|
||||||
ComPtr<ICoreWindow2> coreWindow2;
|
ComPtr<ICoreWindow2> coreWindow2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user