qt6-bb10/src/widgets/kernel
Shawn Rutledge 2692237bb1 Track grab state in QPointingDevicePrivate::activePoints
QQuickEventPoint instances were very long-lived and got reused from one
event to the next.  That was initially done because they were "heavy"
QObjects; but it also became useful to store state in them between
events. But this is in conflict with the ubiquitous event replay
code that assumes it's OK to hold an event instance (especially
a QMouseEvent) for any length of time, and then send it to some widget,
item or window. Clearly QEventPoints must be stored in the QPointerEvent,
if we are to avoid the need for workarounds to keep such old code working.
And now they have d-pointers, so copying is cheap. But replay code
will need to detach() their QEventPoints now.

QEventPoint is useful as an object to hold state, but we now store
the truly persistent state separately in an EventPointData struct,
in QPointingDevicePrivate::activePoints. Incoming events merely
update the persistent points, then we deliver those instead.
Thus when event handler code modifies state, it will be remembered
even when the delivery is done and the QPA event is destroyed.

This gets us a step closer to supporting multiple simultaneous mice.

Within pointer events, the points are moved up to QPointerEvent itself:
 QList<QEventPoint> m_points;
This means pointCount(), point(int i) and points() can be non-virtual.
However in any QSinglePointEvent, the list only contains one point.
We hope that pessimization is worthwhile for the sake of removing
virtual functions, simplifying code in event classes themselves, and
enabling the use of the range-for loop over points() with any kind of
QPointerEvent, not just QTouchEvent. points() is a nicer API for the
sake of range-for looping; but point() is more suited to being
non-const.

In QML it's expected to be OK to emit a signal with a QPointerEvent
by value: that will involve copying the event.  But QEventPoint
instances are explicitly shared, so calling setAccepted() modifies
the instance in activePoints (EventPointData.eventPoint.d->accept);
and the grabbers are stored separately and thus preserved between events.
In code such as MouseArea { onPressed: mouse.accepted = false }
we can either continue to emit the QQuickMouseEvent wrapper
or perhaps QEvent::setAccepted() could become virtual and set
the eventpoint's accepted flag instead, so that it will survive
after the event copy that QML sees is discarded.

The grabChanged() signal is useful to keep QQuickWindow informed
when items or handlers change exclusive or passive grabbers.

When a release happens at a different location than the last move event,
Qt synthesizes an additional move.  But it would be "boring" if
QEventPoint::lastXPosition() accessors in any released eventpoint always
returned the same as the current QEventPoint::xPosition()s just because
of that; and it would mean that the velocity() must always be zero on
release, which would make it hard to use the final velocity to drive an
animation.  So now we expect the lastPositions to be different than
current positions in a released eventpoint.

De-inline some functions whose implementations might be subject to
change later on.  Improve documentation.

Since we have an accessor for pressTimestamp(), we might as well add one for
timestamp() too.  That way users get enough information to calculate
instantaneous velocity, since the plan is for velocity() to be somewhat
smoothed.

