Rename is[Begin|Update|End]Event, reimplement in QWheelEvent

These states correspond well with ScrollPhase, and this abstraction
makes it possible to handle wheel events the same way as mouse events
in Qt Quick: on "begin" we deliver to all Items and Handlers until
all points (the only point) are accepted; on "update" and "end" we
deliver only to the exclusive grabber, if there is one, and to any
passive grabbers.

Change-Id: I702dbd4f2c1bf5962eb3dbb9e4b725300a00a887
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Shawn Rutledge 2020-09-14 16:13:16 +02:00
parent 55a7dd4581
commit 153dcfbbba
4 changed files with 52 additions and 24 deletions

View File

@ -906,7 +906,7 @@ QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *d
/*!
Returns \c true if this event represents a \l {button()}{button} being pressed.
*/
bool QSinglePointEvent::isPressEvent() const
bool QSinglePointEvent::isBeginEvent() const
{
return m_button != Qt::NoButton && m_mouseState.testFlag(m_button);
}
@ -922,7 +922,7 @@ bool QSinglePointEvent::isUpdateEvent() const
/*!
Returns \c true if this event represents a \l {button()}{button} being released.
*/
bool QSinglePointEvent::isReleaseEvent() const
bool QSinglePointEvent::isEndEvent() const
{
return m_button != Qt::NoButton && !m_mouseState.testFlag(m_button);
}
@ -1503,6 +1503,31 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pi
QWheelEvent::~QWheelEvent()
{
}
/*!
Returns \c true if this event's phase() is Qt::ScrollBegin.
*/
bool QWheelEvent::isBeginEvent() const
{
return m_phase == Qt::ScrollBegin;
}
/*!
Returns \c true if this event's phase() is Qt::ScrollUpdate or Qt::ScrollMomentum.
*/
bool QWheelEvent::isUpdateEvent() const
{
return m_phase == Qt::ScrollUpdate || m_phase == Qt::ScrollMomentum;
}
/*!
Returns \c true if this event's phase() is Qt::ScrollEnd.
*/
bool QWheelEvent::isEndEvent() const
{
return m_phase == Qt::ScrollEnd;
}
#endif // QT_CONFIG(wheelevent)
/*!
@ -4738,7 +4763,7 @@ QTouchEvent::~QTouchEvent()
/*!
Returns true if this event includes at least one newly-pressed touchpoint.
*/
bool QTouchEvent::isPressEvent() const
bool QTouchEvent::isBeginEvent() const
{
return m_touchPointStates.testFlag(QEventPoint::State::Pressed);
}
@ -4756,7 +4781,7 @@ bool QTouchEvent::isUpdateEvent() const
/*!
Returns true if this event includes at least one newly-released touchpoint.
*/
bool QTouchEvent::isReleaseEvent() const
bool QTouchEvent::isEndEvent() const
{
return m_touchPointStates.testFlag(QEventPoint::State::Released);
}

View File

@ -210,9 +210,9 @@ public:
const QList<QEventPoint> &points() const { return m_points; }
QEventPoint *pointById(int id);
bool allPointsGrabbed() const;
virtual bool isPressEvent() const { return false; }
virtual bool isBeginEvent() const { return false; }
virtual bool isUpdateEvent() const { return false; }
virtual bool isReleaseEvent() const { return false; }
virtual bool isEndEvent() const { return false; }
bool allPointsAccepted() const;
QObject *exclusiveGrabber(const QEventPoint &point) const;
void setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber);
@ -243,9 +243,9 @@ public:
inline QPointF globalPosition() const
{ Q_ASSERT(!m_points.isEmpty()); return m_points.first().globalPosition(); }
bool isPressEvent() const override;
bool isBeginEvent() const override;
bool isUpdateEvent() const override;
bool isReleaseEvent() const override;
bool isEndEvent() const override;
protected:
QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point,
@ -392,6 +392,9 @@ public:
inline bool isInverted() const { return m_invertedScrolling; }
inline bool hasPixelDelta() const { return !m_pixelDelta.isNull(); }
bool isBeginEvent() const override;
bool isUpdateEvent() const override;
bool isEndEvent() const override;
Qt::MouseEventSource source() const { return Qt::MouseEventSource(m_source); }
protected:
@ -996,9 +999,9 @@ public:
QT_DEPRECATED_VERSION_X_6_0("Use points()")
const QList<QEventPoint> &touchPoints() const { return points(); }
#endif
bool isPressEvent() const override;
bool isBeginEvent() const override;
bool isUpdateEvent() const override;
bool isReleaseEvent() const override;
bool isEndEvent() const override;
protected:
QObject *m_target = nullptr;

