From 97026b4da03dbb9dda460c6046aaa09a23a927bf Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 3 Jun 2019 18:30:23 -0400 Subject: added menubar toggle in the context menu removed two unused actions: actionToolbar_Size and actionToolbar_style added ways to make the menu reappear if you hide everything: - show the toolbar popup when right-clicking around the border of the main window - intercept the Alt key and make the main menu visible --- src/mainwindow.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 01bb4fc1..1098b529 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -653,6 +653,7 @@ void MainWindow::toolbarMenu_aboutToShow() // to avoid deleting the menu, the attribute is removed here ui->menuToolbars->setAttribute(Qt::WA_DeleteOnClose, false); + ui->actionMainMenuToggle->setChecked(ui->menuBar->isVisible()); ui->actionToolBarMainToggle->setChecked(ui->toolBar->isVisible()); ui->actionToolBarLinksToggle->setChecked(ui->linksToolBar->isVisible()); @@ -670,6 +671,11 @@ QMenu* MainWindow::createPopupMenu() return ui->menuToolbars; } +void MainWindow::on_actionMainMenuToggle_triggered() +{ + ui->menuBar->setVisible(!ui->menuBar->isVisible()); +} + void MainWindow::on_actionToolBarMainToggle_triggered() { ui->toolBar->setVisible(!ui->toolBar->isVisible()); @@ -724,6 +730,23 @@ void MainWindow::setToolbarButtonStyle(Qt::ToolButtonStyle s) } } +void MainWindow::on_centralWidget_customContextMenuRequested(const QPoint &pos) +{ + // the custom context menu event bubbles up to here if widgets don't actually + // process this, which would show the menu when right-clicking button, labels, + // etc. + // + // only show the context menu when right-clicking on the central widget + // itself, which is basically just the outer edges of the main window + auto* w = childAt(pos); + if (w != ui->centralWidget) { + return; + } + + auto* m = createPopupMenu(); + m->exec(ui->centralWidget->mapToGlobal(pos)); +} + void MainWindow::scheduleUpdateButton() { if (!m_UpdateProblemsTimer.isActive()) { @@ -1928,6 +1951,10 @@ void MainWindow::readSettings() settings.value("toolbar_button_style").toInt())); } + if (settings.contains("menubar_visible")) { + ui->menuBar->setVisible(settings.value("menubar_visible").toBool()); + } + if (settings.contains("window_split")) { ui->splitter->restoreState(settings.value("window_split").toByteArray()); } @@ -2007,6 +2034,7 @@ void MainWindow::storeSettings(QSettings &settings) { settings.remove("window_state"); settings.remove("toolbar_size"); settings.remove("toolbar_button_style"); + settings.remove("menubar_visible"); settings.remove("window_split"); settings.remove("window_monitor"); settings.remove("log_split"); @@ -2019,6 +2047,7 @@ void MainWindow::storeSettings(QSettings &settings) { settings.setValue("window_state", saveState()); settings.setValue("toolbar_size", ui->toolBar->iconSize()); settings.setValue("toolbar_button_style", static_cast(ui->toolBar->toolButtonStyle())); + settings.setValue("menubar_visible", ui->menuBar->isVisible()); settings.setValue("window_split", ui->splitter->saveState()); settings.setValue("window_monitor", QApplication::desktop()->screenNumber(this)); settings.setValue("log_split", ui->topLevelSplitter->saveState()); @@ -6815,6 +6844,17 @@ void MainWindow::dropEvent(QDropEvent *event) event->accept(); } +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + // if the menubar is hidden, pressing Alt will make it visible + if (event->key() == Qt::Key_Alt) { + if (!ui->menuBar->isVisible()) { + ui->menuBar->setVisible(true); + } + } + + QMainWindow::keyPressEvent(event); +} void MainWindow::on_clickBlankButton_clicked() { -- cgit v1.3.1 From 254304217d6cb00cbedf13f8c493dc6c80e11e24 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 3 Jun 2019 19:00:44 -0400 Subject: renamed some of the menus to remove underscores added Run menu with shortcuts, only visible when there are shortcuts to show fixed menubar visibility not being remembered --- src/mainwindow.cpp | 30 +++++++++++++++++++----------- src/mainwindow.h | 6 +++++- src/mainwindow.ui | 22 ++++++++++++++-------- 3 files changed, 38 insertions(+), 20 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1098b529..62971f00 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -201,6 +201,7 @@ MainWindow::MainWindow(QSettings &initSettings : QMainWindow(parent) , ui(new Ui::MainWindow) , m_WasVisible(false) + , m_menuBarVisible(true) , m_Tutorial(this, "MainWindow") , m_OldProfileIndex(-1) , m_ModListGroupingProxy(nullptr) @@ -321,7 +322,7 @@ MainWindow::MainWindow(QSettings &initSettings resizeLists(modListAdjusted, pluginListAdjusted); QMenu *linkMenu = new QMenu(this); - linkMenu->addAction(QIcon(":/MO/gui/link"), tr("Toolbar"), this, SLOT(linkToolbar())); + linkMenu->addAction(QIcon(":/MO/gui/link"), tr("Toolbar and Menu"), this, SLOT(linkToolbar())); linkMenu->addAction(QIcon(":/MO/gui/link"), tr("Desktop"), this, SLOT(linkDesktop())); linkMenu->addAction(QIcon(":/MO/gui/link"), tr("Start Menu"), this, SLOT(linkMenu())); ui->linkButton->setMenu(linkMenu); @@ -470,7 +471,7 @@ MainWindow::MainWindow(QSettings &initSettings } refreshExecutablesList(); - updateToolBar(); + updatePinnedExecutables(); for (QAction *action : ui->toolBar->actions()) { // set the name of the widget to the name of the action to allow styling @@ -609,13 +610,15 @@ void MainWindow::setupActionMenu(QAction* a) tb->setPopupMode(QToolButton::InstantPopup); } -void MainWindow::updateToolBar() +void MainWindow::updatePinnedExecutables() { for (auto* a : ui->linksToolBar->actions()) { ui->linksToolBar->removeAction(a); a->deleteLater(); } + ui->menuRun->clear(); + bool hasLinks = false; std::vector::iterator begin, end; @@ -625,21 +628,23 @@ void MainWindow::updateToolBar() if (iter->isShownOnToolbar()) { hasLinks = true; - QAction *exeAction = new QAction(iconForExecutable(iter->m_BinaryInfo.filePath()), - iter->m_Title, - ui->toolBar); + QAction *exeAction = new QAction( + iconForExecutable(iter->m_BinaryInfo.filePath()), iter->m_Title); exeAction->setObjectName(QString("custom__") + iter->m_Title); + if (!connect(exeAction, SIGNAL(triggered()), this, SLOT(startExeAction()))) { qDebug("failed to connect trigger?"); } ui->linksToolBar->addAction(exeAction); + ui->menuRun->addAction(exeAction); } } - // don't show the toolbar if there are no links + // don't show the toolbar or menu if there are no links ui->linksToolBar->setVisible(hasLinks); + ui->menuRun->menuAction()->setVisible(hasLinks); } void MainWindow::toolbarMenu_aboutToShow() @@ -674,6 +679,7 @@ QMenu* MainWindow::createPopupMenu() void MainWindow::on_actionMainMenuToggle_triggered() { ui->menuBar->setVisible(!ui->menuBar->isVisible()); + m_menuBarVisible = ui->menuBar->isVisible(); } void MainWindow::on_actionToolBarMainToggle_triggered() @@ -1952,7 +1958,8 @@ void MainWindow::readSettings() } if (settings.contains("menubar_visible")) { - ui->menuBar->setVisible(settings.value("menubar_visible").toBool()); + m_menuBarVisible = settings.value("menubar_visible").toBool(); + ui->menuBar->setVisible(m_menuBarVisible); } if (settings.contains("window_split")) { @@ -2047,7 +2054,7 @@ void MainWindow::storeSettings(QSettings &settings) { settings.setValue("window_state", saveState()); settings.setValue("toolbar_size", ui->toolBar->iconSize()); settings.setValue("toolbar_button_style", static_cast(ui->toolBar->toolButtonStyle())); - settings.setValue("menubar_visible", ui->menuBar->isVisible()); + settings.setValue("menubar_visible", m_menuBarVisible); settings.setValue("window_split", ui->splitter->saveState()); settings.setValue("window_monitor", QApplication::desktop()->screenNumber(this)); settings.setValue("log_split", ui->topLevelSplitter->saveState()); @@ -5001,7 +5008,7 @@ void MainWindow::linkToolbar() Executable &exe(getSelectedExecutable()); exe.showOnToolbar(!exe.isShownOnToolbar()); ui->linkButton->menu()->actions().at(static_cast(ShortcutType::Toolbar))->setIcon(exe.isShownOnToolbar() ? QIcon(":/MO/gui/remove") : QIcon(":/MO/gui/link")); - updateToolBar(); + updatePinnedExecutables(); } namespace { @@ -6189,7 +6196,7 @@ void MainWindow::removeFromToolbar() qDebug("executable doesn't exist any more"); } - updateToolBar(); + updatePinnedExecutables(); } @@ -6850,6 +6857,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) if (event->key() == Qt::Key_Alt) { if (!ui->menuBar->isVisible()) { ui->menuBar->setVisible(true); + m_menuBarVisible = true; } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 09aeb044..4847d65c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -211,7 +211,7 @@ private: void createHelpMenu(); void createEndorseMenu(); - void updateToolBar(); + void updatePinnedExecutables(); void setToolbarSize(const QSize& s); void setToolbarButtonStyle(Qt::ToolButtonStyle s); void toolbarMenu_aboutToShow(); @@ -324,6 +324,10 @@ private: bool m_WasVisible; + // this has to be remembered because by the time storeSettings() is called, + // the window is closed and the menubar is hidden + bool m_menuBarVisible; + MOBase::TutorialControl m_Tutorial; int m_OldProfileIndex; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index e25111e1..e093fd3f 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1392,7 +1392,7 @@ p, li { white-space: pre-wrap; } 21 - + &File @@ -1402,7 +1402,7 @@ p, li { white-space: pre-wrap; } - + &Tools @@ -1413,7 +1413,7 @@ p, li { white-space: pre-wrap; } - + &Help @@ -1421,7 +1421,7 @@ p, li { white-space: pre-wrap; } - + &Edit @@ -1450,11 +1450,17 @@ p, li { white-space: pre-wrap; } - - + + + &Run + + + + - - + + + -- cgit v1.3.1 From ea3f8826f13832e97fde8ae0c50c3533221df34e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 3 Jun 2019 19:09:10 -0400 Subject: more comments --- src/mainwindow.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 62971f00..f8c09b20 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -738,6 +738,10 @@ void MainWindow::setToolbarButtonStyle(Qt::ToolButtonStyle s) void MainWindow::on_centralWidget_customContextMenuRequested(const QPoint &pos) { + // this allows for getting the context menu even if both the menubar and all + // the toolbars are hidden; an alternative is the Alt key handled in + // keyPressEvent() below + // the custom context menu event bubbles up to here if widgets don't actually // process this, which would show the menu when right-clicking button, labels, // etc. -- cgit v1.3.1 From f9906825e7822771f2f3741b1c696e71bf1c76ce Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 3 Jun 2019 19:26:03 -0400 Subject: fixed exit menu item not working --- src/mainwindow.cpp | 8 +++++--- src/mainwindow.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f8c09b20..8eae1914 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1069,12 +1069,12 @@ void MainWindow::showEvent(QShowEvent *event) void MainWindow::closeEvent(QCloseEvent* event) { - if (!exit()) { + if (!confirmExit()) { event->ignore(); } } -bool MainWindow::exit() +bool MainWindow::confirmExit() { m_closing = true; @@ -5518,7 +5518,9 @@ void MainWindow::on_actionUpdate_triggered() void MainWindow::on_actionExit_triggered() { - exit(); + if (confirmExit()) { + qApp->exit(); + } } void MainWindow::actionEndorseMO() diff --git a/src/mainwindow.h b/src/mainwindow.h index 4847d65c..81b6a656 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -153,7 +153,7 @@ public: void displayModInformation(ModInfo::Ptr modInfo, unsigned int index, int tab); - bool exit(); + bool confirmExit(); virtual bool closeWindow(); virtual void setWindowEnabled(bool enabled); -- cgit v1.3.1