forked from hydronautics-team/PoolsideGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
210 lines (176 loc) · 6.77 KB
/
mainwindow.cpp
File metadata and controls
210 lines (176 loc) · 6.77 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
#include "mainwindow.h"
#include <QDebug>
#include <QFileInfo>
#include "ui_settingswindow.h"
#include "serial_client.h"
#include "udp_client.h"
#include <QShortcut>
#include <QApplication>
#include <QThread>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
{
setupUi(this);
//start in full screen format
QMainWindow::showFullScreen();
QMainWindow::menuBar()->setVisible(false);
// update vehicle and all parameters
connect(&wizard, SIGNAL(updateMainWindow()), this, SIGNAL(updateVehicle()));
connect(this, SIGNAL(updateVehicle()), this, SLOT(updateVehiclesMenu()));
connect(this, SIGNAL(updateVehicle()), &settingsWindow, SIGNAL(updateVehicle()));
connect(this, SIGNAL(updateVehicle()), pageROVMode, SLOT(updateVehicle()));
// Reading the key combination of turning the window to the full screen and back
QShortcut *keyCtrlF = new QShortcut(this);
keyCtrlF->setKey(Qt::CTRL+Qt::Key_F);
connect(keyCtrlF, &QShortcut::activated, this, &MainWindow::noFullScreenKey);
// Controller Changed
connect(&settingsWindow, SIGNAL(controllerChanged(unsigned int, QString)), this, SLOT(changeController(unsigned int, QString)));
// Menu:
// Vehicle
// New vehicle
connect(action_create_vehicle, SIGNAL(triggered()), this, SLOT(createVehicle()));
// Choose vehicle and configuration
connect(menu_choose_configuration,SIGNAL(triggered(QAction*)), this, SLOT(chooseConfiguration(QAction*)));
connect(menu_choose_vehicle, SIGNAL(triggered(QAction*)), this, SLOT(chooseVehicle(QAction*)));
// Settings
connect(action_config_com, SIGNAL(triggered()), &settingsWindow, SLOT(showPageConfigRS()));
connect(action_config_thrusters, SIGNAL(triggered()), &settingsWindow, SLOT(showPageConfigThruster()));
connect(action_config_coef, SIGNAL(triggered()), &settingsWindow, SLOT(showPageConfigCoef()));
// Surface control unit
connect(action_config_controls, SIGNAL(triggered()), &settingsWindow, SLOT(showPageConfigControls()));
connect(action_config_view, SIGNAL(triggered()), &settingsWindow, SLOT(showPageConfigView()));
// Other settings
connect(action_about_program, SIGNAL(triggered()), &settingsWindow, SLOT(showPageAboutProgram()));
connect(action_other_settings, SIGNAL(triggered()), &settingsWindow, SLOT(showPageOtherSettings()));
connect(action_full_screen, &QAction::triggered, this, &MainWindow::fullScreen);
settingsFile = QApplication::applicationDirPath() + "/settings.ini"; // path to settings file
checkFile(settingsFile); // check file existance
settings = new QSettings(settingsFile, QSettings::IniFormat);
currentVehicle = settings->value("currentVehicle").toString();
currentConfiguration = settings->value("currentConfiguration").toString();
emit updateVehicle();
Serial_Client *serial_client = new Serial_Client();
serial_client->start();
connect(serial_client, SIGNAL(dataUpdated()), pageROVMode, SLOT(updateData()));
connect(settingsWindow.pageConfigThruster, SIGNAL(ThrusterChanged(unsigned int)), serial_client, SLOT(changeSelectedThruster(unsigned int)));
UDP_Client *udp_client = new UDP_Client();
udp_client->start();
connect(udp_client, SIGNAL(dataUpdated()), pageROVMode, SLOT(updateData()));
connect(udp_client, SIGNAL(dataUpdated()), settingsWindow.pageVehicleSettings, SLOT(updateData()));
controller = new Joystick("null_joy", 10, 0);
if(controller != nullptr) {
delete controller;
}
controller = new Mouse3d("3dMouse", 10);
}
void MainWindow::createVehicle()
{
wizard.startStateMachine();
wizard.show();
}
void MainWindow::chooseVehicle(QAction *action)
{
currentVehicle = action->text();
settings->beginGroup("vehicle/" + currentVehicle + "/configuration");
foreach (QString name, settings->childKeys()) {
if (settings->value(name).toBool()){
currentConfiguration = name;
break;
}
}
settings->endGroup();
settings->setValue("currentVehicle", currentVehicle);
settings->setValue("currentConfiguration", currentConfiguration);
emit updateVehicle();
}
void MainWindow::chooseConfiguration(QAction *action)
{
currentConfiguration = action->text();
settings->setValue("currentConfiguration", currentConfiguration);
updateVehicleConfigurationMenu();
}
void MainWindow::fullScreen()
{
QMainWindow::showFullScreen();
QMainWindow::menuBar()->setVisible(false);
}
void MainWindow::noFullScreenKey()
{
if(QMainWindow::windowState() == Qt::WindowFullScreen){
QMainWindow::showNormal();
QMainWindow::menuBar()->setVisible(true);
}
}
void MainWindow::updateVehiclesMenu()
{
if (!currentVehicle.isEmpty()){
if (!menu_choose_vehicle->isEmpty())
menu_choose_vehicle->clear();
settings->beginGroup("vehicle");
foreach (QString name, settings->childGroups()) {
QAction *vehicle = new QAction(name);
if (name == currentVehicle){
QFont f = vehicle->font();
f.setBold(true);
vehicle->setFont(f);
menu_choose_vehicle->addAction(vehicle);
}
else
menu_choose_vehicle->addAction(vehicle);
}
settings->endGroup();
}
settings->sync();
qDebug () << currentVehicle;
updateVehicleConfigurationMenu();
}
void MainWindow::updateVehicleConfigurationMenu()
{
menu_choose_configuration->clear();
settings->beginGroup("vehicle/" + currentVehicle + "/configuration");
foreach (QString name, settings->childKeys()) {
if (settings->value(name).toBool()){
QAction *configuration = new QAction(name);
if (name == currentConfiguration){
QFont f = configuration->font();
f.setBold(true);
configuration->setFont(f);
menu_choose_configuration->addAction(configuration);
}
else
menu_choose_configuration->addAction(configuration);
}
}
settings->endGroup();
qDebug () << currentConfiguration;
}
void MainWindow::checkFile(QString filename)
{
QFile file(filename);
if(QFileInfo::exists(filename))
{
file.open(QIODevice::ReadWrite | QIODevice::Text);
file.close();
}
else
{
file.open(QIODevice::ReadWrite | QIODevice::Text);
file.close();
}
}
void MainWindow::enableAUVMode()
{
stackedWidget->setCurrentWidget(pageAUVMode);
}
void MainWindow::enableROVMode()
{
stackedWidget->setCurrentWidget(pageROVMode);
}
void MainWindow::changeController(unsigned int id, QString name)
{
if(controller != nullptr) {
delete controller;
}
qDebug()<<"MainWindow changeController"<<endl;
controller = new Mouse3d(name, 5);
}