Change-Id: I2733d847139a1b1bea33c00275459dcd2a145ffc
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-09-16 11:33:03 +02:00
..
kernel.pri Move QStateMachine from QtCore to QtScxml 2020-08-24 20:10:25 +02:00
mac.pri
qaction_widgets.cpp Fix build without features.shortcut 2020-06-05 10:23:48 +09:00
qaction_widgets_p.h Fix build without features.menu 2020-06-04 01:52:21 +09:00
qapplication.cpp Track grab state in QPointingDevicePrivate::activePoints 2020-09-16 11:33:03 +02:00
qapplication.h Phase 2 of removing QDesktopWidget 2020-06-08 20:29:49 +02:00
qapplication_p.h Track grab state in QPointingDevicePrivate::activePoints 2020-09-16 11:33:03 +02:00
qboxlayout.cpp Use QList instead of QVector in widgets 2020-07-02 21:57:06 +02:00
qboxlayout.h Make QLayout::spacing/setSpacing virtual, remove qobject_cast hack 2020-06-09 16:31:54 +02:00
qdesktopwidget.cpp Move QDesktopWidget API used by QApplication into QDesktopWidget 2020-08-17 15:08:39 +02:00
qdesktopwidget_p.h Move QDesktopWidget API used by QApplication into QDesktopWidget 2020-08-17 15:08:39 +02:00
qformlayout.cpp Use QList instead of QVector in widgets 2020-07-02 21:57:06 +02:00
qformlayout.h Make QLayout::spacing/setSpacing virtual, remove qobject_cast hack 2020-06-09 16:31:54 +02:00
qgesture.cpp
qgesture.h
qgesture_p.h
qgesturemanager.cpp Long Live QMap as a refcounted std::map! 2020-08-06 19:15:39 +02:00
qgesturemanager_p.h
qgesturerecognizer.cpp
qgesturerecognizer.h
qgridlayout.cpp Use QList instead of QVector in widgets 2020-07-02 21:57:06 +02:00
qgridlayout.h Make QLayout::spacing/setSpacing virtual, remove qobject_cast hack 2020-06-09 16:31:54 +02:00
qlayout.cpp QLayout::indexOf: redo implementation 2020-08-26 23:07:22 +02:00
qlayout.h QLayout: Make contentsMargins a Q_PROPERTY 2020-09-15 00:46:49 +00:00
qlayout_p.h Avoid use of Q_UNUSED by eliminating the parameter names 2020-07-03 21:10:09 +02:00
qlayoutengine.cpp Use QList instead of QVector in widgets 2020-07-02 21:57:06 +02:00
qlayoutengine_p.h Use QList instead of QVector in widgets 2020-07-02 21:57:06 +02:00
qlayoutitem.cpp Remove dead code from src/widgets 2020-05-11 11:05:15 +02:00
qlayoutitem.h Use C++17 [[maybe_unused]] 2020-09-06 18:31:43 +02:00
qmacgesturerecognizer.cpp Replace calls to deprecated QEvent accessor functions 2020-06-08 19:11:51 +02:00
qmacgesturerecognizer_p.h
qshortcut_widgets.cpp
qsizepolicy.cpp Remove QVariant(int type, void *data, ...) constructor 2020-08-15 10:56:29 +02:00
qsizepolicy.h QSizePolicy: Fix warning about mixing different enums 2020-08-23 02:35:05 +02:00
qstackedlayout.cpp
qstackedlayout.h
qstandardgestures.cpp Refactor pointer event hierarchy 2020-07-10 14:32:56 +02:00
qstandardgestures_p.h
qt_widgets_pch.h
qtestsupport_widgets.cpp Refactor testlib touch functions into qtestsupport_gui and _widgets 2020-09-08 08:02:15 +02:00
qtestsupport_widgets.h Refactor testlib touch functions into qtestsupport_gui and _widgets 2020-09-08 08:02:15 +02:00
qtooltip.cpp Remove usage of QDesktopWidget(Private) from most places in QtWidgets 2020-07-07 11:49:32 +02:00
qtooltip.h Merge QToolTip::showText overloads as per ### Qt 6 comments 2020-06-10 19:59:05 +02:00
qtwidgetsglobal.h
qtwidgetsglobal_p.h
qwhatsthis.cpp Disable operator+ and operator- for QFlags 2020-09-09 06:00:28 +02:00
qwhatsthis.h
qwidget.cpp Fix conversion warnings when setting alpha to QColor 2020-09-15 21:26:11 +02:00
qwidget.h Change QWidget::enterEvent signature to take a QEnterEvent 2020-09-05 02:06:26 +02:00
qwidget_p.h Display combobox popup on the correct screen 2020-08-30 01:56:05 +02:00
qwidgetaction.cpp Add ; to Q_UNUSED 2020-07-07 11:51:48 +02:00
qwidgetaction.h
qwidgetaction_p.h
qwidgetrepaintmanager.cpp Rename local variables masking parameters 2020-07-10 02:37:11 +02:00
qwidgetrepaintmanager_p.h Use QList instead of QVector in widgets 2020-07-02 21:57:06 +02:00
qwidgetstatemachine.cpp Move QStateMachine from QtCore to QtScxml 2020-08-24 20:10:25 +02:00
qwidgetsvariant.cpp Add a metatype helper class for Qt Core 2020-08-24 00:17:19 +02:00
qwidgetwindow.cpp Track grab state in QPointingDevicePrivate::activePoints 2020-09-16 11:33:03 +02:00
qwidgetwindow_p.h Remove dead code from src/widgets 2020-05-11 11:05:15 +02:00
qwindowcontainer.cpp
qwindowcontainer_p.h
win.pri Remove winrt 2020-06-06 20:25:49 +02:00