Skip to content

Commit 47e4a60

Browse files
Fixed some issues in AutoHideDockContainer eventFilter function
1 parent a2a328e commit 47e4a60

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

src/AutoHideDockContainer.cpp

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

489-
bool is_ancestor_of (const QObject *descendant, const QObject *ancestor)
489+
490+
//============================================================================
491+
/**
492+
* Returns true if the object given in ancestor is an ancestor of the object
493+
* given in descendant
494+
*/
495+
static bool objectIsAncestorOf(const QObject* descendant, const QObject* ancestor)
490496
{
491497
if (!ancestor)
498+
{
492499
return false;
493-
while (descendant) {
500+
}
501+
while (descendant)
502+
{
494503
if (descendant == ancestor)
504+
{
495505
return true;
506+
}
496507
descendant = descendant->parent();
497508
}
498509
return false;
499510
}
500511

501512

513+
//============================================================================
514+
/**
515+
* Returns true if the object given in ancestor is the object given in descendant
516+
* or if it is an ancestor of the object given in descendant
517+
*/
518+
static bool isObjectOrAncestor(const QObject *descendant, const QObject *ancestor)
519+
{
520+
if (ancestor && (descendant == ancestor))
521+
{
522+
return true;
523+
}
524+
else
525+
{
526+
return objectIsAncestorOf(descendant, ancestor);
527+
}
528+
}
529+
530+
502531
//============================================================================
503532
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
504533
{
@@ -513,25 +542,18 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
513542
}
514543
else if (event->type() == QEvent::MouseButtonPress)
515544
{
516-
// We check, if the mouse button press is inside the container
517-
// widget. If it is not, i.e. if someone resizes the main window or
518-
// clicks into the application menu or toolbar, then we ignore the
519-
// event
520-
auto Container = dockContainer();
521-
QMouseEvent* me = static_cast<QMouseEvent*>(event);
522-
auto GlobalPos = internal::globalPositionOf(me);
523-
auto pos = Container->mapFromGlobal(GlobalPos);
524-
if (!Container->rect().contains(pos))
545+
auto widget = qobject_cast<QWidget*>(watched);
546+
// Ignore non widget events
547+
if (!widget)
525548
{
526549
return Super::eventFilter(watched, event);
527550
}
528551

529552
// Now we check, if the user clicked inside of this auto hide container.
530-
// If the click is inside of this auto hide container, then we can also
553+
// If the click is inside of this auto hide container, then we can
531554
// ignore the event, because the auto hide overlay should not get collapsed if
532555
// user works in it
533-
pos = mapFromGlobal(GlobalPos);
534-
if (rect().contains(pos))
556+
if (isObjectOrAncestor(widget, this))
535557
{
536558
return Super::eventFilter(watched, event);
537559
}
@@ -540,16 +562,18 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
540562
// because the side tab click handler will call collapseView(). If we
541563
// do not ignore this here, then we will collapse the container and the side tab
542564
// click handler will uncollapse it
543-
auto SideTab = d->SideTab;
544-
pos = SideTab->mapFromGlobal(GlobalPos);
545-
if (SideTab->rect().contains(pos))
565+
if (isObjectOrAncestor(widget, d->SideTab.data()))
546566
{
547567
return Super::eventFilter(watched, event);
548568
}
549569

550-
// If the mouse button down event is in the dock manager but outside
551-
// of the open auto hide container, then the auto hide dock widget
552-
// should get collapsed
570+
// Ignore the mouse click if it is not inside of this container
571+
if (!isObjectOrAncestor(widget, dockContainer()))
572+
{
573+
return Super::eventFilter(watched, event);
574+
}
575+
576+
// user clicked into container - collapse the auto hide widget
553577
collapseView(true);
554578
}
555579
else if (event->type() == internal::FloatingWidgetDragStartEvent)
@@ -608,6 +632,10 @@ bool CAutoHideDockContainer::event(QEvent* event)
608632
d->forwardEventToDockContainer(event);
609633
break;
610634

635+
case QEvent::MouseButtonPress:
636+
return true;
637+
break;
638+
611639
default:
612640
break;
613641
}

0 commit comments

Comments
 (0)