diff --git a/src/AutoHideTab.cpp b/src/AutoHideTab.cpp index 2b5b10d..72bbf0c 100644 --- a/src/AutoHideTab.cpp +++ b/src/AutoHideTab.cpp @@ -31,6 +31,7 @@ #include #include +#include #include "AutoHideDockContainer.h" #include "AutoHideSideBar.h" @@ -49,6 +50,7 @@ struct AutoHideTabPrivate CDockWidget* DockWidget = nullptr; CAutoHideSideBar* SideBar = nullptr; Qt::Orientation Orientation{Qt::Vertical}; + QElapsedTimer TimeSinceHoverMousePress; /** * Private data constructor @@ -229,14 +231,34 @@ void CAutoHideTab::setDockWidget(CDockWidget* DockWidget) //============================================================================ bool CAutoHideTab::event(QEvent* event) { + if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideShowOnMouseOver)) + { + return Super::event(event); + } + switch (event->type()) { case QEvent::Enter: case QEvent::Leave: - case QEvent::MouseButtonPress: d->forwardEventToDockContainer(event); 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: break; } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 2ddb1ab..bf09436 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -2064,7 +2064,7 @@ CDockManager* CDockContainerWidget::dockManager() const //=========================================================================== void CDockContainerWidget::handleAutoHideWidgetEvent(QEvent* e, QWidget* w) { - if (!CDockManager::testAutoHideConfigFlag(CDockManager::ShowAutoHideOnMouseOver)) + if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideShowOnMouseOver)) { return; } diff --git a/src/DockManager.h b/src/DockManager.h index 4fb3c8d..c29ec4a 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -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 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 - 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 | DockAreaHasAutoHideButton ///< the default configuration for left and right side bars