From 14d8b65c25b74527da1313111543f83b09d41880 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 14 Jan 2020 13:38:43 +0200 Subject: Add close action to subwindow list Adding a menu to an action is incompatible with triggerring that action. This means a "Toggle to" action is required as well to preserve the functionality. --- src/mainwindow/menubar.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index 76e08c6..7fdad24 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -508,12 +508,7 @@ QAction *MenuBar::insertPlugin(QMenu *menu) void MenuBar::insertSubWindow(SubWindow *subwindow) { - auto *action = window->addAction(subwindow->windowTitle(), subwindow, [subwindow]() { - if(!subwindow->windowState().testFlag(Qt::WindowMaximized)) - subwindow->showMaximized(); - else - subwindow->showNormal(); - }); + auto *action = window->addAction(subwindow->windowTitle()); action->setCheckable(true); connect(subwindow, &SubWindow::windowStateChanged, action, [action](Qt::WindowStates, Qt::WindowStates state) { @@ -522,4 +517,16 @@ void MenuBar::insertSubWindow(SubWindow *subwindow) connect(subwindow, &SubWindow::windowTitleChanged, action, &QAction::setText); connect(subwindow, &SubWindow::destroyed, action, &QAction::deleteLater); + + auto *optionsMenu = new QMenu; + optionsMenu->addAction(tr("Switch to"), subwindow, [subwindow]() { + if(!subwindow->windowState().testFlag(Qt::WindowMaximized)) + subwindow->showMaximized(); + else + subwindow->showNormal(); + }); + optionsMenu->addAction(tr("Close"), subwindow, [subwindow]() { + subwindow->close(); + }); + action->setMenu(optionsMenu); } -- cgit v1.2.1