quake-tools/source/quam/main_window.cc

53 lines
1.1 KiB
C++
Raw Normal View History

2019-09-27 00:09:09 -07:00
#include "quam/main_window.h"
2019-10-04 10:37:34 -07:00
#include "quam/archive.h"
#include "quam/project.h"
2019-09-27 00:09:09 -07:00
2019-09-28 22:29:31 -07:00
#include <QErrorMessage>
#include <QFileDialog>
2019-09-27 00:09:09 -07:00
MainWindow::MainWindow(QWidget *parent) :
QMainWindow{parent},
2019-09-28 01:17:55 -07:00
Ui::MainWindow{},
m_errors{new QErrorMessage{this}}
2019-09-27 00:09:09 -07:00
{
setupUi(this);
2019-09-28 01:17:55 -07:00
2019-09-28 22:29:31 -07:00
actionClose->setShortcut(QKeySequence{QKeySequence::Close});
actionOpen->setShortcut(QKeySequence{QKeySequence::Open});
actionQuit->setShortcut(QKeySequence{QKeySequence::Quit});
2019-09-28 22:29:31 -07:00
}
MainWindow::~MainWindow() {
2019-09-27 00:09:09 -07:00
}
2019-09-28 01:17:55 -07:00
void MainWindow::fileOpen() {
auto fileName =
QFileDialog::getOpenFileName(
this,
tr("Open Archive"),
QString{},
2019-10-04 10:37:34 -07:00
tr("Quake archive file (*.pak *.wad);;"
"Quake PACK file (*.pak);;"
"Quake WAD2 file (*.wad);;"
2019-09-28 01:17:55 -07:00
"All files (*)"));
if(!fileName.isEmpty()) {
try {
auto st = openReadBin(fileName.toStdString());
2019-10-04 10:37:34 -07:00
auto arc = Arc::readArchive(st);
new Project{std::move(arc), m_errors, mdiArea};
2019-09-28 01:17:55 -07:00
} catch(std::exception const &exc) {
2019-09-28 22:29:31 -07:00
m_errors->showMessage(tr(exc.what()));
2019-09-28 01:17:55 -07:00
}
}
2019-09-27 00:09:09 -07:00
}
2019-09-28 22:29:31 -07:00
void MainWindow::fileClose() {
if(auto win = mdiArea->activeSubWindow()) {
mdiArea->removeSubWindow(win);
}
2019-09-28 22:29:31 -07:00
}
2019-09-27 00:09:09 -07:00
// EOF