diff --git a/sagasu/include/filetreewindow.h b/sagasu/include/filetreewindow.h index 082a3e0..e2d2a47 100644 --- a/sagasu/include/filetreewindow.h +++ b/sagasu/include/filetreewindow.h @@ -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; diff --git a/sagasu/include/mainwindow.h b/sagasu/include/mainwindow.h index bcfae9c..564afd6 100644 --- a/sagasu/include/mainwindow.h +++ b/sagasu/include/mainwindow.h @@ -19,5 +19,7 @@ public: private: QMdiArea *mdiArea = nullptr; - GameData *data; + GameData *data = nullptr; + QTabWidget *partHolder = nullptr; + void refreshParts(QString qString); }; \ No newline at end of file diff --git a/sagasu/src/filetreemodel.cpp b/sagasu/src/filetreemodel.cpp index cc87633..e940065 100644 --- a/sagasu/src/filetreemodel.cpp +++ b/sagasu/src/filetreemodel.cpp @@ -90,6 +90,10 @@ QVariant FileTreeModel::data(const QModelIndex &index, int role) const auto item = static_cast(index.internalPointer()); if (role == Qt::UserRole) { + if (item->type != TreeType::File || item->name.isEmpty()) { + return {}; + } + // build the full path QString path; TreeInformation *parent = item; diff --git a/sagasu/src/filetreewindow.cpp b/sagasu/src/filetreewindow.cpp index 335e0f3..2be36d1 100644 --- a/sagasu/src/filetreewindow.cpp +++ b/sagasu/src/filetreewindow.cpp @@ -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" \ No newline at end of file diff --git a/sagasu/src/main.cpp b/sagasu/src/main.cpp index 9944a9d..d7a0510 100644 --- a/sagasu/src/main.cpp +++ b/sagasu/src/main.cpp @@ -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())); diff --git a/sagasu/src/mainwindow.cpp b/sagasu/src/mainwindow.cpp index e6d2ab6..b8d1fce 100644 --- a/sagasu/src/mainwindow.cpp +++ b/sagasu/src/mainwindow.cpp @@ -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(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")); }