View File

@ -162,23 +162,23 @@ void tst_QMouseEvent::mouseEventBasic()
QCOMPARE(me.isAccepted(), true);
QCOMPARE(me.button(), Qt::LeftButton);
QCOMPARE(me.buttons(), Qt::LeftButton);
QVERIFY(me.isPressEvent());
QVERIFY(!me.isReleaseEvent());
QVERIFY(me.isBeginEvent());
QVERIFY(!me.isEndEvent());
QCOMPARE(me.position(), local);
QCOMPARE(me.scenePosition(), scene);
QCOMPARE(me.globalPosition(), screen);
// Press right button while left is already pressed
me = QMouseEvent(QEvent::MouseButtonPress, local, scene, screen, Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier);
QVERIFY(me.isPressEvent());
QVERIFY(!me.isReleaseEvent());
QVERIFY(me.isBeginEvent());
QVERIFY(!me.isEndEvent());
// Release right button while left is still pressed
me = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::RightButton, Qt::LeftButton, Qt::NoModifier);
QVERIFY(!me.isPressEvent());
QVERIFY(me.isReleaseEvent());
QVERIFY(!me.isBeginEvent());
QVERIFY(me.isEndEvent());
// Release left button in the usual way
me = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
QVERIFY(!me.isPressEvent());
QVERIFY(me.isReleaseEvent());
QVERIFY(!me.isBeginEvent());
QVERIFY(me.isEndEvent());
}
void tst_QMouseEvent::checkMousePressEvent_data()

View File

@ -338,9 +338,9 @@ void tst_QTouchEvent::state()
QEventPoint(1, QEventPoint::State::Pressed, {}, {}));
QCOMPARE(touchEvent.touchPointStates(), QEventPoint::State::Stationary | QEventPoint::State::Pressed);
QCOMPARE(touchEvent.pointCount(), 2);
QVERIFY(touchEvent.isPressEvent());
QVERIFY(touchEvent.isBeginEvent());
QVERIFY(!touchEvent.isUpdateEvent());
QVERIFY(!touchEvent.isReleaseEvent());
QVERIFY(!touchEvent.isEndEvent());
QVERIFY(touchEvent.isInputEvent());
QVERIFY(touchEvent.isPointerEvent());
@ -350,9 +350,9 @@ void tst_QTouchEvent::state()
QEventPoint(1, QEventPoint::State::Pressed, {}, {}));
QCOMPARE(touchEvent.touchPointStates(), QEventPoint::State::Updated | QEventPoint::State::Pressed);
QCOMPARE(touchEvent.pointCount(), 2);
QVERIFY(touchEvent.isPressEvent());
QVERIFY(touchEvent.isBeginEvent());
QVERIFY(!touchEvent.isUpdateEvent());
QVERIFY(!touchEvent.isReleaseEvent());
QVERIFY(!touchEvent.isEndEvent());
touchEvent = QTouchEvent(QEvent::TouchBegin, touchScreenDevice,
Qt::NoModifier, QList<QEventPoint>() <<
@ -360,9 +360,9 @@ void tst_QTouchEvent::state()
QEventPoint(1, QEventPoint::State::Released, {}, {}));
QCOMPARE(touchEvent.touchPointStates(), QEventPoint::State::Updated | QEventPoint::State::Released);
QCOMPARE(touchEvent.pointCount(), 2);
QVERIFY(!touchEvent.isPressEvent());
QVERIFY(!touchEvent.isBeginEvent());
QVERIFY(!touchEvent.isUpdateEvent());
QVERIFY(touchEvent.isReleaseEvent());
QVERIFY(touchEvent.isEndEvent());
}
void tst_QTouchEvent::touchDisabledByDefault()