NOISSUE Make mod folder pages use toolbars instead of button layouts

This commit is contained in:
Petr Mrázek 2019-07-16 01:30:53 +02:00
parent 2eec1df1a0
commit decd4ae7ab
5 changed files with 161 additions and 175 deletions

View File

@ -20,6 +20,7 @@
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QMenu>
#include "MultiMC.h" #include "MultiMC.h"
#include "dialogs/CustomMessageBox.h" #include "dialogs/CustomMessageBox.h"
@ -34,10 +35,9 @@
ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<SimpleModList> mods, QString id, ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<SimpleModList> mods, QString id,
QString iconName, QString displayName, QString helpPage, QString iconName, QString displayName, QString helpPage,
QWidget *parent) QWidget *parent)
: QWidget(parent), ui(new Ui::ModFolderPage) : QMainWindow(parent), ui(new Ui::ModFolderPage)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
m_inst = inst; m_inst = inst;
on_RunningState_changed(m_inst && m_inst->isRunning()); on_RunningState_changed(m_inst && m_inst->isRunning());
m_mods = mods; m_mods = mods;
@ -61,6 +61,13 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<SimpleModList>
connect(m_inst, &BaseInstance::runningStatusChanged, this, &ModFolderPage::on_RunningState_changed); connect(m_inst, &BaseInstance::runningStatusChanged, this, &ModFolderPage::on_RunningState_changed);
} }
QMenu * ModFolderPage::createPopupMenu()
{
QMenu* filteredMenu = QMainWindow::createPopupMenu();
filteredMenu->removeAction(ui->actionsToolbar->toggleViewAction() );
return filteredMenu;
}
void ModFolderPage::openedImpl() void ModFolderPage::openedImpl()
{ {
m_mods->startWatching(); m_mods->startWatching();
@ -97,10 +104,10 @@ void ModFolderPage::on_RunningState_changed(bool running)
return; return;
} }
m_controlsEnabled = !running; m_controlsEnabled = !running;
ui->addModBtn->setEnabled(m_controlsEnabled); ui->actionAdd->setEnabled(m_controlsEnabled);
ui->disableModBtn->setEnabled(m_controlsEnabled); ui->actionDisable->setEnabled(m_controlsEnabled);
ui->enableModBtn->setEnabled(m_controlsEnabled); ui->actionEnable->setEnabled(m_controlsEnabled);
ui->rmModBtn->setEnabled(m_controlsEnabled); ui->actionRemove->setEnabled(m_controlsEnabled);
} }
bool ModFolderPage::shouldDisplay() const bool ModFolderPage::shouldDisplay() const
@ -139,10 +146,10 @@ bool ModFolderPage::modListFilter(QKeyEvent *keyEvent)
switch (keyEvent->key()) switch (keyEvent->key())
{ {
case Qt::Key_Delete: case Qt::Key_Delete:
on_rmModBtn_clicked(); on_actionRemove_triggered();
return true; return true;
case Qt::Key_Plus: case Qt::Key_Plus:
on_addModBtn_clicked(); on_actionAdd_triggered();
return true; return true;
default: default:
break; break;
@ -162,7 +169,7 @@ bool ModFolderPage::eventFilter(QObject *obj, QEvent *ev)
return QWidget::eventFilter(obj, ev); return QWidget::eventFilter(obj, ev);
} }
void ModFolderPage::on_addModBtn_clicked() void ModFolderPage::on_actionAdd_triggered()
{ {
if(!m_controlsEnabled) { if(!m_controlsEnabled) {
return; return;
@ -183,7 +190,7 @@ void ModFolderPage::on_addModBtn_clicked()
} }
} }
void ModFolderPage::on_enableModBtn_clicked() void ModFolderPage::on_actionEnable_triggered()
{ {
if(!m_controlsEnabled) { if(!m_controlsEnabled) {
return; return;
@ -192,7 +199,7 @@ void ModFolderPage::on_enableModBtn_clicked()
m_mods->enableMods(selection.indexes(), true); m_mods->enableMods(selection.indexes(), true);
} }
void ModFolderPage::on_disableModBtn_clicked() void ModFolderPage::on_actionDisable_triggered()
{ {
if(!m_controlsEnabled) { if(!m_controlsEnabled) {
return; return;
@ -201,7 +208,7 @@ void ModFolderPage::on_disableModBtn_clicked()
m_mods->enableMods(selection.indexes(), false); m_mods->enableMods(selection.indexes(), false);
} }
void ModFolderPage::on_rmModBtn_clicked() void ModFolderPage::on_actionRemove_triggered()
{ {
if(!m_controlsEnabled) { if(!m_controlsEnabled) {
return; return;
@ -210,12 +217,12 @@ void ModFolderPage::on_rmModBtn_clicked()
m_mods->deleteMods(selection.indexes()); m_mods->deleteMods(selection.indexes());
} }
void ModFolderPage::on_configFolderBtn_clicked() void ModFolderPage::on_actionView_configs_triggered()
{ {
DesktopServices::openDirectory(m_inst->instanceConfigFolder(), true); DesktopServices::openDirectory(m_inst->instanceConfigFolder(), true);
} }
void ModFolderPage::on_viewModBtn_clicked() void ModFolderPage::on_actionView_Folder_triggered()
{ {
DesktopServices::openDirectory(m_mods->dir().absolutePath(), true); DesktopServices::openDirectory(m_mods->dir().absolutePath(), true);
} }

View File

@ -15,7 +15,7 @@
#pragma once #pragma once
#include <QWidget> #include <QMainWindow>
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "pages/BasePage.h" #include "pages/BasePage.h"
@ -27,14 +27,20 @@ namespace Ui
class ModFolderPage; class ModFolderPage;
} }
class ModFolderPage : public QWidget, public BasePage class ModFolderPage : public QMainWindow, public BasePage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ModFolderPage(BaseInstance *inst, std::shared_ptr<SimpleModList> mods, QString id, explicit ModFolderPage(
QString iconName, QString displayName, QString helpPage = "", BaseInstance *inst,
QWidget *parent = 0); std::shared_ptr<SimpleModList> mods,
QString id,
QString iconName,
QString displayName,
QString helpPage = "",
QWidget *parent = 0
);
virtual ~ModFolderPage(); virtual ~ModFolderPage();
void setFilter(const QString & filter) void setFilter(const QString & filter)
@ -65,6 +71,7 @@ public:
protected: protected:
bool eventFilter(QObject *obj, QEvent *ev) override; bool eventFilter(QObject *obj, QEvent *ev) override;
bool modListFilter(QKeyEvent *ev); bool modListFilter(QKeyEvent *ev);
QMenu * createPopupMenu() override;
protected: protected:
BaseInstance *m_inst = nullptr; BaseInstance *m_inst = nullptr;
@ -89,12 +96,12 @@ private
slots: slots:
void on_filterTextChanged(const QString & newContents); void on_filterTextChanged(const QString & newContents);
void on_RunningState_changed(bool running); void on_RunningState_changed(bool running);
void on_addModBtn_clicked(); void on_actionAdd_triggered();
void on_rmModBtn_clicked(); void on_actionRemove_triggered();
void on_viewModBtn_clicked(); void on_actionEnable_triggered();
void on_enableModBtn_clicked(); void on_actionDisable_triggered();
void on_disableModBtn_clicked(); void on_actionView_Folder_triggered();
void on_configFolderBtn_clicked(); void on_actionView_configs_triggered();
}; };
class CoreModFolderPage : public ModFolderPage class CoreModFolderPage : public ModFolderPage

View File

@ -1,155 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>ModFolderPage</class> <class>ModFolderPage</class>
<widget class="QWidget" name="ModFolderPage"> <widget class="QMainWindow" name="ModFolderPage">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>723</width> <width>1042</width>
<height>532</height> <height>501</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <property name="windowTitle">
<property name="leftMargin"> <string>MainWindow</string>
<number>0</number> </property>
</property> <widget class="QWidget" name="centralwidget">
<property name="topMargin"> <layout class="QGridLayout" name="gridLayout">
<number>0</number> <property name="leftMargin">
</property> <number>0</number>
<property name="rightMargin"> </property>
<number>0</number> <property name="topMargin">
</property> <number>0</number>
<property name="bottomMargin"> </property>
<number>0</number> <property name="rightMargin">
</property> <number>0</number>
<item> </property>
<widget class="QTabWidget" name="tabWidget"> <property name="bottomMargin">
<property name="currentIndex"> <number>0</number>
<number>0</number> </property>
</property> <item row="4" column="1" colspan="3">
<widget class="QWidget" name="tab"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QLineEdit" name="filterEdit">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="filterLabel">
<property name="text">
<string>Filter:</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1" colspan="3">
<widget class="MCModInfoFrame" name="frame">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<attribute name="title">
<string notr="true">Tab 1</string>
</attribute>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0">
<item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="addModBtn">
<property name="text">
<string>&amp;Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="rmModBtn">
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="enableModBtn">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="disableModBtn">
<property name="text">
<string>Disable</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="configFolderBtn">
<property name="toolTip">
<string>Open the 'config' folder in the system file manager.</string>
</property>
<property name="text">
<string>View configs</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="viewModBtn">
<property name="text">
<string>&amp;View Folder</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="3">
<widget class="MCModInfoFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QLineEdit" name="filterEdit">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="filterLabel">
<property name="text">
<string>Filter:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="ModListView" name="modTreeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DropOnly</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget> </widget>
</widget> </item>
</item> <item row="1" column="1" colspan="3">
</layout> <widget class="ModListView" name="modTreeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DropOnly</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="actionsToolbar">
<property name="windowTitle">
<string>Actions</string>
</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">
<enum>RightToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionAdd"/>
<addaction name="actionRemove"/>
<addaction name="actionEnable"/>
<addaction name="actionDisable"/>
<addaction name="separator"/>
<addaction name="actionView_configs"/>
<addaction name="actionView_Folder"/>
</widget>
<action name="actionAdd">
<property name="text">
<string>Add</string>
</property>
</action>
<action name="actionRemove">
<property name="text">
<string>Remove</string>
</property>
</action>
<action name="actionEnable">
<property name="text">
<string>Enable</string>
</property>
</action>
<action name="actionDisable">
<property name="text">
<string>Disable</string>
</property>
</action>
<action name="actionView_configs">
<property name="text">
<string>View configs</string>
</property>
<property name="toolTip">
<string>Open the 'config' folder in the system file manager.</string>
</property>
</action>
<action name="actionView_Folder">
<property name="text">
<string>View Folder</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
@ -164,17 +147,6 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>modTreeView</tabstop>
<tabstop>filterEdit</tabstop>
<tabstop>addModBtn</tabstop>
<tabstop>rmModBtn</tabstop>
<tabstop>enableModBtn</tabstop>
<tabstop>disableModBtn</tabstop>
<tabstop>configFolderBtn</tabstop>
<tabstop>viewModBtn</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -10,7 +10,7 @@ public:
: ModFolderPage(instance, instance->resourcePackList(), "resourcepacks", : ModFolderPage(instance, instance->resourcePackList(), "resourcepacks",
"resourcepacks", tr("Resource packs"), "Resource-packs", parent) "resourcepacks", tr("Resource packs"), "Resource-packs", parent)
{ {
ui->configFolderBtn->setHidden(true); ui->actionView_configs->setVisible(false);
} }
virtual ~ResourcePackPage() {} virtual ~ResourcePackPage() {}

View File

@ -10,7 +10,7 @@ public:
: ModFolderPage(instance, instance->texturePackList(), "texturepacks", "resourcepacks", : ModFolderPage(instance, instance->texturePackList(), "texturepacks", "resourcepacks",
tr("Texture packs"), "Texture-packs", parent) tr("Texture packs"), "Texture-packs", parent)
{ {
ui->configFolderBtn->setHidden(true); ui->actionView_configs->setVisible(false);
} }
virtual ~TexturePackPage() {} virtual ~TexturePackPage() {}
virtual bool shouldDisplay() const override virtual bool shouldDisplay() const override