2014-02-10 13:41:05 +01:00
|
|
|
#include "ViewerWindow.hpp"
|
|
|
|
#include "ViewerWidget.hpp"
|
2014-02-10 16:34:09 +01:00
|
|
|
#include "ArchiveContentsWidget.hpp"
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QFileDialog>
|
2014-02-10 17:15:22 +01:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QSettings>
|
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);
|
|
|
|
|
|
|
|
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();
|
|
|
|
file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit);
|
|
|
|
|
2014-02-10 18:22:07 +01:00
|
|
|
connect(archivewidget, SIGNAL(selectedFileChanged(std::string)), viewer, SLOT(showFile(std::string)));
|
|
|
|
|
2014-02-10 17:15:22 +01:00
|
|
|
QSettings settings("OpenRW", "rwviewer");
|
|
|
|
restoreGeometry(settings.value("geometry").toByteArray());
|
|
|
|
restoreState(settings.value("windowState").toByteArray());
|
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());
|
|
|
|
|
|
|
|
archivewidget->setArchive(ld);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|