summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAl <gabriel.cortesi@outlook.com>2019-06-04 23:49:13 +0200
committerGitHub <noreply@github.com>2019-06-04 23:49:13 +0200
commit2fb33d891f15a598b16d34960a51bff0be30bcdc (patch)
treec815298ad5999e655d0b0ec5b9259599be700a7b /src
parentc41cda79b85f6915a994c2a6cfb2cb89d950c1ef (diff)
parentf9906825e7822771f2f3741b1c696e71bf1c76ce (diff)
Merge pull request #750 from isanae/more-menu-toolbar
Menu bar can be hidden, also shows executable shortcuts
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp78
-rw-r--r--src/mainwindow.h12
-rw-r--r--src/mainwindow.ui46
3 files changed, 102 insertions, 34 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 1f5d5bdc..ebb5d7ab 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<Executable>::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()
@@ -653,6 +658,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 +676,12 @@ QMenu* MainWindow::createPopupMenu()
return ui->menuToolbars;
}
+void MainWindow::on_actionMainMenuToggle_triggered()
+{
+ ui->menuBar->setVisible(!ui->menuBar->isVisible());
+ m_menuBarVisible = ui->menuBar->isVisible();
+}
+
void MainWindow::on_actionToolBarMainToggle_triggered()
{
ui->toolBar->setVisible(!ui->toolBar->isVisible());
@@ -724,6 +736,27 @@ 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.
+ //
+ // 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()) {
@@ -1036,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;
@@ -1929,6 +1962,11 @@ void MainWindow::readSettings()
settings.value("toolbar_button_style").toInt()));
}
+ if (settings.contains("menubar_visible")) {
+ m_menuBarVisible = settings.value("menubar_visible").toBool();
+ ui->menuBar->setVisible(m_menuBarVisible);
+ }
+
if (settings.contains("window_split")) {
ui->splitter->restoreState(settings.value("window_split").toByteArray());
}
@@ -2008,6 +2046,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");
@@ -2020,6 +2059,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<int>(ui->toolBar->toolButtonStyle()));
+ 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());
@@ -4973,7 +5013,7 @@ void MainWindow::linkToolbar()
Executable &exe(getSelectedExecutable());
exe.showOnToolbar(!exe.isShownOnToolbar());
ui->linkButton->menu()->actions().at(static_cast<int>(ShortcutType::Toolbar))->setIcon(exe.isShownOnToolbar() ? QIcon(":/MO/gui/remove") : QIcon(":/MO/gui/link"));
- updateToolBar();
+ updatePinnedExecutables();
}
namespace {
@@ -5479,7 +5519,9 @@ void MainWindow::on_actionUpdate_triggered()
void MainWindow::on_actionExit_triggered()
{
- exit();
+ if (confirmExit()) {
+ qApp->exit();
+ }
}
void MainWindow::actionEndorseMO()
@@ -6161,7 +6203,7 @@ void MainWindow::removeFromToolbar()
qDebug("executable doesn't exist any more");
}
- updateToolBar();
+ updatePinnedExecutables();
}
@@ -6816,6 +6858,18 @@ 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);
+ m_menuBarVisible = true;
+ }
+ }
+
+ QMainWindow::keyPressEvent(event);
+}
void MainWindow::on_clickBlankButton_clicked()
{
diff --git a/src/mainwindow.h b/src/mainwindow.h
index a0cce858..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);
@@ -195,6 +195,7 @@ protected:
virtual void resizeEvent(QResizeEvent *event);
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);
+ void keyPressEvent(QKeyEvent *event) override;
private slots:
void on_actionChange_Game_triggered();
@@ -210,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();
@@ -323,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;
@@ -633,6 +638,7 @@ private slots: // ui slots
void on_actionSettings_triggered();
void on_actionUpdate_triggered();
void on_actionExit_triggered();
+ void on_actionMainMenuToggle_triggered();
void on_actionToolBarMainToggle_triggered();
void on_actionToolBarLinksToggle_triggered();
void on_actionToolBarSmallIcons_triggered();
@@ -642,7 +648,7 @@ private slots: // ui slots
void on_actionToolBarTextOnly_triggered();
void on_actionToolBarIconsAndText_triggered();
-
+ void on_centralWidget_customContextMenuRequested(const QPoint &pos);
void on_bsaList_customContextMenuRequested(const QPoint &pos);
void on_clearFiltersButton_clicked();
void on_btnRefreshData_clicked();
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 9656cbf2..e093fd3f 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -30,6 +30,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="contextMenuPolicy">
+ <enum>Qt::CustomContextMenu</enum>
+ </property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>6</number>
@@ -1389,7 +1392,7 @@ p, li { white-space: pre-wrap; }
<height>21</height>
</rect>
</property>
- <widget class="QMenu" name="menu_File">
+ <widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
@@ -1399,7 +1402,7 @@ p, li { white-space: pre-wrap; }
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
- <widget class="QMenu" name="menu_Tools">
+ <widget class="QMenu" name="menuTools">
<property name="title">
<string>&amp;Tools</string>
</property>
@@ -1410,7 +1413,7 @@ p, li { white-space: pre-wrap; }
<addaction name="separator"/>
<addaction name="actionSettings"/>
</widget>
- <widget class="QMenu" name="menu_Help">
+ <widget class="QMenu" name="menuHelp">
<property name="title">
<string>&amp;Help</string>
</property>
@@ -1418,7 +1421,7 @@ p, li { white-space: pre-wrap; }
<addaction name="actionUpdate"/>
<addaction name="actionEndorseMO"/>
</widget>
- <widget class="QMenu" name="menu_Edit">
+ <widget class="QMenu" name="menuEdit">
<property name="title">
<string>&amp;Edit</string>
</property>
@@ -1432,6 +1435,7 @@ p, li { white-space: pre-wrap; }
<property name="title">
<string>&amp;Toolbars</string>
</property>
+ <addaction name="actionMainMenuToggle"/>
<addaction name="actionToolBarMainToggle"/>
<addaction name="actionToolBarLinksToggle"/>
<addaction name="separator"/>
@@ -1446,11 +1450,17 @@ p, li { white-space: pre-wrap; }
<addaction name="menuToolbars"/>
<addaction name="actionNotifications"/>
</widget>
- <addaction name="menu_File"/>
- <addaction name="menu_Edit"/>
+ <widget class="QMenu" name="menuRun">
+ <property name="title">
+ <string>&amp;Run</string>
+ </property>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuEdit"/>
<addaction name="menuView"/>
- <addaction name="menu_Tools"/>
- <addaction name="menu_Help"/>
+ <addaction name="menuTools"/>
+ <addaction name="menuRun"/>
+ <addaction name="menuHelp"/>
</widget>
<widget class="QToolBar" name="linksToolBar">
<property name="contextMenuPolicy">
@@ -1719,22 +1729,12 @@ p, li { white-space: pre-wrap; }
<string>Exits Mod Organizer</string>
</property>
</action>
- <action name="actionToolbar_Size">
- <property name="text">
- <string>Toolbar Size</string>
- </property>
- </action>
- <action name="actionToolbar_style">
- <property name="text">
- <string>Toolbar Buttons</string>
- </property>
- </action>
<action name="actionToolBarMainToggle">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
- <string>&amp;Main</string>
+ <string>M&amp;ain</string>
</property>
</action>
<action name="actionToolBarLinksToggle">
@@ -1793,6 +1793,14 @@ p, li { white-space: pre-wrap; }
<string>M&amp;edium Icons</string>
</property>
</action>
+ <action name="actionMainMenuToggle">
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>&amp;Menu</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>