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"
|
2019-09-29 22:30:32 -07:00
|
|
|
#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-11-06 22:42:59 -08:00
|
|
|
#include <QMdiSubWindow>
|
|
|
|
|
|
|
|
static bool applyActiveWin(QMdiArea *area, std::function<bool(Project *)> fn) {
|
|
|
|
if(auto subWin = area->activeSubWindow()) {
|
|
|
|
if(auto win = qobject_cast<Project *>(subWin->widget())) {
|
|
|
|
return fn(win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-28 22:29:31 -07:00
|
|
|
|
2019-09-27 00:09:09 -07:00
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QMainWindow{parent},
|
2019-09-28 01:17:55 -07:00
|
|
|
Ui::MainWindow{},
|
2019-09-29 22:30:32 -07:00
|
|
|
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});
|
2019-09-28 03:54:04 -07:00
|
|
|
actionOpen->setShortcut(QKeySequence{QKeySequence::Open});
|
|
|
|
actionQuit->setShortcut(QKeySequence{QKeySequence::Quit});
|
2019-11-06 22:42:59 -08:00
|
|
|
|
|
|
|
actionUp->setShortcut(Qt::ALT + Qt::Key_Up);
|
|
|
|
actionTop->setShortcut(Qt::ALT + Qt::Key_Home);
|
|
|
|
actionBack->setShortcut(QKeySequence{QKeySequence::Back});
|
|
|
|
actionForward->setShortcut(QKeySequence{QKeySequence::Forward});
|
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);;"
|
2019-09-28 03:54:04 -07:00
|
|
|
"Quake WAD2 file (*.wad);;"
|
2019-09-28 01:17:55 -07:00
|
|
|
"All files (*)"));
|
|
|
|
|
|
|
|
if(!fileName.isEmpty()) {
|
|
|
|
try {
|
2019-11-06 22:42:59 -08:00
|
|
|
auto path = std::filesystem::path(fileName.toStdString());
|
|
|
|
auto st = openReadBin(path);
|
|
|
|
auto win = new QMdiSubWindow;
|
|
|
|
auto proj = new Project{st, m_errors, win};
|
|
|
|
win->setWidget(proj);
|
|
|
|
win->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
win->setWindowTitle(QString::fromStdString(path.filename()));
|
|
|
|
mdiArea->addSubWindow(win);
|
|
|
|
win->showMaximized();
|
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() {
|
2019-09-29 22:30:32 -07:00
|
|
|
if(auto win = mdiArea->activeSubWindow()) {
|
|
|
|
mdiArea->removeSubWindow(win);
|
|
|
|
}
|
2019-09-28 22:29:31 -07:00
|
|
|
}
|
|
|
|
|
2019-11-06 22:42:59 -08:00
|
|
|
bool MainWindow::goBack() {
|
|
|
|
return applyActiveWin(mdiArea, [](auto win) {return win->goBack();});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::goForward() {
|
|
|
|
return applyActiveWin(mdiArea, [](auto win) {return win->goForward();});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::goTop() {
|
|
|
|
return applyActiveWin(mdiArea, [](auto win) {return win->goTop();});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::goUp() {
|
|
|
|
return applyActiveWin(mdiArea, [](auto win) {return win->goUp();});
|
|
|
|
}
|
|
|
|
|
2019-09-27 00:09:09 -07:00
|
|
|
// EOF
|