32 #include <QtPrintSupport/QPrinter>
33 #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);
89 paint.translate(midX - (w / 2), midY - (h / 2));
99 QPainter* p =
new QPainter(
this);
116 size_t nbFreq =
tabFreq.size();
119 double width = double(w);
120 double height = double(h);
121 double value[50], hauteur = NAN, L = width * 2 / 3, hzero = NAN;
122 double hmax = 0, largeur = L / (nbFreq + 1), x = width * 1 / 6 + 10;
127 double textPos = NAN;
128 double midFreq = nbFreq / 2.0;
131 for (i = 0; i < nbFreq; i++)
135 if (value[i] != TY_SPECTRE_DEFAULT_VALUE)
147 else if (value[i] < hmin)
153 double echelle = height * 7 / 10 / (-hmin + hmax);
154 hzero = height * 8.5 / 10 + hmin * echelle;
155 if ((hmin == 0) && (hmax == 0))
165 hauteur = value[0] * echelle;
166 double hprev = hzero - hauteur;
168 painter->setPen(QPen(red, 2));
170 for (i = 1; i < nbFreq; i++)
172 hauteur = value[i] * echelle;
173 painter->drawLine((
int)x, (int)hprev, (
int)(x + largeur), (
int)(hzero - hauteur));
174 hprev = hzero - hauteur;
176 if (val !=
ROUND(value[i]))
178 val =
ROUND(value[i]);
179 valMax =
MAX(val, valMax);
182 if ((i ==
int(midFreq)) || (i == (nbFreq - 1)))
190 textPos = hzero + 17;
192 painter->drawLine((
int)x, (
int)(hzero + 5), (
int)x, (
int)(hzero - 5));
193 painter->drawText((
int)(x - 10), (
int)textPos, num.setNum(
tabFreq[i]));
200 painter->drawLine((
int)(width * 1 / 6 + 5), (
int)(hzero - valMax * echelle),
201 (
int)(width * 1 / 6 + 15), (
int)(hzero - valMax * echelle));
202 painter->drawText((
int)(width * 1 / 6 - 25), (
int)(hzero - valMax * echelle), num.setNum(valMax));
204 painter->drawLine((
int)(width * 1 / 6 + 5), (
int)(hzero - (valMax / 2) * echelle),
205 (
int)(width * 1 / 6 + 15), (
int)(hzero - (valMax / 2) * echelle));
206 painter->drawText((
int)(width * 1 / 6 - 25), (
int)(hzero - (valMax / 2) * echelle),
207 num.setNum((valMax / 2)));
209 painter->setPen(QPen(black, 2));
210 painter->drawLine((
int)(width * 1 / 6), (
int)(hzero), (
int)(width * 5 / 6), (
int)hzero);
211 painter->drawLine((
int)(width * 1 / 6 + 10), (
int)(height * 18 / 20), (
int)(width * 1 / 6 + 10),
212 (
int)(hzero - hmax * echelle - 10));
213 painter->drawText((
int)(width * 1 / 6), (
int)(hzero - hmax * echelle - 20),
"dB");
214 painter->drawText((
int)(width * 5 / 6), (
int)hzero,
TR(
"id_abscisse"));
218 painter->setPen(QPen(red, 3));
219 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 * 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)