|
|
|
@ -8,83 +8,205 @@
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent) :
|
|
|
|
|
QDialog(parent)
|
|
|
|
|
#include "../../../apps/opencs/view/doc/filewidget.hpp"
|
|
|
|
|
#include "../../../apps/opencs/view/doc/adjusterwidget.hpp"
|
|
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector *ContentSelectorView::ContentSelector::mInstance = 0;
|
|
|
|
|
QStringList ContentSelectorView::ContentSelector::mFilePaths;
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::configure(QWidget *subject, unsigned char flags)
|
|
|
|
|
{
|
|
|
|
|
assert(!mInstance);
|
|
|
|
|
mInstance = new ContentSelector (subject, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector& ContentSelectorView::ContentSelector::instance()
|
|
|
|
|
{
|
|
|
|
|
assert(mInstance);
|
|
|
|
|
return *mInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned char flags) :
|
|
|
|
|
QWidget(parent), mFlags (flags),
|
|
|
|
|
mAdjusterWidget (0), mFileWidget (0)
|
|
|
|
|
{
|
|
|
|
|
setupUi(this);
|
|
|
|
|
ui.setupUi (this);
|
|
|
|
|
|
|
|
|
|
parent->setLayout(new QGridLayout());
|
|
|
|
|
parent->layout()->addWidget(this);
|
|
|
|
|
|
|
|
|
|
buildContentModel();
|
|
|
|
|
buildGameFileView();
|
|
|
|
|
buildAddonView();
|
|
|
|
|
buildProfilesView();
|
|
|
|
|
buildNewAddonView();
|
|
|
|
|
buildLoadAddonView();
|
|
|
|
|
|
|
|
|
|
updateViews();
|
|
|
|
|
/*
|
|
|
|
|
//mContentModel->sort(3); // Sort by date accessed
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ContentSelectorView::ContentSelector::isFlagged(SelectorFlags flag) const
|
|
|
|
|
{
|
|
|
|
|
return (mFlags & flag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildContentModel()
|
|
|
|
|
{
|
|
|
|
|
if (!isFlagged (Flag_Content))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mContentModel = new ContentSelectorModel::ContentModel();
|
|
|
|
|
connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
|
|
|
|
|
|
|
|
|
|
if (mFilePaths.size()>0)
|
|
|
|
|
{
|
|
|
|
|
foreach (const QString &path, mFilePaths)
|
|
|
|
|
mContentModel->addFiles(path);
|
|
|
|
|
|
|
|
|
|
mFilePaths.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.gameFileView->setCurrentIndex(-1);
|
|
|
|
|
mContentModel->uncheckAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildGameFileView()
|
|
|
|
|
{
|
|
|
|
|
if (!isFlagged (Flag_Content))
|
|
|
|
|
{
|
|
|
|
|
ui.gameFileView->setVisible(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mGameFileProxyModel = new QSortFilterProxyModel(this);
|
|
|
|
|
mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile));
|
|
|
|
|
mGameFileProxyModel->setFilterRole (Qt::UserRole);
|
|
|
|
|
mGameFileProxyModel->setSourceModel (mContentModel);
|
|
|
|
|
|
|
|
|
|
gameFileView->setPlaceholderText(QString("Select a game file..."));
|
|
|
|
|
gameFileView->setModel(mGameFileProxyModel);
|
|
|
|
|
ui.gameFileView->setPlaceholderText(QString("Select a game file..."));
|
|
|
|
|
ui.gameFileView->setModel(mGameFileProxyModel);
|
|
|
|
|
|
|
|
|
|
connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentGameFileIndexChanged(int)));
|
|
|
|
|
connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SIGNAL(signalGameFileChanged(int)));
|
|
|
|
|
connect(ui.gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT (slotCurrentGameFileIndexChanged(int)));
|
|
|
|
|
|
|
|
|
|
gameFileView->setCurrentIndex(-1);
|
|
|
|
|
gameFileView->setCurrentIndex(0);
|
|
|
|
|
ui.gameFileView->setCurrentIndex(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildAddonView()
|
|
|
|
|
{
|
|
|
|
|
if (!isFlagged (Flag_Content))
|
|
|
|
|
{
|
|
|
|
|
ui.addonView->setVisible(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mAddonProxyModel = new QSortFilterProxyModel(this);
|
|
|
|
|
mAddonProxyModel->setFilterRegExp (QString::number((int)ContentSelectorModel::ContentType_Addon));
|
|
|
|
|
mAddonProxyModel->setFilterRole (Qt::UserRole);
|
|
|
|
|
mAddonProxyModel->setDynamicSortFilter (true);
|
|
|
|
|
mAddonProxyModel->setSourceModel (mContentModel);
|
|
|
|
|
|
|
|
|
|
addonView->setModel(mAddonProxyModel);
|
|
|
|
|
ui.addonView->setModel(mAddonProxyModel);
|
|
|
|
|
|
|
|
|
|
connect(addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &)));
|
|
|
|
|
connect(ui.addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildProfilesView()
|
|
|
|
|
{
|
|
|
|
|
profilesComboBox->setPlaceholderText(QString("Select a profile..."));
|
|
|
|
|
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
|
|
|
|
|
if (!isFlagged (Flag_Profile))
|
|
|
|
|
{
|
|
|
|
|
ui.profileGroupBox->setVisible(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.profilesComboBox->setPlaceholderText(QString("Select a profile..."));
|
|
|
|
|
connect(ui.profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildLoadAddonView()
|
|
|
|
|
{
|
|
|
|
|
if (!isFlagged (Flag_LoadAddon))
|
|
|
|
|
{
|
|
|
|
|
ui.projectGroupBox->setVisible (false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.projectCreateButton->setVisible (false);
|
|
|
|
|
// ui.projectButtonBox->setStandardButtons(QDialogButtonBox::Open | QDialogButtonBox::Cancel);
|
|
|
|
|
ui.projectGroupBox->setTitle ("");
|
|
|
|
|
|
|
|
|
|
connect(ui.projectButtonBox, SIGNAL(accepted()), this, SIGNAL(accepted()));
|
|
|
|
|
connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildNewAddonView()
|
|
|
|
|
{
|
|
|
|
|
if (!isFlagged (Flag_NewAddon))
|
|
|
|
|
{
|
|
|
|
|
ui.profileGroupBox->setVisible (false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mFileWidget = new CSVDoc::FileWidget (this);
|
|
|
|
|
mAdjusterWidget = new CSVDoc::AdjusterWidget (this);
|
|
|
|
|
|
|
|
|
|
mFileWidget->setType(true);
|
|
|
|
|
mFileWidget->extensionLabelIsVisible(false);
|
|
|
|
|
|
|
|
|
|
ui.fileWidgetFrame->layout()->addWidget(mFileWidget);
|
|
|
|
|
ui.adjusterWidgetFrame->layout()->addWidget(mAdjusterWidget);
|
|
|
|
|
|
|
|
|
|
ui.projectButtonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
|
|
|
|
ui.projectButtonBox->addButton(ui.projectCreateButton, QDialogButtonBox::ActionRole);
|
|
|
|
|
|
|
|
|
|
connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)),
|
|
|
|
|
mAdjusterWidget, SLOT (setName (const QString&, bool)));
|
|
|
|
|
|
|
|
|
|
connect (mAdjusterWidget, SIGNAL (stateChanged(bool)), this, SLOT (slotUpdateCreateButton(bool)));
|
|
|
|
|
|
|
|
|
|
connect(ui.projectCreateButton, SIGNAL(clicked()), this, SIGNAL(accepted()));
|
|
|
|
|
connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ContentSelectorView::ContentSelector::filename() const
|
|
|
|
|
{
|
|
|
|
|
QString filepath = "";
|
|
|
|
|
|
|
|
|
|
if (mAdjusterWidget)
|
|
|
|
|
filepath = QString::fromAscii(mAdjusterWidget->getPath().c_str());
|
|
|
|
|
|
|
|
|
|
return filepath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::updateViews()
|
|
|
|
|
QStringList ContentSelectorView::ContentSelector::selectedFiles() const
|
|
|
|
|
{
|
|
|
|
|
// Ensure the columns are hidden because sort() re-enables them
|
|
|
|
|
addonView->setColumnHidden(1, true);
|
|
|
|
|
addonView->setColumnHidden(2, true);
|
|
|
|
|
addonView->setColumnHidden(3, true);
|
|
|
|
|
addonView->setColumnHidden(4, true);
|
|
|
|
|
addonView->setColumnHidden(5, true);
|
|
|
|
|
addonView->setColumnHidden(6, true);
|
|
|
|
|
addonView->setColumnHidden(7, true);
|
|
|
|
|
addonView->setColumnHidden(8, true);
|
|
|
|
|
addonView->resizeColumnsToContents();
|
|
|
|
|
QStringList filePaths;
|
|
|
|
|
|
|
|
|
|
if (mContentModel)
|
|
|
|
|
{
|
|
|
|
|
foreach (ContentSelectorModel::EsmFile *file, mContentModel->checkedItems())
|
|
|
|
|
filePaths.append(file->path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filePaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
mContentModel->addFiles(path);
|
|
|
|
|
//mContentModel->sort(3); // Sort by date accessed
|
|
|
|
|
gameFileView->setCurrentIndex(-1);
|
|
|
|
|
mContentModel->uncheckAll();
|
|
|
|
|
// if the model hasn't been instantiated, queue the path
|
|
|
|
|
if (!mInstance)
|
|
|
|
|
mFilePaths.append(path);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mInstance->mContentModel->addFiles(path);
|
|
|
|
|
mInstance->ui.gameFileView->setCurrentIndex(-1);
|
|
|
|
|
mInstance->mContentModel->uncheckAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
|
|
|
|
@ -99,14 +221,14 @@ QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
emit profileChanged(index);
|
|
|
|
|
emit signalProfileChanged(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
static int oldIndex = -1;
|
|
|
|
|
|
|
|
|
|
QAbstractItemModel *const model = gameFileView->model();
|
|
|
|
|
QAbstractItemModel *const model = ui.gameFileView->model();
|
|
|
|
|
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
|
|
|
|
|
|
|
|
|
if (proxy)
|
|
|
|
@ -122,16 +244,37 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
|
|
|
|
|
if (proxy)
|
|
|
|
|
proxy->setDynamicSortFilter(true);
|
|
|
|
|
|
|
|
|
|
emit signalGameFileChanged(true);
|
|
|
|
|
slotUpdateCreateButton(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
QAbstractItemModel *const model = addonView->model();
|
|
|
|
|
//QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
|
|
|
|
QAbstractItemModel *const model = ui.addonView->model();
|
|
|
|
|
|
|
|
|
|
if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked)
|
|
|
|
|
model->setData(index, Qt::Checked, Qt::CheckStateRole);
|
|
|
|
|
else
|
|
|
|
|
model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotUpdateOpenButton(const QStringList &items)
|
|
|
|
|
{
|
|
|
|
|
QPushButton *openButton = ui.projectButtonBox->button(QDialogButtonBox::Open);
|
|
|
|
|
|
|
|
|
|
if (!openButton)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
openButton->setEnabled(!items.isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotUpdateCreateButton(bool)
|
|
|
|
|
{
|
|
|
|
|
//enable only if a game file is selected and the adjuster widget is non-empty
|
|
|
|
|
bool validGameFile = (ui.gameFileView->currentIndex() != -1);
|
|
|
|
|
bool validFilename = false;
|
|
|
|
|
|
|
|
|
|
if (mAdjusterWidget)
|
|
|
|
|
validFilename = mAdjusterWidget->isValid();
|
|
|
|
|
|
|
|
|
|
ui.projectCreateButton->setEnabled(validGameFile && validFilename);
|
|
|
|
|
}
|
|
|
|
|