2022-11-19 15:04:26 +00:00
|
|
|
#include "ImportResourcePackDialog.h"
|
|
|
|
#include "ui_ImportResourcePackDialog.h"
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
#include "Application.h"
|
|
|
|
#include "InstanceList.h"
|
|
|
|
|
2022-11-19 15:59:30 +00:00
|
|
|
#include <InstanceList.h>
|
2022-11-19 16:14:16 +00:00
|
|
|
#include "ui/instanceview/InstanceProxyModel.h"
|
2022-11-19 15:04:26 +00:00
|
|
|
#include "ui/instanceview/InstanceDelegate.h"
|
|
|
|
|
|
|
|
ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ImportResourcePackDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
auto contentsWidget = ui->instanceView;
|
|
|
|
contentsWidget->setViewMode(QListView::ListMode);
|
|
|
|
contentsWidget->setFlow(QListView::LeftToRight);
|
|
|
|
contentsWidget->setIconSize(QSize(48, 48));
|
|
|
|
contentsWidget->setMovement(QListView::Static);
|
|
|
|
contentsWidget->setResizeMode(QListView::Adjust);
|
|
|
|
contentsWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
contentsWidget->setSpacing(5);
|
2022-11-21 10:15:03 +00:00
|
|
|
contentsWidget->setWordWrap(true);
|
2022-11-25 14:51:08 +00:00
|
|
|
contentsWidget->setWrapping(true);
|
|
|
|
// NOTE: We can't have uniform sizes because the text may wrap if it's too long. If we set this, it will cut off the wrapped text.
|
|
|
|
contentsWidget->setUniformItemSizes(false);
|
2022-11-19 15:04:26 +00:00
|
|
|
contentsWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
contentsWidget->setItemDelegate(new ListViewDelegate());
|
|
|
|
|
2022-11-19 16:14:16 +00:00
|
|
|
proxyModel = new InstanceProxyModel(this);
|
|
|
|
proxyModel->setSourceModel(APPLICATION->instances().get());
|
|
|
|
proxyModel->sort(0);
|
|
|
|
contentsWidget->setModel(proxyModel);
|
2022-11-19 15:04:26 +00:00
|
|
|
|
|
|
|
connect(contentsWidget, SIGNAL(doubleClicked(QModelIndex)), SLOT(activated(QModelIndex)));
|
|
|
|
connect(contentsWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
|
|
|
SLOT(selectionChanged(QItemSelection, QItemSelection)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportResourcePackDialog::activated(QModelIndex index)
|
|
|
|
{
|
2022-11-19 15:59:30 +00:00
|
|
|
selectedInstanceKey = index.data(InstanceList::InstanceIDRole).toString();
|
2022-11-19 15:04:26 +00:00
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSelection deselected)
|
|
|
|
{
|
|
|
|
if (selected.empty())
|
|
|
|
return;
|
|
|
|
|
2022-11-19 15:59:30 +00:00
|
|
|
QString key = selected.first().indexes().first().data(InstanceList::InstanceIDRole).toString();
|
2022-11-19 15:04:26 +00:00
|
|
|
if (!key.isEmpty()) {
|
|
|
|
selectedInstanceKey = key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImportResourcePackDialog::~ImportResourcePackDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|