aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/handlers/qquickwheelhandler.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-07-23 13:56:26 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-09-18 20:56:25 +0200
commita97759a336c597327cb82eebc9f45c793aec32c9 (patch)
tree632bbee8568d38af56974e02df5810afcf48aedc /src/quick/handlers/qquickwheelhandler.cpp
parent39f4d687fc37f48cbc181f42797c42be91b4a345 (diff)
Remove QQuickPointerEvent etc.; deliver QPointerEvents directly
QEventPoint does not have an accessor to get the QPointerEvent that it came from, because that's inconsistent with the idea that QPointerEvent instances are temporary, stack-allocated and movable (the pointer would often be wrong or null, therefore could not be relied upon). So most functions that worked directly with QQuickEventPoint before (which fortunately are still private API) now need to receive the QPointerEvent too, which we choose to pass by pointer. QEventPoint is always passed by reference (const where possible) to be consistent with functions in QPointerEvent that take QEventPoint by reference. QEventPoint::velocity() should be always in scene coordinates now, which saves us the trouble of transforming it to each item's coordinate system during delivery, but means that it will need to be done in handlers or applications sometimes. If we were going to transform it, it would be important to also store the sceneVelocity separately in QEventPoint so that the transformation could be done repeatedly for different items. Task-number: QTBUG-72173 Change-Id: I7ee164d2e6893c4e407fb7d579c75aa32843933a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickwheelhandler.cpp')
-rw-r--r--src/quick/handlers/qquickwheelhandler.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/quick/handlers/qquickwheelhandler.cpp b/src/quick/handlers/qquickwheelhandler.cpp
index b55d9aa27b..b9c112a0d2 100644
--- a/src/quick/handlers/qquickwheelhandler.cpp
+++ b/src/quick/handlers/qquickwheelhandler.cpp
@@ -360,60 +360,62 @@ void QQuickWheelHandler::setTargetTransformAroundCursor(bool ttac)
emit targetTransformAroundCursorChanged();
}
-bool QQuickWheelHandler::wantsPointerEvent(QQuickPointerEvent *event)
+bool QQuickWheelHandler::wantsPointerEvent(QPointerEvent *event)
{
if (!event)
return false;
- QQuickPointerScrollEvent *scroll = event->asPointerScrollEvent();
- if (!scroll)
+ if (event->type() != QEvent::Wheel)
return false;
+ QWheelEvent *we = static_cast<QWheelEvent *>(event);
if (!acceptedDevices().testFlag(QPointingDevice::DeviceType::TouchPad)
- && scroll->synthSource() != Qt::MouseEventNotSynthesized)
+ && we->source() != Qt::MouseEventNotSynthesized)
return false;
if (!active()) {
switch (orientation()) {
case Qt::Horizontal:
- if (qFuzzyIsNull(scroll->angleDelta().x()) && qFuzzyIsNull(scroll->pixelDelta().x()))
+ if (!(we->angleDelta().x()) && !(we->pixelDelta().x()))
return false;
break;
case Qt::Vertical:
- if (qFuzzyIsNull(scroll->angleDelta().y()) && qFuzzyIsNull(scroll->pixelDelta().y()))
+ if (!(we->angleDelta().y()) && !(we->pixelDelta().y()))
return false;
break;
}
}
- QQuickEventPoint *point = event->point(0);
- if (QQuickPointerDeviceHandler::wantsPointerEvent(event) && wantsEventPoint(point) && parentContains(point)) {
- setPointId(point->pointId());
+ auto &point = event->point(0);
+ if (QQuickPointerDeviceHandler::wantsPointerEvent(event) && wantsEventPoint(event, point) && parentContains(point)) {
+ setPointId(point.id());
return true;
}
return false;
}
-void QQuickWheelHandler::handleEventPoint(QQuickEventPoint *point)
+void QQuickWheelHandler::handleEventPoint(QPointerEvent *ev, QEventPoint &point)
{
Q_D(QQuickWheelHandler);
- QQuickPointerScrollEvent *event = point->pointerEvent()->asPointerScrollEvent();
+ if (ev->type() != QEvent::Wheel)
+ return;
+ const QWheelEvent *event = static_cast<const QWheelEvent *>(ev);
setActive(true); // ScrollEnd will not happen unless it was already active (see setActive(false) below)
- point->setAccepted();
+ point.setAccepted();
qreal inversion = !d->invertible && event->isInverted() ? -1 : 1;
qreal angleDelta = inversion * qreal(orientation() == Qt::Horizontal ? event->angleDelta().x() :
event->angleDelta().y()) / 8;
d->rotation += angleDelta;
emit rotationChanged();
- emit wheel(event);
+ emit wheel(*event);
if (!d->propertyName.isEmpty() && target()) {
QQuickItem *t = target();
// writing target()'s property is done via QMetaProperty::write() so that any registered interceptors can react.
if (d->propertyName == QLatin1String("scale")) {
qreal multiplier = qPow(d->targetScaleMultiplier, angleDelta * d->rotationScale / 15); // wheel "clicks"
- const QPointF centroidParentPos = t->parentItem()->mapFromScene(point->scenePosition());
+ const QPointF centroidParentPos = t->parentItem()->mapFromScene(point.scenePosition());
const QPointF positionWas = t->position();
const qreal scaleWas = t->scale();
const qreal activePropertyValue = scaleWas * multiplier;
qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "pixel delta" << event->pixelDelta()
- << "@" << point->position() << "in parent" << centroidParentPos
- << "in scene" << point->scenePosition()
+ << "@" << point.position() << "in parent" << centroidParentPos
+ << "in scene" << point.scenePosition()
<< "multiplier" << multiplier << "scale" << scaleWas
<< "->" << activePropertyValue;
d->targetMetaProperty().write(t, activePropertyValue);
@@ -429,10 +431,10 @@ void QQuickWheelHandler::handleEventPoint(QQuickEventPoint *point)
const QPointF positionWas = t->position();
const qreal rotationWas = t->rotation();
const qreal activePropertyValue = rotationWas + angleDelta * d->rotationScale;
- const QPointF centroidParentPos = t->parentItem()->mapFromScene(point->scenePosition());
+ const QPointF centroidParentPos = t->parentItem()->mapFromScene(point.scenePosition());
qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "pixel delta" << event->pixelDelta()
- << "@" << point->position() << "in parent" << centroidParentPos
- << "in scene" << point->scenePosition() << "rotation" << t->rotation()
+ << "@" << point.position() << "in parent" << centroidParentPos
+ << "in scene" << point.scenePosition() << "rotation" << t->rotation()
<< "->" << activePropertyValue;
d->targetMetaProperty().write(t, activePropertyValue);
if (d->targetTransformAroundCursor) {
@@ -444,8 +446,9 @@ void QQuickWheelHandler::handleEventPoint(QQuickEventPoint *point)
t->setPosition(adjPos);
}
} else {
- qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "scaled" << angleDelta << "total" << d->rotation << "pixel delta" << event->pixelDelta()
- << "@" << point->position() << "in scene" << point->scenePosition() << "rotation" << t->rotation();
+ qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "scaled" << angleDelta
+ << "total" << d->rotation << "pixel delta" << event->pixelDelta()
+ << "@" << point.position() << "in scene" << point.scenePosition() << "rotation" << t->rotation();
qreal delta = 0;
if (event->hasPixelDelta()) {
delta = inversion * d->rotationScale * qreal(orientation() == Qt::Horizontal ? event->pixelDelta().x() : event->pixelDelta().y());