From 5a9f23a9adbe3233fa9c2aaf68cc054790b880b9 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 7 Nov 2022 16:28:27 +0100 Subject: [PATCH] Fixed emission of top level event in DockContainerWidget --- demo/MainWindow.cpp | 1 - doc/user-guide.md | 111 +++++++++++++++++----------------- src/AutoHideDockContainer.cpp | 9 --- src/DockContainerWidget.cpp | 19 +++++- 4 files changed, 72 insertions(+), 68 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index b0cb8e4..07dea01 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -717,7 +717,6 @@ CMainWindow::CMainWindow(QWidget *parent) : // uncomment if you would like to enable dock widget auto hiding CDockManager::setAutoHideConfigFlags(CDockManager::DefaultAutoHideConfig); - CDockManager::setAutoHideConfigFlag(CDockManager::AutoHideShowOnMouseOver, true); // uncomment if you would like to enable an equal distribution of the // available size of a splitter to all contained dock widgets diff --git a/doc/user-guide.md b/doc/user-guide.md index e8d882f..45fd7f5 100644 --- a/doc/user-guide.md +++ b/doc/user-guide.md @@ -29,6 +29,10 @@ - [`FloatingContainerForceQWidgetTitleBar` (Linux only)](#floatingcontainerforceqwidgettitlebar-linux-only) - [`MiddleMouseButtonClosesTab`](#middlemousebuttonclosestab) - [Auto-Hide Configuration Flags](#auto-hide-configuration-flags) + - [Auto Hide Dock Widgets](#auto-hide-dock-widgets) + - [Pinning Auto-Hide Widgets to a certain border](#pinning-auto-hide-widgets-to-a-certain-border) + - [Show / Hide Auto-Hide Widgets via Mouse Over](#show--hide-auto-hide-widgets-via-mouse-over) + - [Adding Auto Hide Widgets](#adding-auto-hide-widgets) - [Setting Auto-Hide Flags](#setting-auto-hide-flags) - [`AutoHideFeatureEnabled`](#autohidefeatureenabled) - [`DockAreaHasAutoHideButton`](#dockareahasautohidebutton) @@ -49,10 +53,6 @@ - [Central Widget](#central-widget) - [Empty Dock Area](#empty-dock-area) - [Custom Close Handling](#custom-close-handling) -- [Auto Hide Dock Widgets](#auto-hide-dock-widgets) - - [Pinning Auto-Hide Widgets to a certain border](#pinning-auto-hide-widgets-to-a-certain-border) - - [Show / Hide Auto-Hide Widgets via Mouse Over](#show--hide-auto-hide-widgets-via-mouse-over) - - [Adding Auto Hide Widgets](#adding-auto-hide-widgets) - [Styling](#styling) - [Disabling the Internal Style Sheet](#disabling-the-internal-style-sheet) @@ -500,16 +500,60 @@ possible in various web browsers. ## Auto-Hide Configuration Flags -The Advanced Docking System has a number of global configuration options to -configure the Auto-Hide functionality. The "Auto Hide" feature allows to display -more information using less screen space by hiding or showing windows pinned to -one of the four dock container borders. +### Auto Hide Dock Widgets + +The Advanced Docking System supports "Auto-Hide" functionality for **all** +dock containers. The "Auto Hide" feature allows to display more information +using less screen space by hiding or showing windows pinned to one of the +four dock container borders. + +Enabling this feature adds a button with a pin icon to each dock area. + +![DockAreaHasAutoHideButton true](cfg_flag_DockAreaHasAutoHideButton.png) + +By clicking this button, the current dock widget (or the complete area - depending on the +configuration flags) will be pinned to a certain border. The border is choosen +depending on the location of the dock area. If you click the pin button while +holding down the **Ctrl** key, the whole dock area will be pinned to a certain +border. + +### Pinning Auto-Hide Widgets to a certain border + +If you would like to pin a dock widget or a dock area to a certain border, +then you can right-click into the dock widget tab or into the dock area title bar +to show the context menu. Then you can select the location via the **Pin to** menu: + +![Pin to](AutoHide_PinTo.png) + +### Show / Hide Auto-Hide Widgets via Mouse Over + +Normally Auto-Hide widgets are shown by clicking the Auto-Hide tab and hidden by +clicking the Auto-Hide tab again or by clicking into any other dock widget in +the same container. If the Auto-Hide config flag `AutoHideShowOnMouseOver` is set, +the Auto-Hide widget is shown, if the user hovers over the Auto-Hide tab and is +collapsed if the mouse cursor leaves the Auto-Hide widget. Showing and hiding +by mouse click still works if this feature is enabled. + +### Adding Auto Hide Widgets + +Adding an auto hide widget is similar to adding a dock widget, simply call +`dockManager->addAutoHideDockWidget()`. + +```c++ +CDockManager::setAutoHideConfigFlags(CDockManager::DefaultAutoHideConfig); +d->DockManager = new CDockManager(this); +CDockWidget* TableDockWidget = new CDockWidget("Table 1"); +DockManager->addAutoHideDockWidget(SideBarLeft, TableDockWidget); +``` + +See `autohide` example or the demo application to learn how it works. ### Setting Auto-Hide Flags -You should set the Auto-Hide flags before creating the dock manager -instance. That means, you should set the Auto-Hide flags after setting the -configuration flags. +The Advanced Docking System has a number of global configuration flags to +configure the Auto-Hide functionality. You should set the Auto-Hide flags before +creating the dock manager instance. That means, you should set the Auto-Hide +flags after setting the configuration flags. ```c++ CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); @@ -701,51 +745,6 @@ Normally clicking the close button of a dock widget will just hide the widget an When an entire area is closed, the default behavior is to hide the dock widgets it contains regardless of the `DockWidgetDeleteOnClose` flag except if there is only one dock widget. In this special case, the `DockWidgetDeleteOnClose` flag is followed. This behavior can be changed by setting the `DockWidgetForceCloseWithArea` flag to all the dock widgets that needs to be closed with their area. -## Auto Hide Dock Widgets - -The Advanced Docking System supports "Auto-Hide" functionality for **all** dock containers. The "Auto Hide" feature allows to display more information using less screen space by hiding or showing windows pinned to one of the four dock container borders. - -Enabling this feature adds a button with a pin icon to each dock area. - -![DockAreaHasAutoHideButton true](cfg_flag_DockAreaHasAutoHideButton.png) - -By clicking this button, the current dock widget (or the complete area - depending on the -configuration flags) will be pinned to a certain border. The border is choosen -depending on the location of the dock area. If you click the pin button while -holding down the **Ctrl** key, the whole dock area will be pinned to a certain -border. - -### Pinning Auto-Hide Widgets to a certain border - -If you would like to pin a dock widget or a dock area to a certain border, -then you can right-click into the dock widget tab or into the dock area title bar -to show the context menu. Then you can select the location via the **Pin to** menu: - -![Pin to](AutoHide_PinTo.png) - -### Show / Hide Auto-Hide Widgets via Mouse Over - -Normally Auto-Hide widgets are shown by clicking the Auto-Hide tab and hidden by -clicking the Auto-Hide tab again or by clicking into any other dock widget in -the same container. If the Auto-Hide config flag `AutoHideShowOnMouseOver` is set, -the Auto-Hide widget is shown, if the user hovers over the Auto-Hide tab and is -collapsed if the mouse cursor leaves the Auto-Hide widget. Showing and hiding -my mouse click still works if this feature is enabled. - -### Adding Auto Hide Widgets - -Adding an auto hide widget is similar to adding a dock widget, simply call -`dockManager->addAutoHideDockWidget()`. - -```c++ -CDockManager::setAutoHideConfigFlags(CDockManager::DefaultAutoHideConfig); -d->DockManager = new CDockManager(this); -CDockWidget* TableDockWidget = new CDockWidget("Table 1"); -DockManager->addAutoHideDockWidget(SideBarLeft, TableDockWidget); -``` - -See `autohide` example or the demo application to learn how it works. - ## Styling The Advanced Docking System supports styling via [Qt Style Sheets](https://doc.qt.io/qt-5/stylesheet.html). All components like splitters, tabs, buttons, titlebar and diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index b83d689..6a09fdb 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -380,16 +380,7 @@ void CAutoHideDockContainer::moveContentsToParent() // to the user and he does not have to search where the widget was inserted. d->DockWidget->setDockArea(nullptr); auto DockContainer = dockContainer(); - - // If the container contained only one visible dock widget, the we need - // to emit a top level event for this widget because it is not the one and - // only visible docked widget anymore - auto TopLevelDockWidget = DockContainer->topLevelDockWidget(); DockContainer->addDockWidget(d->getDockWidgetArea(d->SideTabBarArea), d->DockWidget); - if (TopLevelDockWidget) - { - CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidget, false); - } } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index bf09436..c8d5d69 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1360,6 +1360,7 @@ CDockContainerWidget::~CDockContainerWidget() CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) { + auto TopLevelDockWidget = topLevelDockWidget(); CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget(); if (OldDockArea) { @@ -1367,14 +1368,28 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW } Dockwidget->setDockManager(d->DockManager); + CDockAreaWidget* DockArea; if (DockAreaWidget) { - return d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget); + DockArea = d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget); } else { - return d->addDockWidgetToContainer(area, Dockwidget); + DockArea = d->addDockWidgetToContainer(area, Dockwidget); } + + if (TopLevelDockWidget) + { + auto NewTopLevelDockWidget = topLevelDockWidget(); + // If the container contained only one visible dock widget, the we need + // to emit a top level event for this widget because it is not the one and + // only visible docked widget anymore + if (!NewTopLevelDockWidget) + { + CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidget, false); + } + } + return DockArea; }