00001 #include "Histogram.h"
00002
00003
00004 Histogram::Histogram(QWidget* parent ) : QWidget(parent)
00005 {
00006 m_parent = parent;
00007 showHistogram = false;
00008 m_histogram = QImage (321,71, QImage::Format_RGB32);
00009 }
00010
00011
00012 Histogram::~Histogram()
00013 {
00014 }
00015
00016 void Histogram::paintEvent(QPaintEvent* event)
00017 {
00018 QPainter p(this);
00019
00020 if(showHistogram)
00021 {
00022 float xTick = width() / (float) DENSITY_COUNT;
00023 float xStep = 0.0f;
00024 float yStep = 0.0f;
00025
00026
00027 p.translate(0, size().height());
00028
00029 for(int i = 0; i < DENSITY_COUNT; i++)
00030 {
00031 if(m_density[i] != 0)
00032 {
00033 yStep = m_density[i]/100;
00034 }
00035 else
00036 {
00037 yStep = 0.0f;
00038 }
00039
00040 p.drawLine(xStep, 0, xStep, -yStep );
00041 xStep += xTick;
00042 }
00043 }
00044 else
00045 {
00046 printf("size: %d, %d\n", width(), height());
00047 p.drawRect(0, 0, width() -1, height() -1 );
00048 }
00049
00050 }
00051
00052
00053 void Histogram::Show(const int* density)
00054 {
00055
00056
00057
00058
00059
00060 m_density = (int*) density;
00061 showHistogram = true;
00062
00063 m_parent->update();
00064 }
00065
00066
00067
00068 void Histogram::Clear()
00069 {
00070 showHistogram = false;
00071 printf("Clear histogram\n");
00072
00073 m_parent->update();
00074 }