Skip to content

Commit 95b627e

Browse files
Prevent accidental hiding collapsing of an auto hide widget by a mouse click shortly after a mouse over collapse event
1 parent 2569e0a commit 95b627e

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/AutoHideTab.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <QBoxLayout>
3333
#include <QApplication>
34+
#include <QElapsedTimer>
3435

3536
#include "AutoHideDockContainer.h"
3637
#include "AutoHideSideBar.h"
@@ -49,6 +50,7 @@ struct AutoHideTabPrivate
4950
CDockWidget* DockWidget = nullptr;
5051
CAutoHideSideBar* SideBar = nullptr;
5152
Qt::Orientation Orientation{Qt::Vertical};
53+
QElapsedTimer TimeSinceHoverMousePress;
5254

5355
/**
5456
* Private data constructor
@@ -229,14 +231,34 @@ void CAutoHideTab::setDockWidget(CDockWidget* DockWidget)
229231
//============================================================================
230232
bool CAutoHideTab::event(QEvent* event)
231233
{
234+
if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideShowOnMouseOver))
235+
{
236+
return Super::event(event);
237+
}
238+
232239
switch (event->type())
233240
{
234241
case QEvent::Enter:
235242
case QEvent::Leave:
236-
case QEvent::MouseButtonPress:
237243
d->forwardEventToDockContainer(event);
238244
break;
239245

246+
case QEvent::MouseButtonPress:
247+
// If AutoHideShowOnMouseOver is active, then the showing is triggered
248+
// by a MousePressEvent sent to this tab. To prevent accidental hiding
249+
// of the tab by a mouse click, we wait at least 500 ms before we accept
250+
// the mouse click
251+
if (!event->spontaneous())
252+
{
253+
d->TimeSinceHoverMousePress.restart();
254+
d->forwardEventToDockContainer(event);
255+
}
256+
else if (d->TimeSinceHoverMousePress.hasExpired(500))
257+
{
258+
d->forwardEventToDockContainer(event);
259+
}
260+
break;
261+
240262
default:
241263
break;
242264
}

src/DockContainerWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ CDockManager* CDockContainerWidget::dockManager() const
20642064
//===========================================================================
20652065
void CDockContainerWidget::handleAutoHideWidgetEvent(QEvent* e, QWidget* w)
20662066
{
2067-
if (!CDockManager::testAutoHideConfigFlag(CDockManager::ShowAutoHideOnMouseOver))
2067+
if (!CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideShowOnMouseOver))
20682068
{
20692069
return;
20702070
}

src/DockManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
239239
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
240240
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.
241241
AutoHideSideBarsIconOnly = 0x10,///< show only icons in auto hide side tab - if a tab has no icon, then the text will be shown
242-
ShowAutoHideOnMouseOver = 0x20, ///< show the auto hide window on mouse over tab and hide it if mouse leaves auto hide container
242+
AutoHideShowOnMouseOver = 0x20, ///< show the auto hide window on mouse over tab and hide it if mouse leaves auto hide container
243243

244244
DefaultAutoHideConfig = AutoHideFeatureEnabled
245245
| DockAreaHasAutoHideButton ///< the default configuration for left and right side bars

0 commit comments

Comments
 (0)