@@ -486,19 +486,48 @@ void CAutoHideDockContainer::setSize(int Size)
486
486
updateSize ();
487
487
}
488
488
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)
490
496
{
491
497
if (!ancestor)
498
+ {
492
499
return false ;
493
- while (descendant) {
500
+ }
501
+ while (descendant)
502
+ {
494
503
if (descendant == ancestor)
504
+ {
495
505
return true ;
506
+ }
496
507
descendant = descendant->parent ();
497
508
}
498
509
return false ;
499
510
}
500
511
501
512
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
+
502
531
// ============================================================================
503
532
bool CAutoHideDockContainer::eventFilter (QObject* watched, QEvent* event)
504
533
{
@@ -513,25 +542,18 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
513
542
}
514
543
else if (event->type () == QEvent::MouseButtonPress)
515
544
{
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)
525
548
{
526
549
return Super::eventFilter (watched, event);
527
550
}
528
551
529
552
// 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
531
554
// ignore the event, because the auto hide overlay should not get collapsed if
532
555
// user works in it
533
- pos = mapFromGlobal (GlobalPos);
534
- if (rect ().contains (pos))
556
+ if (isObjectOrAncestor (widget, this ))
535
557
{
536
558
return Super::eventFilter (watched, event);
537
559
}
@@ -540,16 +562,18 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
540
562
// because the side tab click handler will call collapseView(). If we
541
563
// do not ignore this here, then we will collapse the container and the side tab
542
564
// 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 ()))
546
566
{
547
567
return Super::eventFilter (watched, event);
548
568
}
549
569
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
553
577
collapseView (true );
554
578
}
555
579
else if (event->type () == internal::FloatingWidgetDragStartEvent)
@@ -608,6 +632,10 @@ bool CAutoHideDockContainer::event(QEvent* event)
608
632
d->forwardEventToDockContainer (event);
609
633
break ;
610
634
635
+ case QEvent::MouseButtonPress:
636
+ return true ;
637
+ break ;
638
+
611
639
default :
612
640
break ;
613
641
}
0 commit comments