2018-02-28 18:42:30 +00:00
|
|
|
#include "ChooseFtbPackDialog.h"
|
2018-03-03 20:22:00 +00:00
|
|
|
#include <QPushButton>
|
2018-02-28 18:42:30 +00:00
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
ChooseFtbPackDialog::ChooseFtbPackDialog(FtbModpackList modpacks) : ui(new Ui::ChooseFtbPackDialog)
|
|
|
|
{
|
2018-02-28 18:42:30 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
filterModel = new FtbFilterModel(this);
|
|
|
|
listModel = new FtbListModel(this);
|
|
|
|
filterModel->setSourceModel(listModel);
|
|
|
|
listModel->fill(modpacks);
|
2018-02-28 18:42:30 +00:00
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
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-02-28 18:42:30 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting()));
|
|
|
|
|
|
|
|
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onSortingSelectionChanged);
|
2018-02-28 18:42:30 +00:00
|
|
|
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onVersionSelectionItemChanged);
|
2018-03-03 20:22:00 +00:00
|
|
|
connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ChooseFtbPackDialog::onPackSelectionChanged);
|
2018-02-28 18:42:30 +00:00
|
|
|
|
|
|
|
ui->modpackInfo->setOpenExternalLinks(true);
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
2018-02-28 18:42:30 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
ChooseFtbPackDialog::~ChooseFtbPackDialog()
|
|
|
|
{
|
2018-02-28 18:42:30 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
void ChooseFtbPackDialog::onPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
|
|
|
{
|
2018-02-28 18:42:30 +00:00
|
|
|
ui->packVersionSelection->clear();
|
2018-03-03 20:22:00 +00:00
|
|
|
FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value<FtbModpack>();
|
2018-02-28 18:42:30 +00:00
|
|
|
|
|
|
|
ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>"
|
2018-03-03 20:22:00 +00:00
|
|
|
"<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>");
|
2018-02-28 18:42:30 +00:00
|
|
|
|
|
|
|
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-03 20:22:00 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!selected.broken);
|
2018-02-28 18:42:30 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
void ChooseFtbPackDialog::onVersionSelectionItemChanged(QString data)
|
|
|
|
{
|
2018-02-28 18:42:30 +00:00
|
|
|
if(data.isNull() || data.isEmpty()) {
|
|
|
|
selectedVersion = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedVersion = data;
|
|
|
|
}
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
FtbModpack ChooseFtbPackDialog::getSelectedModpack()
|
|
|
|
{
|
2018-02-28 18:42:30 +00:00
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
2018-03-03 20:22:00 +00:00
|
|
|
QString ChooseFtbPackDialog::getSelectedVersion()
|
|
|
|
{
|
2018-02-28 18:42:30 +00:00
|
|
|
return selectedVersion;
|
|
|
|
}
|
2018-03-03 20:22:00 +00:00
|
|
|
|
|
|
|
void ChooseFtbPackDialog::onSortingSelectionChanged(QString data)
|
|
|
|
{
|
|
|
|
filterModel->setSorting(filterModel->getAvailableSortings().value(data));
|
|
|
|
}
|