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: {
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
auto touchPoints = touchEvent->points();
bool res = QApplicationPrivate::translateRawTouchEvent(d->widget, touchEvent->pointingDevice(),
touchPoints, touchEvent->timestamp(),
event->spontaneous());
bool res = QApplicationPrivate::translateRawTouchEvent(d->widget, touchEvent);
if (res) {
event->accept();
return true;

View File

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

View File

@ -250,11 +250,7 @@ public:
void appendTouchPoint(const QEventPoint &touchPoint);
void removeTouchPoint(int touchPointId);
void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent);
static bool translateRawTouchEvent(QWidget *widget,
const QPointingDevice *device,
QList<QEventPoint> &touchPoints,
ulong timestamp,
bool spontaneous = true);
static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent);
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
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:
event->ignore();
} else {
event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event->pointingDevice(),
const_cast<QList<QEventPoint> &>(event->points()),
event->timestamp()));
event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event));
}
}