Merge pull request #270 from flowln/dialog

Make a better "Mod download confirmation dialog"
This commit is contained in:
Ezekiel Smith 2022-03-15 00:50:49 +11:00 committed by Sefa Eyeoglu
parent 0681568d3e
commit c560d06b8d
No known key found for this signature in database
GPG Key ID: C10411294912A422
5 changed files with 163 additions and 19 deletions

View File

@ -797,6 +797,8 @@ SET(LAUNCHER_SOURCES
ui/pagedialog/PageDialog.h ui/pagedialog/PageDialog.h
ui/dialogs/ProgressDialog.cpp ui/dialogs/ProgressDialog.cpp
ui/dialogs/ProgressDialog.h ui/dialogs/ProgressDialog.h
ui/dialogs/ReviewMessageBox.cpp
ui/dialogs/ReviewMessageBox.h
ui/dialogs/UpdateDialog.cpp ui/dialogs/UpdateDialog.cpp
ui/dialogs/UpdateDialog.h ui/dialogs/UpdateDialog.h
ui/dialogs/VersionSelectDialog.cpp ui/dialogs/VersionSelectDialog.cpp
@ -905,6 +907,7 @@ qt5_wrap_ui(LAUNCHER_UI
ui/dialogs/AboutDialog.ui ui/dialogs/AboutDialog.ui
ui/dialogs/LoginDialog.ui ui/dialogs/LoginDialog.ui
ui/dialogs/EditAccountDialog.ui ui/dialogs/EditAccountDialog.ui
ui/dialogs/ReviewMessageBox.ui
) )
qt5_add_resources(LAUNCHER_RESOURCES qt5_add_resources(LAUNCHER_RESOURCES

View File

@ -5,7 +5,7 @@
#include <InstanceList.h> #include <InstanceList.h>
#include "ProgressDialog.h" #include "ProgressDialog.h"
#include "CustomMessageBox.h" #include "ReviewMessageBox.h"
#include <QLayout> #include <QLayout>
#include <QPushButton> #include <QPushButton>
@ -75,27 +75,16 @@ void ModDownloadDialog::confirm()
auto keys = modTask.keys(); auto keys = modTask.keys();
keys.sort(Qt::CaseInsensitive); keys.sort(Qt::CaseInsensitive);
auto info = QString(tr("You're about to download the following mods:")); auto confirm_dialog = ReviewMessageBox::create(
info.append("\n\n");
for(auto task : keys){
info.append(task);
info.append("\n --> ");
info.append(tr("File name: "));
info.append(modTask.find(task).value()->getFilename());
info.append('\n');
}
auto confirm_dialog = CustomMessageBox::selectable(
this, this,
tr("Confirm mods to download"), tr("Confirm mods to download")
info,
QMessageBox::NoIcon,
QMessageBox::Cancel | QMessageBox::Ok,
QMessageBox::Ok
); );
auto AcceptButton = confirm_dialog->button(QMessageBox::Ok); for(auto task : keys){
connect(AcceptButton, &QPushButton::clicked, this, &ModDownloadDialog::accept); confirm_dialog->appendMod(task, modTask.find(task).value()->getFilename());
}
connect(confirm_dialog, &QDialog::accepted, this, &ModDownloadDialog::accept);
confirm_dialog->open(); confirm_dialog->open();
} }

View File

@ -0,0 +1,31 @@
#include "ReviewMessageBox.h"
#include "ui_ReviewMessageBox.h"
ReviewMessageBox::ReviewMessageBox(QWidget* parent, QString const& title, QString const& icon)
: QDialog(parent), ui(new Ui::ReviewMessageBox)
{
ui->setupUi(this);
}
ReviewMessageBox::~ReviewMessageBox()
{
delete ui;
}
auto ReviewMessageBox::create(QWidget* parent, QString&& title, QString&& icon) -> ReviewMessageBox*
{
return new ReviewMessageBox(parent, title, icon);
}
void ReviewMessageBox::appendMod(const QString& name, const QString& filename)
{
auto itemTop = new QTreeWidgetItem(ui->modTreeWidget);
itemTop->setText(0, name);
auto filenameItem = new QTreeWidgetItem(itemTop);
filenameItem->setText(0, tr("Filename: %1").arg(filename));
itemTop->insertChildren(0, { filenameItem });
ui->modTreeWidget->addTopLevelItem(itemTop);
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <QDialog>
namespace Ui {
class ReviewMessageBox;
}
class ReviewMessageBox final : public QDialog {
Q_OBJECT
public:
static auto create(QWidget* parent, QString&& title, QString&& icon = "") -> ReviewMessageBox*;
void appendMod(const QString& name, const QString& filename);
~ReviewMessageBox();
private:
ReviewMessageBox(QWidget* parent, const QString& title, const QString& icon);
Ui::ReviewMessageBox* ui;
};

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ReviewMessageBox</class>
<widget class="QDialog" name="ReviewMessageBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Confirm mod selection</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>You're about to download the following mods:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="modTreeWidget">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string/>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ReviewMessageBox</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>200</x>
<y>265</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ReviewMessageBox</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>200</x>
<y>265</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
</ui>