31 #include <QtPrintSupport/QPrinter>
32 #include <QtPrintSupport/QPrintDialog>
34 #define TR(id) OLocalizator::getString("TYSpectreWidget", (id))
52 QPrinter* printer =
new QPrinter();
53 if (pDialog->exec() == QDialog::Accepted)
55 QPrintDialog dialog(printer,
this);
58 QPainter paint(printer);
61 int mid = int(printer->width() / 2) -
62 int(paint.fontMetrics().horizontalAdvance(pDialog->
_lineEditTete->text()) / 2);
63 int midX = int(printer->width() / 2);
64 int midY = int(printer->height() / 2);
66 mid = int(printer->width() / 2) -
67 int(paint.fontMetrics().horizontalAdvance(pDialog->
_lineEditPied->text()) / 2);
68 paint.drawText(mid, printer->height() - 20, pDialog->
_lineEditPied->text());
69 paint.setFont(QFont(
"Helvetica", 15, QFont::Bold));
70 mid = int(printer->width() / 2) -
71 int(paint.fontMetrics().horizontalAdvance(pDialog->
_lineEditTitre->text()) / 2);
72 paint.drawText(mid, printer->height() * 14 / 15, pDialog->
_lineEditTitre->text());
73 paint.setFont(QFont());
75 double Wmetric = printer->width() * 9 / 10;
76 double Hmetric = printer->height() * 8 / 9;
80 double h = Wmetric * (y / x);
85 w = Hmetric * (x / y);
87 paint.translate(midX - (w / 2), midY - (h / 2));
97 QPainter* p =
new QPainter(
this);
112 size_t nbFreq =
tabFreq.size();
115 double width = double(w);
116 double height = double(h);
117 double value[50], hauteur = NAN, L = width * 2 / 3, hzero = NAN;
118 double hmax = 0, largeur = NAN, x = NAN;
123 double textPos = NAN;
124 double midFreq = double(nbFreq) / 2;
127 for (i = 0; i < nbFreq; i++)
131 if (value[i] != TY_SPECTRE_DEFAULT_VALUE)
143 else if (value[i] < hmin)
149 double echelle = height * 7 / 10 / (-hmin + hmax);
150 hzero = height * 8.5 / 10 + hmin * echelle;
152 if ((hmin == 0) && (hmax == 0))
160 largeur = L / (nbFreq + 1);
164 painter->setPen(blue);
170 for (i = 0; i < nbFreq; i++)
172 hauteur = value[i] * echelle;
173 painter->fillRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur,
174 QColor(100, 255, 110));
175 painter->drawRect((
int)x, (int)hzero - hauteur, (
int)largeur, (int)hauteur);
177 if (val !=
ROUND(value[i]))
179 val =
ROUND(value[i]);
180 valMax =
MAX(val, valMax);
183 if ((i ==
int(midFreq)) || (i == (nbFreq - 1)))
191 textPos = hzero + 17;
193 painter->drawLine((
int)x, (
int)(hzero + 5), (
int)x, (
int)(hzero - 5));
194 painter->drawText((
int)(x - 10), (
int)textPos, num.setNum(
tabFreq[i]));
201 painter->setPen(QPen(blue, 2));
202 painter->drawLine((
int)(width * 1 / 12 - 5), (
int)(hzero - valMax * echelle),
203 (
int)(width * 1 / 12 + 5), (
int)(hzero - valMax * echelle));
204 painter->drawText((
int)(width * 1 / 12 - 25), (
int)(hzero - valMax * echelle), num.setNum(valMax));
206 painter->drawLine((
int)(width * 1 / 12 - 5), (
int)(hzero - (valMax / 2) * echelle),
207 (
int)(width * 1 / 12 + 5), (
int)(hzero - (valMax / 2) * echelle));
208 painter->drawText((
int)(width * 1 / 12 - 25), (
int)(hzero - (valMax / 2) * echelle),
209 num.setNum((valMax / 2)));
211 painter->setPen(QPen(black, 2));
212 painter->drawLine((
int)(width * 1 / 12 - 2), (
int)hzero, (
int)(width * 11 / 12), (
int)hzero);
213 painter->drawLine((
int)(width * 1 / 12), (
int)(height * 18 / 20), (
int)(width * 1 / 12),
214 (
int)(hzero - hmax * echelle - 10));
215 painter->drawText((
int)(width * 1 / 12), (
int)(hzero - hmax * echelle - 20),
"dB");
216 painter->drawText((
int)(x + 2 * largeur), (
int)(height * 18 / 20),
TR(
"id_abscisse"));
218 x += width / 3 - 4 * largeur;
232 echelle = height * 7 / 10 / (-hmin + hmax);
233 hzero = height * 8.5 / 10 + hmin * echelle;
234 hauteur = value * echelle;
237 painter->drawLine((
int)x, (int)(height * 18 / 20), (int)x, (
int)(hzero - hmax * echelle - 10));
238 painter->drawLine((
int)(x - 5), (
int)(hzero - value * echelle), (
int)(x + 5),
239 (
int)(hzero - value * echelle));
240 painter->drawText((
int)(x - 15), (
int)(hzero - hmax * echelle - 20), num.setNum(value,
'f', 2));
243 painter->fillRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur, QColor(100, 255, 110));
244 painter->setPen(blue);
245 painter->drawRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur);
246 painter->setPen(black);
247 painter->drawText((
int)(x - 20), (
int)(height * 19 / 20),
TR(
"id_spectre_histo_dbZ"));
263 echelle = height * 7 / 10 / (-hmin + hmax);
264 hzero = height * 8.5 / 10 + hmin * echelle;
265 hauteur = value * echelle;
267 painter->setPen(QPen(black, 2));
269 painter->drawLine((
int)x, (int)(height * 18 / 20), (int)x, (
int)(hzero - hmax * echelle - 10));
270 painter->drawLine((
int)(x - 5), (
int)(hzero - value * echelle), (
int)(x + 5),
271 (
int)(hzero - value * echelle));
272 painter->drawText((
int)x, (int)(hzero - hmax * echelle - 20), num.setNum(value,
'f', 2));
275 painter->fillRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur, QColor(100, 255, 110));
276 painter->setPen(blue);
277 painter->drawRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur);
278 painter->setPen(black);
279 painter->drawText(x, height * 19 / 20,
TR(
"id_spectre_histo_dbA"));
283 painter->setPen(QPen(red, 3));
284 painter->drawText((
int)(width / 10), (
int)(height / 10),
TR(
"id_invalid_spectre"));
int ROUND(double a)
Compute the rounded value of a number.
double MAX(double a, double b)
Return the biggest number of two ones.
Boite de dialogue des parametres d'impression (fichier header)
const std::vector< double > tabFreq
OTabFreq TYTabFreq
Collection des frequences.
double valGlobDBA() const
Compute the global value dB[A] of a one-third Octave spectrum.
double valGlobDBLin() const
Compute the global value dB[Lin] of a one-third Octave spectrum.
double * getTabValReel() override
classe pour une boite de dialogue des parametres d'impression.
QGroupBox * _groupBoxCalcul
QLineEdit * _lineEditPied
QLineEdit * _lineEditTete
QGroupBox * _groupBoxProjet
QLineEdit * _lineEditTitre
virtual TYSpectreForm getForm()
Set/Get de la forme du spectre.
static const TYTabFreq getTabFreqNorm(TYSpectreForm form=SPECTRE_FORM_TIERS)