NOISSUE improve toolbars

This commit is contained in:
Petr Mrázek 2019-07-23 00:48:14 +02:00
parent 1e5b595923
commit bf38021937
15 changed files with 138 additions and 42 deletions

View File

@ -213,6 +213,8 @@ SET(MULTIMC_SOURCES
widgets/VersionSelectWidget.h widgets/VersionSelectWidget.h
widgets/ProgressWidget.h widgets/ProgressWidget.h
widgets/ProgressWidget.cpp widgets/ProgressWidget.cpp
widgets/WideBar.h
widgets/WideBar.cpp
# GUI - instance group view # GUI - instance group view
groupview/GroupedProxyModel.cpp groupview/GroupedProxyModel.cpp

View File

@ -17,6 +17,7 @@
#include "ui_AccountListPage.h" #include "ui_AccountListPage.h"
#include <QItemSelectionModel> #include <QItemSelectionModel>
#include <QMenu>
#include <QDebug> #include <QDebug>
@ -77,6 +78,14 @@ void AccountListPage::changeEvent(QEvent* event)
QMainWindow::changeEvent(event); QMainWindow::changeEvent(event);
} }
QMenu * AccountListPage::createPopupMenu()
{
QMenu* filteredMenu = QMainWindow::createPopupMenu();
filteredMenu->removeAction(ui->toolBar->toggleViewAction() );
return filteredMenu;
}
void AccountListPage::listChanged() void AccountListPage::listChanged()
{ {
updateButtonStates(); updateButtonStates();

View File

@ -61,6 +61,7 @@ public:
private: private:
void changeEvent(QEvent * event) override; void changeEvent(QEvent * event) override;
QMenu * createPopupMenu() override;
public public
slots: slots:

View File

@ -32,22 +32,10 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QToolBar" name="toolBar"> <widget class="WideBar" name="toolBar">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
<property name="movable">
<bool>true</bool>
</property>
<property name="allowedAreas">
<set>Qt::LeftToolBarArea|Qt::RightToolBarArea</set>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>RightToolBarArea</enum> <enum>RightToolBarArea</enum>
</attribute> </attribute>
@ -95,6 +83,11 @@
<extends>QTreeView</extends> <extends>QTreeView</extends>
<header>widgets/VersionListView.h</header> <header>widgets/VersionListView.h</header>
</customwidget> </customwidget>
<customwidget>
<class>WideBar</class>
<extends>QToolBar</extends>
<header>widgets/WideBar.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -38,11 +38,7 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<SimpleModList>
: QMainWindow(parent), ui(new Ui::ModFolderPage) : QMainWindow(parent), ui(new Ui::ModFolderPage)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->actionsToolbar->insertSpacer(ui->actionView_configs);
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);
m_inst = inst; m_inst = inst;
on_RunningState_changed(m_inst && m_inst->isRunning()); on_RunningState_changed(m_inst && m_inst->isRunning());

View File

@ -73,19 +73,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QToolBar" name="actionsToolbar"> <widget class="WideBar" name="actionsToolbar">
<property name="windowTitle"> <property name="windowTitle">
<string>Actions</string> <string>Actions</string>
</property> </property>
<property name="allowedAreas">
<set>Qt::LeftToolBarArea|Qt::RightToolBarArea</set>
</property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum> <enum>Qt::ToolButtonTextOnly</enum>
</property> </property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>RightToolBarArea</enum> <enum>RightToolBarArea</enum>
</attribute> </attribute>
@ -145,6 +139,11 @@
<header>widgets/MCModInfoFrame.h</header> <header>widgets/MCModInfoFrame.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>WideBar</class>
<extends>QToolBar</extends>
<header>widgets/WideBar.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -223,11 +223,7 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent)
m_valid = FS::ensureFolderPathExists(m_folder); m_valid = FS::ensureFolderPathExists(m_folder);
ui->setupUi(this); ui->setupUi(this);
ui->toolBar->insertSpacer(ui->actionView_Folder);
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->listView->setIconSize(QSize(128, 128)); ui->listView->setIconSize(QSize(128, 128));
ui->listView->setGridSize(QSize(192, 160)); ui->listView->setGridSize(QSize(192, 160));

View File

@ -39,10 +39,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QToolBar" name="toolBar"> <widget class="WideBar" name="toolBar">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>RightToolBarArea</enum> <enum>RightToolBarArea</enum>
</attribute> </attribute>
@ -75,6 +78,13 @@
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>WideBar</class>
<extends>QToolBar</extends>
<header>widgets/WideBar.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -128,7 +128,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QToolBar" name="toolBar"> <widget class="WideBar" name="toolBar">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
@ -173,6 +173,13 @@
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>WideBar</class>
<extends>QToolBar</extends>
<header>widgets/WideBar.h</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>serversView</tabstop> <tabstop>serversView</tabstop>
<tabstop>nameLine</tabstop> <tabstop>nameLine</tabstop>

View File

@ -112,10 +112,7 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
{ {
ui->setupUi(this); ui->setupUi(this);
QWidget* spacer = new QWidget(); ui->toolBar->insertSpacer(ui->actionReload);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// toolBar is a pointer to an existing toolbar
ui->toolBar->insertWidget(ui->actionReload, spacer);
m_profile = m_inst->getComponentList(); m_profile = m_inst->getComponentList();

View File

@ -62,7 +62,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QToolBar" name="toolBar"> <widget class="WideBar" name="toolBar">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
@ -239,6 +239,11 @@
<header>widgets/MCModInfoFrame.h</header> <header>widgets/MCModInfoFrame.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>WideBar</class>
<extends>QToolBar</extends>
<header>widgets/WideBar.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -37,10 +37,7 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worl
{ {
ui->setupUi(this); ui->setupUi(this);
QWidget* spacer = new QWidget(); ui->toolBar->insertSpacer(ui->actionRefresh);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// toolBar is a pointer to an existing toolbar
ui->toolBar->insertWidget(ui->actionRefresh, spacer);
QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this); QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this);
proxy->setSortCaseSensitivity(Qt::CaseInsensitive); proxy->setSortCaseSensitivity(Qt::CaseInsensitive);

View File

@ -57,7 +57,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QToolBar" name="toolBar"> <widget class="WideBar" name="toolBar">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
@ -128,6 +128,13 @@
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>WideBar</class>
<extends>QToolBar</extends>
<header>widgets/WideBar.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -0,0 +1,59 @@
#include "WideBar.h"
#include <QToolButton>
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"

View File

@ -0,0 +1,18 @@
#pragma once
#include <QToolBar>
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<QAction *, QAction *> m_actionMap;
};