summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-09-03 18:17:21 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-09-10 14:21:47 +0200
commita81859a3c8d0f8b4367fc63988e1d653d34ed48a (patch)
tree3ed5fee25bbc1cd254d07802b59766f846ca5385 /src
parent62f5ecca7d2b193236cd4e5ccfc96290541b9fff (diff)
Move grabbing API from QEventPoint to QPointerEvent
We plan to move storage of the grabbers into QPointingDevice so that QEventPoint will store only data that does not need to persist between deliveries of individual events. These API changes prepare for that. addPassiveGrabber/removePassiveGrabber is a better API than setPassiveGrabbers(), because it will never require constructing a temporary QList just to call the function. Eventually we need to emit signals to notify about grab changes, so it's better to have incremental changes to the list rather than needing to iterate and find differences. Fix up the docs. QEventPoint IDs are no longer written in hex in debug output. That was done in Qt 5 because an ID was a composite of device ID with the OS-provided touchpoint ID; but since the QPointingDevice is always available, it's more readable if the IDs are in decimal. Change-Id: I86b9016d9b28c331ca05c7c108d9788de93fb642 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/kernel/qevent.cpp154
-rw-r--r--src/gui/kernel/qevent.h25
2 files changed, 115 insertions, 64 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 1e570a647b..3fa4c0e8b2 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -63,9 +63,9 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcPointerGrab, "qt.pointer.grab")
-static const QString pointDeviceName(const QEventPoint *point)
+static const QString pointDeviceName(const QEventPoint &point)
{
- const auto device = point->device();
+ const auto device = point.device();
QString deviceName = (device ? device->name() : QLatin1String("null device"));
deviceName.resize(16, u' '); // shorten, and align in case of sequential output
return deviceName;
@@ -359,56 +359,6 @@ void QEventPoint::setAccepted(bool accepted)
d->accept = accepted;
}
-QObject *QEventPoint::exclusiveGrabber() const
-{ return d->exclusiveGrabber.data(); }
-
-/*
- Informs the delivery logic that the given \a exclusiveGrabber is to
- receive all future update events and the release event containing
- this point, and that delivery to other items can be skipped.
-
- It's mainly for use in Qt Quick at this time.
-*/
-void QEventPoint::setExclusiveGrabber(QObject *exclusiveGrabber)
-{
- if (d->exclusiveGrabber == exclusiveGrabber)
- return;
- if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
- qCDebug(lcPointerGrab) << pointDeviceName(this) << "point" << Qt::hex << d->pointId << d->state << "@" << d->scenePos
- << ": grab" << d->exclusiveGrabber << "->" << exclusiveGrabber;
- }
- d->exclusiveGrabber = exclusiveGrabber;
- d->globalGrabPos = d->globalPos;
-}
-
-const QList<QPointer<QObject> > &QEventPoint::passiveGrabbers() const
-{ return d->passiveGrabbers; }
-
-/*
- Informs the delivery logic that the given \a grabbers are to receive all
- future update events and the release event containing this point,
- regardless where else those events may be delivered.
-
- It's mainly for use in Qt Quick at this time.
-*/
-void QEventPoint::setPassiveGrabbers(const QList<QPointer<QObject> > &grabbers)
-{
- d->passiveGrabbers = grabbers;
- if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
- qCDebug(lcPointerGrab) << pointDeviceName(this) << "point" << Qt::hex << d->pointId << d->state
- << ": grab (passive)" << grabbers;
- }
-}
-
-void QEventPoint::clearPassiveGrabbers()
-{
- if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
- qCDebug(lcPointerGrab) << pointDeviceName(this) << "point" << Qt::hex << d->pointId << d->state
- << ": clearing" << d->passiveGrabbers;
- }
- d->passiveGrabbers.clear();
-}
-
/*! \internal
void QMutableEventPoint::setPosition(const QPointF &pos)
@@ -484,6 +434,104 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
return static_cast<const QPointingDevice *>(m_dev);
}
+/*!
+ Returns the object which has been set to receive all future update events
+ and the release event containing the given \a point.
+
+ It's mainly for use in Qt Quick at this time.
+*/
+QObject *QPointerEvent::exclusiveGrabber(const QEventPoint &point) const
+{
+ return point.d->exclusiveGrabber.data();
+}
+
+/*!
+ Informs the delivery logic that the given \a exclusiveGrabber is to
+ receive all future update events and the release event containing
+ the given \a point, and that delivery to other items can be skipped.
+
+ It's mainly for use in Qt Quick at this time.
+*/
+void QPointerEvent::setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber)
+{
+ if (point.d->exclusiveGrabber == exclusiveGrabber)
+ return;
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << pointDeviceName(point) << "point" << point.id() << point.state()
+ << "@" << point.scenePosition()
+ << ": grab" << point.d->exclusiveGrabber << "->" << exclusiveGrabber;
+ }
+ point.d->exclusiveGrabber = exclusiveGrabber;
+ point.d->globalGrabPos = point.d->globalPos;
+}
+
+/*!
+ Returns the list of objects that have been requested to receive all
+ future update events and the release event containing the given \a point.
+
+ It's mainly for use in Qt Quick at this time.
+
+ \sa QPointerEvent::addPassiveGrabber()
+*/
+QList<QPointer<QObject> > QPointerEvent::passiveGrabbers(const QEventPoint &point) const
+{
+ return point.d->passiveGrabbers;
+}
+
+/*!
+ Informs the delivery logic that the given \a grabber is to receive all
+ future update events and the release event containing the given \a point,
+ regardless where else those events may be delivered.
+
+ It's mainly for use in Qt Quick at this time.
+
+ Returns \c false if \a grabber was already added, \c true otherwise.
+*/
+bool QPointerEvent::addPassiveGrabber(const QEventPoint &point, QObject *grabber)
+{
+ if (point.d->passiveGrabbers.contains(grabber))
+ return false;
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << pointDeviceName(point) << "point" << point.id() << point.state()
+ << ": grab (passive)" << grabber;
+ }
+ point.d->passiveGrabbers << grabber;
+ return true;
+}
+
+/*!
+ Removes the passive \a grabber from the given \a point if it was previously added.
+ Returns \c true if it had been a passive grabber before, \c false if not.
+
+ It's mainly for use in Qt Quick at this time.
+
+ \sa QPointerEvent::addPassiveGrabber()
+*/
+bool QPointerEvent::removePassiveGrabber(const QEventPoint &point, QObject *grabber)
+{
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << pointDeviceName(point) << "point" << point.id() << point.state()
+ << ": removing passive grabber" << grabber;
+ }
+ point.d->passiveGrabbers.removeOne(grabber);
+ return false;
+}
+
+/*!
+ Removes all passive grabbers from the given \a point.
+
+ It's mainly for use in Qt Quick at this time.
+
+ \sa QPointerEvent::addPassiveGrabber()
+*/
+void QPointerEvent::clearPassiveGrabbers(const QEventPoint &point)
+{
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << pointDeviceName(point) << "point" << point.id() << point.state()
+ << ": clearing" << point.d->passiveGrabbers;
+ }
+ point.d->passiveGrabbers.clear();
+}
QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos,
const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
@@ -3928,7 +3976,7 @@ QDebug operator<<(QDebug dbg, const QEventPoint &tp)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
- dbg << "QEventPoint(" << Qt::hex << tp.id() << Qt::dec << " (";
+ dbg << "QEventPoint(" << tp.id() << " (";
QtDebugUtils::formatQPoint(dbg, tp.position());
dbg << " global ";
QtDebugUtils::formatQPoint(dbg, tp.globalPosition());
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index eed6b93156..dd9e76dcd9 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -164,15 +164,11 @@ public:
bool isAccepted() const;
void setAccepted(bool accepted = true);
- QObject *exclusiveGrabber() const;
- void setExclusiveGrabber(QObject *exclusiveGrabber);
- const QList<QPointer <QObject>> &passiveGrabbers() const;
- void setPassiveGrabbers(const QList<QPointer <QObject>> &grabbers);
- void clearPassiveGrabbers();
private:
QEventPointPrivate *d;
friend class QMutableEventPoint;
+ friend class QPointerEvent;
};
#ifndef QT_NO_DEBUG_STREAM
@@ -182,18 +178,25 @@ Q_GUI_EXPORT QDebug operator<<(QDebug, const QEventPoint &);
class Q_GUI_EXPORT QPointerEvent : public QInputEvent
{
public:
+ explicit QPointerEvent(Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
virtual ~QPointerEvent();
+ const QPointingDevice *pointingDevice() const;
+ QPointingDevice::PointerType pointerType() const {
+ return pointingDevice() ? pointingDevice()->pointerType() : QPointingDevice::PointerType::Unknown;
+ }
virtual int pointCount() const = 0;
virtual const QEventPoint &point(int i) const = 0;
virtual bool isPressEvent() const { return false; }
virtual bool isUpdateEvent() const { return false; }
virtual bool isReleaseEvent() const { return false; }
-
- explicit QPointerEvent(Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
- const QPointingDevice *pointingDevice() const;
- QPointingDevice::PointerType pointerType() const {
- return pointingDevice() ? pointingDevice()->pointerType() : QPointingDevice::PointerType::Unknown;
- }
+ bool isPointAccepted(const QEventPoint &point) const;
+ void setPointAccepted(const QEventPoint &point, bool accepted = true);
+ QObject *exclusiveGrabber(const QEventPoint &point) const;
+ void setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber);
+ QList<QPointer <QObject>> passiveGrabbers(const QEventPoint &point) const;
+ void clearPassiveGrabbers(const QEventPoint &point);
+ bool addPassiveGrabber(const QEventPoint &point, QObject *grabber);
+ bool removePassiveGrabber(const QEventPoint &point, QObject *grabber);
};
class Q_GUI_EXPORT QSinglePointEvent : public QPointerEvent