/[qspeakers]/bandpassbox.cpp
ViewVC logotype

Contents of /bandpassbox.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 107 - (show annotations)
Wed May 13 06:13:04 2015 UTC (2 years, 1 month ago) by ben
File size: 3293 byte(s)
complete translation
1 #include <QDebug>
2
3 #include "bandpassbox.h"
4
5 BandPassBox::BandPassBox(double svol, double pvol, double pfreq, unsigned int pnum, double plen, double pdiam) :
6 sealedBox(svol),
7 portedBox(pvol, pfreq, pnum, plen, pdiam)
8 {
9 }
10
11 void BandPassBox::setSealedBoxVolume(double vol)
12 {
13 sealedBox.setVolume(vol);
14 }
15
16 void BandPassBox::setPortedBoxVolume(double vol)
17 {
18 portedBox.setBoxVolume(vol);
19 }
20
21 void BandPassBox::setPortedBoxPortNum(unsigned int val)
22 {
23 portedBox.setPortNum(val);
24 }
25
26 void BandPassBox::setPortedBoxPortLen(double len)
27 {
28 portedBox.setPortLen(len);
29 }
30
31 void BandPassBox::setPortedBoxPortDiam(double diam)
32 {
33 portedBox.setPortDiam(diam);
34 }
35
36 void BandPassBox::setPortedBoxResFreq(double freq)
37 {
38 portedBox.setResFreq(freq);
39 }
40
41 void BandPassBox::updatePortedBoxPorts(double sd, double xmax)
42 {
43 portedBox.updatePorts(sd, xmax);
44 }
45
46 void BandPassBox::updatePortedBoxPortsLength()
47 {
48 portedBox.updatePortsLength();
49 }
50
51 double BandPassBox::getSealedBoxVolume() const
52 {
53 return sealedBox.getVolume();
54 }
55
56 double BandPassBox::getPortedBoxVolume() const
57 {
58 return portedBox.getBoxVolume();
59 }
60
61 unsigned int BandPassBox::getPortedBoxPortNum() const
62 {
63 return portedBox.getPortNum();
64 }
65
66 double BandPassBox::getPortedBoxPortLen() const
67 {
68 return portedBox.getPortLen();
69 }
70
71 double BandPassBox::getPortedBoxPortDiam() const
72 {
73 return portedBox.getPortDiam();
74 }
75
76 double BandPassBox::getPortedBoxResFreq(void) const
77 {
78 return portedBox.getResFreq();
79 }
80
81 QDomElement BandPassBox::toDomElement(QDomDocument &doc) const
82 {
83 QDomElement e = Box::toDomElement(doc);
84 e.setAttribute("type", "bandpass");
85
86 QDomElement b = sealedBox.toDomElement(doc);
87 e.appendChild(b);
88
89 QDomElement c = portedBox.toDomElement(doc);
90 e.appendChild(c);
91
92 return e;
93 }
94
95 void BandPassBox::fromDomElement(const QDomElement &e)
96 {
97 Box::fromDomElement(e);
98 if (e.attribute("type") != "bandpass") {
99 qWarning() << __func__ << "wrong box type! (not bandpass, giving up)";
100 return;
101 }
102
103 QDomElement b = e.firstChildElement("box");
104 while (!b.isNull()) {
105 if (b.attribute("type") == "sealed")
106 sealedBox.fromDomElement(b);
107 else if (b.attribute("type") == "ported")
108 portedBox.fromDomElement(b);
109 b = b.nextSiblingElement("box");
110 }
111 }
112
113 void BandPassBox::render(QPainter *painter, const QRectF &area)
114 {
115 if (!painter)
116 return;
117
118 QString params[6];
119 qreal tab = area.left();
120
121 painter->drawRoundRect(area.toRect(), 5, 5);
122
123 params[0] = QObject::tr("Sealed Vol. %1 L").arg(getSealedBoxVolume());
124 params[1] = QObject::tr("Ported Vol. %1 L").arg(getPortedBoxVolume());
125 params[2] = QObject::tr("Port Diam. %1 cm").arg(getPortedBoxPortDiam());
126 params[3] = QObject::tr("Port Len. %1 cm").arg(QString::number(getPortedBoxPortLen(), 'f', 2));
127 params[4] = QObject::tr("Port Num. %1").arg(getPortedBoxPortNum());
128 params[5] = QObject::tr("Fb %1 Hz").arg(getPortedBoxResFreq());
129
130 for (int i = 0; i < 6; i++) {
131 QString text = params[i];
132 QRectF where(tab, area.top(), area.width() / 6, area.height());
133 QTextOption option(Qt::AlignVCenter|Qt::AlignLeft);
134 painter->drawText(where, text, option);
135 tab += area.width() / 6;
136 }
137 }

  ViewVC Help
Powered by ViewVC 1.1.26