1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-04-19 03:44:45 +08:00

Fixed hiding of AutoHideContainer when clicking outside context menu

This commit is contained in:
Uwe Kindler 2022-11-22 09:01:16 +01:00
parent 5a185268c4
commit aee68c167a
5 changed files with 28 additions and 4 deletions

View File

@ -697,7 +697,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// uncomment the following line if you want to use opaque undocking and // uncomment the following line if you want to use opaque undocking and
// opaque splitter resizing // opaque splitter resizing
//CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig); CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
// uncomment the following line if you want a fixed tab width that does // uncomment the following line if you want a fixed tab width that does
// not change if the visibility of the close button changes // not change if the visibility of the close button changes

View File

@ -486,6 +486,18 @@ void CAutoHideDockContainer::setSize(int Size)
updateSize(); updateSize();
} }
bool is_ancestor_of (const QObject *descendant, const QObject *ancestor)
{
if (!ancestor)
return false;
while (descendant) {
if (descendant == ancestor)
return true;
descendant = descendant->parent();
}
return false;
}
//============================================================================ //============================================================================
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event) bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
@ -503,17 +515,21 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
{ {
// If the user clicked into another window, then we collapse the // If the user clicked into another window, then we collapse the
// auto hide widget // auto hide widget
/*qDebug() << 1;
qDebug() << "is_ancestor_of " << is_ancestor_of(watched, this);
auto widget = qobject_cast<QWidget*>(watched); auto widget = qobject_cast<QWidget*>(watched);
qDebug() << "isAnchestorOf" << isAncestorOf(widget);
if (widget && widget->window() != this->window()) if (widget && widget->window() != this->window())
{ {
collapseView(true); collapseView(true);
return Super::eventFilter(watched, event); return Super::eventFilter(watched, event);
} }*/
// We check, if the mouse button press is inside the container // We check, if the mouse button press is inside the container
// widget. If it is not, i.e. if someone resizes the main window or // widget. If it is not, i.e. if someone resizes the main window or
// clicks into the application menu or toolbar, then we ignore the // clicks into the application menu or toolbar, then we ignore the
// event // event
qDebug() << 2;
auto Container = dockContainer(); auto Container = dockContainer();
QMouseEvent* me = static_cast<QMouseEvent*>(event); QMouseEvent* me = static_cast<QMouseEvent*>(event);
auto GlobalPos = internal::globalPositionOf(me); auto GlobalPos = internal::globalPositionOf(me);
@ -527,6 +543,7 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
// 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 also
// 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
qDebug() << 3;
pos = mapFromGlobal(GlobalPos); pos = mapFromGlobal(GlobalPos);
if (rect().contains(pos)) if (rect().contains(pos))
{ {
@ -537,6 +554,7 @@ 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
qDebug() << 4;
auto SideTab = d->SideTab; auto SideTab = d->SideTab;
pos = SideTab->mapFromGlobal(GlobalPos); pos = SideTab->mapFromGlobal(GlobalPos);
if (SideTab->rect().contains(pos)) if (SideTab->rect().contains(pos))
@ -547,9 +565,11 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
// If the mouse button down event is in the dock manager but outside // If the mouse button down event is in the dock manager but outside
// of the open auto hide container, then the auto hide dock widget // of the open auto hide container, then the auto hide dock widget
// should get collapsed // should get collapsed
qDebug() << 5;
collapseView(true); collapseView(true);
} }
else if (event->type() == internal::FloatingWidgetDragStartEvent) else if (event->type() == internal::FloatingWidgetDragStartEvent
|| event->type() == internal::DockedWidgetDragStartEvent)
{ {
collapseView(true); collapseView(true);
} }

View File

@ -333,9 +333,11 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
if (DraggingFloatingWidget == DraggingState) if (DraggingFloatingWidget == DraggingState)
{ {
FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingFloatingWidget, _this); FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingFloatingWidget, _this);
auto Overlay = DockWidget->dockManager()->containerOverlay(); auto DockManager = DockWidget->dockManager();
auto Overlay = DockManager->containerOverlay();
Overlay->setAllowedAreas(OuterDockAreas); Overlay->setAllowedAreas(OuterDockAreas);
this->FloatingWidget = FloatingWidget; this->FloatingWidget = FloatingWidget;
qApp->postEvent(DockManager, new QEvent((QEvent::Type)internal::DockedWidgetDragStartEvent));
} }
else else
{ {

View File

@ -51,6 +51,7 @@ namespace ads
namespace internal namespace internal
{ {
const int FloatingWidgetDragStartEvent = QEvent::registerEventType(); const int FloatingWidgetDragStartEvent = QEvent::registerEventType();
const int DockedWidgetDragStartEvent = QEvent::registerEventType();
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
static QString _window_manager; static QString _window_manager;
static QHash<QString, xcb_atom_t> _xcb_atom_cache; static QHash<QString, xcb_atom_t> _xcb_atom_cache;

View File

@ -152,6 +152,7 @@ static const bool Restore = false;
static const char* const ClosedProperty = "close"; static const char* const ClosedProperty = "close";
static const char* const DirtyProperty = "dirty"; static const char* const DirtyProperty = "dirty";
extern const int FloatingWidgetDragStartEvent; extern const int FloatingWidgetDragStartEvent;
extern const int DockedWidgetDragStartEvent;
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
// Utils to directly communicate with the X server // Utils to directly communicate with the X server