feat+refactor: add shortcuts to mod downloader and clean up
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
127b558f95
commit
a8bcd85c93
@ -19,36 +19,33 @@
|
||||
#include "ModDownloadDialog.h"
|
||||
|
||||
#include <BaseVersion.h>
|
||||
#include <icons/IconList.h>
|
||||
#include <InstanceList.h>
|
||||
#include <icons/IconList.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "ReviewMessageBox.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLayout>
|
||||
#include <QPushButton>
|
||||
#include <QValidator>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
#include "ui/widgets/PageContainer.h"
|
||||
#include "ui/pages/modplatform/modrinth/ModrinthModPage.h"
|
||||
#include "ModDownloadTask.h"
|
||||
#include "ui/pages/modplatform/flame/FlameModPage.h"
|
||||
#include "ui/pages/modplatform/modrinth/ModrinthModPage.h"
|
||||
#include "ui/widgets/PageContainer.h"
|
||||
|
||||
|
||||
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods, QWidget *parent,
|
||||
BaseInstance *instance)
|
||||
: QDialog(parent), mods(mods), m_instance(instance)
|
||||
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget* parent, BaseInstance* instance)
|
||||
: QDialog(parent), mods(mods), m_verticalLayout(new QVBoxLayout(this)), m_instance(instance)
|
||||
{
|
||||
setObjectName(QStringLiteral("ModDownloadDialog"));
|
||||
|
||||
resize(std::max(0.5*parent->width(), 400.0), std::max(0.75*parent->height(), 400.0));
|
||||
|
||||
m_verticalLayout = new QVBoxLayout(this);
|
||||
m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
|
||||
|
||||
resize(std::max(0.5 * parent->width(), 400.0), std::max(0.75 * parent->height(), 400.0));
|
||||
|
||||
setWindowIcon(APPLICATION->getThemedIcon("new"));
|
||||
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below.
|
||||
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not
|
||||
// move this below.
|
||||
m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
m_container = new PageContainer(this);
|
||||
@ -65,6 +62,8 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods
|
||||
OkButton->setDefault(true);
|
||||
OkButton->setAutoDefault(true);
|
||||
OkButton->setText(tr("Review and confirm"));
|
||||
OkButton->setShortcut(tr("Ctrl+Return"));
|
||||
OkButton->setToolTip(tr("Opens a new popup to review your selected mods and confirm your selection. Shortcut: Ctrl+Return"));
|
||||
connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::confirm);
|
||||
|
||||
auto CancelButton = m_buttons->button(QDialogButtonBox::Cancel);
|
||||
@ -118,9 +117,9 @@ void ModDownloadDialog::accept()
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
QList<BasePage *> ModDownloadDialog::getPages()
|
||||
QList<BasePage*> ModDownloadDialog::getPages()
|
||||
{
|
||||
QList<BasePage *> pages;
|
||||
QList<BasePage*> pages;
|
||||
|
||||
pages.append(new ModrinthModPage(this, m_instance));
|
||||
if (APPLICATION->currentCapabilities() & Application::SupportsFlame)
|
||||
@ -129,7 +128,7 @@ QList<BasePage *> ModDownloadDialog::getPages()
|
||||
return pages;
|
||||
}
|
||||
|
||||
void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task)
|
||||
void ModDownloadDialog::addSelectedMod(QString name, ModDownloadTask* task)
|
||||
{
|
||||
removeSelectedMod(name);
|
||||
modTask.insert(name, task);
|
||||
@ -137,16 +136,16 @@ void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* tas
|
||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty());
|
||||
}
|
||||
|
||||
void ModDownloadDialog::removeSelectedMod(const QString &name)
|
||||
void ModDownloadDialog::removeSelectedMod(QString name)
|
||||
{
|
||||
if(modTask.contains(name))
|
||||
if (modTask.contains(name))
|
||||
delete modTask.find(name).value();
|
||||
modTask.remove(name);
|
||||
|
||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty());
|
||||
}
|
||||
|
||||
bool ModDownloadDialog::isModSelected(const QString &name, const QString& filename) const
|
||||
bool ModDownloadDialog::isModSelected(QString name, QString filename) const
|
||||
{
|
||||
// FIXME: Is there a way to check for versions without checking the filename
|
||||
// as a heuristic, other than adding such info to ModDownloadTask itself?
|
||||
@ -154,16 +153,13 @@ bool ModDownloadDialog::isModSelected(const QString &name, const QString& filena
|
||||
return iter != modTask.end() && (iter.value()->getFilename() == filename);
|
||||
}
|
||||
|
||||
bool ModDownloadDialog::isModSelected(const QString &name) const
|
||||
bool ModDownloadDialog::isModSelected(QString name) const
|
||||
{
|
||||
auto iter = modTask.find(name);
|
||||
return iter != modTask.end();
|
||||
}
|
||||
|
||||
ModDownloadDialog::~ModDownloadDialog()
|
||||
const QList<ModDownloadTask*> ModDownloadDialog::getTasks()
|
||||
{
|
||||
}
|
||||
|
||||
const QList<ModDownloadTask*> ModDownloadDialog::getTasks() {
|
||||
return modTask.values();
|
||||
}
|
||||
|
@ -21,11 +21,9 @@
|
||||
#include <QDialog>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "BaseVersion.h"
|
||||
#include "ui/pages/BasePageProvider.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "ModDownloadTask.h"
|
||||
#include "ui/pages/modplatform/flame/FlameModPage.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "ui/pages/BasePageProvider.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -41,16 +39,16 @@ class ModDownloadDialog : public QDialog, public BasePageProvider
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods, QWidget *parent, BaseInstance *instance);
|
||||
~ModDownloadDialog();
|
||||
explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget* parent, BaseInstance* instance);
|
||||
~ModDownloadDialog() override = default;
|
||||
|
||||
QString dialogTitle() override;
|
||||
QList<BasePage *> getPages() override;
|
||||
QList<BasePage*> getPages() override;
|
||||
|
||||
void addSelectedMod(const QString & name = QString(), ModDownloadTask * task = nullptr);
|
||||
void removeSelectedMod(const QString & name = QString());
|
||||
bool isModSelected(const QString & name, const QString & filename) const;
|
||||
bool isModSelected(const QString & name) const;
|
||||
void addSelectedMod(QString name = QString(), ModDownloadTask* task = nullptr);
|
||||
void removeSelectedMod(QString name = QString());
|
||||
bool isModSelected(QString name, QString filename) const;
|
||||
bool isModSelected(QString name) const;
|
||||
|
||||
const QList<ModDownloadTask*> getTasks();
|
||||
const std::shared_ptr<ModFolderModel> &mods;
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "BuildConfig.h"
|
||||
#include "Json.h"
|
||||
#include "ModPage.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "ui/dialogs/ModDownloadDialog.h"
|
||||
|
@ -76,6 +76,7 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
|
||||
});
|
||||
|
||||
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
||||
ui->packView->installEventFilter(this);
|
||||
}
|
||||
|
||||
ModPage::~ModPage()
|
||||
@ -98,6 +99,18 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool
|
||||
auto* keyEvent = dynamic_cast<QKeyEvent*>(event);
|
||||
if (keyEvent->key() == Qt::Key_Return) {
|
||||
triggerSearch();
|
||||
keyEvent->accept();
|
||||
return true;
|
||||
}
|
||||
} else if (watched == ui->packView && event->type() == QEvent::KeyPress) {
|
||||
auto* keyEvent = dynamic_cast<QKeyEvent*>(event);
|
||||
if (keyEvent->key() == Qt::Key_Return) {
|
||||
onModSelected();
|
||||
|
||||
// To have the 'select mod' button outlined instead of the 'review and confirm' one
|
||||
ui->modSelectionButton->setFocus(Qt::FocusReason::ShortcutFocusReason);
|
||||
ui->packView->setFocus(Qt::FocusReason::NoFocusReason);
|
||||
|
||||
keyEvent->accept();
|
||||
return true;
|
||||
}
|
||||
@ -172,6 +185,9 @@ void ModPage::onVersionSelectionChanged(QString data)
|
||||
|
||||
void ModPage::onModSelected()
|
||||
{
|
||||
if (selectedVersion < 0)
|
||||
return;
|
||||
|
||||
auto& version = current.versions[selectedVersion];
|
||||
if (dialog->isModSelected(current.name, version.fileName)) {
|
||||
dialog->removeSelectedMod(current.name);
|
||||
|
Loading…
Reference in New Issue
Block a user