Introduce QEvent::isPointerEvent()
This makes high-level event dispatching easier: for example in Qt Quick,
all pointer events should eventually be delivered to items in a similar way.
Implemented in a similar way as d1111632e2
.
Change-Id: I2f0c4914bab228162f3b932dda8a88051ec2a4d7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
fb9ec8ad44
commit
c7f7279969
@ -295,7 +295,7 @@ QT_BEGIN_NAMESPACE
|
||||
Contructs an event object of type \a type.
|
||||
*/
|
||||
QEvent::QEvent(Type type)
|
||||
: d(nullptr), t(type), posted(false), spont(false), m_accept(true), m_inputEvent(false)
|
||||
: d(nullptr), t(type), posted(false), spont(false), m_accept(true), m_inputEvent(false), m_pointerEvent(false)
|
||||
{
|
||||
Q_TRACE(QEvent_ctor, this, t);
|
||||
}
|
||||
@ -322,7 +322,16 @@ QEvent::QEvent(const QEvent &other)
|
||||
\since 6.0
|
||||
\fn QEvent::QEvent(Type type, QEvent::InputEventTag)
|
||||
|
||||
Constructs an event object of type \a type, setting the inputEvent flag to true.
|
||||
Constructs an event object of type \a type, setting the inputEvent flag to \c true.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\since 6.0
|
||||
\fn QEvent::QEvent(Type type, QEvent::PointerEventTag)
|
||||
|
||||
Constructs an event object of type \a type, setting the pointerEvent and
|
||||
inputEvent flags to \c true.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -423,6 +432,14 @@ QEvent::~QEvent()
|
||||
subclasses.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QEvent::isPointerEvent() const
|
||||
\since 6.0
|
||||
|
||||
Returns \c true if the event object is a QPointerEvent or one of its
|
||||
subclasses.
|
||||
*/
|
||||
|
||||
namespace {
|
||||
template <size_t N>
|
||||
struct QBasicAtomicBitField {
|
||||
|
@ -308,12 +308,15 @@ public:
|
||||
inline void ignore() { m_accept = false; }
|
||||
|
||||
inline bool isInputEvent() const noexcept { return m_inputEvent; }
|
||||
inline bool isPointerEvent() const noexcept { return m_pointerEvent; }
|
||||
|
||||
static int registerEventType(int hint = -1) noexcept;
|
||||
|
||||
protected:
|
||||
struct InputEventTag { explicit InputEventTag() = default; };
|
||||
QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; }
|
||||
struct PointerEventTag { explicit PointerEventTag() = default; };
|
||||
QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; }
|
||||
QEventPrivate *d;
|
||||
ushort t;
|
||||
|
||||
@ -322,7 +325,8 @@ private:
|
||||
ushort spont : 1;
|
||||
ushort m_accept : 1;
|
||||
ushort m_inputEvent : 1;
|
||||
ushort reserved : 12;
|
||||
ushort m_pointerEvent : 1;
|
||||
ushort reserved : 11;
|
||||
|
||||
friend class QCoreApplication;
|
||||
friend class QCoreApplicationPrivate;
|
||||
|
@ -164,6 +164,13 @@ QInputEvent::QInputEvent(Type type, const QInputDevice *dev, Qt::KeyboardModifie
|
||||
: QEvent(type, QEvent::InputEventTag{}), m_dev(dev), m_modState(modifiers)
|
||||
{}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
QInputEvent::QInputEvent(QEvent::Type type, QEvent::PointerEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers)
|
||||
: QEvent(type, QEvent::PointerEventTag{}), m_dev(dev), m_modState(modifiers)
|
||||
{}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
@ -345,7 +352,7 @@ QPointF QEventPoint::lastNormalizedPos() const
|
||||
}
|
||||
|
||||
QPointerEvent::QPointerEvent(QEvent::Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers)
|
||||
: QInputEvent(type, dev, modifiers)
|
||||
: QInputEvent(type, QEvent::PointerEventTag{}, dev, modifiers)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,8 @@ public:
|
||||
inline void setTimestamp(ulong timestamp) { m_timeStamp = timestamp; }
|
||||
|
||||
protected:
|
||||
QInputEvent(Type type, PointerEventTag, const QInputDevice *m_dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
|
||||
|
||||
const QInputDevice *m_dev = nullptr;
|
||||
Qt::KeyboardModifiers m_modState = Qt::NoModifier;
|
||||
ulong m_timeStamp = 0;
|
||||
|
@ -115,6 +115,8 @@ void tst_QMouseEvent::mouseEventBasic()
|
||||
QPointF screen(300, 300);
|
||||
// Press left button
|
||||
QMouseEvent me(QEvent::MouseButtonPress, local, scene, screen, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QVERIFY(me.isInputEvent());
|
||||
QVERIFY(me.isPointerEvent());
|
||||
QCOMPARE(me.isAccepted(), true);
|
||||
QCOMPARE(me.button(), Qt::LeftButton);
|
||||
QCOMPARE(me.buttons(), Qt::LeftButton);
|
||||
|
@ -302,6 +302,8 @@ void tst_QTouchEvent::state()
|
||||
QVERIFY(touchEvent.isPressEvent());
|
||||
QVERIFY(!touchEvent.isUpdateEvent());
|
||||
QVERIFY(!touchEvent.isReleaseEvent());
|
||||
QVERIFY(touchEvent.isInputEvent());
|
||||
QVERIFY(touchEvent.isPointerEvent());
|
||||
|
||||
touchEvent = QTouchEvent(QEvent::TouchBegin, touchScreenDevice,
|
||||
Qt::NoModifier, QList<QEventPoint>() <<
|
||||
|
Loading…
Reference in New Issue
Block a user