Improve encapsuation of touch/mouse event specific things
This makes it easy to avoid casts when using the classes. Change-Id: I27bd1244bffb3a7d2cdb4572c229333e4c499d9b Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
c856d877e7
commit
a5e7897dd7
|
@ -506,26 +506,6 @@ QQuickPointerEvent *QQuickPointerTouchEvent::reset(QEvent *event) {
|
|||
return this;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Returns the original touch event, or nullptr if it was not a touch event.
|
||||
*/
|
||||
QTouchEvent *QQuickPointerEvent::asTouchEvent() const {
|
||||
if (!isTouchEvent())
|
||||
return nullptr;
|
||||
return static_cast<QTouchEvent *>(m_event);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Returns the original mouse event, or nullptr if it was not a mouse event.
|
||||
*/
|
||||
QMouseEvent *QQuickPointerEvent::asMouseEvent() const {
|
||||
if (isMouseEvent())
|
||||
return static_cast<QMouseEvent *>(m_event);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QQuickEventPoint *QQuickPointerMouseEvent::point(int i) const {
|
||||
if (i == 0)
|
||||
return m_mousePoint;
|
||||
|
@ -554,6 +534,11 @@ bool QQuickPointerMouseEvent::allPointsAccepted() const {
|
|||
return m_mousePoint->isAccepted();
|
||||
}
|
||||
|
||||
QMouseEvent *QQuickPointerMouseEvent::asMouseEvent() const
|
||||
{
|
||||
return static_cast<QMouseEvent *>(m_event);
|
||||
}
|
||||
|
||||
bool QQuickPointerTouchEvent::allPointsAccepted() const {
|
||||
for (int i = 0; i < m_pointCount; ++i) {
|
||||
if (!m_touchPoints.at(i)->isAccepted())
|
||||
|
@ -704,6 +689,11 @@ QTouchEvent *QQuickPointerTouchEvent::touchEventForItem(const QList<const QQuick
|
|||
return touchEvent;
|
||||
}
|
||||
|
||||
QTouchEvent *QQuickPointerTouchEvent::asTouchEvent() const
|
||||
{
|
||||
return static_cast<QTouchEvent *>(m_event);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
||||
Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickPointerDevice *dev) {
|
||||
|
|
|
@ -64,6 +64,8 @@ QT_BEGIN_NAMESPACE
|
|||
class QQuickItem;
|
||||
class QQuickPointerDevice;
|
||||
class QQuickPointerEvent;
|
||||
class QQuickPointerMouseEvent;
|
||||
class QQuickPointerTabletEvent;
|
||||
class QQuickPointerTouchEvent;
|
||||
|
||||
class QQuickKeyEvent : public QObject
|
||||
|
@ -346,12 +348,12 @@ public: // property accessors
|
|||
public: // helpers for C++ only (during event delivery)
|
||||
virtual QQuickPointerEvent *reset(QEvent *ev) = 0;
|
||||
|
||||
QTouchEvent *asTouchEvent() const;
|
||||
QMouseEvent *asMouseEvent() const;
|
||||
|
||||
virtual bool isMouseEvent() const { return false; }
|
||||
virtual bool isTouchEvent() const { return false; }
|
||||
virtual bool isTabletEvent() const { return false; }
|
||||
virtual QQuickPointerMouseEvent *asPointerMouseEvent() { return nullptr; }
|
||||
virtual QQuickPointerTouchEvent *asPointerTouchEvent() { return nullptr; }
|
||||
virtual QQuickPointerTabletEvent *asPointerTabletEvent() { return nullptr; }
|
||||
virtual const QQuickPointerMouseEvent *asPointerMouseEvent() const { return nullptr; }
|
||||
virtual const QQuickPointerTouchEvent *asPointerTouchEvent() const { return nullptr; }
|
||||
virtual const QQuickPointerTabletEvent *asPointerTabletEvent() const { return nullptr; }
|
||||
bool isValid() const { return m_event != nullptr; }
|
||||
virtual bool allPointsAccepted() const = 0;
|
||||
|
||||
|
@ -379,12 +381,15 @@ public:
|
|||
}
|
||||
|
||||
QQuickPointerEvent *reset(QEvent *) override;
|
||||
bool isMouseEvent() const override { return true; }
|
||||
QQuickPointerMouseEvent *asPointerMouseEvent() override { return this; }
|
||||
const QQuickPointerMouseEvent *asPointerMouseEvent() const override { return this; }
|
||||
int pointCount() const override { return 1; }
|
||||
QQuickEventPoint *point(int i) const override;
|
||||
QQuickEventPoint *pointById(quint64 pointId) const override;
|
||||
bool allPointsAccepted() const override;
|
||||
|
||||
QMouseEvent *asMouseEvent() const;
|
||||
|
||||
private:
|
||||
QQuickEventPoint *m_mousePoint;
|
||||
};
|
||||
|
@ -397,7 +402,8 @@ public:
|
|||
{}
|
||||
|
||||
QQuickPointerEvent *reset(QEvent *) override;
|
||||
bool isTouchEvent() const override { return true; }
|
||||
QQuickPointerTouchEvent *asPointerTouchEvent() override { return this; }
|
||||
const QQuickPointerTouchEvent *asPointerTouchEvent() const override { return this; }
|
||||
int pointCount() const override { return m_pointCount; }
|
||||
QQuickEventPoint *point(int i) const override;
|
||||
QQuickEventPoint *pointById(quint64 pointId) const override;
|
||||
|
@ -407,6 +413,8 @@ public:
|
|||
QMouseEvent *syntheticMouseEvent(int pointID, QQuickItem *relativeTo) const;
|
||||
QTouchEvent *touchEventForItem(const QList<const QQuickEventPoint *> &newPoints, QQuickItem *relativeTo) const;
|
||||
|
||||
QTouchEvent *asTouchEvent() const;
|
||||
|
||||
private:
|
||||
int m_pointCount;
|
||||
QVector<QQuickEventTouchPoint *> m_touchPoints;
|
||||
|
|
|
@ -2174,9 +2174,9 @@ void QQuickWindowPrivate::deliverPointerEvent(QQuickPointerEvent *event)
|
|||
// the usecase a bit evil, but we at least don't want to lose events.
|
||||
++pointerEventRecursionGuard;
|
||||
|
||||
if (QMouseEvent *mouse = event->asMouseEvent()) {
|
||||
deliverMouseEvent(mouse);
|
||||
} else if (event->isTouchEvent()) {
|
||||
if (QQuickPointerMouseEvent *mouse = event->asPointerMouseEvent()) {
|
||||
deliverMouseEvent(mouse->asMouseEvent());
|
||||
} else if (event->asPointerTouchEvent()) {
|
||||
deliverTouchEvent(event);
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
|
@ -2217,7 +2217,7 @@ QVector<QQuickItem *> QQuickWindowPrivate::pointerTargets(QQuickItem *item, cons
|
|||
|
||||
void QQuickWindowPrivate::deliverTouchEvent(QQuickPointerEvent *event)
|
||||
{
|
||||
qCDebug(DBG_TOUCH) << " - delivering" << event->asTouchEvent();
|
||||
qCDebug(DBG_TOUCH) << " - delivering" << event->asPointerTouchEvent()->asTouchEvent();
|
||||
|
||||
// List of all items that received an event before
|
||||
// When we have TouchBegin this is and will stay empty
|
||||
|
@ -2365,7 +2365,8 @@ bool QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, const QQ
|
|||
const QSet<quint64> &matchingNewPoints, const QList<const QQuickEventPoint *> &matchingPoints,
|
||||
QSet<QQuickItem *> *hasFiltered)
|
||||
{
|
||||
auto pointerTouchEvent = static_cast<const QQuickPointerTouchEvent*>(event);
|
||||
auto pointerTouchEvent = event->asPointerTouchEvent();
|
||||
Q_ASSERT(pointerTouchEvent);
|
||||
QScopedPointer<QTouchEvent> touchEvent(pointerTouchEvent->touchEventForItem(matchingPoints, item));
|
||||
if (touchEvent.data()->touchPoints().isEmpty())
|
||||
return false;
|
||||
|
@ -2375,7 +2376,7 @@ bool QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, const QQ
|
|||
|
||||
// First check whether the parent wants to be a filter,
|
||||
// and if the parent accepts the event we are done.
|
||||
if (sendFilteredTouchEvent(item->parentItem(), item, event->asTouchEvent(), hasFiltered)) {
|
||||
if (sendFilteredTouchEvent(item->parentItem(), item, pointerTouchEvent->asTouchEvent(), hasFiltered)) {
|
||||
// If the touch was accepted (regardless by whom or in what form),
|
||||
// update acceptedNewPoints
|
||||
qCDebug(DBG_TOUCH) << " - can't. intercepted " << touchEvent.data() << " to " << item->parentItem() << " instead of " << item;
|
||||
|
|
|
@ -2329,21 +2329,20 @@ void tst_qquickwindow::pointerEventTypeAndPointCount()
|
|||
QQuickPointerMouseEvent pme;
|
||||
pme.reset(&me);
|
||||
QVERIFY(pme.isValid());
|
||||
QVERIFY(pme.isMouseEvent());
|
||||
QVERIFY(!pme.isTouchEvent());
|
||||
QVERIFY(!pme.isTabletEvent());
|
||||
QVERIFY(pme.asMouseEvent());
|
||||
QVERIFY(!pme.asTouchEvent());
|
||||
QCOMPARE(pme.asMouseEvent(), &me);
|
||||
QVERIFY(pme.asPointerMouseEvent());
|
||||
QVERIFY(!pme.asPointerTouchEvent());
|
||||
QVERIFY(!pme.asPointerTabletEvent());
|
||||
// QVERIFY(!pe->asTabletEvent()); // TODO
|
||||
QCOMPARE(pme.pointCount(), 1);
|
||||
|
||||
QQuickPointerTouchEvent pte;
|
||||
pte.reset(&te);
|
||||
QVERIFY(pte.isValid());
|
||||
QVERIFY(!pte.isMouseEvent());
|
||||
QVERIFY(pte.isTouchEvent());
|
||||
QVERIFY(!pte.isTabletEvent());
|
||||
QVERIFY(!pte.asMouseEvent());
|
||||
QCOMPARE(pte.asTouchEvent(), &te);
|
||||
QVERIFY(!pte.asPointerMouseEvent());
|
||||
QVERIFY(pte.asPointerTouchEvent());
|
||||
QVERIFY(!pte.asPointerTabletEvent());
|
||||
QVERIFY(pte.asTouchEvent());
|
||||
// QVERIFY(!pte.asTabletEvent()); // TODO
|
||||
QCOMPARE(pte.pointCount(), 1);
|
||||
|
|
Loading…
Reference in New Issue