Refactor QApplication::translateRawTouchEvent to take a QTouchEvent*

Both call sites just pass the data from an existing QTouchEvent through,
so just pass the QTouchEvent through instead.

Amends 20d4f45a132606f7a910050d468519108486e9cf.

Pick-to: 6.2
Change-Id: If3b9508b83311889b58e109e7f64743985b8b178
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-08-24 13:22:52 +02:00
parent 1ecf2212fa
commit 6bf70bc014
4 changed files with 11 additions and 21 deletions

View File

@ -922,9 +922,7 @@ bool QGraphicsProxyWidget::event(QEvent *event)
case QEvent::TouchEnd: { case QEvent::TouchEnd: {
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
auto touchPoints = touchEvent->points(); auto touchPoints = touchEvent->points();
bool res = QApplicationPrivate::translateRawTouchEvent(d->widget, touchEvent->pointingDevice(), bool res = QApplicationPrivate::translateRawTouchEvent(d->widget, touchEvent);
touchPoints, touchEvent->timestamp(),
event->spontaneous());
if (res) { if (res) {
event->accept(); event->accept();
return true; return true;

View File

@ -3916,17 +3916,15 @@ void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent
// TODO setExclusiveGrabber() to be consistent with Qt Quick? // TODO setExclusiveGrabber() to be consistent with Qt Quick?
} }
bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, const QTouchEvent *te)
const QPointingDevice *device,
QList<QEventPoint> &touchPoints,
ulong timestamp,
bool spontaneous)
{ {
QApplicationPrivate *d = self; QApplicationPrivate *d = self;
// TODO get rid of this QPair // TODO get rid of this QPair
typedef QPair<QEventPoint::State, QList<QEventPoint> > StatesAndTouchPoints; typedef QPair<QEventPoint::State, QList<QEventPoint> > StatesAndTouchPoints;
QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents; QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
const auto *device = te->pointingDevice();
auto touchPoints = te->points(); // touch points will be mutated
for (auto &touchPoint : touchPoints) { for (auto &touchPoint : touchPoints) {
// update state // update state
QPointer<QObject> target; QPointer<QObject> target;
@ -4011,7 +4009,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
QMutableTouchEvent touchEvent(eventType, device, QGuiApplication::keyboardModifiers(), QMutableTouchEvent touchEvent(eventType, device, QGuiApplication::keyboardModifiers(),
it.value().second); it.value().second);
bool containsPress = updateTouchPointsForWidget(widget, &touchEvent); bool containsPress = updateTouchPointsForWidget(widget, &touchEvent);
touchEvent.setTimestamp(timestamp); touchEvent.setTimestamp(te->timestamp());
touchEvent.setTarget(widget); touchEvent.setTarget(widget);
if (containsPress) if (containsPress)
@ -4022,8 +4020,8 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
{ {
// if the TouchBegin handler recurses, we assume that means the event // if the TouchBegin handler recurses, we assume that means the event
// has been implicitly accepted and continue to send touch events // has been implicitly accepted and continue to send touch events
bool res = spontaneous ? QApplication::sendSpontaneousEvent(widget, &touchEvent) bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
: QApplication::sendEvent(widget, &touchEvent); : QApplication::sendEvent(widget, &touchEvent);
if (res && touchEvent.isAccepted()) { if (res && touchEvent.isAccepted()) {
accepted = true; accepted = true;
if (!widget.isNull()) if (!widget.isNull())
@ -4037,8 +4035,8 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
|| QGestureManager::gesturePending(widget) || QGestureManager::gesturePending(widget)
#endif #endif
) { ) {
bool res = spontaneous ? QApplication::sendSpontaneousEvent(widget, &touchEvent) bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
: QApplication::sendEvent(widget, &touchEvent); : QApplication::sendEvent(widget, &touchEvent);
if (res && touchEvent.isAccepted()) if (res && touchEvent.isAccepted())
accepted = true; accepted = true;
// widget can be deleted on TouchEnd // widget can be deleted on TouchEnd

View File

@ -250,11 +250,7 @@ public:
void appendTouchPoint(const QEventPoint &touchPoint); void appendTouchPoint(const QEventPoint &touchPoint);
void removeTouchPoint(int touchPointId); void removeTouchPoint(int touchPointId);
void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent); void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent);
static bool translateRawTouchEvent(QWidget *widget, static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent);
const QPointingDevice *device,
QList<QEventPoint> &touchPoints,
ulong timestamp,
bool spontaneous = true);
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp); static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override; QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override;

View File

@ -698,9 +698,7 @@ void QWidgetWindow::handleTouchEvent(QTouchEvent *event)
// events instead, which QWidgetWindow::handleMouseEvent will forward correctly: // events instead, which QWidgetWindow::handleMouseEvent will forward correctly:
event->ignore(); event->ignore();
} else { } else {
event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event->pointingDevice(), event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event));
const_cast<QList<QEventPoint> &>(event->points()),
event->timestamp()));
} }
} }