2014-02-10 13:41:05 +01:00
|
|
|
#include "ViewerWindow.hpp"
|
2014-02-11 06:46:29 +01:00
|
|
|
#include <engine/GameWorld.hpp>
|
2014-02-10 13:41:05 +01:00
|
|
|
#include "ViewerWidget.hpp"
|
2014-02-10 16:34:09 +01:00
|
|
|
#include "ArchiveContentsWidget.hpp"
|
2014-02-12 07:42:07 +01:00
|
|
|
#include "ModelFramesWidget.hpp"
|
2014-02-10 16:34:09 +01:00
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QFileDialog>
|
2014-02-10 17:15:22 +01:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QSettings>
|
2014-02-10 13:41:05 +01:00
|
|
|
|
2014-02-11 15:41:46 +01:00
|
|
|
static int MaxRecentArchives = 5;
|
|
|
|
|
2014-02-10 13:41:05 +01:00
|
|
|
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(parent, flags)
|
|
|
|
{
|
2014-02-10 16:34:09 +01:00
|
|
|
setMinimumSize(640, 480);
|
|
|
|
|
2014-02-10 13:41:05 +01:00
|
|
|
viewer = new ViewerWidget();
|
|
|
|
this->setCentralWidget(viewer);
|
2014-02-10 16:34:09 +01:00
|
|
|
|
|
|
|
archivewidget = new ArchiveContentsWidget;
|
2014-02-10 17:15:22 +01:00
|
|
|
archivewidget->setObjectName("archivewidget");
|
2014-02-10 16:34:09 +01:00
|
|
|
this->addDockWidget(Qt::LeftDockWidgetArea, archivewidget);
|
|
|
|
|
2014-02-12 07:42:07 +01:00
|
|
|
frameswidget = new ModelFramesWidget;
|
|
|
|
frameswidget->setObjectName("frameswidget");
|
|
|
|
this->addDockWidget(Qt::RightDockWidgetArea, frameswidget);
|
|
|
|
|
2014-02-10 16:34:09 +01:00
|
|
|
QMenuBar* mb = this->menuBar();
|
|
|
|
QMenu* file = mb->addMenu("&File");
|
|
|
|
file->addAction("Open &Archive", this, SLOT(openArchive()));
|
2014-02-10 17:15:22 +01:00
|
|
|
file->addSeparator();
|
2014-02-11 15:41:46 +01:00
|
|
|
for(int i = 0; i < MaxRecentArchives; ++i) {
|
|
|
|
QAction* r = file->addAction("");
|
|
|
|
recentArchives.append(r);
|
|
|
|
connect(r, SIGNAL(triggered()), SLOT(openRecent()));
|
|
|
|
}
|
|
|
|
recentSep = file->addSeparator();
|
2014-02-10 17:15:22 +01:00
|
|
|
file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit);
|
|
|
|
|
2014-02-11 06:46:29 +01:00
|
|
|
connect(archivewidget, SIGNAL(selectedFileChanged(QString)), viewer, SLOT(showFile(QString)));
|
2014-02-12 07:42:07 +01:00
|
|
|
connect(viewer, SIGNAL(fileOpened(QString)), SLOT(openFileChanged(QString)));
|
2014-02-10 18:22:07 +01:00
|
|
|
|
2014-02-10 17:15:22 +01:00
|
|
|
QSettings settings("OpenRW", "rwviewer");
|
|
|
|
restoreGeometry(settings.value("geometry").toByteArray());
|
|
|
|
restoreState(settings.value("windowState").toByteArray());
|
2014-02-11 15:41:46 +01:00
|
|
|
|
|
|
|
updateRecentArchives();
|
2014-02-10 16:34:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewerWindow::openArchive(const QString& name)
|
|
|
|
{
|
|
|
|
QString rname = name;
|
|
|
|
QString lower = name.toLower();
|
|
|
|
if(lower.endsWith(".img")) {
|
|
|
|
rname = rname.left(rname.size()-4);
|
|
|
|
}
|
|
|
|
|
|
|
|
LoaderIMG ld;
|
|
|
|
ld.load(rname.toStdString());
|
|
|
|
|
2014-02-11 06:46:29 +01:00
|
|
|
viewer->world()->gameData.loadIMG(rname.toStdString());
|
|
|
|
|
2014-02-10 16:34:09 +01:00
|
|
|
archivewidget->setArchive(ld);
|
2014-02-11 15:41:46 +01:00
|
|
|
|
|
|
|
QSettings settings("OpenRW", "rwviewer");
|
|
|
|
QStringList recent = settings.value("recentArchives").toStringList();
|
|
|
|
recent.removeAll(name);
|
|
|
|
recent.prepend(name);
|
|
|
|
while(recent.size() > MaxRecentArchives) recent.removeLast();
|
|
|
|
settings.setValue("recentArchives", recent);
|
|
|
|
|
|
|
|
updateRecentArchives();
|
2014-02-10 16:34:09 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 17:15:22 +01:00
|
|
|
void ViewerWindow::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
|
|
|
QSettings settings("OpenRW", "rwviewer");
|
|
|
|
settings.setValue("geometry", saveGeometry());
|
|
|
|
settings.setValue("windowState", saveState());
|
|
|
|
QMainWindow::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-02-10 16:34:09 +01:00
|
|
|
void ViewerWindow::openArchive()
|
|
|
|
{
|
|
|
|
QFileDialog dialog(this, "Open Archive", QDir::homePath(), "IMG Archives (*.img)");
|
|
|
|
if(dialog.exec()) {
|
|
|
|
openArchive(dialog.selectedFiles().at(0));
|
|
|
|
}
|
2014-02-10 13:41:05 +01:00
|
|
|
}
|
2014-02-11 06:46:29 +01:00
|
|
|
|
2014-02-12 07:42:07 +01:00
|
|
|
void ViewerWindow::openFileChanged(const QString& name)
|
2014-02-11 06:46:29 +01:00
|
|
|
{
|
|
|
|
setWindowTitle(name);
|
2014-02-12 07:42:07 +01:00
|
|
|
if(viewer->fileMode() == ViewerWidget::DFF) {
|
|
|
|
frameswidget->setModel(viewer->currentModel());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
frameswidget->setModel(nullptr);
|
|
|
|
}
|
2014-02-11 06:46:29 +01:00
|
|
|
}
|
|
|
|
|
2014-02-11 15:41:46 +01:00
|
|
|
void ViewerWindow::openRecent()
|
|
|
|
{
|
|
|
|
QAction* r = qobject_cast< QAction* >(sender());
|
|
|
|
if(r) {
|
|
|
|
openArchive(r->data().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewerWindow::updateRecentArchives()
|
|
|
|
{
|
|
|
|
QSettings settings("OpenRW", "rwviewer");
|
|
|
|
QStringList recent = settings.value("recentArchives").toStringList();
|
|
|
|
|
|
|
|
for(int i = 0; i < MaxRecentArchives; ++i) {
|
|
|
|
if(i < recent.size()) {
|
|
|
|
QString fnm(QFileInfo(recent[i]).fileName());
|
|
|
|
recentArchives[i]->setText(tr("&%1 - %2").arg(i).arg(fnm));
|
|
|
|
recentArchives[i]->setData(recent[i]);
|
|
|
|
recentArchives[i]->setVisible(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
recentArchives[i]->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
recentSep->setVisible(recent.size() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|