2018-03-01 00:12:30 +05:30
|
|
|
#include "ChooseFtbPackDialog.h"
|
2018-03-04 01:52:00 +05:30
|
|
|
#include <QPushButton>
|
2018-03-01 00:12:30 +05:30
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
ChooseFtbPackDialog::ChooseFtbPackDialog(FtbModpackList modpacks) : ui(new Ui::ChooseFtbPackDialog)
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
filterModel = new FtbFilterModel(this);
|
|
|
|
listModel = new FtbListModel(this);
|
|
|
|
filterModel->setSourceModel(listModel);
|
|
|
|
listModel->fill(modpacks);
|
2018-03-01 00:12:30 +05:30
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
ui->packList->setModel(filterModel);
|
|
|
|
ui->packList->setSortingEnabled(true);
|
|
|
|
ui->packList->header()->hide();
|
|
|
|
ui->packList->setIndentation(0);
|
|
|
|
|
|
|
|
filterModel->setSorting(FtbFilterModel::Sorting::ByName);
|
|
|
|
|
|
|
|
for(int i = 0; i < filterModel->getAvailableSortings().size(); i++){
|
|
|
|
ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i));
|
2018-03-01 00:12:30 +05:30
|
|
|
}
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting()));
|
|
|
|
|
|
|
|
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onSortingSelectionChanged);
|
2018-03-01 00:12:30 +05:30
|
|
|
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onVersionSelectionItemChanged);
|
2018-03-04 01:52:00 +05:30
|
|
|
connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ChooseFtbPackDialog::onPackSelectionChanged);
|
2018-03-01 00:12:30 +05:30
|
|
|
|
|
|
|
ui->modpackInfo->setOpenExternalLinks(true);
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
2018-03-01 00:12:30 +05:30
|
|
|
}
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
ChooseFtbPackDialog::~ChooseFtbPackDialog()
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
void ChooseFtbPackDialog::onPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
ui->packVersionSelection->clear();
|
2018-03-04 01:52:00 +05:30
|
|
|
FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value<FtbModpack>();
|
2018-03-01 00:12:30 +05:30
|
|
|
|
|
|
|
ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>"
|
2018-03-04 01:52:00 +05:30
|
|
|
"<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>");
|
2018-03-01 00:12:30 +05:30
|
|
|
|
|
|
|
bool currentAdded = false;
|
|
|
|
|
|
|
|
for(int i = 0; i < selectedPack.oldVersions.size(); i++) {
|
|
|
|
if(selectedPack.currentVersion == selectedPack.oldVersions.at(i)) {
|
|
|
|
currentAdded = true;
|
|
|
|
}
|
|
|
|
ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!currentAdded) {
|
|
|
|
ui->packVersionSelection->addItem(selectedPack.currentVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
selected = selectedPack;
|
2018-03-04 01:52:00 +05:30
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!selected.broken);
|
2018-03-01 00:12:30 +05:30
|
|
|
}
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
void ChooseFtbPackDialog::onVersionSelectionItemChanged(QString data)
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
if(data.isNull() || data.isEmpty()) {
|
|
|
|
selectedVersion = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedVersion = data;
|
|
|
|
}
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
FtbModpack ChooseFtbPackDialog::getSelectedModpack()
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
2018-03-04 01:52:00 +05:30
|
|
|
QString ChooseFtbPackDialog::getSelectedVersion()
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
return selectedVersion;
|
|
|
|
}
|
2018-03-04 01:52:00 +05:30
|
|
|
|
|
|
|
void ChooseFtbPackDialog::onSortingSelectionChanged(QString data)
|
|
|
|
{
|
|
|
|
filterModel->setSorting(filterModel->getAvailableSortings().value(data));
|
|
|
|
}
|