aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-09-23 16:55:10 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-10-07 11:08:41 +0200
commit6857ad3e686a5e2b45d28a7f47dca3210608da50 (patch)
tree1769fe1b9a26a690f2b6c641ffac7492df28edf3 /src/quick
parent49391fcc41d871836868452b8300938d0b94f00e (diff)
QQuickListView: prevent mouse delivery in floating header or footer
Earlier we reimplemented the contains() method of ListView to prevent dragging in an Overlay or Pullback header or footer. But in QQuickWindow (QQuickWindowPrivate::pointerTargets()), an early check prevents delivery of pointer events to an item that is clipped and for which contains() returns false, and also to its children. In that case, the header or footer no longer responds to a mouse event even if you put a MouseArea in it. Reverts 6ad3445f1e159d9beea936b66d267dcaacdc5d6c; reimplemented using similar logic in a new QQuickListViewPrivate::wantsPointerEvent() method, overriding QQuickFlickablePrivate::wantsPointerEvent(), which is now checked in event-handling code in addition to checking the interactive flag. Done-with: Wang Chuan <ouchuanm@outlook.com> Pick-to: 5.15 Task-number: QTBUG-74046 Fixes: QTBUG-85302 Change-Id: I9474f035d26b74ee36c0ac19e45a77de2e694bf1 Reviewed-by: Wang Chuan <ouchuanm@outlook.com> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/items/qquickflickable.cpp10
-rw-r--r--src/quick/items/qquickflickable_p_p.h3
-rw-r--r--src/quick/items/qquicklistview.cpp56
-rw-r--r--src/quick/items/qquicklistview_p.h2
4 files changed, 55 insertions, 16 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp
index d20f23466b..f29153967a 100644
--- a/src/quick/items/qquickflickable.cpp
+++ b/src/quick/items/qquickflickable.cpp
@@ -1424,7 +1424,7 @@ void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event)
void QQuickFlickable::mousePressEvent(QMouseEvent *event)
{
Q_D(QQuickFlickable);
- if (d->interactive) {
+ if (d->interactive && d->wantsPointerEvent(event)) {
if (!d->pressed)
d->handleMousePressEvent(event);
event->accept();
@@ -1436,7 +1436,7 @@ void QQuickFlickable::mousePressEvent(QMouseEvent *event)
void QQuickFlickable::mouseMoveEvent(QMouseEvent *event)
{
Q_D(QQuickFlickable);
- if (d->interactive) {
+ if (d->interactive && d->wantsPointerEvent(event)) {
d->handleMouseMoveEvent(event);
event->accept();
} else {
@@ -1447,7 +1447,7 @@ void QQuickFlickable::mouseMoveEvent(QMouseEvent *event)
void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event)
{
Q_D(QQuickFlickable);
- if (d->interactive) {
+ if (d->interactive && d->wantsPointerEvent(event)) {
if (d->delayedPressEvent) {
d->replayDelayedPress();
@@ -1475,7 +1475,7 @@ void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event)
void QQuickFlickable::wheelEvent(QWheelEvent *event)
{
Q_D(QQuickFlickable);
- if (!d->interactive) {
+ if (!d->interactive || !d->wantsPointerEvent(event)) {
QQuickItem::wheelEvent(event);
return;
}
@@ -2444,7 +2444,7 @@ bool QQuickFlickable::filterMouseEvent(QQuickItem *receiver, QMouseEvent *event)
bool QQuickFlickable::childMouseEventFilter(QQuickItem *i, QEvent *e)
{
Q_D(QQuickFlickable);
- if (!isVisible() || !isEnabled() || !isInteractive()) {
+ if (!isVisible() || !isEnabled() || !isInteractive() || !d->wantsPointerEvent(e)) {
d->cancelInteraction();
return QQuickItem::childMouseEventFilter(i, e);
}
diff --git a/src/quick/items/qquickflickable_p_p.h b/src/quick/items/qquickflickable_p_p.h
index 0d7f27492a..c85ccb733f 100644
--- a/src/quick/items/qquickflickable_p_p.h
+++ b/src/quick/items/qquickflickable_p_p.h
@@ -208,6 +208,9 @@ public:
void addPointerHandler(QQuickPointerHandler *h) override;
+ // TODO Qt 6: QPointerEvent
+ virtual bool wantsPointerEvent(const QEvent *) { return true; }
+
public:
QQuickItem *contentItem;
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index c2285c38ea..ced9e27855 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE
#define QML_FLICK_SNAPONETHRESHOLD 30
#endif
+Q_LOGGING_CATEGORY(lcEvents, "qt.quick.listview.events")
+
class FxListItemSG;
class QQuickListViewPrivate : public QQuickItemViewPrivate
@@ -143,6 +145,9 @@ public:
void fixupHeader();
void fixupHeaderCompleted();
+
+ bool wantsPointerEvent(const QEvent *event) override;
+
QQuickListView::Orientation orient;
qreal visiblePos;
qreal averageSize;
@@ -179,6 +184,7 @@ public:
bool correctFlick : 1;
bool inFlickCorrection : 1;
+ bool wantedMousePress : 1;
QQuickListViewPrivate()
: orient(QQuickListView::Vertical)
@@ -192,7 +198,7 @@ public:
, sectionCriteria(nullptr), currentSectionItem(nullptr), nextSectionItem(nullptr)
, overshootDist(0.0), desiredViewportPosition(0.0), fixupHeaderPosition(0.0)
, headerNeedsSeparateFixup(false), desiredHeaderVisible(false)
- , correctFlick(false), inFlickCorrection(false)
+ , correctFlick(false), inFlickCorrection(false), wantedMousePress(false)
{
highlightMoveDuration = -1; //override default value set in base class
}
@@ -3819,20 +3825,52 @@ QQuickListViewAttached *QQuickListView::qmlAttachedProperties(QObject *obj)
return new QQuickListViewAttached(obj);
}
-bool QQuickListView::contains(const QPointF &point) const
+/*! \internal
+ Prevents clicking or dragging through floating headers (QTBUG-74046).
+*/
+bool QQuickListViewPrivate::wantsPointerEvent(const QEvent *event)
{
- bool ret = QQuickItemView::contains(point);
- // QTBUG-74046: if a mouse press "falls through" a floating header or footer, don't allow dragging the list from there
- if (ret) {
- if (auto header = headerItem()) {
- if (headerPositioning() != QQuickListView::InlineHeader && header->contains(mapToItem(header, point)))
+ Q_Q(const QQuickListView);
+ bool ret = true;
+
+ QPointF pos;
+ // TODO switch not needed in Qt 6: use points().first().position()
+ switch (event->type()) {
+ case QEvent::Wheel:
+ pos = static_cast<const QWheelEvent *>(event)->position();
+ break;
+ case QEvent::MouseButtonPress:
+ pos = static_cast<const QMouseEvent *>(event)->position();
+ break;
+ default:
+ break;
+ }
+
+ if (!pos.isNull()) {
+ if (auto header = q->headerItem()) {
+ if (q->headerPositioning() != QQuickListView::InlineHeader &&
+ header->contains(q->mapToItem(header, pos)))
ret = false;
}
- if (auto footer = footerItem()) {
- if (footerPositioning() != QQuickListView::InlineFooter && footer->contains(mapToItem(footer, point)))
+ if (auto footer = q->footerItem()) {
+ if (q->footerPositioning() != QQuickListView::InlineFooter &&
+ footer->contains(q->mapToItem(footer, pos)))
ret = false;
}
}
+
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ wantedMousePress = ret;
+ break;
+ case QEvent::MouseMove:
+ ret = wantedMousePress;
+ break;
+ default:
+ break;
+ }
+
+ qCDebug(lcEvents) << q << (ret ? "WANTS" : "DOESN'T want") << event;
return ret;
}
diff --git a/src/quick/items/qquicklistview_p.h b/src/quick/items/qquicklistview_p.h
index be91dafaca..260e26923f 100644
--- a/src/quick/items/qquicklistview_p.h
+++ b/src/quick/items/qquicklistview_p.h
@@ -181,8 +181,6 @@ public:
static QQuickListViewAttached *qmlAttachedProperties(QObject *);
- bool contains(const QPointF &point) const override;
-
public Q_SLOTS:
void incrementCurrentIndex();
void decrementCurrentIndex();