1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-23 12:37:45 +00:00

sagasu: Prepare for a better parts view, move properties into it

This commit is contained in:
Joshua Goins 2023-10-12 19:46:58 -04:00
parent 56353be167
commit 4fa1460b66
6 changed files with 45 additions and 16 deletions

View file

@ -15,8 +15,8 @@ public:
explicit FileTreeWindow(GameData *data, QWidget *parent = nullptr);
Q_SIGNALS:
void openFileProperties(QString path);
void extractFile(QString path);
void pathSelected(QString path);
private:
GameData *data = nullptr;

View file

@ -19,5 +19,7 @@ public:
private:
QMdiArea *mdiArea = nullptr;
GameData *data;
GameData *data = nullptr;
QTabWidget *partHolder = nullptr;
void refreshParts(QString qString);
};

View file

@ -90,6 +90,10 @@ QVariant FileTreeModel::data(const QModelIndex &index, int role) const
auto item = static_cast<TreeInformation *>(index.internalPointer());
if (role == Qt::UserRole) {
if (item->type != TreeType::File || item->name.isEmpty()) {
return {};
}
// build the full path
QString path;
TreeInformation *parent = item;

View file

@ -31,11 +31,6 @@ FileTreeWindow::FileTreeWindow(GameData *data, QWidget *parent)
auto menu = new QMenu();
auto propertiesAction = menu->addAction(QStringLiteral("Properties"));
connect(propertiesAction, &QAction::triggered, this, [=] {
Q_EMIT openFileProperties(path);
});
auto extractAction = menu->addAction(QStringLiteral("Extract.."));
connect(extractAction, &QAction::triggered, this, [=] {
Q_EMIT extractFile(path);
@ -44,6 +39,13 @@ FileTreeWindow::FileTreeWindow(GameData *data, QWidget *parent)
menu->exec(treeWidget->mapToGlobal(pos));
}
});
connect(treeWidget, &QTreeView::clicked, [this, treeWidget](const QModelIndex &item) {
if (item.isValid()) {
auto path = m_fileModel->data(item, Qt::UserRole).toString();
Q_EMIT pathSelected(path);
}
});
}
#include "moc_filetreewindow.cpp"

View file

@ -18,8 +18,6 @@ int main(int argc, char *argv[])
physis_initialize_logging();
app.setStyle(QStringLiteral("Windows"));
const QString gameDir{getGameDirectory()};
const std::string gameDirStd{gameDir.toStdString()};
MainWindow w(physis_gamedata_initialize(gameDirStd.c_str()));

View file

@ -18,14 +18,13 @@ MainWindow::MainWindow(GameData *data)
{
setupMenubar();
mdiArea = new QMdiArea();
setCentralWidget(mdiArea);
auto dummyWidget = new QWidget();
setCentralWidget(dummyWidget);
auto layout = new QHBoxLayout();
dummyWidget->setLayout(layout);
auto tree = new FileTreeWindow(data);
connect(tree, &FileTreeWindow::openFileProperties, this, [=](QString path) {
auto window = mdiArea->addSubWindow(new FilePropertiesWindow(data, path));
window->show();
});
connect(tree, &FileTreeWindow::extractFile, this, [this, data](QString path) {
const QFileInfo info(path);
@ -41,6 +40,30 @@ MainWindow::MainWindow(GameData *data)
file.write(reinterpret_cast<const char *>(fileData.data), fileData.size);
}
});
connect(tree, &FileTreeWindow::pathSelected, this, [=](QString path) {
refreshParts(path);
});
tree->setMaximumWidth(200);
layout->addWidget(tree);
mdiArea->addSubWindow(tree);
partHolder = new QTabWidget();
partHolder->setMinimumWidth(800);
partHolder->setMinimumHeight(720);
layout->addWidget(partHolder);
refreshParts({});
}
void MainWindow::refreshParts(QString path)
{
partHolder->clear();
std::string pathStd = path.toStdString();
if (path.isEmpty() || !physis_gamedata_exists(data, pathStd.c_str())) {
return;
}
// Add properties tab
auto propertiesWidget = new FilePropertiesWindow(data, path);
partHolder->addTab(propertiesWidget, QStringLiteral("Properties"));
}