From 40a9828fbab0e9a8b7f070714bdd87d3f279e18c Mon Sep 17 00:00:00 2001 From: flow Date: Wed, 23 Feb 2022 19:17:33 -0300 Subject: [PATCH] fix: improve readability and set ok button as disabled by default --- launcher/ui/dialogs/ModDownloadDialog.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index a56c2e64..23ca8731 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -40,6 +40,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods // Bonk Qt over its stupid head and make sure it understands which button is the default one... // See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button auto OkButton = m_buttons->button(QDialogButtonBox::Ok); + OkButton->setEnabled(false); OkButton->setDefault(true); OkButton->setAutoDefault(true); connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::confirm); @@ -89,7 +90,7 @@ void ModDownloadDialog::confirm() tr("Confirm mods to download"), info, QMessageBox::NoIcon, - {QMessageBox::Cancel, QMessageBox::Ok}, + QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Ok ); @@ -117,13 +118,8 @@ QList ModDownloadDialog::getPages() void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task) { - if(modTask.contains(name)) - delete modTask.find(name).value(); - - if(task) - modTask.insert(name, task); - else - modTask.remove(name); + removeSelectedMod(name); + modTask.insert(name, task); m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty()); } @@ -133,6 +129,8 @@ void ModDownloadDialog::removeSelectedMod(const QString &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