diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8fd03cdb76..468523ab9c 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -4655,14 +4655,14 @@ QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const \obsolete This function is deprecated in 5.9 because it returns the outer bounds of the touchpoint regardless of rotation, whereas a touchpoint is more correctly - modeled as an ellipse at position pos() with horizontalDiameter() and - verticalDiameter() which are independent of rotation(). + modeled as an ellipse at position pos() with ellipseDiameters() + which are independent of rotation(). - \sa scenePos(), horizontalDiameter(), verticalDiameter() + \sa scenePos(), ellipseDiameters() */ QRectF QTouchEvent::TouchPoint::rect() const { - QRectF ret(0, 0, d->horizontalDiameter, d->verticalDiameter); + QRectF ret(QPointF(), d->ellipseDiameters); ret.moveCenter(d->pos); return ret; } @@ -4674,14 +4674,14 @@ QRectF QTouchEvent::TouchPoint::rect() const \obsolete This function is deprecated in 5.9 because it returns the outer bounds of the touchpoint regardless of rotation, whereas a touchpoint is more correctly - modeled as an ellipse at position scenePos() with horizontalDiameter() and - verticalDiameter() which are independent of rotation(). + modeled as an ellipse at position scenePos() with ellipseDiameters() + which are independent of rotation(). - \sa scenePos(), horizontalDiameter(), verticalDiameter() + \sa scenePos(), ellipseDiameters() */ QRectF QTouchEvent::TouchPoint::sceneRect() const { - QRectF ret(0, 0, d->horizontalDiameter, d->verticalDiameter); + QRectF ret(QPointF(), d->ellipseDiameters); ret.moveCenter(d->scenePos); return ret; } @@ -4693,14 +4693,14 @@ QRectF QTouchEvent::TouchPoint::sceneRect() const \obsolete This function is deprecated because it returns the outer bounds of the touchpoint regardless of rotation, whereas a touchpoint is more correctly - modeled as an ellipse at position screenPos() with horizontalDiameter() and - verticalDiameter() which are independent of rotation(). + modeled as an ellipse at position screenPos() with ellipseDiameters() + which are independent of rotation(). - \sa screenPos(), horizontalDiameter(), verticalDiameter() + \sa screenPos(), ellipseDiameters() */ QRectF QTouchEvent::TouchPoint::screenRect() const { - QRectF ret(0, 0, d->horizontalDiameter, d->verticalDiameter); + QRectF ret(QPointF(), d->ellipseDiameters); ret.moveCenter(d->screenPos); return ret; } @@ -4729,26 +4729,15 @@ qreal QTouchEvent::TouchPoint::rotation() const /*! \since 5.9 - Returns the width of the bounding ellipse of this touch point. - The return value is in logical pixels, along the horizontal axis - when rotation() is zero. Most touchscreens do not detect the shape of the - contact point, so zero is the most common value. + Returns the width and height of the bounding ellipse of this touch point. + The return value is in logical pixels. Most touchscreens do not detect the + shape of the contact point, so a null size is the most common value. + In other cases the diameters may be nonzero and equal (the ellipse is + approximated as a circle). */ -qreal QTouchEvent::TouchPoint::horizontalDiameter() const +QSizeF QTouchEvent::TouchPoint::ellipseDiameters() const { - return d->horizontalDiameter; -} - -/*! - \since 5.9 - Returns the height of the bounding ellipse of this touch point. - The return value is in logical pixels, along the vertical axis - when rotation() is zero. Most touchscreens do not detect the shape - of the contact point, so zero is the most common value. -*/ -qreal QTouchEvent::TouchPoint::verticalDiameter() const -{ - return d->verticalDiameter; + return d->ellipseDiameters; } /*! @@ -4920,8 +4909,7 @@ void QTouchEvent::TouchPoint::setRect(const QRectF &rect) if (d->ref.load() != 1) d = d->detach(); d->pos = rect.center(); - d->verticalDiameter = rect.height(); - d->horizontalDiameter = rect.width(); + d->ellipseDiameters = rect.size(); } /*! \internal \obsolete */ @@ -4930,8 +4918,7 @@ void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect) if (d->ref.load() != 1) d = d->detach(); d->scenePos = sceneRect.center(); - d->verticalDiameter = sceneRect.height(); - d->horizontalDiameter = sceneRect.width(); + d->ellipseDiameters = sceneRect.size(); } /*! \internal \obsolete */ @@ -4940,8 +4927,7 @@ void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect) if (d->ref.load() != 1) d = d->detach(); d->screenPos = screenRect.center(); - d->verticalDiameter = screenRect.height(); - d->horizontalDiameter = screenRect.width(); + d->ellipseDiameters = screenRect.size(); } /*! \internal */ @@ -4961,19 +4947,11 @@ void QTouchEvent::TouchPoint::setRotation(qreal angle) } /*! \internal */ -void QTouchEvent::TouchPoint::setVerticalDiameter(qreal dia) +void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia) { if (d->ref.load() != 1) d = d->detach(); - d->verticalDiameter = dia; -} - -/*! \internal */ -void QTouchEvent::TouchPoint::setHorizontalDiameter(qreal dia) -{ - if (d->ref.load() != 1) - d = d->detach(); - d->horizontalDiameter = dia; + d->ellipseDiameters = dia; } /*! \internal */ diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 982072c7d4..d7b7b636b2 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -870,8 +870,7 @@ public: qreal pressure() const; qreal rotation() const; - qreal horizontalDiameter() const; - qreal verticalDiameter() const; + QSizeF ellipseDiameters() const; QVector2D velocity() const; InfoFlags flags() const; @@ -898,8 +897,7 @@ public: void setScreenRect(const QRectF &screenRect); // deprecated void setPressure(qreal pressure); void setRotation(qreal angle); - void setVerticalDiameter(qreal dia); - void setHorizontalDiameter(qreal dia); + void setEllipseDiameters(const QSizeF &dia); void setVelocity(const QVector2D &v); void setFlags(InfoFlags flags); void setRawScreenPositions(const QVector &positions); diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index a8b4d520d4..f67284eebb 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -65,10 +65,9 @@ public: : ref(1), id(id), state(Qt::TouchPointReleased), - pressure(qreal(-1.)), - rotation(qreal(0.)), - verticalDiameter(0), - horizontalDiameter(0) + pressure(-1), + rotation(0), + ellipseDiameters(0, 0) { } inline QTouchEventTouchPointPrivate *detach() @@ -89,8 +88,7 @@ public: lastPos, lastScenePos, lastScreenPos, lastNormalizedPos; qreal pressure; qreal rotation; - qreal verticalDiameter; - qreal horizontalDiameter; + QSizeF ellipseDiameters; QVector2D velocity; QTouchEvent::TouchPoint::InfoFlags flags; QVector rawScreenPositions; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 4d1caa9232..bf5f6b5f64 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2568,8 +2568,6 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To // so we can modify it as long as we're careful NOT to call setters and // otherwise NOT to cause the d-pointer to be detached. touchPoint.d->scenePos = touchPoint.screenPos(); - touchPoint.d->verticalDiameter = touchPoint.screenRect().height(); - touchPoint.d->horizontalDiameter = touchPoint.screenRect().width(); touchPoint.d->startScenePos = touchPoint.startScreenPos(); touchPoint.d->lastScenePos = touchPoint.lastScreenPos(); @@ -2635,13 +2633,10 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QTouchEvent::TouchPoint &touchPoint = touchEvent._touchPoints[i]; // preserve the sub-pixel resolution - QRectF rect = touchPoint.screenRect(); - const QPointF screenPos = rect.center(); + const QPointF screenPos = touchPoint.screenPos(); const QPointF delta = screenPos - screenPos.toPoint(); touchPoint.d->pos = w->mapFromGlobal(screenPos.toPoint()) + delta; - touchPoint.d->verticalDiameter = rect.height(); - touchPoint.d->horizontalDiameter = rect.width(); if (touchPoint.state() == Qt::TouchPointPressed) { // touchPoint is actually a reference to one that is stored in activeTouchPoints, // and we are now going to store the startPos and lastPos there, for the benefit diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 9588b631a0..1bdfcfada2 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3550,11 +3550,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) touchEvent->setTarget(widget); for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) { QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i]; - QRectF rect = pt.rect(); - rect.translate(offset); - pt.d->pos = rect.center(); - pt.d->verticalDiameter = rect.height(); - pt.d->horizontalDiameter = rect.width(); + pt.d->pos = pt.pos() + offset; pt.d->startPos = pt.startPos() + offset; pt.d->lastPos = pt.lastPos() + offset; } @@ -4251,14 +4247,10 @@ bool QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEven QTouchEvent::TouchPoint &touchPoint = touchEvent->_touchPoints[i]; // preserve the sub-pixel resolution - QRectF rect = touchPoint.screenRect(); - const QPointF screenPos = rect.center(); + const QPointF screenPos = touchPoint.screenRect().center(); const QPointF delta = screenPos - screenPos.toPoint(); - rect.moveCenter(widget->mapFromGlobal(screenPos.toPoint()) + delta); - touchPoint.d->pos = rect.center(); - touchPoint.d->verticalDiameter = rect.height(); - touchPoint.d->horizontalDiameter = rect.width(); + touchPoint.d->pos = widget->mapFromGlobal(screenPos.toPoint()) + delta; touchPoint.d->startPos = widget->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta; touchPoint.d->lastPos = widget->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta;