-
Notifications
You must be signed in to change notification settings - Fork 0
/
SinusConfigLine.cpp
executable file
·110 lines (97 loc) · 3.18 KB
/
SinusConfigLine.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
// This
#include "SinusConfigLine.h"
// Qt
#include <QtMath>
#include <QHBoxLayout>
/* ============================================================================
*
* */
SinusConfigLine::SinusConfigLine(QWidget *parent)
: QWidget(parent)
, mCoeffA(new QDoubleSpinBox())
, mCoeffB(new QDoubleSpinBox())
, mFrequence(new QDoubleSpinBox())
{
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(mCoeffA);
layout->addWidget(mCoeffB);
layout->addWidget(mFrequence);
mCoeffA->setRange(0,0xFFFFFFF);
mCoeffB->setRange(0,0xFFFFFFF);
mFrequence->setRange(0,0xFFFFFFF);
connect(mCoeffA, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SinusConfigLine::onCoeffAChange);
connect(mCoeffB, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SinusConfigLine::onCoeffBChange);
connect(mFrequence, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SinusConfigLine::onFrequenceChange);
mCoeffA->setValue(1);
mCoeffB->setValue(0);
updateFrequence();
}
/* ============================================================================
*
* */
void SinusConfigLine::setEnabled(bool v)
{
mCoeffA->setEnabled(v);
mCoeffB->setEnabled(v);
mFrequence->setEnabled(v);
}
/* ============================================================================
*
* */
double SinusConfigLine::sinVal(double x)
{
return qSin( (mCoeffA->value() * x) + mCoeffB->value() );
}
/* ============================================================================
*
* */
double SinusConfigLine::periode()
{
double T = 1.0 / mFrequence->value();
return T;
}
/* ============================================================================
*
* */
void SinusConfigLine::updateCoeffA()
{
disconnect(mCoeffA, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SinusConfigLine::onCoeffAChange);
double T = 1.0 / mFrequence->value();
mCoeffA->setValue((2.0*M_PI) / T);
connect(mCoeffA, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SinusConfigLine::onCoeffAChange);
emit coeffAChanged();
}
/* ============================================================================
*
* */
void SinusConfigLine::updateFrequence()
{
disconnect(mFrequence, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SinusConfigLine::onFrequenceChange);
double T = (2.0*M_PI) / mCoeffA->value();
mFrequence->setValue(1.0/T);
connect(mFrequence, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SinusConfigLine::onFrequenceChange);
}
/* ============================================================================
*
* */
void SinusConfigLine::onCoeffAChange(double v)
{
Q_UNUSED(v);
updateFrequence();
emit coeffAChanged();
}
/* ============================================================================
*
* */
void SinusConfigLine::onCoeffBChange(double v)
{
Q_UNUSED(v);
}
/* ============================================================================
*
* */
void SinusConfigLine::onFrequenceChange(double v)
{
Q_UNUSED(v);
updateCoeffA();
}