Added context menu actions for titleBar and dock widget tab auto hide

This commit is contained in:
Uwe Kindler 2022-11-02 12:45:45 +01:00
parent 9c14c62637
commit b5a179555a
6 changed files with 57 additions and 22 deletions

View File

@ -27,7 +27,6 @@
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include <AutoHideDockContainer.h>
#include "DockAreaTitleBar.h" #include "DockAreaTitleBar.h"
#include <QPushButton> #include <QPushButton>
@ -53,6 +52,7 @@
#include "DockComponentsFactory.h" #include "DockComponentsFactory.h"
#include "DockFocusController.h" #include "DockFocusController.h"
#include "ElidingLabel.h" #include "ElidingLabel.h"
#include "AutoHideDockContainer.h"
#include <iostream> #include <iostream>
@ -137,7 +137,6 @@ struct DockAreaTitleBarPrivate
return this->DragState == dragState; return this->DragState == dragState;
} }
/** /**
* Starts floating * Starts floating
*/ */
@ -493,7 +492,21 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
//============================================================================ //============================================================================
void CDockAreaTitleBar::onAutoHideButtonClicked() void CDockAreaTitleBar::onAutoHideButtonClicked()
{ {
d->DockArea->setAutoHide(!d->DockArea->isAutoHide()); if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea))
{
d->DockArea->toggleAutoHide();
}
else
{
d->DockArea->currentDockWidget()->toggleAutoHide();
}
}
//============================================================================
void CDockAreaTitleBar::onAutoHideDockAreaClicked()
{
d->DockArea->toggleAutoHide();
} }
@ -538,7 +551,6 @@ void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev)
if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting))
{ {
//d->TabBar->currentTab()->setFocus(Qt::OtherFocusReason);
d->dockManager()->dockFocusController()->setDockWidgetTabFocused(d->TabBar->currentTab()); d->dockManager()->dockFocusController()->setDockWidgetTabFocused(d->TabBar->currentTab());
} }
return; return;
@ -652,13 +664,23 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
return; return;
} }
bool IsAutoHide = d->DockArea->isAutoHide();
QMenu Menu(this); QMenu Menu(this);
auto Action = Menu.addAction(tr("Detach Group"), this, SLOT(onUndockButtonClicked())); auto Action = Menu.addAction(IsAutoHide ? tr("Detach") : tr("Detach Group"),
this, SLOT(onUndockButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)); 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(onAutoHideDockAreaClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable));
}
Menu.addSeparator(); Menu.addSeparator();
Action = Menu.addAction(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)); Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas())); if (!IsAutoHide)
{
Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas()));
}
Menu.exec(ev->globalPos()); Menu.exec(ev->globalPos());
} }

View File

@ -62,6 +62,7 @@ private Q_SLOTS:
void onTabsMenuActionTriggered(QAction* Action); void onTabsMenuActionTriggered(QAction* Action);
void onCurrentTabChanged(int Index); void onCurrentTabChanged(int Index);
void onAutoHideButtonClicked(); void onAutoHideButtonClicked();
void onAutoHideDockAreaClicked();
protected: protected:
/** /**

View File

@ -1304,23 +1304,20 @@ void CDockAreaWidget::setAutoHide(bool Enable)
return; return;
} }
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea) auto area = calculateSideTabBarArea();
&& features().testFlag(CDockWidget::DockWidgetPinnable)) for (const auto DockWidget : openedDockWidgets())
{ {
auto area = calculateSideTabBarArea(); if (Enable == isAutoHide())
for (const auto DockWidget : openedDockWidgets())
{ {
if (Enable == isAutoHide()) continue;
{
continue;
}
dockContainer()->createAndSetupAutoHideContainer(area, DockWidget);
} }
}
else if (!DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable))
{ {
currentDockWidget()->setAutoHide(true); continue;
}
dockContainer()->createAndSetupAutoHideContainer(area, DockWidget);
} }
} }

View File

@ -391,7 +391,9 @@ public Q_SLOTS:
void closeArea(); void closeArea();
/** /**
* Sets the dock area into auto hide mode or into normal mode * Sets the dock area into auto hide mode or into normal mode.
* If the dock area is switched to auto hide mode, then all dock widgets
* that are pinable will be added to the sidebar
*/ */
void setAutoHide(bool Enable); void setAutoHide(bool Enable);

View File

@ -515,6 +515,11 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget())); auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget()));
Action->setEnabled(isDetachable); Action->setEnabled(isDetachable);
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled))
{
Action = Menu.addAction(tr("Auto Hide"), this, SLOT(autoHideDockWidget()));
Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable));
}
Menu.addSeparator(); Menu.addSeparator();
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested())); Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
Action->setEnabled(isClosable()); Action->setEnabled(isClosable());
@ -700,6 +705,13 @@ void CDockWidgetTab::detachDockWidget()
} }
//===========================================================================
void CDockWidgetTab::autoHideDockWidget()
{
d->DockWidget->setAutoHide(true);
}
//============================================================================ //============================================================================
bool CDockWidgetTab::event(QEvent *e) bool CDockWidgetTab::event(QEvent *e)
{ {

View File

@ -63,6 +63,7 @@ private:
private Q_SLOTS: private Q_SLOTS:
void detachDockWidget(); void detachDockWidget();
void autoHideDockWidget();
protected: protected:
virtual void mousePressEvent(QMouseEvent* ev) override; virtual void mousePressEvent(QMouseEvent* ev) override;