mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Implemented ContentSelector as a singleton "charm" modifier for
FileDialog...
This commit is contained in:
parent
3b40192e90
commit
24b167b755
@ -29,8 +29,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
|
|||||||
, mLauncherSettings(launcherSettings)
|
, mLauncherSettings(launcherSettings)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
// mContentSelector.setParent(parent);
|
/*
|
||||||
|
|
||||||
// QMetaObject::connectSlotsByName(this);
|
// QMetaObject::connectSlotsByName(this);
|
||||||
|
|
||||||
projectGroupBox->hide();
|
projectGroupBox->hide();
|
||||||
@ -52,7 +51,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
|
|||||||
setupDataFiles();
|
setupDataFiles();
|
||||||
|
|
||||||
|
|
||||||
updateViews();
|
updateViews();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::buildContentModel()
|
void DataFilesPage::buildContentModel()
|
||||||
@ -112,10 +111,10 @@ void DataFilesPage::updateViews()
|
|||||||
|
|
||||||
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
|
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
|
||||||
{
|
{
|
||||||
mContentModel->addFiles(path);
|
// mContentModel->addFiles(path);
|
||||||
//mContentModel->sort(3); // Sort by date accessed
|
//mContentModel->sort(3); // Sort by date accessed
|
||||||
gameFileView->setCurrentIndex(-1);
|
// ui.gameFileView->setCurrentIndex(-1);
|
||||||
mContentModel->uncheckAll();
|
// mContentModel->uncheckAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::createActions()
|
void DataFilesPage::createActions()
|
||||||
|
@ -123,37 +123,34 @@ void CS::Editor::loadDocument()
|
|||||||
void CS::Editor::openFiles()
|
void CS::Editor::openFiles()
|
||||||
{
|
{
|
||||||
std::vector<boost::filesystem::path> files;
|
std::vector<boost::filesystem::path> files;
|
||||||
QStringList paths = mFileDialog.checkedItemsPaths();
|
|
||||||
|
|
||||||
foreach (const QString &path, paths) {
|
foreach (const QString &path, mFileDialog.selectedFilepaths()) {
|
||||||
files.push_back(path.toStdString());
|
files.push_back(path.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \todo Get the save path from the file dialogue
|
/// \todo Get the save path from the file dialogue
|
||||||
|
|
||||||
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), false);
|
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), false);
|
||||||
|
|
||||||
mViewManager.addView (document);
|
mViewManager.addView (document);
|
||||||
mFileDialog.hide();
|
mFileDialog.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::createNewFile()
|
void CS::Editor::createNewFile()
|
||||||
{
|
{
|
||||||
std::vector<boost::filesystem::path> files;
|
std::vector<boost::filesystem::path> files;
|
||||||
QStringList paths = mFileDialog.checkedItemsPaths();
|
|
||||||
|
|
||||||
foreach (const QString &path, paths) {
|
foreach (const QString &path, mFileDialog.selectedFilepaths()) {
|
||||||
files.push_back(path.toStdString());
|
files.push_back(path.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
files.push_back(mFileDialog.fileName().toStdString());
|
files.push_back(mFileDialog.filename().toStdString());
|
||||||
|
|
||||||
/// \todo Get the save path from the file dialogue.
|
/// \todo Get the save path from the file dialogue.
|
||||||
|
|
||||||
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), true);
|
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), true);
|
||||||
|
|
||||||
mViewManager.addView (document);
|
mViewManager.addView (document);
|
||||||
mFileDialog.hide();
|
mFileDialog.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::createNewGame (const boost::filesystem::path& file)
|
void CS::Editor::createNewGame (const boost::filesystem::path& file)
|
||||||
|
@ -10,107 +10,76 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QGridLayout>
|
||||||
|
|
||||||
#include <components/contentselector/model/esmfile.hpp>
|
#include <components/contentselector/model/esmfile.hpp>
|
||||||
#include <components/contentselector/view/lineedit.hpp>
|
#include <components/contentselector/view/lineedit.hpp>
|
||||||
|
#include "components/contentselector/view/contentselector.hpp"
|
||||||
#include "filewidget.hpp"
|
|
||||||
#include "adjusterwidget.hpp"
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
CSVDoc::FileDialog::FileDialog(QWidget *parent) :
|
CSVDoc::FileDialog::FileDialog(QWidget *parent) :
|
||||||
ContentSelector(parent),
|
QDialog(parent),
|
||||||
mFileWidget (new FileWidget (this)),
|
mOpenFileFlags (ContentSelectorView::Flag_Content | ContentSelectorView::Flag_LoadAddon),
|
||||||
mAdjusterWidget (new AdjusterWidget (this)),
|
mNewFileFlags (ContentSelectorView::Flag_Content | ContentSelectorView::Flag_NewAddon)
|
||||||
mEnable_1(false),
|
|
||||||
mEnable_2(false)
|
|
||||||
{
|
|
||||||
// Hide the profile elements
|
|
||||||
profileGroupBox->hide();
|
|
||||||
addonView->showColumn(2);
|
|
||||||
|
|
||||||
|
{
|
||||||
resize(400, 400);
|
resize(400, 400);
|
||||||
|
|
||||||
mFileWidget->setType(true);
|
|
||||||
mFileWidget->extensionLabelIsVisible(false);
|
|
||||||
|
|
||||||
connect(projectCreateButton, SIGNAL(clicked()), this, SIGNAL(createNewFile()));
|
|
||||||
|
|
||||||
connect(projectButtonBox, SIGNAL(accepted()), this, SIGNAL(openFiles()));
|
|
||||||
connect(projectButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
||||||
|
|
||||||
connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)),
|
|
||||||
mAdjusterWidget, SLOT (setName (const QString&, bool)));
|
|
||||||
|
|
||||||
connect (mAdjusterWidget, SIGNAL (stateChanged (bool)), this, SLOT (slotAdjusterChanged(bool)));
|
|
||||||
connect (this, SIGNAL (signalGameFileChanged(int)), this, SLOT (slotGameFileSelected(int)));
|
|
||||||
connect (this, SIGNAL (signalUpdateCreateButton(bool, int)), this, SLOT (slotEnableCreateButton(bool, int)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::FileDialog::updateOpenButton(const QStringList &items)
|
void CSVDoc::FileDialog::addFiles(const QString &path)
|
||||||
{
|
{
|
||||||
QPushButton *openButton = projectButtonBox->button(QDialogButtonBox::Open);
|
ContentSelectorView::ContentSelector::addFiles(path);
|
||||||
|
|
||||||
if (!openButton)
|
|
||||||
return;
|
|
||||||
|
|
||||||
openButton->setEnabled(!items.isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::FileDialog::slotEnableCreateButton(bool enable, int widgetNumber)
|
QString CSVDoc::FileDialog::filename()
|
||||||
{
|
{
|
||||||
|
return ContentSelectorView::ContentSelector::instance().filename();
|
||||||
if (widgetNumber == 1)
|
|
||||||
mEnable_1 = enable;
|
|
||||||
|
|
||||||
if (widgetNumber == 2)
|
|
||||||
mEnable_2 = enable;
|
|
||||||
|
|
||||||
projectCreateButton->setEnabled(mEnable_1 && mEnable_2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CSVDoc::FileDialog::fileName()
|
QStringList CSVDoc::FileDialog::selectedFilepaths()
|
||||||
{
|
{
|
||||||
return mFileWidget->getName();
|
return ContentSelectorView::ContentSelector::instance().selectedFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::FileDialog::showDialog()
|
||||||
|
{
|
||||||
|
show();
|
||||||
|
raise();
|
||||||
|
activateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::FileDialog::openFile()
|
void CSVDoc::FileDialog::openFile()
|
||||||
{
|
{
|
||||||
setWindowTitle(tr("Open"));
|
setWindowTitle(tr("Open"));
|
||||||
|
|
||||||
mFileWidget->hide();
|
ContentSelectorView::ContentSelector::configure(this, mOpenFileFlags);
|
||||||
adjusterWidgetFrame->hide();
|
|
||||||
projectCreateButton->hide();
|
|
||||||
projectGroupBox->setTitle(tr(""));
|
|
||||||
projectButtonBox->button(QDialogButtonBox::Open)->setEnabled(false);
|
|
||||||
|
|
||||||
show();
|
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||||
raise();
|
SIGNAL (accepted()), this, SIGNAL (openFiles()));
|
||||||
activateWindow();
|
|
||||||
|
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||||
|
SIGNAL (rejected()), this, SLOT (slotRejected()));
|
||||||
|
|
||||||
|
showDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::FileDialog::newFile()
|
void CSVDoc::FileDialog::newFile()
|
||||||
{
|
{
|
||||||
setWindowTitle(tr("New"));
|
setWindowTitle(tr("New"));
|
||||||
|
|
||||||
fileWidgetFrame->layout()->addWidget(mFileWidget);
|
ContentSelectorView::ContentSelector::configure(this, mNewFileFlags);
|
||||||
adjusterWidgetFrame->layout()->addWidget(mAdjusterWidget);
|
|
||||||
|
|
||||||
projectButtonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||||
projectButtonBox->addButton(projectCreateButton, QDialogButtonBox::ActionRole);
|
SIGNAL (accepted()), this, SIGNAL (createNewFile()));
|
||||||
|
|
||||||
show();
|
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||||
raise();
|
SIGNAL (rejected()), this, SLOT (slotRejected()));
|
||||||
activateWindow();
|
|
||||||
|
showDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::FileDialog::slotAdjusterChanged(bool value)
|
void CSVDoc::FileDialog::slotRejected()
|
||||||
{
|
{
|
||||||
emit signalUpdateCreateButton(mAdjusterWidget->isValid(), 2);
|
close();
|
||||||
}
|
|
||||||
|
|
||||||
void CSVDoc::FileDialog::slotGameFileSelected(int value)
|
|
||||||
{
|
|
||||||
emit signalUpdateCreateButton(value > -1, 1);
|
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
#include "../../../../components/contentselector/view/contentselector.hpp"
|
||||||
#include "components/contentselector/view/contentselector.hpp"
|
|
||||||
#include "ui_datafilespage.h"
|
|
||||||
|
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
@ -19,6 +17,8 @@ class QLabel;
|
|||||||
class DataFilesModel;
|
class DataFilesModel;
|
||||||
class PluginsProxyModel;
|
class PluginsProxyModel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace ContentSelectorView
|
namespace ContentSelectorView
|
||||||
{
|
{
|
||||||
class LineEdit;
|
class LineEdit;
|
||||||
@ -26,42 +26,38 @@ namespace ContentSelectorView
|
|||||||
|
|
||||||
namespace CSVDoc
|
namespace CSVDoc
|
||||||
{
|
{
|
||||||
class FileWidget;
|
class FileDialog : public QDialog
|
||||||
class AdjusterWidget;
|
|
||||||
|
|
||||||
class FileDialog : public ContentSelectorView::ContentSelector
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
FileWidget *mFileWidget;
|
unsigned char mOpenFileFlags;
|
||||||
AdjusterWidget *mAdjusterWidget;
|
unsigned char mNewFileFlags;
|
||||||
|
|
||||||
bool mEnable_1;
|
|
||||||
bool mEnable_2;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FileDialog(QWidget *parent = 0);
|
explicit FileDialog(QWidget *parent = 0);
|
||||||
|
|
||||||
void openFile();
|
void openFile();
|
||||||
void newFile();
|
void newFile();
|
||||||
|
void addFiles (const QString &path);
|
||||||
|
|
||||||
QString fileName();
|
QString filename();
|
||||||
|
QStringList selectedFilepaths();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void showDialog();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void openFiles();
|
void openFiles();
|
||||||
void createNewFile();
|
void createNewFile();
|
||||||
|
|
||||||
void signalUpdateCreateButton (bool, int);
|
|
||||||
void signalUpdateCreateButtonFlags(int);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
void slotRejected();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//void updateViews();
|
|
||||||
void updateOpenButton(const QStringList &items);
|
|
||||||
void slotEnableCreateButton(bool enable, int widgetNumber);
|
|
||||||
void slotAdjusterChanged(bool value);
|
|
||||||
void slotGameFileSelected(int value);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // FILEDIALOG_HPP
|
#endif // FILEDIALOG_HPP
|
||||||
|
@ -8,83 +8,205 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent) :
|
#include "../../../apps/opencs/view/doc/filewidget.hpp"
|
||||||
QDialog(parent)
|
#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)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
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)
|
||||||
|
{
|
||||||
|
ui.setupUi (this);
|
||||||
|
|
||||||
|
parent->setLayout(new QGridLayout());
|
||||||
|
parent->layout()->addWidget(this);
|
||||||
|
|
||||||
buildContentModel();
|
buildContentModel();
|
||||||
buildGameFileView();
|
buildGameFileView();
|
||||||
buildAddonView();
|
buildAddonView();
|
||||||
buildProfilesView();
|
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()
|
void ContentSelectorView::ContentSelector::buildContentModel()
|
||||||
{
|
{
|
||||||
|
if (!isFlagged (Flag_Content))
|
||||||
|
return;
|
||||||
|
|
||||||
mContentModel = new ContentSelectorModel::ContentModel();
|
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()
|
void ContentSelectorView::ContentSelector::buildGameFileView()
|
||||||
{
|
{
|
||||||
|
if (!isFlagged (Flag_Content))
|
||||||
|
{
|
||||||
|
ui.gameFileView->setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mGameFileProxyModel = new QSortFilterProxyModel(this);
|
mGameFileProxyModel = new QSortFilterProxyModel(this);
|
||||||
mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile));
|
mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile));
|
||||||
mGameFileProxyModel->setFilterRole (Qt::UserRole);
|
mGameFileProxyModel->setFilterRole (Qt::UserRole);
|
||||||
mGameFileProxyModel->setSourceModel (mContentModel);
|
mGameFileProxyModel->setSourceModel (mContentModel);
|
||||||
|
|
||||||
gameFileView->setPlaceholderText(QString("Select a game file..."));
|
ui.gameFileView->setPlaceholderText(QString("Select a game file..."));
|
||||||
gameFileView->setModel(mGameFileProxyModel);
|
ui.gameFileView->setModel(mGameFileProxyModel);
|
||||||
|
|
||||||
connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentGameFileIndexChanged(int)));
|
connect(ui.gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT (slotCurrentGameFileIndexChanged(int)));
|
||||||
connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SIGNAL(signalGameFileChanged(int)));
|
|
||||||
|
|
||||||
gameFileView->setCurrentIndex(-1);
|
ui.gameFileView->setCurrentIndex(-1);
|
||||||
gameFileView->setCurrentIndex(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentSelectorView::ContentSelector::buildAddonView()
|
void ContentSelectorView::ContentSelector::buildAddonView()
|
||||||
{
|
{
|
||||||
|
if (!isFlagged (Flag_Content))
|
||||||
|
{
|
||||||
|
ui.addonView->setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mAddonProxyModel = new QSortFilterProxyModel(this);
|
mAddonProxyModel = new QSortFilterProxyModel(this);
|
||||||
mAddonProxyModel->setFilterRegExp (QString::number((int)ContentSelectorModel::ContentType_Addon));
|
mAddonProxyModel->setFilterRegExp (QString::number((int)ContentSelectorModel::ContentType_Addon));
|
||||||
mAddonProxyModel->setFilterRole (Qt::UserRole);
|
mAddonProxyModel->setFilterRole (Qt::UserRole);
|
||||||
mAddonProxyModel->setDynamicSortFilter (true);
|
mAddonProxyModel->setDynamicSortFilter (true);
|
||||||
mAddonProxyModel->setSourceModel (mContentModel);
|
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()
|
void ContentSelectorView::ContentSelector::buildProfilesView()
|
||||||
{
|
{
|
||||||
profilesComboBox->setPlaceholderText(QString("Select a profile..."));
|
if (!isFlagged (Flag_Profile))
|
||||||
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
|
{
|
||||||
|
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::updateViews()
|
void ContentSelectorView::ContentSelector::buildLoadAddonView()
|
||||||
{
|
{
|
||||||
// Ensure the columns are hidden because sort() re-enables them
|
if (!isFlagged (Flag_LoadAddon))
|
||||||
addonView->setColumnHidden(1, true);
|
{
|
||||||
addonView->setColumnHidden(2, true);
|
ui.projectGroupBox->setVisible (false);
|
||||||
addonView->setColumnHidden(3, true);
|
return;
|
||||||
addonView->setColumnHidden(4, true);
|
}
|
||||||
addonView->setColumnHidden(5, true);
|
|
||||||
addonView->setColumnHidden(6, true);
|
ui.projectCreateButton->setVisible (false);
|
||||||
addonView->setColumnHidden(7, true);
|
// ui.projectButtonBox->setStandardButtons(QDialogButtonBox::Open | QDialogButtonBox::Cancel);
|
||||||
addonView->setColumnHidden(8, true);
|
ui.projectGroupBox->setTitle ("");
|
||||||
addonView->resizeColumnsToContents();
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList ContentSelectorView::ContentSelector::selectedFiles() const
|
||||||
|
{
|
||||||
|
QStringList filePaths;
|
||||||
|
|
||||||
|
if (mContentModel)
|
||||||
|
{
|
||||||
|
foreach (ContentSelectorModel::EsmFile *file, mContentModel->checkedItems())
|
||||||
|
filePaths.append(file->path());
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
|
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
|
||||||
{
|
{
|
||||||
mContentModel->addFiles(path);
|
// if the model hasn't been instantiated, queue the path
|
||||||
//mContentModel->sort(3); // Sort by date accessed
|
if (!mInstance)
|
||||||
gameFileView->setCurrentIndex(-1);
|
mFilePaths.append(path);
|
||||||
mContentModel->uncheckAll();
|
else
|
||||||
|
{
|
||||||
|
mInstance->mContentModel->addFiles(path);
|
||||||
|
mInstance->ui.gameFileView->setCurrentIndex(-1);
|
||||||
|
mInstance->mContentModel->uncheckAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
|
QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
|
||||||
@ -99,14 +221,14 @@ QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
|
|||||||
|
|
||||||
void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index)
|
void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index)
|
||||||
{
|
{
|
||||||
emit profileChanged(index);
|
emit signalProfileChanged(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int index)
|
void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int index)
|
||||||
{
|
{
|
||||||
static int oldIndex = -1;
|
static int oldIndex = -1;
|
||||||
|
|
||||||
QAbstractItemModel *const model = gameFileView->model();
|
QAbstractItemModel *const model = ui.gameFileView->model();
|
||||||
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
||||||
|
|
||||||
if (proxy)
|
if (proxy)
|
||||||
@ -122,16 +244,37 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
|
|||||||
if (proxy)
|
if (proxy)
|
||||||
proxy->setDynamicSortFilter(true);
|
proxy->setDynamicSortFilter(true);
|
||||||
|
|
||||||
emit signalGameFileChanged(true);
|
slotUpdateCreateButton(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index)
|
void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
QAbstractItemModel *const model = addonView->model();
|
QAbstractItemModel *const model = ui.addonView->model();
|
||||||
//QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
|
||||||
|
|
||||||
if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked)
|
if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked)
|
||||||
model->setData(index, Qt::Checked, Qt::CheckStateRole);
|
model->setData(index, Qt::Checked, Qt::CheckStateRole);
|
||||||
else
|
else
|
||||||
model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
|
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);
|
||||||
|
}
|
||||||
|
@ -9,12 +9,33 @@ namespace ContentSelectorModel { class ContentModel; }
|
|||||||
|
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
|
||||||
|
namespace CSVDoc
|
||||||
|
{
|
||||||
|
class FileWidget;
|
||||||
|
class AdjusterWidget;
|
||||||
|
}
|
||||||
namespace ContentSelectorView
|
namespace ContentSelectorView
|
||||||
{
|
{
|
||||||
class ContentSelector : public QDialog, protected Ui::DataFilesPage
|
enum SelectorFlags
|
||||||
|
{
|
||||||
|
Flag_Content = 0x01, // gamefile combobox & addon list view
|
||||||
|
Flag_NewAddon = 0x02, // enable project button box (Create/Cancel) and file/adjuster widgets
|
||||||
|
Flag_LoadAddon = 0x04, // enable project button box (Open/Cancel)
|
||||||
|
Flag_Profile = 0x08 // enable profile combo box
|
||||||
|
};
|
||||||
|
|
||||||
|
class ContentSelector : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
unsigned char mFlags;
|
||||||
|
|
||||||
|
static ContentSelector *mInstance;
|
||||||
|
static QStringList mFilePaths;
|
||||||
|
|
||||||
|
CSVDoc::FileWidget *mFileWidget;
|
||||||
|
CSVDoc::AdjusterWidget *mAdjusterWidget;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
ContentSelectorModel::ContentModel *mContentModel;
|
ContentSelectorModel::ContentModel *mContentModel;
|
||||||
@ -23,30 +44,46 @@ namespace ContentSelectorView
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit ContentSelector(QWidget *parent = 0);
|
static void configure(QWidget *subject, unsigned char flags = Flag_Content);
|
||||||
|
static ContentSelector &instance();
|
||||||
|
static void addFiles(const QString &path);
|
||||||
|
|
||||||
static ContentSelector &cast(QWidget *subject); //static constructor function for singleton performance.
|
|
||||||
|
|
||||||
void addFiles(const QString &path);
|
|
||||||
void setCheckState(QModelIndex index, QSortFilterProxyModel *model);
|
void setCheckState(QModelIndex index, QSortFilterProxyModel *model);
|
||||||
QStringList checkedItemsPaths();
|
QStringList checkedItemsPaths();
|
||||||
|
QString filename() const;
|
||||||
|
QStringList selectedFiles() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
explicit ContentSelector(QWidget *parent = 0, unsigned char flags = Flag_Content);
|
||||||
|
Ui::DataFilesPage ui;
|
||||||
|
|
||||||
void buildContentModel();
|
void buildContentModel();
|
||||||
void buildGameFileView();
|
void buildGameFileView();
|
||||||
void buildAddonView();
|
void buildAddonView();
|
||||||
void buildProfilesView();
|
void buildProfilesView();
|
||||||
|
void buildNewAddonView();
|
||||||
|
void buildLoadAddonView();
|
||||||
|
|
||||||
|
bool isFlagged(SelectorFlags flag) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void profileChanged(int index);
|
void accepted();
|
||||||
|
void rejected();
|
||||||
|
|
||||||
|
void signalProfileChanged(int index);
|
||||||
void signalGameFileChanged(int value);
|
void signalGameFileChanged(int value);
|
||||||
|
|
||||||
|
void signalCreateButtonClicked();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateViews();
|
|
||||||
void slotCurrentProfileIndexChanged(int index);
|
void slotCurrentProfileIndexChanged(int index);
|
||||||
void slotCurrentGameFileIndexChanged(int index);
|
void slotCurrentGameFileIndexChanged(int index);
|
||||||
void slotAddonTableItemClicked(const QModelIndex &index);
|
void slotAddonTableItemClicked(const QModelIndex &index);
|
||||||
|
|
||||||
|
void slotUpdateCreateButton (bool);
|
||||||
|
void slotUpdateOpenButton(const QStringList &items);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user