1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-26 13:47:46 +00:00
novus/sagasu/src/mainwindow.cpp

70 lines
2 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "mainwindow.h"
#include <QApplication>
#include <QDesktopServices>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QMenuBar>
#include "filepropertieswindow.h"
#include "filetreewindow.h"
2023-10-10 18:02:13 -04:00
MainWindow::MainWindow(GameData *data)
2023-10-10 18:22:38 -04:00
: NovusMainWindow()
, data(data)
2023-10-10 18:02:13 -04:00
{
2023-10-10 18:22:38 -04:00
setupMenubar();
auto dummyWidget = new QWidget();
setCentralWidget(dummyWidget);
auto layout = new QHBoxLayout();
dummyWidget->setLayout(layout);
auto tree = new FileTreeWindow(data);
connect(tree, &FileTreeWindow::extractFile, this, [this, data](QString path) {
const QFileInfo info(path);
const QString savePath = QFileDialog::getSaveFileName(this, tr("Save File"), info.fileName(), QStringLiteral("*.%1").arg(info.completeSuffix()));
if (!savePath.isEmpty()) {
qInfo() << "Saving to" << savePath;
std::string savePathStd = path.toStdString();
auto fileData = physis_gamedata_extract_file(data, savePathStd.c_str());
QFile file(savePath);
file.open(QIODevice::WriteOnly);
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);
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"));
}