31 #include <QtPrintSupport/QPrinter>
32 #include <QtPrintSupport/QPrintDialog>
35 #define TR(id) OLocalizator::getString("TYSpectreWidget", (id))
53 QPrinter* printer =
new QPrinter();
54 if (pDialog->exec() == QDialog::Accepted)
56 QPrintDialog dialog(printer,
this);
59 QPainter paint(printer);
62 int mid = int(printer->width() / 2) -
63 int(paint.fontMetrics().horizontalAdvance(pDialog->
_lineEditTete->text()) / 2);
64 int midX = int(printer->width() / 2);
65 int midY = int(printer->height() / 2);
67 mid = int(printer->width() / 2) -
68 int(paint.fontMetrics().horizontalAdvance(pDialog->
_lineEditPied->text()) / 2);
69 paint.drawText(mid, printer->height() - 20, pDialog->
_lineEditPied->text());
70 paint.setFont(QFont(
"Helvetica", 15, QFont::Bold));
71 mid = int(printer->width() / 2) -
72 int(paint.fontMetrics().horizontalAdvance(pDialog->
_lineEditTitre->text()) / 2);
73 paint.drawText(mid, printer->height() * 14 / 15, pDialog->
_lineEditTitre->text());
74 paint.setFont(QFont());
76 double Wmetric = printer->width() * 9 / 10;
77 double Hmetric = printer->height() * 8 / 9;
81 double h = Wmetric * (y / x);
86 w = Hmetric * (x / y);
88 paint.translate(midX - (w / 2), midY - (h / 2));
98 QPainter* p =
new QPainter(
this);
113 size_t nbFreq =
tabFreq.size();
116 double width = double(w);
117 double height = double(h);
118 double value[50], hauteur = NAN, L = width * 2 / 3, hzero = NAN;
119 double hmax = 0, largeur = NAN, x = NAN;
124 double textPos = NAN;
125 double midFreq = double(nbFreq) / 2;
127 for (i = 0; i < nbFreq; i++)
137 else if (value[i] < hmin)
143 double echelle = height * 7 / 10 / (-hmin + hmax);
144 hzero = height * 8.5 / 10 + hmin * echelle;
146 if ((hmin == 0) && (hmax == 0))
154 largeur = L / (nbFreq + 1);
158 painter->setPen(Qt::blue);
163 for (i = 0; i < nbFreq; i++)
165 hauteur = value[i] * echelle;
166 painter->fillRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur,
167 QColor(100, 255, 110));
168 painter->drawRect((
int)x, (int)hzero - hauteur, (
int)largeur, (int)hauteur);
170 if (val !=
ROUND(value[i]))
172 val =
ROUND(value[i]);
173 valMax =
MAX(val, valMax);
176 if ((i ==
int(midFreq)) || (i == (nbFreq - 1)))
184 textPos = hzero + 17;
186 painter->drawLine((
int)x, (
int)(hzero + 5), (
int)x, (
int)(hzero - 5));
187 painter->drawText((
int)(x - 10), (
int)textPos, num.setNum(
tabFreq[i]));
194 painter->setPen(QPen(Qt::blue, 2));
195 painter->drawLine((
int)(width * 1 / 12 - 5), (
int)(hzero - valMax * echelle),
196 (
int)(width * 1 / 12 + 5), (
int)(hzero - valMax * echelle));
197 painter->drawText((
int)(width * 1 / 12 - 25), (
int)(hzero - valMax * echelle), num.setNum(valMax));
199 painter->drawLine((
int)(width * 1 / 12 - 5), (
int)(hzero - (valMax / 2) * echelle),
200 (
int)(width * 1 / 12 + 5), (
int)(hzero - (valMax / 2) * echelle));
201 painter->drawText((
int)(width * 1 / 12 - 25), (
int)(hzero - (valMax / 2) * echelle),
202 num.setNum((valMax / 2)));
204 painter->setPen(QPen(Qt::black, 2));
205 painter->drawLine((
int)(width * 1 / 12 - 2), (
int)hzero, (
int)(width * 11 / 12), (
int)hzero);
206 painter->drawLine((
int)(width * 1 / 12), (
int)(height * 18 / 20), (
int)(width * 1 / 12),
207 (
int)(hzero - hmax * echelle - 10));
208 painter->drawText((
int)(width * 1 / 12), (
int)(hzero - hmax * echelle - 20),
"dB");
209 painter->drawText((
int)(x + 2 * largeur), (
int)(height * 18 / 20),
TR(
"id_abscisse"));
211 x += width / 3 - 4 * largeur;
225 echelle = height * 7 / 10 / (-hmin + hmax);
226 hzero = height * 8.5 / 10 + hmin * echelle;
227 hauteur = value * echelle;
230 painter->drawLine((
int)x, (int)(height * 18 / 20), (int)x, (
int)(hzero - hmax * echelle - 10));
231 painter->drawLine((
int)(x - 5), (
int)(hzero - value * echelle), (
int)(x + 5),
232 (
int)(hzero - value * echelle));
233 painter->drawText((
int)(x - 15), (
int)(hzero - hmax * echelle - 20), num.setNum(value,
'f', 2));
236 painter->fillRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur, QColor(100, 255, 110));
237 painter->setPen(Qt::blue);
238 painter->drawRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur);
239 painter->setPen(Qt::black);
240 painter->drawText((
int)(x - 20), (
int)(height * 19 / 20),
TR(
"id_spectre_histo_dbZ"));
256 echelle = height * 7 / 10 / (-hmin + hmax);
257 hzero = height * 8.5 / 10 + hmin * echelle;
258 hauteur = value * echelle;
260 painter->setPen(QPen(Qt::black, 2));
262 painter->drawLine((
int)x, (int)(height * 18 / 20), (int)x, (
int)(hzero - hmax * echelle - 10));
263 painter->drawLine((
int)(x - 5), (
int)(hzero - value * echelle), (
int)(x + 5),
264 (
int)(hzero - value * echelle));
265 painter->drawText((
int)x, (int)(hzero - hmax * echelle - 20), num.setNum(value,
'f', 2));
268 painter->fillRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur, QColor(100, 255, 110));
269 painter->setPen(Qt::blue);
270 painter->drawRect((
int)x, (int)(hzero - hauteur), (int)largeur, (
int)hauteur);
271 painter->setPen(Qt::black);
272 painter->drawText(x, height * 19 / 20,
TR(
"id_spectre_histo_dbA"));
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)