/[qspeakers]/speaker.cpp
ViewVC logotype

Contents of /speaker.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations)
Thu May 7 22:54:16 2015 UTC (2 years, 1 month ago) by ben
File size: 3825 byte(s)
improve printing, current tab only
1 #include "speaker.h"
2 #include <QDebug>
3
4 Speaker::Speaker() :
5 fs(0.0),
6 vas(0.0),
7 re(0.0),
8 qts(0.0),
9 sd(0.0),
10 xmax(0.0)
11 {
12 }
13
14 Speaker::Speaker(const Speaker &copy)
15 {
16 this->fs = copy.getFs();
17 this->vas = copy.getVas();
18 this->re = copy.getRe();
19 this->qts = copy.getQts();
20 this->sd = copy.getSd();
21 this->xmax = copy.getXmax();
22
23 this->vendor = copy.getVendor();
24 this->model = copy.getModel();
25 }
26
27 Speaker::~Speaker()
28 {
29 /* nothing to do, just for QMetatype */
30 }
31
32 bool Speaker::operator!=(const Speaker& r) const
33 {
34 return this->fs != r.getFs() ||
35 this->vas != r.getVas() ||
36 this->re != r.getRe() ||
37 this->qts != r.getQts() ||
38 this->sd != r.getSd() ||
39 this->xmax != r.getXmax();
40 }
41
42 bool Speaker::operator==(const Speaker& r) const
43 {
44 return !(*this != r);
45 }
46
47 bool Speaker::isValid() const
48 {
49 return !vendor.isNull() && !model.isNull();
50 }
51
52 void Speaker::setVendor(const QString &vnd)
53 {
54 vendor = vnd;
55 }
56
57 void Speaker::setModel(const QString &mdl)
58 {
59 model = mdl;
60 }
61
62 void Speaker::setFs(double val)
63 {
64 fs = val;
65 }
66
67 void Speaker::setVas(double val)
68 {
69 vas = val;
70 }
71
72 void Speaker::setRe(double val)
73 {
74 re = val;
75 }
76
77 void Speaker::setQts(double val)
78 {
79 qts = val;
80 }
81
82 void Speaker::setSd(double val)
83 {
84 sd = val;
85 }
86
87 void Speaker::setXmax(double val)
88 {
89 xmax = val;
90 }
91
92 QString Speaker::getVendor() const
93 {
94 return vendor;
95 }
96
97 QString Speaker::getModel() const
98 {
99 return model;
100 }
101
102 double Speaker::getFs() const
103 {
104 return fs;
105 }
106
107 double Speaker::getVas() const
108 {
109 return vas;
110 }
111
112 double Speaker::getRe() const
113 {
114 return re;
115 }
116
117 double Speaker::getQts() const
118 {
119 return qts;
120 }
121
122 double Speaker::getSd() const
123 {
124 return sd;
125 }
126
127 double Speaker::getXmax() const
128 {
129 return xmax;
130 }
131
132 QDomElement Speaker::toDomElement(QDomDocument &doc) const
133 {
134 QDomElement e = doc.createElement("speaker");
135
136 e.setAttribute("vendor", vendor);
137 e.setAttribute("model", model);
138
139 QLocale c(QLocale::C);
140 e.setAttribute("fs", c.toString(fs));
141 e.setAttribute("vas", c.toString(vas));
142 e.setAttribute("re", c.toString(re));
143 e.setAttribute("qts", c.toString(qts));
144 e.setAttribute("sd", c.toString(sd));
145 e.setAttribute("xmax", c.toString(xmax));
146
147 return e;
148 }
149
150 void Speaker::fromDomElement(const QDomElement &el)
151 {
152 vendor = el.attribute("vendor");
153 model = el.attribute("model");
154
155 QLocale c(QLocale::C);
156 fs = c.toDouble(el.attribute("fs"));
157 vas = c.toDouble(el.attribute("vas"));
158 re = c.toDouble(el.attribute("re"));
159 qts = c.toDouble(el.attribute("qts"));
160 sd = c.toDouble(el.attribute("sd"));
161 xmax = c.toDouble(el.attribute("xmax"));
162 }
163
164 void Speaker::render(QPainter *painter, const QRectF &area)
165 {
166 if (!painter)
167 return;
168
169 painter->drawRoundRect(area.toRect(), 5, 5);
170
171 QString params[6];
172
173 params[0] = QString::fromUtf8("Fs: %1 Hz").arg(getFs());
174 params[1] = QString::fromUtf8("Qts: %1").arg(getQts());
175 params[2] = QString::fromUtf8("Vas: %1 L").arg(getVas());
176 params[3] = QString::fromUtf8("Sd: %1 m²").arg(getSd());
177 params[4] = QString::fromUtf8("Xmax: %1 mm").arg(getXmax());
178 params[5] = QString::fromUtf8("Re: %1 Ohm").arg(getRe());
179
180 qreal tab = area.left();
181
182 QString text = getVendor() + " " + getModel();
183 QRectF where(area.left(), area.top(), area.width(), area.height() / 2);
184 QTextOption option(Qt::AlignCenter);
185 painter->drawText(where, text, option);
186
187 for (int i = 0; i < 6; i++) {
188 where.setRect(tab, area.top() + area.height() / 2, area.width() / 6, area.height() / 2);
189 text = params[i];
190 option.setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
191 painter->drawText(where, text, option);
192 tab += area.width() / 6;
193 }
194 }

  ViewVC Help
Powered by ViewVC 1.1.26