Default QQuickItem::acceptTouchEvents to true until Qt 6

This is a partial revert of 1457df74f4
to avoid making a mandatory API change so soon.

Change-Id: I05040579fa36d3dc5ef7616861f6d17adf500d2c
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Shawn Rutledge 2017-05-02 11:34:19 +02:00
parent d84af8b815
commit ab91e7fa02
8 changed files with 30 additions and 6 deletions

View File

@ -270,6 +270,7 @@ void QQuickFlickablePrivate::init()
qmlobject_connect(&velocityTimeline, QQuickTimeLine, SIGNAL(completed()), qmlobject_connect(&velocityTimeline, QQuickTimeLine, SIGNAL(completed()),
q, QQuickFlickable, SLOT(velocityTimelineCompleted())) q, QQuickFlickable, SLOT(velocityTimelineCompleted()))
q->setAcceptedMouseButtons(Qt::LeftButton); q->setAcceptedMouseButtons(Qt::LeftButton);
q->setAcceptTouchEvents(false); // rely on mouse events synthesized from touch
q->setFiltersChildMouseEvents(true); q->setFiltersChildMouseEvents(true);
QQuickItemPrivate *viewportPrivate = QQuickItemPrivate::get(contentItem); QQuickItemPrivate *viewportPrivate = QQuickItemPrivate::get(contentItem);
viewportPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry); viewportPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry);

View File

@ -3171,7 +3171,11 @@ QQuickItemPrivate::QQuickItemPrivate()
, antialiasingValid(false) , antialiasingValid(false)
, isTabFence(false) , isTabFence(false)
, replayingPressEvent(false) , replayingPressEvent(false)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
, touchEnabled(true)
#else
, touchEnabled(false) , touchEnabled(false)
#endif
, dirtyAttributes(0) , dirtyAttributes(0)
, nextDirtyItem(0) , nextDirtyItem(0)
, prevDirtyItem(0) , prevDirtyItem(0)

View File

@ -85,6 +85,7 @@ void QQuickMouseAreaPrivate::init()
{ {
Q_Q(QQuickMouseArea); Q_Q(QQuickMouseArea);
q->setAcceptedMouseButtons(Qt::LeftButton); q->setAcceptedMouseButtons(Qt::LeftButton);
q->setAcceptTouchEvents(false); // rely on mouse events synthesized from touch
q->setFiltersChildMouseEvents(true); q->setFiltersChildMouseEvents(true);
if (qmlVisualTouchDebugging()) { if (qmlVisualTouchDebugging()) {
q->setFlag(QQuickItem::ItemHasContents); q->setFlag(QQuickItem::ItemHasContents);

View File

@ -324,6 +324,9 @@ QQuickRectangle::QQuickRectangle(QQuickItem *parent)
: QQuickItem(*(new QQuickRectanglePrivate), parent) : QQuickItem(*(new QQuickRectanglePrivate), parent)
{ {
setFlag(ItemHasContents); setFlag(ItemHasContents);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
setAcceptTouchEvents(false);
#endif
} }
/*! /*!

View File

@ -2668,9 +2668,15 @@ void QQuickWindowPrivate::updateFilteringParentItems(const QVector<QQuickItem *>
} }
filteringParentItems.clear(); filteringParentItems.clear();
for (QQuickItem *item : targetItems) { for (QQuickItem *item : targetItems) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool acceptsTouchEvents = item->acceptTouchEvents();
#else
// In versions prior to Qt 6, we can't trust item->acceptTouchEvents() here, because it defaults to true.
bool acceptsTouchEvents = false;
#endif
QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(item); QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(item);
// If the item neither handles events nor has handlers which do, then it will never be a receiver, so filtering is irrelevant // If the item neither handles events nor has handlers which do, then it will never be a receiver, so filtering is irrelevant.
if (!item->acceptedMouseButtons() && !item->acceptTouchEvents() && if (!item->acceptedMouseButtons() && !acceptsTouchEvents &&
!(itemPriv->extra.isAllocated() && !itemPriv->extra->pointerHandlers.isEmpty())) !(itemPriv->extra.isAllocated() && !itemPriv->extra->pointerHandlers.isEmpty()))
continue; continue;
QQuickItem *parent = item->parentItem(); QQuickItem *parent = item->parentItem();

View File

@ -64,7 +64,11 @@ public:
, ungrabs(0) , ungrabs(0)
, m_active(false) , m_active(false)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
setAcceptTouchEvents(true); setAcceptTouchEvents(true);
#else
setAcceptedMouseButtons(Qt::LeftButton); // not really, but we want touch events
#endif
} }
QPointF pos() const { return m_pos; } QPointF pos() const { return m_pos; }

View File

@ -46,11 +46,14 @@ class TestItem : public QQuickItem
Q_OBJECT Q_OBJECT
public: public:
TestItem(QQuickItem *parent = 0) TestItem(QQuickItem *parent = 0)
: QQuickItem(parent), focused(false), pressCount(0), releaseCount(0) : QQuickItem(parent), focused(false), pressCount(0), releaseCount(0)
, wheelCount(0), acceptIncomingTouchEvents(true) , wheelCount(0), acceptIncomingTouchEvents(true)
, touchEventReached(false), timestamp(0) , touchEventReached(false), timestamp(0)
, lastWheelEventPos(0, 0), lastWheelEventGlobalPos(0, 0) { , lastWheelEventPos(0, 0), lastWheelEventGlobalPos(0, 0)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
setAcceptTouchEvents(true); setAcceptTouchEvents(true);
#endif
} }
bool focused; bool focused;

View File

@ -74,7 +74,9 @@ public:
: QQuickItem(parent), touchUngrabCount(0), acceptMouse(false), acceptTouch(false), filterTouch(false), point0(-1) : QQuickItem(parent), touchUngrabCount(0), acceptMouse(false), acceptTouch(false), filterTouch(false), point0(-1)
{ {
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
setAcceptTouchEvents(true); setAcceptTouchEvents(true);
#endif
} }
void touchEvent(QTouchEvent *event) void touchEvent(QTouchEvent *event)