From 07d0bdc8ed716f733bdf2aa10c2cfdba84199c62 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 15 Nov 2022 10:46:15 +0100 Subject: [PATCH] Improved CAutoHideDockContainer::eventFilter function to collapse the auto hide widget if someone clicks into another window --- src/AutoHideDockContainer.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index 637d545..4471ff6 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -482,23 +482,24 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event) } else if (event->type() == QEvent::MouseButtonPress) { - auto Container = dockContainer(); - // First we check, if the mouse button press is inside the container + // If the user clicked into another window, then we collapse the + // auto hide widget + auto widget = qobject_cast(watched); + if (widget && widget->window() != this->window()) + { + collapseView(true); + return Super::eventFilter(watched, event); + } + + // We check, if the mouse button press is inside the container // widget. If it is not, i.e. if someone resizes the main window or // clicks into the application menu or toolbar, then we ignore the // event - auto widget = qobject_cast(watched); - bool IsContainer = false; - while (widget) - { - if (widget == Container) - { - IsContainer = true; - } - widget = widget->parentWidget(); - } - - if (!IsContainer) + auto Container = dockContainer(); + QMouseEvent* me = static_cast(event); + auto GlobalPos = internal::globalPositionOf(me); + auto pos = Container->mapFromGlobal(GlobalPos); + if (!Container->rect().contains(pos)) { return Super::eventFilter(watched, event); } @@ -507,9 +508,7 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event) // If the click is inside of this auto hide container, then we can also // ignore the event, because the auto hide overlay should not get collapsed if // user works in it - QMouseEvent* me = static_cast(event); - auto GlobalPos = internal::globalPositionOf(me); - auto pos = mapFromGlobal(GlobalPos); + pos = mapFromGlobal(GlobalPos); if (rect().contains(pos)) { return Super::eventFilter(watched, event);