-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
145 lines (114 loc) · 3.32 KB
/
mainwindow.cpp
File metadata and controls
145 lines (114 loc) · 3.32 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsView>
#include <QCloseEvent>
// #include "computation.h"
#include <QMessageBox>
#include "newcomputationwindow.h"
#include <QFileDialog>
MainWindow::MainWindow()
{
MatrixView = new QGraphicsView(this);
setCentralWidget(MatrixView);
createActions();
createMenus();
}
MainWindow::~MainWindow()
{
}
void MainWindow::createActions()
{
newComp = new QAction(tr("&New Computation..."), this);
newComp->setStatusTip("Starts a new computation");
QObject::connect(newComp, SIGNAL(triggered()), this, SLOT(newComputation()));
loadComp = new QAction(tr("&Load Computation..."), this);
loadComp->setStatusTip("Loads a previously saved computation");
saveComp = new QAction(tr("&Save Computation..."), this);
saveComp->setStatusTip("Saves a previously saved computation");
exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcuts(QKeySequence::Quit);
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
}
void MainWindow::createMenus()
{
compMenu = menuBar()->addMenu(tr("&Computation"));
compMenu->addAction(newComp);
compMenu->addAction(loadComp);
compMenu->addAction(saveComp);
compMenu->addSeparator();
compMenu->addAction(exitAct);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
QMessageBox::StandardButton ret = saveChanges();
switch(ret)
{
case QMessageBox::Save:
saveComputation(); // deliberate fallthrough
case QMessageBox::Discard:
event->accept();
break;
default:
event->ignore();
}
}
void MainWindow::saveComputation()
{
//todo: tie in to backend
// ask for file name...
QString fileName = QFileDialog::getSaveFileName(this);
if(fileName.isEmpty())
{
return;
}
// otherwise, pass on file name to actual backend
return;
}
void MainWindow::newComputation()
{
NewComputationWindow *newWindow = new NewComputationWindow(this);
QObject::connect(newWindow, SIGNAL(computationCreated(int,int)), this, SLOT(startComputation(int, int)));
newWindow->show();
newWindow->activateWindow();
}
QMessageBox::StandardButton MainWindow::saveChanges()
{
// todo
QMessageBox::StandardButton msg;
msg = QMessageBox::question(this, tr("Application"),
tr("What do you want to do with the current computation?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
return msg;
}
void MainWindow::startComputation(int k, int l)
{
// starting multiple computations = recipe for disaster...
newComp->setDisabled(true);
loadComp->setDisabled(true);
// todo
return;
}
void MainWindow::loadComputation()
{
newComp->setDisabled(true);
loadComp->setDisabled(true);
//todo: tie in to backend
return;
}
void MainWindow::cancelComputation()
{
QMessageBox::StandardButton ret = saveChanges();
switch(ret)
{
case QMessageBox::Save:
saveComputation(); //deliberate fallthrough
case QMessageBox::Discard:
newComp->setDisabled(false);
loadComp->setDisabled(true);
break;
case QMessageBox::Cancel:
default:
break;
};
}