Maraiah/tycho/cc/menu.cc

151 lines
2.7 KiB
C++
Raw Permalink Normal View History

2019-05-30 00:09:58 -07:00
#include "tycho.h"
Menu::Menu(QWidget *parent) :
2019-07-05 20:21:11 -07:00
QMainWindow(parent)
2019-05-15 21:28:33 -07:00
{
2019-07-05 20:21:11 -07:00
setupUi(this);
2019-06-13 19:52:25 -07:00
setWindowIcon(::getIcon("pfhor-hand"));
2019-07-05 20:21:11 -07:00
actionAbout->setShortcut(QKeySequence(QKeySequence::HelpContents));
actionClose->setShortcut(QKeySequence(QKeySequence::Close));
actionMapProps->setShortcut(QKeySequence(tr("Ctrl+P")));
actionNew->setShortcut(QKeySequence(QKeySequence::New));
actionOpen->setShortcut(QKeySequence(QKeySequence::Open));
actionQuit->setShortcut(QKeySequence(QKeySequence::Quit));
2019-06-13 19:52:25 -07:00
2019-07-05 20:21:11 -07:00
dbgPrintFunc();
2019-05-15 21:28:33 -07:00
}
Menu::~Menu()
2019-05-15 21:28:33 -07:00
{
2019-07-05 20:21:11 -07:00
dbgPrintFunc();
2019-05-30 00:09:58 -07:00
}
void Menu::mapNew()
2019-05-30 00:09:58 -07:00
{
2019-07-05 20:21:11 -07:00
QScopedPointer proj{new Project(Project::Map)};
2019-06-13 18:10:33 -07:00
2019-07-05 20:21:11 -07:00
addProject(proj.take());
2019-05-30 00:09:58 -07:00
}
void Menu::mapOpen()
2019-05-30 00:09:58 -07:00
{
2019-07-05 20:21:11 -07:00
auto fname =
QFileDialog::getOpenFileName(
this,
tr("Open Map File"),
QString(),
tr("Marathon Map files (*.scen *.sceA Map);;"
"Marathon Physics files (*.phys *.phyA Physics);;"
"Aleph One Image files (*.imgA);;"
"All files (*)"));
if(!fname.isEmpty()) {
QScopedPointer proj{new Project(Project::Map)};
if(proj->model()->open(fname)) {
addProject(proj.take());
}
}
2019-05-30 00:09:58 -07:00
}
void Menu::openAbout()
2019-05-30 00:09:58 -07:00
{
2019-07-05 20:21:11 -07:00
QDialog dlg{this};
Ui::About ui{};
2019-05-30 00:09:58 -07:00
2019-07-05 20:21:11 -07:00
ui.setupUi(&dlg);
2019-06-14 10:03:32 -07:00
2019-07-05 20:21:11 -07:00
auto text = ui.labelText->text();
2019-06-14 10:23:16 -07:00
2019-07-05 20:21:11 -07:00
text.replace("AUTHORS",
tr(::tychoAuthors()).replace(':', ", ").toHtmlEscaped());
text.replace("HOMEPAGE", tr(::tychoHomepage()));
text.replace("REPOSITORY", tr(::tychoRepository()));
text.replace("VERSION", tr(::tychoVersion()));
2019-06-14 10:23:16 -07:00
2019-07-05 20:21:11 -07:00
ui.labelText->setText(text);
2019-06-14 10:03:32 -07:00
2019-07-05 20:21:11 -07:00
connect(ui.btnLicense, &QPushButton::clicked, this, [&](){
openLicense(&dlg);
});
2019-06-14 10:03:32 -07:00
2019-07-05 20:21:11 -07:00
dlg.exec();
2019-06-14 10:03:32 -07:00
}
2019-06-30 22:25:54 -07:00
void Menu::openAboutQt()
{
2019-07-05 20:21:11 -07:00
QMessageBox::aboutQt(this);
2019-06-30 22:25:54 -07:00
}
2019-06-14 10:03:32 -07:00
void Menu::openLicense(QWidget *parent)
{
2019-07-05 20:21:11 -07:00
QDialog dlg{parent};
Ui::License ui{};
2019-06-14 10:03:32 -07:00
2019-07-05 20:21:11 -07:00
ui.setupUi(&dlg);
2019-06-14 10:03:32 -07:00
2019-07-05 20:21:11 -07:00
ui.text->setPlainText(tychoLicenseText());
2019-06-14 10:03:32 -07:00
2019-07-05 20:21:11 -07:00
connect(ui.btnCopy, &QPushButton::clicked, this, [&]() {
ui.text->selectAll();
ui.text->copy();
});
2019-05-30 00:09:58 -07:00
2019-07-05 20:21:11 -07:00
dlg.exec();
2019-05-16 14:50:59 -07:00
}
void Menu::openMapProperties()
2019-05-16 14:50:59 -07:00
{
2019-07-05 20:21:11 -07:00
auto proj = activeProject();
2019-06-13 18:10:33 -07:00
2019-07-05 20:21:11 -07:00
if(proj && proj->type() == Project::Map) {
MapProps props{proj};
props.exec();
}
2019-06-13 18:10:33 -07:00
}
void Menu::updateActions()
{
2019-07-05 20:21:11 -07:00
std::optional<Project::Type> active;
2019-06-13 18:10:33 -07:00
2019-07-05 20:21:11 -07:00
if(auto proj = activeProject()) {
active = proj->type();
}
2019-07-05 20:21:11 -07:00
actionClose->setEnabled(!!active);
actionMapProps->setEnabled(active == Project::Map);
2019-06-13 18:10:33 -07:00
}
2019-06-13 19:52:25 -07:00
void Menu::closeEvent(QCloseEvent *event)
{
2019-07-05 20:21:11 -07:00
for(auto *win : mdiArea->subWindowList()) {
if(!win->close()) {
event->ignore();
return;
}
}
event->accept();
2019-06-13 19:52:25 -07:00
}
2019-06-17 03:32:22 -07:00
Project *Menu::activeProject() const
2019-06-13 18:10:33 -07:00
{
2019-07-05 20:21:11 -07:00
return qobject_cast<Project *>(activeSubWindow());
2019-06-13 18:10:33 -07:00
}
QMdiSubWindow *Menu::activeSubWindow() const
{
2019-07-05 20:21:11 -07:00
return mdiArea->activeSubWindow();
2019-06-13 18:10:33 -07:00
}
2019-06-17 03:32:22 -07:00
void Menu::addProject(Project *proj)
2019-06-13 18:10:33 -07:00
{
2019-07-05 20:21:11 -07:00
auto win = mdiArea->addSubWindow(proj);
2019-07-05 20:21:11 -07:00
win->showMaximized();
2019-05-15 21:28:33 -07:00
}
// EOF