Added support for auto hiding a dock area / widget to a specific border via context menu

This commit is contained in:
Uwe Kindler 2022-11-03 16:44:40 +01:00
parent 04ea1c68a7
commit 409d4489cc
5 changed files with 42 additions and 39 deletions

View File

@ -655,6 +655,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// uncomment the following line to enable focus highlighting of the dock
// widget that has the focus
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
CDockManager::setConfigFlag(CDockManager::AlwaysShowTabs, true);
// uncomment if you would like to enable dock widget auto hiding
CDockManager::setAutoHideConfigFlags(CDockManager::DefaultAutoHideConfig);

View File

@ -150,9 +150,6 @@ public:
* Setter for spacing property - sets the spacing
*/
void setSpacing(int Spacing);
Q_SIGNALS:
void sideTabAutoHideToggleRequested();
};
} // namespace ads
//-----------------------------------------------------------------------------

View File

@ -689,22 +689,22 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
return;
}
bool IsAutoHide = d->DockArea->isAutoHide();
bool IsTopLevelArea = d->DockArea->isTopLevelArea();
const bool isAutoHide = d->DockArea->isAutoHide();
const bool isTopLevelArea = d->DockArea->isTopLevelArea();
QAction* Action;
QMenu Menu(this);
if (!IsTopLevelArea)
if (!isTopLevelArea)
{
Action = Menu.addAction(IsAutoHide ? tr("Detach") : tr("Detach Group"),
Action = Menu.addAction(isAutoHide ? tr("Detach") : tr("Detach Group"),
this, SLOT(onUndockButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled))
{
Action = Menu.addAction(IsAutoHide ? tr("Dock") : tr("Auto Hide Group"), this, SLOT(onAutoHideDockAreaActionClicked()));
Action = Menu.addAction(isAutoHide ? tr("Dock") : tr("Auto Hide Group"), this, SLOT(onAutoHideDockAreaActionClicked()));
auto AreaIsPinnable = d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable);
Action->setEnabled(AreaIsPinnable);
if (!IsAutoHide)
if (!isAutoHide)
{
auto menu = Menu.addMenu(tr("Auto Hide Group To..."));
menu->setEnabled(AreaIsPinnable);
@ -716,12 +716,11 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
}
Menu.addSeparator();
}
Action = Menu.addAction(IsAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked()));
Action = Menu.addAction(isAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
if (!IsAutoHide)
if (!isAutoHide && !isTopLevelArea)
{
Action = Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas()));
Action->setEnabled(!IsTopLevelArea);
}
Menu.exec(ev->globalPos());
}

View File

@ -537,7 +537,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
{
setCurrentDockWidget(NextOpenDockWidget);
}
else if (d->ContentsLayout->isEmpty() && DockContainer->dockAreaCount() >= 1) // Don't remove empty dock areas that are auto hidden, they'll be deleted by the auto hide dock
else if (d->ContentsLayout->isEmpty() && DockContainer->dockAreaCount() >= 1)
{
ADS_PRINT("Dock Area empty");
DockContainer->removeDockArea(this);
@ -827,22 +827,20 @@ void CDockAreaWidget::updateTitleBarVisibility()
return;
}
if (CDockManager::testConfigFlag(CDockManager::AlwaysShowTabs))
{
return;
}
if (!d->TitleBar)
{
return;
}
bool IsAutoHide = isAutoHide();
if (!CDockManager::testConfigFlag(CDockManager::AlwaysShowTabs))
{
bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating()
|| CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar));
Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1);
bool IsAutoHide = isAutoHide();
Hidden &= !IsAutoHide; // Titlebar must always be visible when auto hidden so it can be dragged
d->TitleBar->setVisible(!Hidden);
}
if (isAutoHideFeatureEnabled())
{

View File

@ -518,14 +518,17 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
}
d->saveDragStartMousePosition(ev->globalPos());
QMenu Menu(this);
const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable);
const bool isNotOnlyTabInContainer = !d->DockArea->dockContainer()->hasTopLevelDockWidget();
const bool isTopLevelArea = d->DockArea->isTopLevelArea();
const bool isDetachable = isFloatable && isNotOnlyTabInContainer;
QAction* Action;
QMenu Menu(this);
auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget()));
if (!isTopLevelArea)
{
Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget()));
Action->setEnabled(isDetachable);
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled))
{
@ -540,10 +543,15 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
}
}
Menu.addSeparator();
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
Action->setEnabled(isClosable());
Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested()));
if (d->DockArea->openDockWidgetsCount() > 1)
{
Action = Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested()));
}
Menu.exec(ev->globalPos());
}