diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-03-27 16:06:11 +0000 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-07-10 14:32:56 +0200 |
commit | 4e400369c08db251cd489fec1229398c224d02b4 (patch) | |
tree | 6279489dce7b0469d590461798deccf5d1193e29 /src/widgets/kernel/qstandardgestures.cpp | |
parent | 773a6bffd78b363577d27604e17f4ee08ff07e77 (diff) |
Refactor pointer event hierarchy
Some goals that have hopefully been achieved are:
- make QPointerEvent and QEventPoint resemble their Qt Quick
counterparts to such an extent that we can remove those wrappers
and go back to delivering the original events in Qt Quick
- make QEventPoint much smaller than QTouchEvent::TouchPoint, with no pimpl
- remove most public setters
- reduce the usage of complex constructors that take many arguments
- don't repeat ourselves: move accessors and storage upwards
rather than having redundant ones in subclasses
- standardize the set of accessors in QPointerEvent
- maintain source compatibility as much as possible: do not require
modifying event-handling code in any QWidget subclass
To avoid public setters we now introduce a few QMutable* subclasses.
This is a bit like the Builder pattern except that it doesn't involve
constructing a separate disposable object: the main event type can be
cast to the mutable type at any time to enable modifications, iff the
code is linked with gui-private. Therefore event classes can have
less-"complete" constructors, because internal Qt code can use setters
the same way it could use the ones in QTouchEvent before; and the event
classes don't need many friends. Even some read-accessors can be kept
private unless we are sure we want to expose them.
Task-number: QTBUG-46266
Fixes: QTBUG-72173
Change-Id: I740e4e40165b7bc41223d38b200bbc2b403e07b6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/kernel/qstandardgestures.cpp')
-rw-r--r-- | src/widgets/kernel/qstandardgestures.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/widgets/kernel/qstandardgestures.cpp b/src/widgets/kernel/qstandardgestures.cpp index 0a637ab6f8..48a2770df3 100644 --- a/src/widgets/kernel/qstandardgestures.cpp +++ b/src/widgets/kernel/qstandardgestures.cpp @@ -71,7 +71,7 @@ QGesture *QPanGestureRecognizer::create(QObject *target) return new QPanGesture; } -static QPointF panOffset(const QList<QTouchEvent::TouchPoint> &touchPoints, int maxCount) +static QPointF panOffset(const QList<QEventPoint> &touchPoints, int maxCount) { QPointF result; const int count = qMin(touchPoints.size(), maxCount); @@ -92,7 +92,7 @@ QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, case QEvent::TouchBegin: { const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); result = QGestureRecognizer::MayBeGesture; - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); + QEventPoint p = ev->touchPoints().at(0); d->lastOffset = d->offset = QPointF(); d->pointCount = m_pointCount; break; @@ -185,8 +185,8 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state, const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); d->changeFlags = { }; if (ev->touchPoints().size() == 2) { - QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); - QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); + QEventPoint p1 = ev->touchPoints().at(0); + QEventPoint p2 = ev->touchPoints().at(1); d->hotSpot = p1.globalPosition(); d->isHotSpotSet = true; @@ -209,7 +209,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state, } else { d->lastScaleFactor = d->scaleFactor; QLineF line(p1.globalPosition(), p2.globalPosition()); - QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos()); + QLineF lastLine(p1.globalLastPosition(), p2.globalLastPosition()); qreal newScaleFactor = line.length() / lastLine.length(); if (newScaleFactor > kSingleStepScaleMax || newScaleFactor < kSingleStepScaleMin) return QGestureRecognizer::Ignore; @@ -315,9 +315,9 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state, result = QGestureRecognizer::CancelGesture; else if (ev->touchPoints().size() == 3) { d->state = QSwipeGesturePrivate::ThreePointsReached; - QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); - QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); - QTouchEvent::TouchPoint p3 = ev->touchPoints().at(2); + QEventPoint p1 = ev->touchPoints().at(0); + QEventPoint p2 = ev->touchPoints().at(1); + QEventPoint p3 = ev->touchPoints().at(2); if (d->lastPositions[0].isNull()) { d->lastPositions[0] = p1.globalPressPosition().toPoint(); @@ -381,7 +381,7 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state, result = QGestureRecognizer::Ignore; break; case QSwipeGesturePrivate::ThreePointsReached: - result = (ev->touchPointStates() & Qt::TouchPointPressed) + result = (ev->touchPointStates() & QEventPoint::State::Pressed) ? QGestureRecognizer::CancelGesture : QGestureRecognizer::Ignore; break; } @@ -447,7 +447,7 @@ QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state, case QEvent::TouchUpdate: case QEvent::TouchEnd: { if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); + QEventPoint p = ev->touchPoints().at(0); QPoint delta = p.position().toPoint() - p.pressPosition().toPoint(); enum { TapRadius = 40 }; if (delta.manhattanLength() <= TapRadius) { @@ -551,7 +551,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, case QEvent::TouchUpdate: { const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); if (d->timerId && ev->touchPoints().size() == 1) { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); + QEventPoint p = ev->touchPoints().at(0); QPoint delta = p.position().toPoint() - p.pressPosition().toPoint(); if (delta.manhattanLength() <= TapRadius) return QGestureRecognizer::MayBeGesture; |