GH-358 Make version page use a toolbar for all the actions

This should make it possible to make it fit on small screens again.
This commit is contained in:
Petr Mrázek 2019-07-14 05:37:10 +02:00
parent 62e1bf327d
commit e4273d6a17
3 changed files with 301 additions and 363 deletions

View File

@ -16,8 +16,10 @@
#include "MultiMC.h"
#include <QMessageBox>
#include <QLabel>
#include <QEvent>
#include <QKeyEvent>
#include <QMenu>
#include "VersionPage.h"
#include "ui_VersionPage.h"
@ -43,8 +45,6 @@
#include "Exception.h"
#include "Version.h"
#include "MultiMC.h"
#include <meta/Index.h>
#include <meta/VersionList.h>
@ -100,11 +100,33 @@ bool VersionPage::shouldDisplay() const
return !m_inst->isRunning();
}
QMenu * VersionPage::createPopupMenu()
{
QMenu* filteredMenu = QMainWindow::createPopupMenu();
filteredMenu->removeAction( ui->toolBar->toggleViewAction() );
return filteredMenu;
}
VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::VersionPage), m_inst(inst)
: QMainWindow(parent), ui(new Ui::VersionPage), m_inst(inst)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
auto labelSelection = new QLabel(tr("Selection"));
labelSelection->setAlignment(Qt::AlignHCenter);
ui->toolBar->insertWidget(ui->actionChange_version, labelSelection);
auto labelEdit = new QLabel(tr("Edit"));
labelEdit->setAlignment(Qt::AlignHCenter);
ui->toolBar->insertWidget(ui->actionCustomize, labelEdit);
auto labelInstall = new QLabel(tr("Install"));
labelInstall->setAlignment(Qt::AlignHCenter);
ui->toolBar->insertWidget(ui->actionInstall_Forge, labelInstall);
auto labelAdvanced = new QLabel(tr("Advanced"));
labelAdvanced->setAlignment(Qt::AlignHCenter);
ui->toolBar->insertWidget(ui->actionAdd_to_Minecraft_jar, labelAdvanced);
m_profile = m_inst->getComponentList();
reloadComponentList();
@ -178,15 +200,16 @@ void VersionPage::updateVersionControls()
auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft"));
bool newCraft = minecraftVersion >= Version("1.14");
bool oldCraft = minecraftVersion <= Version("1.12.2");
ui->fabricBtn->setEnabled(newCraft);
ui->forgeBtn->setEnabled(oldCraft);
ui->liteloaderBtn->setEnabled(oldCraft);
ui->actionInstall_Fabric->setEnabled(newCraft);
ui->actionInstall_Forge->setEnabled(oldCraft);
ui->actionInstall_LiteLoader->setEnabled(oldCraft);
ui->actionReload->setEnabled(true);
}
else {
ui->fabricBtn->setEnabled(false);
ui->forgeBtn->setEnabled(false);
ui->liteloaderBtn->setEnabled(false);
ui->reloadBtn->setEnabled(false);
ui->actionInstall_Fabric->setEnabled(false);
ui->actionInstall_Forge->setEnabled(false);
ui->actionInstall_LiteLoader->setEnabled(false);
ui->actionReload->setEnabled(false);
}
updateButtons();
}
@ -212,13 +235,13 @@ bool VersionPage::reloadComponentList()
}
}
void VersionPage::on_reloadBtn_clicked()
void VersionPage::on_actionReload_triggered()
{
reloadComponentList();
m_container->refreshContainer();
}
void VersionPage::on_removeBtn_clicked()
void VersionPage::on_actionRemove_triggered()
{
if (ui->packageView->currentIndex().isValid())
{
@ -233,7 +256,7 @@ void VersionPage::on_removeBtn_clicked()
m_container->refreshContainer();
}
void VersionPage::on_modBtn_clicked()
void VersionPage::on_actionInstall_mods_triggered()
{
if(m_container)
{
@ -241,7 +264,7 @@ void VersionPage::on_modBtn_clicked()
}
}
void VersionPage::on_jarmodBtn_clicked()
void VersionPage::on_actionAdd_to_Minecraft_jar_triggered()
{
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
if(!list.empty())
@ -251,7 +274,7 @@ void VersionPage::on_jarmodBtn_clicked()
updateButtons();
}
void VersionPage::on_jarBtn_clicked()
void VersionPage::on_actionReplace_Minecraft_jar_triggered()
{
auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
if(!jarPath.isEmpty())
@ -261,7 +284,7 @@ void VersionPage::on_jarBtn_clicked()
updateButtons();
}
void VersionPage::on_moveUpBtn_clicked()
void VersionPage::on_actionMove_up_triggered()
{
try
{
@ -274,7 +297,7 @@ void VersionPage::on_moveUpBtn_clicked()
updateButtons();
}
void VersionPage::on_moveDownBtn_clicked()
void VersionPage::on_actionMove_down_triggered()
{
try
{
@ -287,7 +310,7 @@ void VersionPage::on_moveDownBtn_clicked()
updateButtons();
}
void VersionPage::on_changeVersionBtn_clicked()
void VersionPage::on_actionChange_version_triggered()
{
auto versionRow = currentRow();
if(versionRow == -1)
@ -305,12 +328,12 @@ void VersionPage::on_changeVersionBtn_clicked()
// FIXME: this is a horrible HACK. Get version filtering information from the actual metadata...
if(uid == "net.minecraftforge")
{
on_forgeBtn_clicked();
on_actionInstall_Forge_triggered();
return;
}
else if (uid == "com.mumfrey.liteloader")
{
on_liteloaderBtn_clicked();
on_actionInstall_LiteLoader_triggered();
return;
}
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
@ -339,7 +362,7 @@ void VersionPage::on_changeVersionBtn_clicked()
m_container->refreshContainer();
}
void VersionPage::on_downloadBtn_clicked()
void VersionPage::on_actionDownload_triggered()
{
if (!MMC->accounts()->anyAccountIsValid())
{
@ -364,7 +387,7 @@ void VersionPage::on_downloadBtn_clicked()
m_container->refreshContainer();
}
void VersionPage::on_forgeBtn_clicked()
void VersionPage::on_actionInstall_Forge_triggered()
{
auto vlist = ENV.metadataIndex()->get("net.minecraftforge");
if(!vlist)
@ -393,7 +416,7 @@ void VersionPage::on_forgeBtn_clicked()
}
}
void VersionPage::on_fabricBtn_clicked()
void VersionPage::on_actionInstall_Fabric_triggered()
{
auto vlist = ENV.metadataIndex()->get("net.fabricmc.fabric-loader");
if(!vlist)
@ -420,7 +443,7 @@ void VersionPage::on_fabricBtn_clicked()
}
}
void VersionPage::on_addEmptyBtn_clicked()
void VersionPage::on_actionAdd_Empty_triggered()
{
NewComponentDialog compdialog(QString(), QString(), this);
QStringList blacklist;
@ -438,7 +461,7 @@ void VersionPage::on_addEmptyBtn_clicked()
}
}
void VersionPage::on_liteloaderBtn_clicked()
void VersionPage::on_actionInstall_LiteLoader_triggered()
{
auto vlist = ENV.metadataIndex()->get("com.mumfrey.liteloader");
if(!vlist)
@ -499,23 +522,23 @@ void VersionPage::updateButtons(int row)
auto patch = m_profile->getComponent(row);
if (!patch)
{
ui->removeBtn->setDisabled(true);
ui->moveDownBtn->setDisabled(true);
ui->moveUpBtn->setDisabled(true);
ui->changeVersionBtn->setDisabled(true);
ui->editBtn->setDisabled(true);
ui->customizeBtn->setDisabled(true);
ui->revertBtn->setDisabled(true);
ui->actionRemove->setDisabled(true);
ui->actionMove_down->setDisabled(true);
ui->actionMove_up->setDisabled(true);
ui->actionChange_version->setDisabled(true);
ui->actionEdit->setDisabled(true);
ui->actionCustomize->setDisabled(true);
ui->actionRevert->setDisabled(true);
}
else
{
ui->removeBtn->setEnabled(patch->isRemovable());
ui->moveDownBtn->setEnabled(patch->isMoveable());
ui->moveUpBtn->setEnabled(patch->isMoveable());
ui->changeVersionBtn->setEnabled(patch->isVersionChangeable());
ui->editBtn->setEnabled(patch->isCustom());
ui->customizeBtn->setEnabled(patch->isCustomizable());
ui->revertBtn->setEnabled(patch->isRevertible());
ui->actionRemove->setEnabled(patch->isRemovable());
ui->actionMove_down->setEnabled(patch->isMoveable());
ui->actionMove_up->setEnabled(patch->isMoveable());
ui->actionChange_version->setEnabled(patch->isVersionChangeable());
ui->actionEdit->setEnabled(patch->isCustom());
ui->actionCustomize->setEnabled(patch->isCustomizable());
ui->actionRevert->setEnabled(patch->isRevertible());
}
}
@ -544,7 +567,7 @@ int VersionPage::currentRow()
return ui->packageView->selectionModel()->selectedRows().first().row();
}
void VersionPage::on_customizeBtn_clicked()
void VersionPage::on_actionCustomize_triggered()
{
auto version = currentRow();
if(version == -1)
@ -565,7 +588,7 @@ void VersionPage::on_customizeBtn_clicked()
preselect(currentIdx);
}
void VersionPage::on_editBtn_clicked()
void VersionPage::on_actionEdit_triggered()
{
auto version = current();
if(!version)
@ -581,7 +604,7 @@ void VersionPage::on_editBtn_clicked()
MMC->openJsonEditor(filename);
}
void VersionPage::on_revertBtn_clicked()
void VersionPage::on_actionRevert_triggered()
{
auto version = currentRow();
if(version == -1)

View File

@ -15,7 +15,7 @@
#pragma once
#include <QWidget>
#include <QMainWindow>
#include "minecraft/MinecraftInstance.h"
#include "minecraft/ComponentList.h"
@ -26,7 +26,7 @@ namespace Ui
class VersionPage;
}
class VersionPage : public QWidget, public BasePage
class VersionPage : public QMainWindow, public BasePage
{
Q_OBJECT
@ -49,24 +49,24 @@ public:
virtual bool shouldDisplay() const override;
private slots:
void on_fabricBtn_clicked();
void on_forgeBtn_clicked();
void on_addEmptyBtn_clicked();
void on_liteloaderBtn_clicked();
void on_reloadBtn_clicked();
void on_removeBtn_clicked();
void on_moveUpBtn_clicked();
void on_moveDownBtn_clicked();
void on_jarmodBtn_clicked();
void on_jarBtn_clicked();
void on_revertBtn_clicked();
void on_editBtn_clicked();
void on_modBtn_clicked();
void on_customizeBtn_clicked();
void on_downloadBtn_clicked();
void on_actionChange_version_triggered();
void on_actionInstall_Forge_triggered();
void on_actionInstall_Fabric_triggered();
void on_actionAdd_Empty_triggered();
void on_actionInstall_LiteLoader_triggered();
void on_actionReload_triggered();
void on_actionRemove_triggered();
void on_actionMove_up_triggered();
void on_actionMove_down_triggered();
void on_actionAdd_to_Minecraft_jar_triggered();
void on_actionReplace_Minecraft_jar_triggered();
void on_actionRevert_triggered();
void on_actionEdit_triggered();
void on_actionInstall_mods_triggered();
void on_actionCustomize_triggered();
void on_actionDownload_triggered();
void updateVersionControls();
void on_changeVersionBtn_clicked();
private:
Component * current();
@ -76,6 +76,8 @@ private:
int doUpdate();
protected:
QMenu * createPopupMenu() override;
/// FIXME: this shouldn't be necessary!
bool reloadComponentList();

View File

@ -1,16 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VersionPage</class>
<widget class="QWidget" name="VersionPage">
<widget class="QMainWindow" name="VersionPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>870</width>
<height>1008</height>
<width>961</width>
<height>1091</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
@ -24,16 +28,8 @@
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string notr="true">Tab 1</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="ModListView" name="packageView">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
@ -52,227 +48,7 @@
</attribute>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Selection</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="changeVersionBtn">
<property name="toolTip">
<string>Change version of the selected package.</string>
</property>
<property name="text">
<string>Change version</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="moveUpBtn">
<property name="toolTip">
<string>Make the selected package apply sooner.</string>
</property>
<property name="text">
<string>Move up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="moveDownBtn">
<property name="toolTip">
<string>Make the selected package apply later.</string>
</property>
<property name="text">
<string>Move down</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeBtn">
<property name="toolTip">
<string>Remove selected package from the instance.</string>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="LineSeparator" name="separator_4" native="true"/>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Edit</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="customizeBtn">
<property name="toolTip">
<string>Customize selected package.</string>
</property>
<property name="text">
<string>Customize</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editBtn">
<property name="toolTip">
<string>Edit selected package.</string>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="revertBtn">
<property name="toolTip">
<string>Revert the selected package to default.</string>
</property>
<property name="text">
<string>Revert</string>
</property>
</widget>
</item>
<item>
<widget class="LineSeparator" name="separator" native="true"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Install</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="forgeBtn">
<property name="toolTip">
<string>Install the Minecraft Forge package.</string>
</property>
<property name="text">
<string>Install Forge</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fabricBtn">
<property name="toolTip">
<string>Install the Fabric Loader package.</string>
</property>
<property name="text">
<string>Install Fabric</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="liteloaderBtn">
<property name="toolTip">
<string>Install the LiteLoader package.</string>
</property>
<property name="text">
<string>Install LiteLoader</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="modBtn">
<property name="toolTip">
<string>Install normal mods.</string>
</property>
<property name="text">
<string>Install mods</string>
</property>
</widget>
</item>
<item>
<widget class="LineSeparator" name="widget" native="true"/>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Advanced</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="jarmodBtn">
<property name="toolTip">
<string>Add a mod into the Minecraft jar file.</string>
</property>
<property name="text">
<string>Add to Minecraft.jar</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="jarBtn">
<property name="text">
<string>Replace Minecraft.jar</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addEmptyBtn">
<property name="text">
<string>Add Empty</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reloadBtn">
<property name="toolTip">
<string>Reload all packages.</string>
</property>
<property name="text">
<string>Reload</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="downloadBtn">
<property name="toolTip">
<string>Download the files needed to launch the instance now.</string>
</property>
<property name="text">
<string>Download All</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>111</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="MCModInfoFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
@ -283,23 +59,180 @@
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</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="actionChange_version"/>
<addaction name="actionMove_up"/>
<addaction name="actionMove_down"/>
<addaction name="actionRemove"/>
<addaction name="separator"/>
<addaction name="actionCustomize"/>
<addaction name="actionEdit"/>
<addaction name="actionRevert"/>
<addaction name="separator"/>
<addaction name="actionInstall_Forge"/>
<addaction name="actionInstall_Fabric"/>
<addaction name="actionInstall_LiteLoader"/>
<addaction name="actionInstall_mods"/>
<addaction name="separator"/>
<addaction name="actionAdd_to_Minecraft_jar"/>
<addaction name="actionReplace_Minecraft_jar"/>
<addaction name="actionAdd_Empty"/>
<addaction name="actionReload"/>
<addaction name="actionDownload_All"/>
</widget>
<action name="actionChange_version">
<property name="text">
<string>Change version</string>
</property>
<property name="toolTip">
<string>Change version of the selected package.</string>
</property>
</action>
<action name="actionMove_up">
<property name="text">
<string>Move up</string>
</property>
<property name="toolTip">
<string>Make the selected package apply sooner.</string>
</property>
</action>
<action name="actionMove_down">
<property name="text">
<string>Move down</string>
</property>
<property name="toolTip">
<string>Make the selected package apply later.</string>
</property>
</action>
<action name="actionRemove">
<property name="text">
<string>Remove</string>
</property>
<property name="toolTip">
<string>Remove selected package from the instance.</string>
</property>
</action>
<action name="actionCustomize">
<property name="text">
<string>Customize</string>
</property>
<property name="toolTip">
<string>Customize selected package.</string>
</property>
</action>
<action name="actionEdit">
<property name="text">
<string>Edit</string>
</property>
<property name="toolTip">
<string>Edit selected package.</string>
</property>
</action>
<action name="actionRevert">
<property name="text">
<string>Revert</string>
</property>
<property name="toolTip">
<string>Revert the selected package to default.</string>
</property>
</action>
<action name="actionInstall_Forge">
<property name="text">
<string>Install Forge</string>
</property>
<property name="toolTip">
<string>Install the Minecraft Forge package.</string>
</property>
</action>
<action name="actionInstall_Fabric">
<property name="text">
<string>Install Fabric</string>
</property>
<property name="toolTip">
<string>Install the Fabric Loader package.</string>
</property>
</action>
<action name="actionInstall_LiteLoader">
<property name="text">
<string>Install LiteLoader</string>
</property>
<property name="toolTip">
<string>Install the LiteLoader package.</string>
</property>
</action>
<action name="actionInstall_mods">
<property name="text">
<string>Install mods</string>
</property>
<property name="toolTip">
<string>Install normal mods.</string>
</property>
</action>
<action name="actionAdd_to_Minecraft_jar">
<property name="text">
<string>Add to Minecraft.jar</string>
</property>
<property name="toolTip">
<string>Add a mod into the Minecraft jar file.</string>
</property>
</action>
<action name="actionReplace_Minecraft_jar">
<property name="text">
<string>Replace Minecraft.jar</string>
</property>
</action>
<action name="actionAdd_Empty">
<property name="text">
<string>Add Empty</string>
</property>
<property name="toolTip">
<string>Add an empty custom package.</string>
</property>
</action>
<action name="actionReload">
<property name="text">
<string>Reload</string>
</property>
<property name="toolTip">
<string>Reload all packages.</string>
</property>
</action>
<action name="actionDownload_All">
<property name="text">
<string>Download All</string>
</property>
<property name="toolTip">
<string>Download the files needed to launch the instance now.</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>ModListView</class>
<extends>QTreeView</extends>
<header>widgets/ModListView.h</header>
</customwidget>
<customwidget>
<class>LineSeparator</class>
<extends>QWidget</extends>
<header>widgets/LineSeparator.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>MCModInfoFrame</class>
<extends>QFrame</extends>
@ -307,26 +240,6 @@
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>packageView</tabstop>
<tabstop>changeVersionBtn</tabstop>
<tabstop>moveUpBtn</tabstop>
<tabstop>moveDownBtn</tabstop>
<tabstop>removeBtn</tabstop>
<tabstop>customizeBtn</tabstop>
<tabstop>editBtn</tabstop>
<tabstop>revertBtn</tabstop>
<tabstop>forgeBtn</tabstop>
<tabstop>fabricBtn</tabstop>
<tabstop>liteloaderBtn</tabstop>
<tabstop>modBtn</tabstop>
<tabstop>jarmodBtn</tabstop>
<tabstop>jarBtn</tabstop>
<tabstop>addEmptyBtn</tabstop>
<tabstop>reloadBtn</tabstop>
<tabstop>downloadBtn</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>