Add grabber context pointers
In Qt Quick we now need to keep track of which QQDeliveryAgent is responsible when a point is grabbed, either passively or exclusively. When we re-deliver to that grabber, we need to do it via the same agent, so that the same scene transform is used, and the grabber will see the event in the correct coordinate system. It's easier to track this mapping here instead of in a separate map in Qt Quick. (This is an alternative to 40330b8f0a717098982d1f54f34a18a8262b1f55: it was not possible to use QFlatMap, because we need to keep the passive grabbers in the same order as they were added. We don't use a QList of structs, because QPointerEvent::passiveGrabbers() needs to return a QList of just the grabbers, and it's not as efficient to construct that list in the accessor.) Change-Id: I457114f816736749d2ea5ee48fa03524eb93d2d0 Task-number: QTBUG-92944 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit c8736e8e614066e46bc267356ee7757e42ed6e5f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
bced3a2477
commit
14f20bde1c
@ -504,6 +504,8 @@ void QPointingDevicePrivate::setExclusiveGrabber(const QPointerEvent *event, con
|
||||
QMutableEventPoint::from(persistentPoint->eventPoint).setGlobalGrabPosition(point.globalPosition());
|
||||
if (exclusiveGrabber)
|
||||
emit q->grabChanged(exclusiveGrabber, QPointingDevice::GrabExclusive, event, point);
|
||||
else
|
||||
persistentPoint->exclusiveGrabberContext.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -541,6 +543,17 @@ bool QPointingDevicePrivate::addPassiveGrabber(const QPointerEvent *event, const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QPointingDevicePrivate::setPassiveGrabberContext(QPointingDevicePrivate::EventPointData *epd, QObject *grabber, QObject *context)
|
||||
{
|
||||
int i = epd->passiveGrabbers.indexOf(grabber);
|
||||
if (i < 0)
|
||||
return false;
|
||||
if (epd->passiveGrabbersContext.size() <= i)
|
||||
epd->passiveGrabbersContext.resize(i + 1);
|
||||
epd->passiveGrabbersContext[i] = context;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QPointingDevicePrivate::removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber)
|
||||
{
|
||||
Q_Q(QPointingDevice);
|
||||
@ -557,6 +570,10 @@ bool QPointingDevicePrivate::removePassiveGrabber(const QPointerEvent *event, co
|
||||
}
|
||||
emit q->grabChanged(grabber, QPointingDevice::UngrabPassive, event, point);
|
||||
persistentPoint->passiveGrabbers.removeAt(i);
|
||||
if (persistentPoint->passiveGrabbersContext.size()) {
|
||||
Q_ASSERT(persistentPoint->passiveGrabbersContext.size() > i);
|
||||
persistentPoint->passiveGrabbersContext.removeAt(i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -579,6 +596,7 @@ void QPointingDevicePrivate::clearPassiveGrabbers(const QPointerEvent *event, co
|
||||
for (auto g : persistentPoint->passiveGrabbers)
|
||||
emit q->grabChanged(g, QPointingDevice::UngrabPassive, event, point);
|
||||
persistentPoint->passiveGrabbers.clear();
|
||||
persistentPoint->passiveGrabbersContext.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -602,6 +620,7 @@ void QPointingDevicePrivate::removeGrabber(QObject *grabber, bool cancel)
|
||||
<< "@" << epd.eventPoint.scenePosition()
|
||||
<< ": grab" << grabber << "-> nullptr";
|
||||
epd.exclusiveGrabber.clear();
|
||||
epd.exclusiveGrabberContext.clear();
|
||||
emit q->grabChanged(grabber,
|
||||
cancel ? QPointingDevice::CancelGrabExclusive : QPointingDevice::UngrabExclusive,
|
||||
nullptr, epd.eventPoint);
|
||||
@ -611,6 +630,10 @@ void QPointingDevicePrivate::removeGrabber(QObject *grabber, bool cancel)
|
||||
qCDebug(lcPointerGrab) << name << "point" << epd.eventPoint.id() << epd.eventPoint.state()
|
||||
<< ": removing passive grabber" << grabber;
|
||||
epd.passiveGrabbers.removeAt(pi);
|
||||
if (epd.passiveGrabbersContext.size()) {
|
||||
Q_ASSERT(epd.passiveGrabbersContext.size() > pi);
|
||||
epd.passiveGrabbersContext.removeAt(pi);
|
||||
}
|
||||
emit q->grabChanged(grabber,
|
||||
cancel ? QPointingDevice::CancelGrabPassive : QPointingDevice::UngrabPassive,
|
||||
nullptr, epd.eventPoint);
|
||||
|
@ -88,7 +88,9 @@ public:
|
||||
struct EventPointData {
|
||||
QEventPoint eventPoint;
|
||||
QPointer<QObject> exclusiveGrabber;
|
||||
QPointer<QObject> exclusiveGrabberContext; // extra info about where the grab happened
|
||||
QList<QPointer <QObject> > passiveGrabbers;
|
||||
QList<QPointer <QObject> > passiveGrabbersContext; // parallel list: extra info about where the grabs happened
|
||||
};
|
||||
EventPointData *queryPointById(int id) const;
|
||||
EventPointData *pointById(int id) const;
|
||||
@ -100,6 +102,7 @@ public:
|
||||
void setExclusiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *exclusiveGrabber);
|
||||
bool removeExclusiveGrabber(const QPointerEvent *event, const QObject *grabber);
|
||||
bool addPassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber);
|
||||
static bool setPassiveGrabberContext(EventPointData *epd, QObject *grabber, QObject *context);
|
||||
bool removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber);
|
||||
void clearPassiveGrabbers(const QPointerEvent *event, const QEventPoint &point);
|
||||
void removeGrabber(QObject *grabber, bool cancel = false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user