-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetUnitDialog.cpp
44 lines (39 loc) · 1.19 KB
/
SetUnitDialog.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
#include "SetUnitDialog.h"
#include "ui_SetUnitDialog.h"
#include "ImageWindow.h"
#include <QDoubleValidator>
SetUnitDialog::SetUnitDialog(ImageWindow *image_wnd, QWidget *parent) :
QDialog(parent),
ui(new Ui::SetUnitDialog)
{
ui->setupUi(this);
this->image_wnd = image_wnd;
this->setWindowTitle("Set custom unit");
}
void SetUnitDialog::addPixVal(double val) {
ui->pixVal->addItem(QString::asprintf("%.2f", val));
}
SetUnitDialog::~SetUnitDialog()
{
delete ui;
}
void SetUnitDialog::on_setButton_clicked()
{
const double n_pix = ui->pixVal->currentText().toDouble();
const double n_unit = ui->unitVal->text().toDouble();
const double unitPerPix = n_unit / n_pix;
QString unitName = ui->unitName->text();
this->image_wnd->setCustomUnit(unitName, unitPerPix);
this->close();
}
void SetUnitDialog::on_pixVal_currentTextChanged(const QString &arg1)
{
QString newVal = arg1;
int cursorPos = ui->pixVal->currentIndex();
QDoubleValidator validator(0.01, 1000*1000, 2);
if (validator.validate(newVal, cursorPos) == QValidator::Invalid) {
this->ui->setButton->setEnabled(false);
} else {
this->ui->setButton->setEnabled(true);
}
}