Skip to content

Commit aee68c1

Browse files
Fixed hiding of AutoHideContainer when clicking outside context menu
1 parent 5a18526 commit aee68c1

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

demo/MainWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
697697

698698
// uncomment the following line if you want to use opaque undocking and
699699
// opaque splitter resizing
700-
//CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
700+
CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
701701

702702
// uncomment the following line if you want a fixed tab width that does
703703
// not change if the visibility of the close button changes

src/AutoHideDockContainer.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@ void CAutoHideDockContainer::setSize(int Size)
486486
updateSize();
487487
}
488488

489+
bool is_ancestor_of (const QObject *descendant, const QObject *ancestor)
490+
{
491+
if (!ancestor)
492+
return false;
493+
while (descendant) {
494+
if (descendant == ancestor)
495+
return true;
496+
descendant = descendant->parent();
497+
}
498+
return false;
499+
}
500+
489501

490502
//============================================================================
491503
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
@@ -503,17 +515,21 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
503515
{
504516
// If the user clicked into another window, then we collapse the
505517
// auto hide widget
518+
/*qDebug() << 1;
519+
qDebug() << "is_ancestor_of " << is_ancestor_of(watched, this);
506520
auto widget = qobject_cast<QWidget*>(watched);
521+
qDebug() << "isAnchestorOf" << isAncestorOf(widget);
507522
if (widget && widget->window() != this->window())
508523
{
509524
collapseView(true);
510525
return Super::eventFilter(watched, event);
511-
}
526+
}*/
512527

513528
// We check, if the mouse button press is inside the container
514529
// widget. If it is not, i.e. if someone resizes the main window or
515530
// clicks into the application menu or toolbar, then we ignore the
516531
// event
532+
qDebug() << 2;
517533
auto Container = dockContainer();
518534
QMouseEvent* me = static_cast<QMouseEvent*>(event);
519535
auto GlobalPos = internal::globalPositionOf(me);
@@ -527,6 +543,7 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
527543
// If the click is inside of this auto hide container, then we can also
528544
// ignore the event, because the auto hide overlay should not get collapsed if
529545
// user works in it
546+
qDebug() << 3;
530547
pos = mapFromGlobal(GlobalPos);
531548
if (rect().contains(pos))
532549
{
@@ -537,6 +554,7 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
537554
// because the side tab click handler will call collapseView(). If we
538555
// do not ignore this here, then we will collapse the container and the side tab
539556
// click handler will uncollapse it
557+
qDebug() << 4;
540558
auto SideTab = d->SideTab;
541559
pos = SideTab->mapFromGlobal(GlobalPos);
542560
if (SideTab->rect().contains(pos))
@@ -547,9 +565,11 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
547565
// If the mouse button down event is in the dock manager but outside
548566
// of the open auto hide container, then the auto hide dock widget
549567
// should get collapsed
568+
qDebug() << 5;
550569
collapseView(true);
551570
}
552-
else if (event->type() == internal::FloatingWidgetDragStartEvent)
571+
else if (event->type() == internal::FloatingWidgetDragStartEvent
572+
|| event->type() == internal::DockedWidgetDragStartEvent)
553573
{
554574
collapseView(true);
555575
}

src/DockWidgetTab.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,11 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
333333
if (DraggingFloatingWidget == DraggingState)
334334
{
335335
FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingFloatingWidget, _this);
336-
auto Overlay = DockWidget->dockManager()->containerOverlay();
336+
auto DockManager = DockWidget->dockManager();
337+
auto Overlay = DockManager->containerOverlay();
337338
Overlay->setAllowedAreas(OuterDockAreas);
338339
this->FloatingWidget = FloatingWidget;
340+
qApp->postEvent(DockManager, new QEvent((QEvent::Type)internal::DockedWidgetDragStartEvent));
339341
}
340342
else
341343
{

src/ads_globals.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace ads
5151
namespace internal
5252
{
5353
const int FloatingWidgetDragStartEvent = QEvent::registerEventType();
54+
const int DockedWidgetDragStartEvent = QEvent::registerEventType();
5455
#ifdef Q_OS_LINUX
5556
static QString _window_manager;
5657
static QHash<QString, xcb_atom_t> _xcb_atom_cache;

src/ads_globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static const bool Restore = false;
152152
static const char* const ClosedProperty = "close";
153153
static const char* const DirtyProperty = "dirty";
154154
extern const int FloatingWidgetDragStartEvent;
155+
extern const int DockedWidgetDragStartEvent;
155156

156157
#ifdef Q_OS_LINUX
157158
// Utils to directly communicate with the X server

0 commit comments

Comments
 (0)