summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2016-12-06 14:48:44 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2016-12-09 13:44:55 +0000
commit201f89f463ae82fe8e9239d7312907062e9a8d15 (patch)
treebff62d570082aa6e096123a85399517e9acc5973
parenta30fca8711374edfefb2085aaa64ac98971b7c40 (diff)
QTouchEvent::TouchPoint: replace ellipse diameters with QSizeF
It makes assignment a bit more succinct and efficient since they are usually set together. Since we store the diameters and the points separately, we no longer need to worry about updating rects by moving their centers. QGuiApplication and QApplication don't need to alter the diameters: they are set once when the event is constructed. Also fix the initialization of pressure and rotation: 418b6f6899ee414aff29c91a4ae17eed8791a617 did it by casting a double to qreal, whereas a plain integer constant will be auto-converted by the compiler anyway. Change-Id: Ib9956d2def21278b8ae042147d917da156e77e52 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--src/gui/kernel/qevent.cpp70
-rw-r--r--src/gui/kernel/qevent.h6
-rw-r--r--src/gui/kernel/qevent_p.h10
-rw-r--r--src/gui/kernel/qguiapplication.cpp7
-rw-r--r--src/widgets/kernel/qapplication.cpp14
5 files changed, 34 insertions, 73 deletions
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)
-{
- if (d->ref.load() != 1)
- d = d->detach();
- d->verticalDiameter = dia;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setHorizontalDiameter(qreal dia)
+void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &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<QPointF> &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<QPointF> 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;