-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
speakerdialog.cpp
117 lines (99 loc) · 4.07 KB
/
speakerdialog.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
#include <QPushButton>
#include <QDebug>
#include "speakerdialog.h"
#include "ui_speakerdialog.h"
#include "speaker.h"
#include "speakerdb.h"
SpeakerDialog::SpeakerDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SpeakerDialog)
{
ui->setupUi(this);
/* do not enable 'ok' since model and vendor are empty */
ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
connect(this, &SpeakerDialog::accepted, this, &SpeakerDialog::onSpeakerAccepted);
connect(this, &SpeakerDialog::rejected, this, &SpeakerDialog::onSpeakerRejected);
connect(ui->vendorLineEdit, &QLineEdit::textChanged, this, &SpeakerDialog::onVendorTextChanged);
connect(ui->modelLineEdit, &QLineEdit::textChanged, this, &SpeakerDialog::onModelTextChanged);
}
SpeakerDialog::SpeakerDialog(const Speaker &edit, QWidget *parent) :
QDialog(parent),
ui(new Ui::SpeakerDialog)
{
ui->setupUi(this);
ui->fsDoubleSpinBox->setValue(edit.getFs());
ui->qtsDoubleSpinBox->setValue(edit.getQts());
ui->vasDoubleSpinBox->setValue(edit.getVas());
ui->zDoubleSpinBox->setValue(edit.getZ());
ui->diaDoubleSpinBox->setValue(edit.getDia());
ui->reDoubleSpinBox->setValue(edit.getRe());
ui->sdDoubleSpinBox->setValue(edit.getSd());
ui->xmaxDoubleSpinBox->setValue(edit.getXmax());
ui->leDoubleSpinBox->setValue(edit.getLe());
ui->qmsDoubleSpinBox->setValue(edit.getQms());
ui->qesDoubleSpinBox->setValue(edit.getQes());
ui->splDoubleSpinBox->setValue(edit.getSpl());
ui->peDoubleSpinBox->setValue(edit.getPe());
ui->blDoubleSpinBox->setValue(edit.getBL());
ui->vcSpinBox->setValue(edit.getVc());
oldVendor = edit.getVendor();
oldModel = edit.getModel();
ui->vendorLineEdit->setText(oldVendor);
ui->modelLineEdit->setText(oldModel);
connect(this, &SpeakerDialog::accepted, this, &SpeakerDialog::onSpeakerAccepted);
connect(this, &SpeakerDialog::rejected, this, &SpeakerDialog::onSpeakerRejected);
connect(ui->vendorLineEdit, &QLineEdit::textChanged, this, &SpeakerDialog::onVendorTextChanged);
connect(ui->modelLineEdit, &QLineEdit::textChanged, this, &SpeakerDialog::onModelTextChanged);
}
SpeakerDialog::~SpeakerDialog()
{
delete ui;
}
void SpeakerDialog::onVendorTextChanged(QString text)
{
if (text.isNull() || text.isEmpty())
ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
else if (!ui->modelLineEdit->text().isNull() && !ui->modelLineEdit->text().isEmpty())
ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
void SpeakerDialog::onModelTextChanged(QString text)
{
if (text.isNull() || text.isEmpty())
ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
else if (!ui->vendorLineEdit->text().isNull() && !ui->vendorLineEdit->text().isEmpty())
ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
void SpeakerDialog::onSpeakerAccepted()
{
Speaker spk;
QString vendor = ui->vendorLineEdit->text();
QString model = ui->modelLineEdit->text();
spk.setVendor(vendor);
spk.setModel(model);
spk.setFs(ui->fsDoubleSpinBox->value());
spk.setVas(ui->vasDoubleSpinBox->value());
spk.setQts(ui->qtsDoubleSpinBox->value());
spk.setZ(ui->zDoubleSpinBox->value());
spk.setDia(ui->diaDoubleSpinBox->value());
spk.setRe(ui->reDoubleSpinBox->value());
spk.setSd(ui->sdDoubleSpinBox->value());
spk.setXmax(ui->xmaxDoubleSpinBox->value());
spk.setLe(ui->leDoubleSpinBox->value());
spk.setQms(ui->qmsDoubleSpinBox->value());
spk.setQes(ui->qesDoubleSpinBox->value());
spk.setSpl(ui->splDoubleSpinBox->value());
spk.setPe(ui->peDoubleSpinBox->value());
spk.setBL(ui->blDoubleSpinBox->value());
spk.setVc(ui->vcSpinBox->value());
spk.computeEmptyParams();
if (oldVendor.isNull() || oldModel.isNull()) {
SpeakerDb::insertOrReplace(vendor, model, spk);
} else {
SpeakerDb::insertOrReplace(oldVendor, oldModel, spk);
}
emit speakerInserted(spk);
}
void SpeakerDialog::onSpeakerRejected()
{
emit speakerCancelled();
}