mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-19 03:44:45 +08:00
Fixed some issues in AutoHideDockContainer eventFilter function
This commit is contained in:
parent
a2a328e3c7
commit
47e4a6065a
@ -486,19 +486,48 @@ void CAutoHideDockContainer::setSize(int Size)
|
|||||||
updateSize();
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_ancestor_of (const QObject *descendant, const QObject *ancestor)
|
|
||||||
|
//============================================================================
|
||||||
|
/**
|
||||||
|
* Returns true if the object given in ancestor is an ancestor of the object
|
||||||
|
* given in descendant
|
||||||
|
*/
|
||||||
|
static bool objectIsAncestorOf(const QObject* descendant, const QObject* ancestor)
|
||||||
{
|
{
|
||||||
if (!ancestor)
|
if (!ancestor)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
while (descendant) {
|
}
|
||||||
|
while (descendant)
|
||||||
|
{
|
||||||
if (descendant == ancestor)
|
if (descendant == ancestor)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
descendant = descendant->parent();
|
descendant = descendant->parent();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
/**
|
||||||
|
* Returns true if the object given in ancestor is the object given in descendant
|
||||||
|
* or if it is an ancestor of the object given in descendant
|
||||||
|
*/
|
||||||
|
static bool isObjectOrAncestor(const QObject *descendant, const QObject *ancestor)
|
||||||
|
{
|
||||||
|
if (ancestor && (descendant == ancestor))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return objectIsAncestorOf(descendant, ancestor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
||||||
{
|
{
|
||||||
@ -513,25 +542,18 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
|||||||
}
|
}
|
||||||
else if (event->type() == QEvent::MouseButtonPress)
|
else if (event->type() == QEvent::MouseButtonPress)
|
||||||
{
|
{
|
||||||
// We check, if the mouse button press is inside the container
|
auto widget = qobject_cast<QWidget*>(watched);
|
||||||
// widget. If it is not, i.e. if someone resizes the main window or
|
// Ignore non widget events
|
||||||
// clicks into the application menu or toolbar, then we ignore the
|
if (!widget)
|
||||||
// event
|
|
||||||
auto Container = dockContainer();
|
|
||||||
QMouseEvent* me = static_cast<QMouseEvent*>(event);
|
|
||||||
auto GlobalPos = internal::globalPositionOf(me);
|
|
||||||
auto pos = Container->mapFromGlobal(GlobalPos);
|
|
||||||
if (!Container->rect().contains(pos))
|
|
||||||
{
|
{
|
||||||
return Super::eventFilter(watched, event);
|
return Super::eventFilter(watched, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we check, if the user clicked inside of this auto hide container.
|
// Now we check, if the user clicked inside of this auto hide container.
|
||||||
// If the click is inside of this auto hide container, then we can also
|
// If the click is inside of this auto hide container, then we can
|
||||||
// ignore the event, because the auto hide overlay should not get collapsed if
|
// ignore the event, because the auto hide overlay should not get collapsed if
|
||||||
// user works in it
|
// user works in it
|
||||||
pos = mapFromGlobal(GlobalPos);
|
if (isObjectOrAncestor(widget, this))
|
||||||
if (rect().contains(pos))
|
|
||||||
{
|
{
|
||||||
return Super::eventFilter(watched, event);
|
return Super::eventFilter(watched, event);
|
||||||
}
|
}
|
||||||
@ -540,16 +562,18 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
|||||||
// because the side tab click handler will call collapseView(). If we
|
// because the side tab click handler will call collapseView(). If we
|
||||||
// do not ignore this here, then we will collapse the container and the side tab
|
// do not ignore this here, then we will collapse the container and the side tab
|
||||||
// click handler will uncollapse it
|
// click handler will uncollapse it
|
||||||
auto SideTab = d->SideTab;
|
if (isObjectOrAncestor(widget, d->SideTab.data()))
|
||||||
pos = SideTab->mapFromGlobal(GlobalPos);
|
|
||||||
if (SideTab->rect().contains(pos))
|
|
||||||
{
|
{
|
||||||
return Super::eventFilter(watched, event);
|
return Super::eventFilter(watched, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the mouse button down event is in the dock manager but outside
|
// Ignore the mouse click if it is not inside of this container
|
||||||
// of the open auto hide container, then the auto hide dock widget
|
if (!isObjectOrAncestor(widget, dockContainer()))
|
||||||
// should get collapsed
|
{
|
||||||
|
return Super::eventFilter(watched, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// user clicked into container - collapse the auto hide widget
|
||||||
collapseView(true);
|
collapseView(true);
|
||||||
}
|
}
|
||||||
else if (event->type() == internal::FloatingWidgetDragStartEvent)
|
else if (event->type() == internal::FloatingWidgetDragStartEvent)
|
||||||
@ -608,6 +632,10 @@ bool CAutoHideDockContainer::event(QEvent* event)
|
|||||||
d->forwardEventToDockContainer(event);
|
d->forwardEventToDockContainer(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case QEvent::MouseButtonPress:
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user