mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +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)
|
||||
{
|
||||
setupUi(this);
|
||||
// mContentSelector.setParent(parent);
|
||||
|
||||
/*
|
||||
// QMetaObject::connectSlotsByName(this);
|
||||
|
||||
projectGroupBox->hide();
|
||||
@ -52,7 +51,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
|
||||
setupDataFiles();
|
||||
|
||||
|
||||
updateViews();
|
||||
updateViews();*/
|
||||
}
|
||||
|
||||
void DataFilesPage::buildContentModel()
|
||||
@ -112,10 +111,10 @@ void DataFilesPage::updateViews()
|
||||
|
||||
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
|
||||
{
|
||||
mContentModel->addFiles(path);
|
||||
// mContentModel->addFiles(path);
|
||||
//mContentModel->sort(3); // Sort by date accessed
|
||||
gameFileView->setCurrentIndex(-1);
|
||||
mContentModel->uncheckAll();
|
||||
// ui.gameFileView->setCurrentIndex(-1);
|
||||
// mContentModel->uncheckAll();
|
||||
}
|
||||
|
||||
void DataFilesPage::createActions()
|
||||
|
@ -123,37 +123,34 @@ void CS::Editor::loadDocument()
|
||||
void CS::Editor::openFiles()
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
/// \todo Get the save path from the file dialogue
|
||||
|
||||
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), false);
|
||||
|
||||
mViewManager.addView (document);
|
||||
mFileDialog.hide();
|
||||
mFileDialog.close();
|
||||
}
|
||||
|
||||
void CS::Editor::createNewFile()
|
||||
{
|
||||
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(mFileDialog.fileName().toStdString());
|
||||
files.push_back(mFileDialog.filename().toStdString());
|
||||
|
||||
/// \todo Get the save path from the file dialogue.
|
||||
|
||||
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), true);
|
||||
|
||||
mViewManager.addView (document);
|
||||
mFileDialog.hide();
|
||||
mFileDialog.close();
|
||||
}
|
||||
|
||||
void CS::Editor::createNewGame (const boost::filesystem::path& file)
|
||||
|
@ -10,107 +10,76 @@
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QGroupBox>
|
||||
#include <QGridLayout>
|
||||
|
||||
#include <components/contentselector/model/esmfile.hpp>
|
||||
#include <components/contentselector/view/lineedit.hpp>
|
||||
|
||||
#include "filewidget.hpp"
|
||||
#include "adjusterwidget.hpp"
|
||||
#include "components/contentselector/view/contentselector.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
CSVDoc::FileDialog::FileDialog(QWidget *parent) :
|
||||
ContentSelector(parent),
|
||||
mFileWidget (new FileWidget (this)),
|
||||
mAdjusterWidget (new AdjusterWidget (this)),
|
||||
mEnable_1(false),
|
||||
mEnable_2(false)
|
||||
{
|
||||
// Hide the profile elements
|
||||
profileGroupBox->hide();
|
||||
addonView->showColumn(2);
|
||||
QDialog(parent),
|
||||
mOpenFileFlags (ContentSelectorView::Flag_Content | ContentSelectorView::Flag_LoadAddon),
|
||||
mNewFileFlags (ContentSelectorView::Flag_Content | ContentSelectorView::Flag_NewAddon)
|
||||
|
||||
{
|
||||
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);
|
||||
|
||||
if (!openButton)
|
||||
return;
|
||||
|
||||
openButton->setEnabled(!items.isEmpty());
|
||||
ContentSelectorView::ContentSelector::addFiles(path);
|
||||
}
|
||||
|
||||
void CSVDoc::FileDialog::slotEnableCreateButton(bool enable, int widgetNumber)
|
||||
QString CSVDoc::FileDialog::filename()
|
||||
{
|
||||
|
||||
if (widgetNumber == 1)
|
||||
mEnable_1 = enable;
|
||||
|
||||
if (widgetNumber == 2)
|
||||
mEnable_2 = enable;
|
||||
|
||||
projectCreateButton->setEnabled(mEnable_1 && mEnable_2);
|
||||
return ContentSelectorView::ContentSelector::instance().filename();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
setWindowTitle(tr("Open"));
|
||||
|
||||
mFileWidget->hide();
|
||||
adjusterWidgetFrame->hide();
|
||||
projectCreateButton->hide();
|
||||
projectGroupBox->setTitle(tr(""));
|
||||
projectButtonBox->button(QDialogButtonBox::Open)->setEnabled(false);
|
||||
ContentSelectorView::ContentSelector::configure(this, mOpenFileFlags);
|
||||
|
||||
show();
|
||||
raise();
|
||||
activateWindow();
|
||||
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||
SIGNAL (accepted()), this, SIGNAL (openFiles()));
|
||||
|
||||
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||
SIGNAL (rejected()), this, SLOT (slotRejected()));
|
||||
|
||||
showDialog();
|
||||
}
|
||||
|
||||
void CSVDoc::FileDialog::newFile()
|
||||
{
|
||||
setWindowTitle(tr("New"));
|
||||
|
||||
fileWidgetFrame->layout()->addWidget(mFileWidget);
|
||||
adjusterWidgetFrame->layout()->addWidget(mAdjusterWidget);
|
||||
ContentSelectorView::ContentSelector::configure(this, mNewFileFlags);
|
||||
|
||||
projectButtonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
||||
projectButtonBox->addButton(projectCreateButton, QDialogButtonBox::ActionRole);
|
||||
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||
SIGNAL (accepted()), this, SIGNAL (createNewFile()));
|
||||
|
||||
show();
|
||||
raise();
|
||||
activateWindow();
|
||||
connect (&ContentSelectorView::ContentSelector::instance(),
|
||||
SIGNAL (rejected()), this, SLOT (slotRejected()));
|
||||
|
||||
showDialog();
|
||||
}
|
||||
|
||||
void CSVDoc::FileDialog::slotAdjusterChanged(bool value)
|
||||
void CSVDoc::FileDialog::slotRejected()
|
||||
{
|
||||
emit signalUpdateCreateButton(mAdjusterWidget->isValid(), 2);
|
||||
}
|
||||
|
||||
void CSVDoc::FileDialog::slotGameFileSelected(int value)
|
||||
{
|
||||
emit signalUpdateCreateButton(value > -1, 1);
|
||||
close();
|
||||
}
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include "components/contentselector/view/contentselector.hpp"
|
||||
#include "ui_datafilespage.h"
|
||||
#include "../../../../components/contentselector/view/contentselector.hpp"
|
||||
|
||||
class QDialogButtonBox;
|
||||
class QSortFilterProxyModel;
|
||||
@ -19,6 +17,8 @@ class QLabel;
|
||||
class DataFilesModel;
|
||||
class PluginsProxyModel;
|
||||
|
||||
|
||||
|
||||
namespace ContentSelectorView
|
||||
{
|
||||
class LineEdit;
|
||||
@ -26,42 +26,38 @@ namespace ContentSelectorView
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class FileWidget;
|
||||
class AdjusterWidget;
|
||||
|
||||
class FileDialog : public ContentSelectorView::ContentSelector
|
||||
class FileDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
FileWidget *mFileWidget;
|
||||
AdjusterWidget *mAdjusterWidget;
|
||||
|
||||
bool mEnable_1;
|
||||
bool mEnable_2;
|
||||
unsigned char mOpenFileFlags;
|
||||
unsigned char mNewFileFlags;
|
||||
|
||||
public:
|
||||
explicit FileDialog(QWidget *parent = 0);
|
||||
|
||||
void openFile();
|
||||
void newFile();
|
||||
void addFiles (const QString &path);
|
||||
|
||||
QString fileName();
|
||||
QString filename();
|
||||
QStringList selectedFilepaths();
|
||||
|
||||
private:
|
||||
|
||||
void showDialog();
|
||||
|
||||
signals:
|
||||
|
||||
void openFiles();
|
||||
void createNewFile();
|
||||
|
||||
void signalUpdateCreateButton (bool, int);
|
||||
void signalUpdateCreateButtonFlags(int);
|
||||
|
||||
public slots:
|
||||
|
||||
void slotRejected();
|
||||
|
||||
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
|
||||
|
@ -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)
|
||||
{
|
||||
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();
|
||||
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::updateViews()
|
||||
void ContentSelectorView::ContentSelector::buildLoadAddonView()
|
||||
{
|
||||
// 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();
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -9,12 +9,33 @@ namespace ContentSelectorModel { class ContentModel; }
|
||||
|
||||
class QSortFilterProxyModel;
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class FileWidget;
|
||||
class AdjusterWidget;
|
||||
}
|
||||
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
|
||||
|
||||
unsigned char mFlags;
|
||||
|
||||
static ContentSelector *mInstance;
|
||||
static QStringList mFilePaths;
|
||||
|
||||
CSVDoc::FileWidget *mFileWidget;
|
||||
CSVDoc::AdjusterWidget *mAdjusterWidget;
|
||||
|
||||
protected:
|
||||
|
||||
ContentSelectorModel::ContentModel *mContentModel;
|
||||
@ -23,30 +44,46 @@ namespace ContentSelectorView
|
||||
|
||||
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);
|
||||
QStringList checkedItemsPaths();
|
||||
QString filename() const;
|
||||
QStringList selectedFiles() const;
|
||||
|
||||
private:
|
||||
|
||||
explicit ContentSelector(QWidget *parent = 0, unsigned char flags = Flag_Content);
|
||||
Ui::DataFilesPage ui;
|
||||
|
||||
void buildContentModel();
|
||||
void buildGameFileView();
|
||||
void buildAddonView();
|
||||
void buildProfilesView();
|
||||
void buildNewAddonView();
|
||||
void buildLoadAddonView();
|
||||
|
||||
bool isFlagged(SelectorFlags flag) const;
|
||||
|
||||
signals:
|
||||
void profileChanged(int index);
|
||||
void accepted();
|
||||
void rejected();
|
||||
|
||||
void signalProfileChanged(int index);
|
||||
void signalGameFileChanged(int value);
|
||||
|
||||
void signalCreateButtonClicked();
|
||||
|
||||
private slots:
|
||||
void updateViews();
|
||||
|
||||
void slotCurrentProfileIndexChanged(int index);
|
||||
void slotCurrentGameFileIndexChanged(int index);
|
||||
void slotAddonTableItemClicked(const QModelIndex &index);
|
||||
|
||||
void slotUpdateCreateButton (bool);
|
||||
void slotUpdateOpenButton(const QStringList &items);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user