2 * AnglesHistogramPainter.cpp 08/01/28
4 * Angles histogram painter.
6 * Copyright: (c) 2008 CTU Dragons
7 * CTU FEE - Department of Control Engineering
8 * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
14 #include "AnglesHistogramPainter.h"
16 #define ANGLES_HISTOGRAM_HEIGHT 70
18 AnglesHistogramPainter::AnglesHistogramPainter
19 (struct angles_freq *angles, int count)
21 background = QBrush(QColor(220, 220, 220));
22 this->angles = angles;
24 setSize(count, ANGLES_HISTOGRAM_HEIGHT);
27 AnglesHistogramPainter::~AnglesHistogramPainter()
31 void AnglesHistogramPainter::paint(QPainter *painter, QPaintEvent *event)
36 QRect rect = event->rect();
38 painter->fillRect(rect, background);
39 painter->setPen(QColor(20, 20, 20));
41 /* the first one is with highest frequency, use to calibrate
43 max = angles[0].frequency;
44 for (int i=0; i<count; i++) {
45 /* skip angles with frequency = zero */
46 if ((int)(angles[i].frequency) == 0)
49 /* description for three angles with highest frequency*/
51 /* correction to show text inside the view */
52 if ((int)(angles[i].angle) > 310)
53 cor = -(int)(angles[i].angle-320)-10;
55 painter->setPen(QColor(255, 20, 20));
57 (int)(angles[i].angle)+cor,
59 (double)angles[i].frequency /
60 (double)max*(height-20)+1),
63 .arg(angles[i].frequency));
64 painter->setPen(QColor(20, 20, 20));
68 painter->drawLine((int)(angles[i].angle),
70 (int)(angles[i].angle),
72 (double)angles[i].frequency /
73 (double)max*(height-20)));
77 void AnglesHistogramPainter::setCount(int count)
80 setSize(count, ANGLES_HISTOGRAM_HEIGHT);
83 void AnglesHistogramPainter::setSize(int width, int height)
86 this->height = height;
89 QSize AnglesHistogramPainter::size()
91 return QSize(width, height);