Skip to content

Commit

Permalink
Added minimize and close action to Auto Hide context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
githubuser0xFFFF committed Oct 19, 2023
1 parent 9ec97a8 commit 0f8096e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions demo/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ void MainWindowPrivate::createContent()

// Tests CustomCloseHandling without DeleteOnClose
LabelDockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true);
LabelDockWidget->setWindowTitle(LabelDockWidget->windowTitle() + " [Custom Close]");
QObject::connect(LabelDockWidget, &ads::CDockWidget::closeRequested, [LabelDockWidget, this]()
{
int Result = QMessageBox::question(_this, "Custom Close Request",
Expand Down
33 changes: 31 additions & 2 deletions src/DockAreaTitleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,24 @@ void CDockAreaTitleBar::onCloseButtonClicked()
}


//============================================================================
void CDockAreaTitleBar::onAutoHideCloseActionTriggered()
{
d->DockArea->closeArea();
}


//============================================================================
void CDockAreaTitleBar::onAutoHideMinimizeActionTriggered()
{
auto AutoHideContainer = d->DockArea->autoHideDockContainer();
if (AutoHideContainer)
{
AutoHideContainer->collapseView(true);
}
}


//============================================================================
void CDockAreaTitleBar::onUndockButtonClicked()
{
Expand Down Expand Up @@ -735,7 +753,17 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
}
Menu.addSeparator();
}
Action = Menu.addAction(isAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked()));

if (isAutoHide)
{
Action = Menu.addAction(tr("Minimize"), this, SLOT(onAutoHideMinimizeActionTriggered()));
Action = Menu.addAction(tr("Close"), this, SLOT(onAutoHideCloseActionTriggered()));
}
else
{
Action = Menu.addAction(isAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked()));
}

Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
if (!isAutoHide && !isTopLevelArea)
{
Expand Down Expand Up @@ -782,7 +810,8 @@ QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const
case TitleBarButtonClose:
if (d->DockArea->isAutoHide())
{
return tr("Close");
bool Minimize = CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideCloseButtonCollapsesDock);
return Minimize ? tr("Minimize") : tr("Close");
}

if (CDockManager::testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
Expand Down
2 changes: 2 additions & 0 deletions src/DockAreaTitleBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class ADS_EXPORT CDockAreaTitleBar : public QFrame
private Q_SLOTS:
void onTabsMenuAboutToShow();
void onCloseButtonClicked();
void onAutoHideCloseActionTriggered();
void onAutoHideMinimizeActionTriggered();
void onUndockButtonClicked();
void onTabsMenuActionTriggered(QAction* Action);
void onCurrentTabChanged(int Index);
Expand Down

0 comments on commit 0f8096e

Please sign in to comment.