Prevent accidental hiding collapsing of an auto hide widget by a mouse click shortly after a mouse over collapse event

This commit is contained in:
Uwe Kindler 2022-11-07 10:15:14 +01:00
parent 2569e0aa05
commit 95b627e83e
3 changed files with 25 additions and 3 deletions

View File

@ -31,6 +31,7 @@
#include <QBoxLayout> #include <QBoxLayout>
#include <QApplication> #include <QApplication>
#include <QElapsedTimer>
#include "AutoHideDockContainer.h" #include "AutoHideDockContainer.h"
#include "AutoHideSideBar.h" #include "AutoHideSideBar.h"
@ -49,6 +50,7 @@ struct AutoHideTabPrivate
CDockWidget* DockWidget = nullptr; CDockWidget* DockWidget = nullptr;
CAutoHideSideBar* SideBar = nullptr; CAutoHideSideBar* SideBar = nullptr;
Qt::Orientation Orientation{Qt::Vertical}; Qt::Orientation Orientation{Qt::Vertical};
QElapsedTimer TimeSinceHoverMousePress;
/** /**
* Private data constructor * Private data constructor
@ -229,14 +231,34 @@ void CAutoHideTab::setDockWidget(CDockWidget* DockWidget)
//============================================================================ //============================================================================
bool CAutoHideTab::event(QEvent* event) bool CAutoHideTab::event(QEvent* event)
{ {
if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideShowOnMouseOver))
{
return Super::event(event);
}
switch (event->type()) switch (event->type())
{ {
case QEvent::Enter: case QEvent::Enter:
case QEvent::Leave: case QEvent::Leave:
case QEvent::MouseButtonPress:
d->forwardEventToDockContainer(event); d->forwardEventToDockContainer(event);
break; break;
case QEvent::MouseButtonPress:
// If AutoHideShowOnMouseOver is active, then the showing is triggered
// by a MousePressEvent sent to this tab. To prevent accidental hiding
// of the tab by a mouse click, we wait at least 500 ms before we accept
// the mouse click
if (!event->spontaneous())
{
d->TimeSinceHoverMousePress.restart();
d->forwardEventToDockContainer(event);
}
else if (d->TimeSinceHoverMousePress.hasExpired(500))
{
d->forwardEventToDockContainer(event);
}
break;
default: default:
break; break;
} }

View File

@ -2064,7 +2064,7 @@ CDockManager* CDockContainerWidget::dockManager() const
//=========================================================================== //===========================================================================
void CDockContainerWidget::handleAutoHideWidgetEvent(QEvent* e, QWidget* w) void CDockContainerWidget::handleAutoHideWidgetEvent(QEvent* e, QWidget* w)
{ {
if (!CDockManager::testAutoHideConfigFlag(CDockManager::ShowAutoHideOnMouseOver)) if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideShowOnMouseOver))
{ {
return; return;
} }

View File

@ -239,7 +239,7 @@ public:
AutoHideButtonTogglesArea = 0x04, //!< If the flag is set, the auto hide button enables auto hiding for all dock widgets in an area, if disabled, only the current dock widget will be toggled AutoHideButtonTogglesArea = 0x04, //!< If the flag is set, the auto hide button enables auto hiding for all dock widgets in an area, if disabled, only the current dock widget will be toggled
AutoHideButtonCheckable = 0x08, //!< If the flag is set, the auto hide button will be checked and unchecked depending on the auto hide state. Mainly for styling purposes. AutoHideButtonCheckable = 0x08, //!< If the flag is set, the auto hide button will be checked and unchecked depending on the auto hide state. Mainly for styling purposes.
AutoHideSideBarsIconOnly = 0x10,///< show only icons in auto hide side tab - if a tab has no icon, then the text will be shown AutoHideSideBarsIconOnly = 0x10,///< show only icons in auto hide side tab - if a tab has no icon, then the text will be shown
ShowAutoHideOnMouseOver = 0x20, ///< show the auto hide window on mouse over tab and hide it if mouse leaves auto hide container AutoHideShowOnMouseOver = 0x20, ///< show the auto hide window on mouse over tab and hide it if mouse leaves auto hide container
DefaultAutoHideConfig = AutoHideFeatureEnabled DefaultAutoHideConfig = AutoHideFeatureEnabled
| DockAreaHasAutoHideButton ///< the default configuration for left and right side bars | DockAreaHasAutoHideButton ///< the default configuration for left and right side bars