diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index e3f4b345a..73fe261ab 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -213,6 +213,8 @@ SET(MULTIMC_SOURCES widgets/VersionSelectWidget.h widgets/ProgressWidget.h widgets/ProgressWidget.cpp + widgets/WideBar.h + widgets/WideBar.cpp # GUI - instance group view groupview/GroupedProxyModel.cpp diff --git a/application/pages/global/AccountListPage.cpp b/application/pages/global/AccountListPage.cpp index 6ea6df9be..5270a3053 100644 --- a/application/pages/global/AccountListPage.cpp +++ b/application/pages/global/AccountListPage.cpp @@ -17,6 +17,7 @@ #include "ui_AccountListPage.h" #include +#include #include @@ -77,6 +78,14 @@ void AccountListPage::changeEvent(QEvent* event) QMainWindow::changeEvent(event); } +QMenu * AccountListPage::createPopupMenu() +{ + QMenu* filteredMenu = QMainWindow::createPopupMenu(); + filteredMenu->removeAction(ui->toolBar->toggleViewAction() ); + return filteredMenu; +} + + void AccountListPage::listChanged() { updateButtonStates(); diff --git a/application/pages/global/AccountListPage.h b/application/pages/global/AccountListPage.h index f4c94119d..9de73f702 100644 --- a/application/pages/global/AccountListPage.h +++ b/application/pages/global/AccountListPage.h @@ -61,6 +61,7 @@ public: private: void changeEvent(QEvent * event) override; + QMenu * createPopupMenu() override; public slots: diff --git a/application/pages/global/AccountListPage.ui b/application/pages/global/AccountListPage.ui index b56d0b59a..433c1f7f6 100644 --- a/application/pages/global/AccountListPage.ui +++ b/application/pages/global/AccountListPage.ui @@ -32,22 +32,10 @@ - + toolBar - - true - - - Qt::LeftToolBarArea|Qt::RightToolBarArea - - - Qt::ToolButtonTextOnly - - - false - RightToolBarArea @@ -95,6 +83,11 @@ QTreeView
widgets/VersionListView.h
+ + WideBar + QToolBar +
widgets/WideBar.h
+
diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp index bd070b94e..d0de4ac21 100644 --- a/application/pages/instance/ModFolderPage.cpp +++ b/application/pages/instance/ModFolderPage.cpp @@ -38,11 +38,7 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr : QMainWindow(parent), ui(new Ui::ModFolderPage) { ui->setupUi(this); - - QWidget* spacer = new QWidget(); - spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - // toolBar is a pointer to an existing toolbar - ui->actionsToolbar->insertWidget(ui->actionView_configs, spacer); + ui->actionsToolbar->insertSpacer(ui->actionView_configs); m_inst = inst; on_RunningState_changed(m_inst && m_inst->isRunning()); diff --git a/application/pages/instance/ModFolderPage.ui b/application/pages/instance/ModFolderPage.ui index 1fcaa4d91..55908bb59 100644 --- a/application/pages/instance/ModFolderPage.ui +++ b/application/pages/instance/ModFolderPage.ui @@ -73,19 +73,13 @@
- + Actions - - Qt::LeftToolBarArea|Qt::RightToolBarArea - Qt::ToolButtonTextOnly - - false - RightToolBarArea @@ -145,6 +139,11 @@
widgets/MCModInfoFrame.h
1 + + WideBar + QToolBar +
widgets/WideBar.h
+
diff --git a/application/pages/instance/ScreenshotsPage.cpp b/application/pages/instance/ScreenshotsPage.cpp index b470202fa..d73fda517 100644 --- a/application/pages/instance/ScreenshotsPage.cpp +++ b/application/pages/instance/ScreenshotsPage.cpp @@ -223,11 +223,7 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent) m_valid = FS::ensureFolderPathExists(m_folder); ui->setupUi(this); - - QWidget* spacer = new QWidget(); - spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - // toolBar is a pointer to an existing toolbar - ui->toolBar->insertWidget(ui->actionView_Folder, spacer); + ui->toolBar->insertSpacer(ui->actionView_Folder); ui->listView->setIconSize(QSize(128, 128)); ui->listView->setGridSize(QSize(192, 160)); diff --git a/application/pages/instance/ScreenshotsPage.ui b/application/pages/instance/ScreenshotsPage.ui index a669e2920..42d4db640 100644 --- a/application/pages/instance/ScreenshotsPage.ui +++ b/application/pages/instance/ScreenshotsPage.ui @@ -39,10 +39,13 @@
- + toolBar + + Qt::ToolButtonTextOnly + RightToolBarArea @@ -75,6 +78,13 @@ + + + WideBar + QToolBar +
widgets/WideBar.h
+
+
diff --git a/application/pages/instance/ServersPage.ui b/application/pages/instance/ServersPage.ui index 5023cd737..9c31abe39 100644 --- a/application/pages/instance/ServersPage.ui +++ b/application/pages/instance/ServersPage.ui @@ -128,7 +128,7 @@
- + toolBar @@ -173,6 +173,13 @@ + + + WideBar + QToolBar +
widgets/WideBar.h
+
+
serversView nameLine diff --git a/application/pages/instance/VersionPage.cpp b/application/pages/instance/VersionPage.cpp index a34f564cf..8b95c8b22 100644 --- a/application/pages/instance/VersionPage.cpp +++ b/application/pages/instance/VersionPage.cpp @@ -112,10 +112,7 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) { ui->setupUi(this); - QWidget* spacer = new QWidget(); - spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - // toolBar is a pointer to an existing toolbar - ui->toolBar->insertWidget(ui->actionReload, spacer); + ui->toolBar->insertSpacer(ui->actionReload); m_profile = m_inst->getComponentList(); diff --git a/application/pages/instance/VersionPage.ui b/application/pages/instance/VersionPage.ui index cb02a9ca2..e16f18bc9 100644 --- a/application/pages/instance/VersionPage.ui +++ b/application/pages/instance/VersionPage.ui @@ -62,7 +62,7 @@
- + toolBar @@ -239,6 +239,11 @@
widgets/MCModInfoFrame.h
1 + + WideBar + QToolBar +
widgets/WideBar.h
+
diff --git a/application/pages/instance/WorldListPage.cpp b/application/pages/instance/WorldListPage.cpp index bd5599919..75805838e 100644 --- a/application/pages/instance/WorldListPage.cpp +++ b/application/pages/instance/WorldListPage.cpp @@ -37,10 +37,7 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worl { ui->setupUi(this); - QWidget* spacer = new QWidget(); - spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - // toolBar is a pointer to an existing toolbar - ui->toolBar->insertWidget(ui->actionRefresh, spacer); + ui->toolBar->insertSpacer(ui->actionRefresh); QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this); proxy->setSortCaseSensitivity(Qt::CaseInsensitive); diff --git a/application/pages/instance/WorldListPage.ui b/application/pages/instance/WorldListPage.ui index 37721ae00..b7a9e57a5 100644 --- a/application/pages/instance/WorldListPage.ui +++ b/application/pages/instance/WorldListPage.ui @@ -57,7 +57,7 @@
- + toolBar @@ -128,6 +128,13 @@ + + + WideBar + QToolBar +
widgets/WideBar.h
+
+
diff --git a/application/widgets/WideBar.cpp b/application/widgets/WideBar.cpp new file mode 100644 index 000000000..ee0a67e39 --- /dev/null +++ b/application/widgets/WideBar.cpp @@ -0,0 +1,59 @@ +#include "WideBar.h" +#include + +class ActionButton : public QToolButton +{ + Q_OBJECT +public: + ActionButton(QAction * action, QWidget * parent = 0) : QToolButton(parent), m_action(action) { + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + connect(action, &QAction::changed, this, &ActionButton::actionChanged); + connect(this, &ActionButton::clicked, action, &QAction::trigger); + actionChanged(); + }; +private slots: + void actionChanged() { + setEnabled(m_action->isEnabled()); + setChecked(m_action->isChecked()); + setCheckable(m_action->isCheckable()); + setText(m_action->text()); + setIcon(m_action->icon()); + setToolTip(m_action->toolTip()); + setHidden(!m_action->isVisible()); + } +private: + QAction * m_action; +}; + + +WideBar::WideBar(const QString& title, QWidget* parent) : QToolBar(title, parent) +{ + setFloatable(false); + setMovable(false); +} + +WideBar::WideBar(QWidget* parent) : QToolBar(parent) +{ + setFloatable(false); + setMovable(false); +} + +void WideBar::addAction(QAction* action) +{ + auto actionButton = new ActionButton(action, this); + auto newAction = addWidget(actionButton); + m_actionMap[action] = newAction; +} + +void WideBar::insertSpacer(QAction* action) +{ + if(!m_actionMap.contains(action)) { + return; + } + + QWidget* spacer = new QWidget(); + spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + insertWidget(m_actionMap[action], spacer); +} + +#include "WideBar.moc" diff --git a/application/widgets/WideBar.h b/application/widgets/WideBar.h new file mode 100644 index 000000000..38da35d07 --- /dev/null +++ b/application/widgets/WideBar.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +class WideBar : public QToolBar +{ + Q_OBJECT + +public: + explicit WideBar(const QString &title, QWidget * parent = nullptr); + explicit WideBar(QWidget * parent = nullptr); + + void addAction(QAction *action); + void insertSpacer(QAction *action); + +private: + QMap m_actionMap; +};