-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainWindow.cpp
96 lines (80 loc) · 2.48 KB
/
MainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "VSLapp.h"
#include <QCloseEvent>
#include <QSettings>
#include <QFileDialog>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_recentFiles(this)
{
ui->setupUi(this);
m_recentFiles.attachToMenuAfterItem(ui->menuFile, "Open...", SLOT(loadFile(QString)));
VSLapp::mainWindowSetup(this);
connect(ui->osgForm, SIGNAL(showMessage(QString)),
ui->statusBar, SLOT(showMessage(QString)));
connect(ui->actionClose, SIGNAL(triggered(bool)),
ui->osgForm, SLOT(removeAllNodes()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionFileOpen_triggered()
{
QSettings settings;
QString FileTypes = QString("%1;;All Files (*.*)").arg(OsgForm::getFileExtensions());
loadFile(QFileDialog::getOpenFileName(this, "Select File",
settings.value("currentDirectory").toString(),
FileTypes));
}
void MainWindow::on_actionFileSave_triggered()
{
ui->osgForm->saveFile(
m_recentFiles.getRecentFiles().at(0));
}
void MainWindow::on_actionFileSaveAs_triggered()
{
QSettings settings;
QString fileName = QFileDialog::getSaveFileName(this,
"Save File as",
settings.value("currentDirectory").toString()
);
ui->osgForm->saveFile(fileName);
m_recentFiles.setMostRecentFile(fileName);
}
void MainWindow::on_actionHelpAbout_triggered()
{
VSLapp::showAboutDialog(this);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (shouldAbortClose()) {
event->ignore();
} else {
VSLapp::mainWindowSave(this);
event->accept();
}
}
void MainWindow::loadFile(QString filename)
{
if (filename.isEmpty())
return;
QSettings settings;
QFileInfo fi(filename);
if (!fi.exists()) {
QMessageBox::warning(this, "File Open Error", QString("File '%1' does not exist").arg(filename));
return;
}
settings.setValue("currentDirectory", fi.absolutePath());
m_recentFiles.setMostRecentFile(filename);
ui->osgForm->openFile(filename);
}
bool MainWindow::shouldAbortClose()
{
// Ask all open documents to save/close
// If application should not close then return "true"
return false;
}