aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-07-06 13:15:25 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-07-07 22:35:42 +0200
commit48da34f3d797f58b3eda9ed0a98aa1776d75d946 (patch)
tree01200e18fd4c35e39e4a1ae21f06a69a7f2ebff1 /src
parent6363bc8bfebdedad9f4b871f99c23c9b7b0e8bc7 (diff)
QQuickOverlay: Handle hover events
With recent changes to hover handling logic, hover events would have been sent to the "main window", even if a popup were modal. As this is unwanted (a modally blocked button should not auto-raise when hovered), we now prevent delivery of those events in QQuickOverlay and overlayEvent. The logic is the same as for mouse and touch events: If we get a matching event, we ask the popup to handle it. The popup then uses the existing blockInput logic to decide whether the event should be blocked or forwarded. Pick-to: 6.2 Change-Id: I2194fd8e832592efd5b7b9697412bdaeaea74b83 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickoverlay.cpp20
-rw-r--r--src/quicktemplates2/qquickoverlay_p_p.h1
-rw-r--r--src/quicktemplates2/qquickpopup.cpp17
-rw-r--r--src/quicktemplates2/qquickpopup_p_p.h1
4 files changed, 39 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp
index 982834d8..6689d93c 100644
--- a/src/quicktemplates2/qquickoverlay.cpp
+++ b/src/quicktemplates2/qquickoverlay.cpp
@@ -207,6 +207,22 @@ bool QQuickOverlayPrivate::handleMouseEvent(QQuickItem *source, QMouseEvent *eve
return false;
}
+bool QQuickOverlayPrivate::handleHoverEvent(QQuickItem *source, QHoverEvent *event, QQuickPopup *target)
+{
+ switch (event->type()) {
+ case QEvent::HoverEnter:
+ case QEvent::HoverMove:
+ case QEvent::HoverLeave:
+ if (target)
+ return target->overlayEvent(source, event);
+ return false;
+ default:
+ Q_UNREACHABLE(); // function must only be called on hover events
+ break;
+ }
+ return false;
+}
+
#if QT_CONFIG(quicktemplates2_multitouch)
bool QQuickOverlayPrivate::handleTouchEvent(QQuickItem *source, QTouchEvent *event, QQuickPopup *target)
{
@@ -474,6 +490,10 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event)
case QEvent::TouchEnd:
return d->handleTouchEvent(item, static_cast<QTouchEvent *>(event), popup);
#endif
+ case QEvent::HoverEnter:
+ case QEvent::HoverMove:
+ case QEvent::HoverLeave:
+ return d->handleHoverEvent(item, static_cast<QHoverEvent *>(event), popup);
case QEvent::MouseButtonPress:
case QEvent::MouseMove:
diff --git a/src/quicktemplates2/qquickoverlay_p_p.h b/src/quicktemplates2/qquickoverlay_p_p.h
index ef3d9ee2..fbb2f86c 100644
--- a/src/quicktemplates2/qquickoverlay_p_p.h
+++ b/src/quicktemplates2/qquickoverlay_p_p.h
@@ -74,6 +74,7 @@ public:
bool handleRelease(QQuickItem *source, QEvent *event, QQuickPopup *target);
bool handleMouseEvent(QQuickItem *source, QMouseEvent *event, QQuickPopup *target = nullptr);
+ bool handleHoverEvent(QQuickItem *source, QHoverEvent *event, QQuickPopup *target = nullptr);
#if QT_CONFIG(quicktemplates2_multitouch)
bool handleTouchEvent(QQuickItem *source, QTouchEvent *event, QQuickPopup *target = nullptr);
#endif
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index ebb85c12..cb78d634 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -412,6 +412,19 @@ bool QQuickPopupPrivate::handleMouseEvent(QQuickItem *item, QMouseEvent *event)
}
}
+bool QQuickPopupPrivate::handleHoverEvent(QQuickItem *item, QHoverEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::HoverEnter:
+ case QEvent::HoverMove:
+ case QEvent::HoverLeave:
+ return blockInput(item, event->scenePosition());
+ default:
+ Q_UNREACHABLE();
+ return false;
+ }
+}
+
#if QT_CONFIG(quicktemplates2_multitouch)
bool QQuickPopupPrivate::handleTouchEvent(QQuickItem *item, QTouchEvent *event)
{
@@ -2558,6 +2571,10 @@ bool QQuickPopup::overlayEvent(QQuickItem *item, QEvent *event)
case QEvent::TouchEnd:
return d->handleTouchEvent(item, static_cast<QTouchEvent *>(event));
#endif
+ case QEvent::HoverEnter:
+ case QEvent::HoverMove:
+ case QEvent::HoverLeave:
+ return d->handleHoverEvent(item, static_cast<QHoverEvent *>(event));
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h
index 5ce1d291..0a00c2aa 100644
--- a/src/quicktemplates2/qquickpopup_p_p.h
+++ b/src/quicktemplates2/qquickpopup_p_p.h
@@ -120,6 +120,7 @@ public:
virtual void handleUngrab();
bool handleMouseEvent(QQuickItem *item, QMouseEvent *event);
+ bool handleHoverEvent(QQuickItem *item, QHoverEvent *event);
#if QT_CONFIG(quicktemplates2_multitouch)
bool handleTouchEvent(QQuickItem *item, QTouchEvent *event);
#endif