Implemented a file dialog for the editor using launcher .ui
@ -1,21 +0,0 @@
|
|||||||
<!DOCTYPE RCC><RCC version="1.0">
|
|
||||||
<qresource prefix="/images">
|
|
||||||
<file alias="clear.png">resources/images/clear.png</file>
|
|
||||||
<file alias="down.png">resources/images/down.png</file>
|
|
||||||
<file alias="openmw.png">resources/images/openmw.png</file>
|
|
||||||
<file alias="openmw-plugin.png">resources/images/openmw-plugin.png</file>
|
|
||||||
<file alias="openmw-header.png">resources/images/openmw-header.png</file>
|
|
||||||
<file alias="playpage-background.png">resources/images/playpage-background.png</file>
|
|
||||||
</qresource>
|
|
||||||
<qresource prefix="icons/tango">
|
|
||||||
<file alias="index.theme">resources/icons/tango/index.theme</file>
|
|
||||||
<file alias="video-display.png">resources/icons/tango/video-display.png</file>
|
|
||||||
<file alias="16x16/document-new.png">resources/icons/tango/document-new.png</file>
|
|
||||||
<file alias="16x16/edit-copy.png">resources/icons/tango/edit-copy.png</file>
|
|
||||||
<file alias="16x16/edit-delete.png">resources/icons/tango/edit-delete.png</file>
|
|
||||||
<file alias="16x16/go-bottom.png">resources/icons/tango/go-bottom.png</file>
|
|
||||||
<file alias="16x16/go-down.png">resources/icons/tango/go-down.png</file>
|
|
||||||
<file alias="16x16/go-top.png">resources/icons/tango/go-top.png</file>
|
|
||||||
<file alias="16x16/go-up.png">resources/icons/tango/go-up.png</file>
|
|
||||||
</qresource>
|
|
||||||
</RCC>
|
|
@ -0,0 +1,272 @@
|
|||||||
|
#include "filedialog.hpp"
|
||||||
|
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QRegExpValidator>
|
||||||
|
#include <QRegExp>
|
||||||
|
#include <QSpacerItem>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include <components/fileorderlist/model/datafilesmodel.hpp>
|
||||||
|
#include <components/fileorderlist/model/pluginsproxymodel.hpp>
|
||||||
|
#include <components/fileorderlist/model/esm/esmfile.hpp>
|
||||||
|
|
||||||
|
#include <components/fileorderlist/utils/lineedit.hpp>
|
||||||
|
|
||||||
|
FileDialog::FileDialog(QWidget *parent) :
|
||||||
|
QDialog(parent)
|
||||||
|
{
|
||||||
|
setupUi(this);
|
||||||
|
|
||||||
|
// Models
|
||||||
|
mDataFilesModel = new DataFilesModel(this);
|
||||||
|
|
||||||
|
mMastersProxyModel = new QSortFilterProxyModel();
|
||||||
|
mMastersProxyModel->setFilterRegExp(QString("^.*\\.esm"));
|
||||||
|
mMastersProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
mMastersProxyModel->setSourceModel(mDataFilesModel);
|
||||||
|
|
||||||
|
mPluginsProxyModel = new PluginsProxyModel();
|
||||||
|
mPluginsProxyModel->setFilterRegExp(QString("^.*\\.esp"));
|
||||||
|
mPluginsProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
mPluginsProxyModel->setSourceModel(mDataFilesModel);
|
||||||
|
|
||||||
|
mFilterProxyModel = new QSortFilterProxyModel();
|
||||||
|
mFilterProxyModel->setDynamicSortFilter(true);
|
||||||
|
mFilterProxyModel->setSourceModel(mPluginsProxyModel);
|
||||||
|
|
||||||
|
QCheckBox checkBox;
|
||||||
|
unsigned int height = checkBox.sizeHint().height() + 4;
|
||||||
|
|
||||||
|
mastersTable->setModel(mMastersProxyModel);
|
||||||
|
mastersTable->setObjectName("MastersTable");
|
||||||
|
mastersTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
mastersTable->setSortingEnabled(false);
|
||||||
|
mastersTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
mastersTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
mastersTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
mastersTable->setAlternatingRowColors(true);
|
||||||
|
mastersTable->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
|
||||||
|
// Set the row height to the size of the checkboxes
|
||||||
|
mastersTable->verticalHeader()->setDefaultSectionSize(height);
|
||||||
|
mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
|
||||||
|
mastersTable->verticalHeader()->hide();
|
||||||
|
|
||||||
|
pluginsTable->setModel(mFilterProxyModel);
|
||||||
|
pluginsTable->setObjectName("PluginsTable");
|
||||||
|
pluginsTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
pluginsTable->setSortingEnabled(false);
|
||||||
|
pluginsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
pluginsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
pluginsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
pluginsTable->setAlternatingRowColors(true);
|
||||||
|
pluginsTable->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
|
||||||
|
pluginsTable->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
|
||||||
|
pluginsTable->verticalHeader()->setDefaultSectionSize(height);
|
||||||
|
pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
|
||||||
|
|
||||||
|
// Hide the profile elements
|
||||||
|
profileLabel->hide();
|
||||||
|
profilesComboBox->hide();
|
||||||
|
newProfileButton->hide();
|
||||||
|
deleteProfileButton->hide();
|
||||||
|
|
||||||
|
// Add some extra widgets
|
||||||
|
QHBoxLayout *nameLayout = new QHBoxLayout();
|
||||||
|
QSpacerItem *spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||||
|
|
||||||
|
mNameLabel = new QLabel(tr("File Name:"), this);
|
||||||
|
|
||||||
|
QRegExpValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9\\s]*$"));
|
||||||
|
mNameLineEdit = new LineEdit(this);
|
||||||
|
mNameLineEdit->setValidator(validator);
|
||||||
|
|
||||||
|
nameLayout->addSpacerItem(spacer);
|
||||||
|
nameLayout->addWidget(mNameLabel);
|
||||||
|
nameLayout->addWidget(mNameLineEdit);
|
||||||
|
|
||||||
|
mButtonBox = new QDialogButtonBox(this);
|
||||||
|
|
||||||
|
mCreateButton = new QPushButton(tr("Create"), this);
|
||||||
|
mCreateButton->setEnabled(false);
|
||||||
|
|
||||||
|
verticalLayout->addLayout(nameLayout);
|
||||||
|
verticalLayout->addWidget(mButtonBox);
|
||||||
|
|
||||||
|
// Set sizes
|
||||||
|
QList<int> sizeList;
|
||||||
|
sizeList << 175;
|
||||||
|
sizeList << 200;
|
||||||
|
|
||||||
|
splitter->setSizes(sizeList);
|
||||||
|
|
||||||
|
resize(600, 400);
|
||||||
|
|
||||||
|
connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
|
||||||
|
connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList)));
|
||||||
|
connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString)));
|
||||||
|
|
||||||
|
connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
|
||||||
|
|
||||||
|
connect(pluginsTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
|
||||||
|
connect(mastersTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
|
||||||
|
|
||||||
|
connect(mCreateButton, SIGNAL(clicked()), this, SLOT(createButtonClicked()));
|
||||||
|
|
||||||
|
connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
|
connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::updateViews()
|
||||||
|
{
|
||||||
|
// Ensure the columns are hidden because sort() re-enables them
|
||||||
|
mastersTable->setColumnHidden(1, true);
|
||||||
|
mastersTable->setColumnHidden(3, true);
|
||||||
|
mastersTable->setColumnHidden(4, true);
|
||||||
|
mastersTable->setColumnHidden(5, true);
|
||||||
|
mastersTable->setColumnHidden(6, true);
|
||||||
|
mastersTable->setColumnHidden(7, true);
|
||||||
|
mastersTable->setColumnHidden(8, true);
|
||||||
|
mastersTable->resizeColumnsToContents();
|
||||||
|
|
||||||
|
pluginsTable->setColumnHidden(1, true);
|
||||||
|
pluginsTable->setColumnHidden(3, true);
|
||||||
|
pluginsTable->setColumnHidden(4, true);
|
||||||
|
pluginsTable->setColumnHidden(5, true);
|
||||||
|
pluginsTable->setColumnHidden(6, true);
|
||||||
|
pluginsTable->setColumnHidden(7, true);
|
||||||
|
pluginsTable->setColumnHidden(8, true);
|
||||||
|
pluginsTable->resizeColumnsToContents();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::updateOpenButton(const QStringList &items)
|
||||||
|
{
|
||||||
|
QPushButton *openButton = mButtonBox->button(QDialogButtonBox::Open);
|
||||||
|
|
||||||
|
if (!openButton)
|
||||||
|
return;
|
||||||
|
|
||||||
|
openButton->setEnabled(!items.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::updateCreateButton(const QString &name)
|
||||||
|
{
|
||||||
|
if (!mCreateButton->isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
mCreateButton->setEnabled(!name.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::filterChanged(const QString &filter)
|
||||||
|
{
|
||||||
|
QRegExp filterRe(filter, Qt::CaseInsensitive, QRegExp::FixedString);
|
||||||
|
mFilterProxyModel->setFilterRegExp(filterRe);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::addFiles(const QString &path)
|
||||||
|
{
|
||||||
|
mDataFilesModel->addFiles(path);
|
||||||
|
mDataFilesModel->sort(3); // Sort by date accessed
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::setEncoding(const QString &encoding)
|
||||||
|
{
|
||||||
|
mDataFilesModel->setEncoding(encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::setCheckState(QModelIndex index)
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QObject *object = QObject::sender();
|
||||||
|
|
||||||
|
// Not a signal-slot call
|
||||||
|
if (!object)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
if (object->objectName() == QLatin1String("PluginsTable")) {
|
||||||
|
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(
|
||||||
|
mFilterProxyModel->mapToSource(index));
|
||||||
|
|
||||||
|
if (sourceIndex.isValid()) {
|
||||||
|
(mDataFilesModel->checkState(sourceIndex) == Qt::Checked)
|
||||||
|
? mDataFilesModel->setCheckState(sourceIndex, Qt::Unchecked)
|
||||||
|
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object->objectName() == QLatin1String("MastersTable")) {
|
||||||
|
QModelIndex sourceIndex = mMastersProxyModel->mapToSource(index);
|
||||||
|
|
||||||
|
if (sourceIndex.isValid()) {
|
||||||
|
(mDataFilesModel->checkState(sourceIndex) == Qt::Checked)
|
||||||
|
? mDataFilesModel->setCheckState(sourceIndex, Qt::Unchecked)
|
||||||
|
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList FileDialog::checkedItemsPaths()
|
||||||
|
{
|
||||||
|
return mDataFilesModel->checkedItemsPaths();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileDialog::fileName()
|
||||||
|
{
|
||||||
|
return mNameLineEdit->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::openFile()
|
||||||
|
{
|
||||||
|
setWindowTitle(tr("Open"));
|
||||||
|
|
||||||
|
mNameLabel->hide();
|
||||||
|
mNameLineEdit->hide();
|
||||||
|
mCreateButton->hide();
|
||||||
|
|
||||||
|
mButtonBox->removeButton(mCreateButton);
|
||||||
|
mButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Open);
|
||||||
|
QPushButton *openButton = mButtonBox->button(QDialogButtonBox::Open);
|
||||||
|
openButton->setEnabled(false);
|
||||||
|
|
||||||
|
show();
|
||||||
|
raise();
|
||||||
|
activateWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::newFile()
|
||||||
|
{
|
||||||
|
setWindowTitle(tr("New"));
|
||||||
|
|
||||||
|
mNameLabel->show();
|
||||||
|
mNameLineEdit->clear();
|
||||||
|
mNameLineEdit->show();
|
||||||
|
mCreateButton->show();
|
||||||
|
|
||||||
|
mButtonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
||||||
|
mButtonBox->addButton(mCreateButton, QDialogButtonBox::ActionRole);
|
||||||
|
|
||||||
|
show();
|
||||||
|
raise();
|
||||||
|
activateWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::accept()
|
||||||
|
{
|
||||||
|
emit openFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::createButtonClicked()
|
||||||
|
{
|
||||||
|
emit createNewFile();
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
#ifndef FILEDIALOG_HPP
|
||||||
|
#define FILEDIALOG_HPP
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
#include "ui_datafilespage.h"
|
||||||
|
|
||||||
|
class QDialogButtonBox;
|
||||||
|
class QSortFilterProxyModel;
|
||||||
|
class QAbstractItemModel;
|
||||||
|
class QPushButton;
|
||||||
|
class QStringList;
|
||||||
|
class QString;
|
||||||
|
class QMenu;
|
||||||
|
|
||||||
|
class DataFilesModel;
|
||||||
|
class PluginsProxyModel;
|
||||||
|
|
||||||
|
class FileDialog : public QDialog, private Ui::DataFilesPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit FileDialog(QWidget *parent = 0);
|
||||||
|
void addFiles(const QString &path);
|
||||||
|
void setEncoding(const QString &encoding);
|
||||||
|
|
||||||
|
void openFile();
|
||||||
|
void newFile();
|
||||||
|
void accepted();
|
||||||
|
|
||||||
|
QStringList checkedItemsPaths();
|
||||||
|
QString fileName();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void openFiles();
|
||||||
|
void createNewFile();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void accept();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateViews();
|
||||||
|
void updateOpenButton(const QStringList &items);
|
||||||
|
void updateCreateButton(const QString &name);
|
||||||
|
void setCheckState(QModelIndex index);
|
||||||
|
|
||||||
|
void filterChanged(const QString &filter);
|
||||||
|
|
||||||
|
void createButtonClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLabel *mNameLabel;
|
||||||
|
LineEdit *mNameLineEdit;
|
||||||
|
|
||||||
|
QPushButton *mCreateButton;
|
||||||
|
QDialogButtonBox *mButtonBox;
|
||||||
|
|
||||||
|
DataFilesModel *mDataFilesModel;
|
||||||
|
|
||||||
|
PluginsProxyModel *mPluginsProxyModel;
|
||||||
|
QSortFilterProxyModel *mMastersProxyModel;
|
||||||
|
QSortFilterProxyModel *mFilterProxyModel;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILEDIALOG_HPP
|
@ -1,293 +0,0 @@
|
|||||||
#include <QtGui>
|
|
||||||
|
|
||||||
#include <components/esm/esmreader.hpp>
|
|
||||||
#include <components/files/configurationmanager.hpp>
|
|
||||||
|
|
||||||
#include "model/datafilesmodel.hpp"
|
|
||||||
#include "model/esm/esmfile.hpp"
|
|
||||||
|
|
||||||
#include "utils/lineedit.hpp"
|
|
||||||
|
|
||||||
#include "datafileslist.hpp"
|
|
||||||
|
|
||||||
#include <boost/version.hpp>
|
|
||||||
/**
|
|
||||||
* Workaround for problems with whitespaces in paths in older versions of Boost library
|
|
||||||
*/
|
|
||||||
#if (BOOST_VERSION <= 104600)
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline boost::filesystem::path lexical_cast<boost::filesystem::path, std::string>(const std::string& arg)
|
|
||||||
{
|
|
||||||
return boost::filesystem::path(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* namespace boost */
|
|
||||||
#endif /* (BOOST_VERSION <= 104600) */
|
|
||||||
|
|
||||||
using namespace ESM;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//sort QModelIndexList ascending
|
|
||||||
bool rowGreaterThan(const QModelIndex &index1, const QModelIndex &index2)
|
|
||||||
{
|
|
||||||
return index1.row() >= index2.row();
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort QModelIndexList descending
|
|
||||||
bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2)
|
|
||||||
{
|
|
||||||
return index1.row() <= index2.row();
|
|
||||||
}
|
|
||||||
|
|
||||||
DataFilesList::DataFilesList(Files::ConfigurationManager &cfg, QWidget *parent)
|
|
||||||
: QWidget(parent)
|
|
||||||
, mCfgMgr(cfg)
|
|
||||||
{
|
|
||||||
// Model
|
|
||||||
mFilesModel = new DataFilesModel(this);
|
|
||||||
|
|
||||||
mFilesProxyModel = new QSortFilterProxyModel();
|
|
||||||
mFilesProxyModel->setDynamicSortFilter(true);
|
|
||||||
mFilesProxyModel->setSourceModel(mFilesModel);
|
|
||||||
|
|
||||||
// Filter toolbar
|
|
||||||
QLabel *filterLabel = new QLabel(tr("&Filter:"), this);
|
|
||||||
LineEdit *filterLineEdit = new LineEdit(this);
|
|
||||||
filterLabel->setBuddy(filterLineEdit);
|
|
||||||
|
|
||||||
QToolBar *filterToolBar = new QToolBar(this);
|
|
||||||
filterToolBar->setMovable(false);
|
|
||||||
|
|
||||||
// Create a container widget and a layout to get the spacer to work
|
|
||||||
QWidget *filterWidget = new QWidget(this);
|
|
||||||
QHBoxLayout *filterLayout = new QHBoxLayout(filterWidget);
|
|
||||||
QSpacerItem *hSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
||||||
|
|
||||||
filterLayout->addItem(hSpacer1);
|
|
||||||
filterLayout->addWidget(filterLabel);
|
|
||||||
filterLayout->addWidget(filterLineEdit);
|
|
||||||
|
|
||||||
filterToolBar->addWidget(filterWidget);
|
|
||||||
|
|
||||||
QCheckBox checkBox;
|
|
||||||
unsigned int height = checkBox.sizeHint().height() + 4;
|
|
||||||
|
|
||||||
mFilesTable = new QTableView(this);
|
|
||||||
mFilesTable->setModel(mFilesProxyModel);
|
|
||||||
mFilesTable->setObjectName("PluginsTable");
|
|
||||||
mFilesTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
mFilesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
||||||
mFilesTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
||||||
mFilesTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
||||||
mFilesTable->setAlternatingRowColors(true);
|
|
||||||
mFilesTable->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
|
|
||||||
mFilesTable->horizontalHeader()->setStretchLastSection(true);
|
|
||||||
mFilesTable->horizontalHeader()->hide();
|
|
||||||
|
|
||||||
mFilesTable->verticalHeader()->setDefaultSectionSize(height);
|
|
||||||
mFilesTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
|
|
||||||
mFilesTable->setColumnHidden(1, true);
|
|
||||||
mFilesTable->setColumnHidden(2, true);
|
|
||||||
mFilesTable->setColumnHidden(3, true);
|
|
||||||
mFilesTable->setColumnHidden(4, true);
|
|
||||||
mFilesTable->setColumnHidden(5, true);
|
|
||||||
mFilesTable->setColumnHidden(6, true);
|
|
||||||
mFilesTable->setColumnHidden(7, true);
|
|
||||||
mFilesTable->setColumnHidden(8, true);
|
|
||||||
|
|
||||||
QVBoxLayout *pageLayout = new QVBoxLayout(this);
|
|
||||||
|
|
||||||
pageLayout->addWidget(filterToolBar);
|
|
||||||
pageLayout->addWidget(mFilesTable);
|
|
||||||
|
|
||||||
connect(mFilesTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
|
|
||||||
|
|
||||||
connect(mFilesModel, SIGNAL(checkedItemsChanged(QStringList,QStringList)), mFilesModel, SLOT(slotcheckedItemsChanged(QStringList,QStringList)));
|
|
||||||
|
|
||||||
connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
|
|
||||||
|
|
||||||
connect(mFilesTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
|
|
||||||
|
|
||||||
createActions();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::createActions()
|
|
||||||
{
|
|
||||||
// Refresh the plugins
|
|
||||||
QAction *refreshAction = new QAction(tr("Refresh"), this);
|
|
||||||
refreshAction->setShortcut(QKeySequence(tr("F5")));
|
|
||||||
connect(refreshAction, SIGNAL(triggered()), this, SLOT(refresh()));
|
|
||||||
|
|
||||||
// Context menu actions
|
|
||||||
mCheckAction = new QAction(tr("Check selected"), this);
|
|
||||||
connect(mCheckAction, SIGNAL(triggered()), this, SLOT(check()));
|
|
||||||
|
|
||||||
mUncheckAction = new QAction(tr("Uncheck selected"), this);
|
|
||||||
connect(mUncheckAction, SIGNAL(triggered()), this, SLOT(uncheck()));
|
|
||||||
|
|
||||||
// Context menu for the plugins table
|
|
||||||
mContextMenu = new QMenu(this);
|
|
||||||
|
|
||||||
mContextMenu->addAction(mCheckAction);
|
|
||||||
mContextMenu->addAction(mUncheckAction);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataFilesList::setupDataFiles(Files::PathContainer dataDirs, const QString encoding)
|
|
||||||
{
|
|
||||||
// Set the charset for reading the esm/esp files
|
|
||||||
if (!encoding.isEmpty() && encoding != QLatin1String("win1252")) {
|
|
||||||
mFilesModel->setEncoding(encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the paths to the respective models
|
|
||||||
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) {
|
|
||||||
QString path = QString::fromStdString(it->string());
|
|
||||||
path.remove(QChar('\"'));
|
|
||||||
mFilesModel->addFiles(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
mFilesModel->sort(0);
|
|
||||||
// mMastersTable->sortByColumn(3, Qt::AscendingOrder);
|
|
||||||
// mPluginsTable->sortByColumn(3, Qt::AscendingOrder);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::selectedFiles(std::vector<boost::filesystem::path>& paths)
|
|
||||||
{
|
|
||||||
QStringList pluginPaths = mFilesModel->checkedItemsPaths();
|
|
||||||
foreach (const QString &path, pluginPaths)
|
|
||||||
{
|
|
||||||
paths.push_back(path.toStdString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::check()
|
|
||||||
{
|
|
||||||
// Check the current selection
|
|
||||||
if (!mFilesTable->selectionModel()->hasSelection()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndexList indexes = mFilesTable->selectionModel()->selectedIndexes();
|
|
||||||
|
|
||||||
//sort selection ascending because selectedIndexes returns an unsorted list
|
|
||||||
//qSort(indexes.begin(), indexes.end(), rowSmallerThan);
|
|
||||||
|
|
||||||
foreach (const QModelIndex &index, indexes) {
|
|
||||||
if (!index.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
mFilesModel->setCheckState(index, Qt::Checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::uncheck()
|
|
||||||
{
|
|
||||||
// uncheck the current selection
|
|
||||||
if (!mFilesTable->selectionModel()->hasSelection()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndexList indexes = mFilesTable->selectionModel()->selectedIndexes();
|
|
||||||
|
|
||||||
//sort selection ascending because selectedIndexes returns an unsorted list
|
|
||||||
//qSort(indexes.begin(), indexes.end(), rowSmallerThan);
|
|
||||||
|
|
||||||
foreach (const QModelIndex &index, indexes) {
|
|
||||||
if (!index.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
mFilesModel->setCheckState(index, Qt::Unchecked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::refresh()
|
|
||||||
{
|
|
||||||
mFilesModel->sort(0);
|
|
||||||
|
|
||||||
|
|
||||||
// Refresh the plugins table
|
|
||||||
mFilesTable->scrollToTop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DataFilesList::setCheckState(QModelIndex index)
|
|
||||||
{
|
|
||||||
if (!index.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QObject *object = QObject::sender();
|
|
||||||
|
|
||||||
// Not a signal-slot call
|
|
||||||
if (!object)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (object->objectName() == QLatin1String("PluginsTable")) {
|
|
||||||
QModelIndex sourceIndex = mFilesProxyModel->mapToSource(index);
|
|
||||||
|
|
||||||
(mFilesModel->checkState(sourceIndex) == Qt::Checked)
|
|
||||||
? mFilesModel->setCheckState(sourceIndex, Qt::Unchecked)
|
|
||||||
: mFilesModel->setCheckState(sourceIndex, Qt::Checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::uncheckAll()
|
|
||||||
{
|
|
||||||
mFilesModel->uncheckAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::filterChanged(const QString filter)
|
|
||||||
{
|
|
||||||
QRegExp regExp(filter, Qt::CaseInsensitive, QRegExp::FixedString);
|
|
||||||
mFilesProxyModel->setFilterRegExp(regExp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::showContextMenu(const QPoint &point)
|
|
||||||
{
|
|
||||||
// Make sure there are plugins in the view
|
|
||||||
if (!mFilesTable->selectionModel()->hasSelection()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint globalPos = mFilesTable->mapToGlobal(point);
|
|
||||||
|
|
||||||
QModelIndexList indexes = mFilesTable->selectionModel()->selectedIndexes();
|
|
||||||
|
|
||||||
// Show the check/uncheck actions depending on the state of the selected items
|
|
||||||
mUncheckAction->setEnabled(false);
|
|
||||||
mCheckAction->setEnabled(false);
|
|
||||||
|
|
||||||
foreach (const QModelIndex &index, indexes) {
|
|
||||||
if (!index.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
(mFilesModel->checkState(index) == Qt::Checked)
|
|
||||||
? mUncheckAction->setEnabled(true)
|
|
||||||
: mCheckAction->setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show menu
|
|
||||||
mContextMenu->exec(globalPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataFilesList::setCheckState(const QString& element, Qt::CheckState state)
|
|
||||||
{
|
|
||||||
EsmFile *file = mFilesModel->findItem(element);
|
|
||||||
if (file)
|
|
||||||
{
|
|
||||||
mFilesModel->setCheckState(mFilesModel->indexFromItem(file), Qt::Checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList DataFilesList::checkedFiles()
|
|
||||||
{
|
|
||||||
return mFilesModel->checkedItems();
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
#ifndef DATAFILESLIST_H
|
|
||||||
#define DATAFILESLIST_H
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QModelIndex>
|
|
||||||
#include <components/files/collections.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
class QTableView;
|
|
||||||
class QSortFilterProxyModel;
|
|
||||||
class QSettings;
|
|
||||||
class QAction;
|
|
||||||
class QToolBar;
|
|
||||||
class QMenu;
|
|
||||||
class ProfilesComboBox;
|
|
||||||
class DataFilesModel;
|
|
||||||
|
|
||||||
class TextInputDialog;
|
|
||||||
|
|
||||||
namespace Files { struct ConfigurationManager; }
|
|
||||||
|
|
||||||
class DataFilesList : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
DataFilesList(Files::ConfigurationManager& cfg, QWidget *parent = 0);
|
|
||||||
|
|
||||||
bool setupDataFiles(Files::PathContainer dataDirs, const QString encoding);
|
|
||||||
void selectedFiles(std::vector<boost::filesystem::path>& paths);
|
|
||||||
void uncheckAll();
|
|
||||||
QStringList checkedFiles();
|
|
||||||
void setCheckState(const QString& element, Qt::CheckState);
|
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setCheckState(QModelIndex index);
|
|
||||||
|
|
||||||
void filterChanged(const QString filter);
|
|
||||||
void showContextMenu(const QPoint &point);
|
|
||||||
|
|
||||||
// Action slots
|
|
||||||
// void moveUp();
|
|
||||||
// void moveDown();
|
|
||||||
// void moveTop();
|
|
||||||
// void moveBottom();
|
|
||||||
void check();
|
|
||||||
void uncheck();
|
|
||||||
void refresh();
|
|
||||||
|
|
||||||
private:
|
|
||||||
DataFilesModel *mFilesModel;
|
|
||||||
|
|
||||||
QSortFilterProxyModel *mFilesProxyModel;
|
|
||||||
|
|
||||||
QTableView *mFilesTable;
|
|
||||||
|
|
||||||
QMenu *mContextMenu;
|
|
||||||
|
|
||||||
// QAction *mMoveUpAction;
|
|
||||||
// QAction *mMoveDownAction;
|
|
||||||
// QAction *mMoveTopAction;
|
|
||||||
// QAction *mMoveBottomAction;
|
|
||||||
QAction *mCheckAction;
|
|
||||||
QAction *mUncheckAction;
|
|
||||||
|
|
||||||
Files::ConfigurationManager &mCfgMgr;
|
|
||||||
|
|
||||||
// const QStringList checkedPlugins();
|
|
||||||
// const QStringList selectedMasters();
|
|
||||||
|
|
||||||
void createActions();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Before Width: | Height: | Size: 477 B After Width: | Height: | Size: 477 B |
Before Width: | Height: | Size: 498 B After Width: | Height: | Size: 498 B |
Before Width: | Height: | Size: 793 B After Width: | Height: | Size: 793 B |
Before Width: | Height: | Size: 663 B After Width: | Height: | Size: 663 B |
Before Width: | Height: | Size: 683 B After Width: | Height: | Size: 683 B |
Before Width: | Height: | Size: 636 B After Width: | Height: | Size: 636 B |
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 652 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 236 KiB |
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE RCC><RCC version="1.0">
|
||||||
|
<qresource prefix="images">
|
||||||
|
<file alias="clear.png">images/clear.png</file>
|
||||||
|
<file alias="down.png">images/down.png</file>
|
||||||
|
<file alias="openmw.png">images/openmw.png</file>
|
||||||
|
<file alias="openmw-plugin.png">images/openmw-plugin.png</file>
|
||||||
|
<file alias="openmw-header.png">images/openmw-header.png</file>
|
||||||
|
<file alias="playpage-background.png">images/playpage-background.png</file>
|
||||||
|
</qresource>
|
||||||
|
<qresource prefix="icons/tango">
|
||||||
|
<file alias="index.theme">icons/tango/index.theme</file>
|
||||||
|
<file alias="video-display.png">icons/tango/video-display.png</file>
|
||||||
|
<file alias="16x16/document-new.png">icons/tango/document-new.png</file>
|
||||||
|
<file alias="16x16/edit-copy.png">icons/tango/edit-copy.png</file>
|
||||||
|
<file alias="16x16/edit-delete.png">icons/tango/edit-delete.png</file>
|
||||||
|
<file alias="16x16/go-bottom.png">icons/tango/go-bottom.png</file>
|
||||||
|
<file alias="16x16/go-down.png">icons/tango/go-down.png</file>
|
||||||
|
<file alias="16x16/go-top.png">icons/tango/go-top.png</file>
|
||||||
|
<file alias="16x16/go-up.png">icons/tango/go-up.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|