-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
220 lines (190 loc) · 5.54 KB
/
mainwindow.cpp
File metadata and controls
220 lines (190 loc) · 5.54 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// #include <winnt.h>
#include <QString>
#include <QStringList>
#include <QFileDialog>
#include <QMessageBox>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mylog.h"
// ----------------------------------------------------------------------
#ifdef MDEBUG
const char *debugSavegameFilename = "C:/Users/dinozaur/Documents/SH5/data/cfg/SaveGames/00000002/Campaign-2024-10-09_2354/CampaignMission.mis";
#endif
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, saveGameFileName("")
{
// this block should be before QOpenGLWidget creation in UI construction
QSurfaceFormat fmt;
fmt.setSamples(8);
QSurfaceFormat::setDefaultFormat(fmt);
ui->setupUi(this);
mylogger::logptr = ui->textEdit_Memo1;// very dangerous exporting, dirty and quick
mylogger::log("Mainwindow constructor started");
filter = std::make_shared<TFilter>();
// DecimalSeparator='.';
// init filter fields here
ui->spinMinGroup->setValue(0);
ui->chZeroSpeeds->setCheckState(Qt::Unchecked);
ui->eradius_of_intercept->setText("50");
ui->e_flt_type_of_ship->setText("");
ui->daysBeforeLineEdit->setText("0.0");
ui->daysAfterLineEdit->setText("1.0");
// world setup
installNewWorld(std::make_shared<TWorld>());
#ifdef MDEBUG
load_world(debugSavegameFilename);
#endif
// interface start setup
QObject::connect(ui->Image1, &TmyGLWidget::size_changed, this, &MainWindow::update_m);
QObject::connect(ui->Image1, &TmyGLWidget::scale_changed, this, &MainWindow::update_m);
QObject::connect(ui->Image1, &TmyGLWidget::changed_polar_coords, this, &MainWindow::update_polar_coords);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::load_world(const QString &fname)
{
std::shared_ptr<TWorld>wp = std::make_shared<TWorld>();
bool ok = wp->load_file(fname);
if (ok) {
saveGameFileName = fname;
installNewWorld(wp);
ui->Image1->worldChanged();
mylogger::log("U-Boat params:");
world->my_boat.dump(ui->textEdit_Memo1);
ui->Image1->viewpoint.pos = world->my_boat.coord;
ui->Image1->viewpoint.m = ui->e_coef->text().toDouble();
update_m();
ui->e_tmp->setText("File loaded successfully");
}
else {
ui->e_tmp->setText("Failed to load world");
}
}
// ---------------------------------------------------------------------------
void MainWindow::update_m()
{
TmyGLWidget *img = ui->Image1;
double sq_size = img->viewpoint.m * img->width() / 1000.0;
ui->e_sq_size->setText(QString("%1").arg(sq_size));
ui->e_coef->setText(QString("%1").arg(img->viewpoint.m));
}
void MainWindow::update_polar_coords(double r, double head)
{
ui->e_dist->setText(QString("%1").arg(r, 0, 'f', 3));
ui->e_head->setText(QString("%1").arg(head, 5, 'f', 1, '0'));
}
// ---------------------------------------------------------------------------
void MainWindow::on_actionOpen_triggered()
{
QString fileName = QFileDialog::getOpenFileName(
this
, "Open Save Game"
#ifdef MDEBUG
, debugSavegameFilename
#else
, ""
#endif
, "Save Game (*.mis)"
);
if (fileName.isEmpty()) return;
ui->e_coords->setText(fileName);
load_world(fileName);
}
void MainWindow::on_pbToBoat_clicked()
{
ui->Image1->setScale(ui->e_coef->text().toDouble());
ui->Image1->toBoat();
ui->Image1->update();
}
void MainWindow::installNewWorld(std::shared_ptr<TWorld> iw)
{
world = iw;
ui->Image1->setWorld(world);
filter->installNewWorld(iw);
}
void MainWindow::on_spinMinGroup_valueChanged(int )
{
filter->set_min_group_size(ui->spinMinGroup->value());
ui->Image1->update();
}
void MainWindow::on_chZeroSpeeds_stateChanged(int )
{
filter->set_draw_zero_speed_only(ui->chZeroSpeeds->isChecked());
ui->Image1->update();
}
void MainWindow::on_eradius_of_intercept_textChanged(const QString &)
{
bool ok;
QString txt = ui->eradius_of_intercept->text();
int radius = txt.toInt(&ok);
if (!ok) {
if (txt.isEmpty())
radius = 0;
else
return; // wrong value at input? do nothing.
}
ui->Image1->interceptRadius = radius;
filter->set_radius(radius);
ui->Image1->update();
}
void MainWindow::on_tbZoomIn_clicked()
{
ui->Image1->viewpoint.m /= 2;
update_m();
ui->Image1->update();
}
void MainWindow::on_tbZoomOut_clicked()
{
ui->Image1->viewpoint.m *= 2;
update_m();
ui->Image1->update();
}
void MainWindow::on_e_flt_type_of_ship_textChanged(const QString &arg1)
{
bool ok;
int test = arg1.toInt(&ok);
if (!ok)
filter->set_type(0); // draw all types
else
filter->set_type(test);
ui->Image1->update();
}
void MainWindow::on_e_coef_textChanged(const QString &arg1)
{
bool ok;
double val = arg1.toDouble(&ok);
if (!ok) return;
ui->Image1->viewpoint.m = val;
ui->Image1->update();
update_m();
}
void MainWindow::on_pbReloadFile_clicked()
{
load_world(saveGameFileName);
}
void MainWindow::on_daysBeforeLineEdit_textChanged(const QString &arg1)
{
bool ok;
double test = arg1.toDouble(&ok);
if (ok) {
filter->set_days_before(test); // update filter
ui->Image1->update();
}
}
void MainWindow::on_daysAfterLineEdit_textChanged(const QString &arg1)
{
bool ok;
double test = arg1.toDouble(&ok);
if (ok) {
filter->set_days_after(test); // update filter
ui->Image1->update();
}
}
void MainWindow::on_Image1_resized()
{
ui->Image1->onResized();
}