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