|
|
@ -1,5 +1,7 @@
|
|
|
|
#include "contentselector.hpp"
|
|
|
|
#include "contentselector.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ui_contentselector.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/contentselector/model/esmfile.hpp>
|
|
|
|
#include <components/contentselector/model/esmfile.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QClipboard>
|
|
|
@ -9,14 +11,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool showOMWScripts)
|
|
|
|
ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool showOMWScripts)
|
|
|
|
: QObject(parent)
|
|
|
|
: QObject(parent)
|
|
|
|
|
|
|
|
, ui(std::make_unique<Ui::ContentSelector>())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui.setupUi(parent);
|
|
|
|
ui->setupUi(parent);
|
|
|
|
ui.addonView->setDragDropMode(QAbstractItemView::InternalMove);
|
|
|
|
ui->addonView->setDragDropMode(QAbstractItemView::InternalMove);
|
|
|
|
|
|
|
|
|
|
|
|
if (!showOMWScripts)
|
|
|
|
if (!showOMWScripts)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui.languageComboBox->setHidden(true);
|
|
|
|
ui->languageComboBox->setHidden(true);
|
|
|
|
ui.refreshButton->setHidden(true);
|
|
|
|
ui->refreshButton->setHidden(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buildContentModel(showOMWScripts);
|
|
|
|
buildContentModel(showOMWScripts);
|
|
|
@ -24,21 +27,23 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool show
|
|
|
|
buildAddonView();
|
|
|
|
buildAddonView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector::~ContentSelector() = default;
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildContentModel(bool showOMWScripts)
|
|
|
|
void ContentSelectorView::ContentSelector::buildContentModel(bool showOMWScripts)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QIcon warningIcon(ui.addonView->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(QSize(16, 15)));
|
|
|
|
QIcon warningIcon(ui->addonView->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(QSize(16, 15)));
|
|
|
|
mContentModel = new ContentSelectorModel::ContentModel(this, warningIcon, showOMWScripts);
|
|
|
|
mContentModel = new ContentSelectorModel::ContentModel(this, warningIcon, showOMWScripts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildGameFileView()
|
|
|
|
void ContentSelectorView::ContentSelector::buildGameFileView()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui.gameFileView->addItem(tr("<No game file>"));
|
|
|
|
ui->gameFileView->addItem(tr("<No game file>"));
|
|
|
|
ui.gameFileView->setVisible(true);
|
|
|
|
ui->gameFileView->setVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.gameFileView, qOverload<int>(&ComboBox::currentIndexChanged), this,
|
|
|
|
connect(ui->gameFileView, qOverload<int>(&ComboBox::currentIndexChanged), this,
|
|
|
|
&ContentSelector::slotCurrentGameFileIndexChanged);
|
|
|
|
&ContentSelector::slotCurrentGameFileIndexChanged);
|
|
|
|
|
|
|
|
|
|
|
|
ui.gameFileView->setCurrentIndex(0);
|
|
|
|
ui->gameFileView->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class AddOnProxyModel : public QSortFilterProxyModel
|
|
|
|
class AddOnProxyModel : public QSortFilterProxyModel
|
|
|
@ -60,9 +65,34 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ContentSelectorView::ContentSelector::isGamefileSelected() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ui->gameFileView->currentIndex() > 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* ContentSelectorView::ContentSelector::uiWidget() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ui->contentGroupBox;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QComboBox* ContentSelectorView::ContentSelector::languageBox() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ui->languageComboBox;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QToolButton* ContentSelectorView::ContentSelector::refreshButton() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ui->refreshButton;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QLineEdit* ContentSelectorView::ContentSelector::searchFilter() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ui->searchFilter;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildAddonView()
|
|
|
|
void ContentSelectorView::ContentSelector::buildAddonView()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui.addonView->setVisible(true);
|
|
|
|
ui->addonView->setVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
mAddonProxyModel = new AddOnProxyModel(this);
|
|
|
|
mAddonProxyModel = new AddOnProxyModel(this);
|
|
|
|
mAddonProxyModel->setFilterRegularExpression(searchFilter()->text());
|
|
|
|
mAddonProxyModel->setFilterRegularExpression(searchFilter()->text());
|
|
|
@ -70,12 +100,12 @@ void ContentSelectorView::ContentSelector::buildAddonView()
|
|
|
|
mAddonProxyModel->setDynamicSortFilter(true);
|
|
|
|
mAddonProxyModel->setDynamicSortFilter(true);
|
|
|
|
mAddonProxyModel->setSourceModel(mContentModel);
|
|
|
|
mAddonProxyModel->setSourceModel(mContentModel);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard);
|
|
|
|
connect(ui->searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard);
|
|
|
|
connect(ui.searchFilter, &QLineEdit::textEdited, this, &ContentSelector::slotSearchFilterTextChanged);
|
|
|
|
connect(ui->searchFilter, &QLineEdit::textEdited, this, &ContentSelector::slotSearchFilterTextChanged);
|
|
|
|
|
|
|
|
|
|
|
|
ui.addonView->setModel(mAddonProxyModel);
|
|
|
|
ui->addonView->setModel(mAddonProxyModel);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated);
|
|
|
|
connect(ui->addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated);
|
|
|
|
connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this,
|
|
|
|
connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this,
|
|
|
|
&ContentSelector::signalAddonDataChanged);
|
|
|
|
&ContentSelector::signalAddonDataChanged);
|
|
|
|
buildContextMenu();
|
|
|
|
buildContextMenu();
|
|
|
@ -83,10 +113,10 @@ void ContentSelectorView::ContentSelector::buildAddonView()
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildContextMenu()
|
|
|
|
void ContentSelectorView::ContentSelector::buildContextMenu()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui.addonView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
ui->addonView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(ui.addonView, &QTableView::customContextMenuRequested, this, &ContentSelector::slotShowContextMenu);
|
|
|
|
connect(ui->addonView, &QTableView::customContextMenuRequested, this, &ContentSelector::slotShowContextMenu);
|
|
|
|
|
|
|
|
|
|
|
|
mContextMenu = new QMenu(ui.addonView);
|
|
|
|
mContextMenu = new QMenu(ui->addonView);
|
|
|
|
mContextMenu->addAction(tr("&Check Selected"), this, SLOT(slotCheckMultiSelectedItems()));
|
|
|
|
mContextMenu->addAction(tr("&Check Selected"), this, SLOT(slotCheckMultiSelectedItems()));
|
|
|
|
mContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems()));
|
|
|
|
mContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems()));
|
|
|
|
mContextMenu->addAction(tr("&Copy Path(s) to Clipboard"), this, SLOT(slotCopySelectedItemsPaths()));
|
|
|
|
mContextMenu->addAction(tr("&Copy Path(s) to Clipboard"), this, SLOT(slotCopySelectedItemsPaths()));
|
|
|
@ -116,7 +146,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename)
|
|
|
|
if (!filename.isEmpty())
|
|
|
|
if (!filename.isEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const ContentSelectorModel::EsmFile* file = mContentModel->item(filename);
|
|
|
|
const ContentSelectorModel::EsmFile* file = mContentModel->item(filename);
|
|
|
|
index = ui.gameFileView->findText(file->fileName());
|
|
|
|
index = ui->gameFileView->findText(file->fileName());
|
|
|
|
|
|
|
|
|
|
|
|
// verify that the current index is also checked in the model
|
|
|
|
// verify that the current index is also checked in the model
|
|
|
|
if (!mContentModel->setCheckState(filename, true))
|
|
|
|
if (!mContentModel->setCheckState(filename, true))
|
|
|
@ -126,7 +156,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ui.gameFileView->setCurrentIndex(index);
|
|
|
|
ui->gameFileView->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::clearCheckStates()
|
|
|
|
void ContentSelectorView::ContentSelector::clearCheckStates()
|
|
|
@ -143,7 +173,7 @@ void ContentSelectorView::ContentSelector::setContentList(const QStringList& lis
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (list.isEmpty())
|
|
|
|
if (list.isEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
slotCurrentGameFileIndexChanged(ui.gameFileView->currentIndex());
|
|
|
|
slotCurrentGameFileIndexChanged(ui->gameFileView->currentIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
mContentModel->setContentList(list);
|
|
|
|
mContentModel->setContentList(list);
|
|
|
@ -164,14 +194,14 @@ void ContentSelectorView::ContentSelector::addFiles(const QString& path, bool ne
|
|
|
|
// add any game files to the combo box
|
|
|
|
// add any game files to the combo box
|
|
|
|
for (const QString& gameFileName : mContentModel->gameFiles())
|
|
|
|
for (const QString& gameFileName : mContentModel->gameFiles())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ui.gameFileView->findText(gameFileName) == -1)
|
|
|
|
if (ui->gameFileView->findText(gameFileName) == -1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui.gameFileView->addItem(gameFileName);
|
|
|
|
ui->gameFileView->addItem(gameFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ui.gameFileView->currentIndex() != 0)
|
|
|
|
if (ui->gameFileView->currentIndex() != 0)
|
|
|
|
ui.gameFileView->setCurrentIndex(0);
|
|
|
|
ui->gameFileView->setCurrentIndex(0);
|
|
|
|
|
|
|
|
|
|
|
|
mContentModel->uncheckAll();
|
|
|
|
mContentModel->uncheckAll();
|
|
|
|
mContentModel->checkForLoadOrderErrors();
|
|
|
|
mContentModel->checkForLoadOrderErrors();
|
|
|
@ -194,10 +224,10 @@ void ContentSelectorView::ContentSelector::clearFiles()
|
|
|
|
|
|
|
|
|
|
|
|
QString ContentSelectorView::ContentSelector::currentFile() const
|
|
|
|
QString ContentSelectorView::ContentSelector::currentFile() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QModelIndex currentIdx = ui.addonView->currentIndex();
|
|
|
|
QModelIndex currentIdx = ui->addonView->currentIndex();
|
|
|
|
|
|
|
|
|
|
|
|
if (!currentIdx.isValid() && ui.gameFileView->currentIndex() > 0)
|
|
|
|
if (!currentIdx.isValid() && ui->gameFileView->currentIndex() > 0)
|
|
|
|
return ui.gameFileView->currentText();
|
|
|
|
return ui->gameFileView->currentText();
|
|
|
|
|
|
|
|
|
|
|
|
QModelIndex idx = mContentModel->index(mAddonProxyModel->mapToSource(currentIdx).row(), 0, QModelIndex());
|
|
|
|
QModelIndex idx = mContentModel->index(mAddonProxyModel->mapToSource(currentIdx).row(), 0, QModelIndex());
|
|
|
|
return mContentModel->data(idx, Qt::DisplayRole).toString();
|
|
|
|
return mContentModel->data(idx, Qt::DisplayRole).toString();
|
|
|
@ -225,7 +255,7 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool selected)
|
|
|
|
void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool selected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QString fileName = ui.gameFileView->itemText(index);
|
|
|
|
QString fileName = ui->gameFileView->itemText(index);
|
|
|
|
const ContentSelectorModel::EsmFile* file = mContentModel->item(fileName);
|
|
|
|
const ContentSelectorModel::EsmFile* file = mContentModel->item(fileName);
|
|
|
|
if (file != nullptr)
|
|
|
|
if (file != nullptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -253,14 +283,14 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QMo
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos)
|
|
|
|
void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QPoint globalPos = ui.addonView->viewport()->mapToGlobal(pos);
|
|
|
|
QPoint globalPos = ui->addonView->viewport()->mapToGlobal(pos);
|
|
|
|
mContextMenu->exec(globalPos);
|
|
|
|
mContextMenu->exec(globalPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked)
|
|
|
|
void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked;
|
|
|
|
Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked;
|
|
|
|
for (const QModelIndex& index : ui.addonView->selectionModel()->selectedIndexes())
|
|
|
|
for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index);
|
|
|
|
QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index);
|
|
|
|
if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState)
|
|
|
|
if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState)
|
|
|
@ -284,7 +314,7 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
QString filepaths;
|
|
|
|
QString filepaths;
|
|
|
|
for (const QModelIndex& index : ui.addonView->selectionModel()->selectedIndexes())
|
|
|
|
for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int row = mAddonProxyModel->mapToSource(index).row();
|
|
|
|
int row = mAddonProxyModel->mapToSource(index).row();
|
|
|
|
const ContentSelectorModel::EsmFile* file = mContentModel->item(row);
|
|
|
|
const ContentSelectorModel::EsmFile* file = mContentModel->item(row);
|
|
|
@ -299,5 +329,5 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths()
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QString& newText)
|
|
|
|
void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QString& newText)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui.addonView->setDragEnabled(newText.isEmpty());
|
|
|
|
ui->addonView->setDragEnabled(newText.isEmpty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|