Improved context menu of DockAreaWidget

This commit is contained in:
Uwe Kindler 2022-11-02 13:06:42 +01:00
parent b5a179555a
commit d2c08aca70
4 changed files with 37 additions and 11 deletions

View File

@ -665,21 +665,27 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
}
bool IsAutoHide = d->DockArea->isAutoHide();
bool IsTopLevelArea = d->DockArea->isTopLevelArea();
QAction* Action;
QMenu Menu(this);
auto 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(onAutoHideDockAreaClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable));
}
Menu.addSeparator();
if (!IsTopLevelArea)
{
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(onAutoHideDockAreaClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable));
}
Menu.addSeparator();
}
Action = Menu.addAction(IsAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
if (!IsAutoHide)
{
Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas()));
Action = Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas()));
Action->setEnabled(!IsTopLevelArea);
}
Menu.exec(ev->globalPos());
}

View File

@ -1405,6 +1405,19 @@ void CDockAreaWidget::onDockWidgetFeaturesChanged()
}
//============================================================================
bool CDockAreaWidget::isTopLevelArea() const
{
auto Container = dockContainer();
if (!Container)
{
return false;
}
return (Container->topLevelDockArea() == this);
}
#ifdef Q_OS_WIN
//============================================================================
bool CDockAreaWidget::event(QEvent *e)

View File

@ -376,6 +376,12 @@ public:
*/
bool containsCentralWidget() const;
/**
* If this dock area is the one and only visible area in a container, then
* this function returns true
*/
bool isTopLevelArea() const;
public Q_SLOTS:
/**

View File

@ -163,7 +163,8 @@ protected:
CDockWidget* topLevelDockWidget() const;
/**
* Returns the top level dock area.
* If the container has only one single visible dock area, then this
* functions returns this top level dock area
*/
CDockAreaWidget* topLevelDockArea() const;