From bf38021937a555249905d38cda0d4ea5fbc43fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 23 Jul 2019 00:48:14 +0200 Subject: [PATCH] NOISSUE improve toolbars --- application/CMakeLists.txt | 2 + application/pages/global/AccountListPage.cpp | 9 +++ application/pages/global/AccountListPage.h | 1 + application/pages/global/AccountListPage.ui | 19 ++---- application/pages/instance/ModFolderPage.cpp | 6 +- application/pages/instance/ModFolderPage.ui | 13 ++-- .../pages/instance/ScreenshotsPage.cpp | 6 +- application/pages/instance/ScreenshotsPage.ui | 12 +++- application/pages/instance/ServersPage.ui | 9 ++- application/pages/instance/VersionPage.cpp | 5 +- application/pages/instance/VersionPage.ui | 7 ++- application/pages/instance/WorldListPage.cpp | 5 +- application/pages/instance/WorldListPage.ui | 9 ++- application/widgets/WideBar.cpp | 59 +++++++++++++++++++ application/widgets/WideBar.h | 18 ++++++ 15 files changed, 138 insertions(+), 42 deletions(-) create mode 100644 application/widgets/WideBar.cpp create mode 100644 application/widgets/WideBar.h diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index e3f4b345..73fe261a 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 6ea6df9b..5270a305 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 f4c94119..9de73f70 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 b56d0b59..433c1f7f 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 bd070b94..d0de4ac2 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 1fcaa4d9..55908bb5 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 b470202f..d73fda51 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 a669e292..42d4db64 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 5023cd73..9c31abe3 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 a34f564c..8b95c8b2 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 cb02a9ca..e16f18bc 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 bd559991..75805838 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 37721ae0..b7a9e57a 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 00000000..ee0a67e3 --- /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 00000000..38da35d0 --- /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; +};