-
Notifications
You must be signed in to change notification settings - Fork 0
/
menuform.cpp
128 lines (91 loc) · 3.64 KB
/
menuform.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
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
#include "menuform.h"
#include "ui_menuform.h"
#include "ui_mainwindow.h"
#include <iostream>
MenuForm::MenuForm(QWidget *parent, CalibrationData *calibData) :
QWidget(parent),
ui(new Ui::menuForm)
{
m_calibrationData = calibData;
ui->setupUi(this);
}
MenuForm::~MenuForm()
{
delete ui;
}
void MenuForm::on_distortionCalibrationButton_clicked()
{
emit signalShowCalibrationForm();
}
void MenuForm::on_perspectiveCalibration_clicked()
{
emit signalShowHomographyForm();
}
void MenuForm::on_drawingButton_clicked()
{
emit signalShowDrawingForm();
}
void MenuForm::on_loadProjectButton_clicked()
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Select project file"), qApp->applicationDirPath(),"Text Files(*.txt)");
std::string path = filePath.toStdString();
if(QFile::exists(filePath))
{
QFileInfo fi(filePath);
if(fi.suffix() == "txt"){
m_calibrationData->setProjectPath(path);
m_calibrationData->loadCalibrationData(path);
}else{return;}
}else{
return;
}
checkDataStatus();
emit signalSetMainWindowName(m_calibrationData->getProjectName());
ui->saveProjectLine->setText(QString::fromStdString(m_calibrationData->getProjectName()));
}
void MenuForm::on_saveProjectButton_clicked()
{
QString projectName = ui->saveProjectLine->text();
std::string fileName;
if(projectName.isEmpty()){
fileName = "default";
}else{fileName = projectName.toStdString();}
m_calibrationData->setProjectName(fileName);
QString filePath = QFileDialog::getExistingDirectory(this, tr("Select storage folder"), qApp->applicationDirPath());
std::string path = filePath.toStdString();
std::string pathToFile = path + "/" + fileName + ".txt";
m_calibrationData->setProjectPath(pathToFile);
m_calibrationData->saveCalibrationData();
emit signalSetMainWindowName(m_calibrationData->getProjectName());
checkDataStatus();
ui->saveProjectLine->setText(QString::fromStdString(m_calibrationData->getProjectName()));
}
void MenuForm::checkDataStatus(){
QPixmap redLed(":/Resources/red-light.png");
QPixmap greenLed(":/Resources/green-light.png");
if(m_calibrationData->getHomographyMatrix().empty()){
ui->matrixStatusLight->setPixmap(redLed.scaled(ui->matrixStatusLight->size(),Qt::KeepAspectRatio, Qt::SmoothTransformation));
ui->drawingButton->setEnabled(false);
ui->drawInfoLabel->setStyleSheet(QStringLiteral("QLabel{color: rgb(255, 0, 0);}"));
ui->drawInfoLabel->setText("No homography matrix inserted.");
}else{
ui->matrixStatusLight->setPixmap(greenLed.scaled(ui->matrixStatusLight->size(),Qt::KeepAspectRatio, Qt::SmoothTransformation));
ui->drawingButton->setEnabled(true);
ui->drawInfoLabel->setText("");
}
if(m_calibrationData->getDistoritonCoefficient() == 0){
ui->coefficientsStatusLight->setPixmap(redLed.scaled(ui->matrixStatusLight->size(),Qt::KeepAspectRatio, Qt::SmoothTransformation));
}else{
ui->coefficientsStatusLight->setPixmap(greenLed.scaled(ui->matrixStatusLight->size(),Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
if(m_calibrationData->getProjectName().empty()){
ui->distortionCalibrationButton->setEnabled(false);
ui->perspectiveCalibration->setEnabled(false);
ui->loadInfoLabel->setStyleSheet(QStringLiteral("QLabel{color: rgb(255, 0, 0);}"));
ui->loadInfoLabel->setText("No project loaded.");
}else{
ui->distortionCalibrationButton->setEnabled(true);
ui->perspectiveCalibration->setEnabled(true);
ui->loadInfoLabel->setText("");
}
}