SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "HeatColorBar.h" 00003 using namespace spikestream; 00004 00005 //SpikeStream includes 00006 #include "GlobalVariables.h" 00007 #include "Util.h" 00008 using namespace spikestream; 00009 00010 //Qt includes 00011 #include <QPainter> 00012 00013 //Other includes 00014 #include "math.h" 00015 00016 00018 HeatColorBar::HeatColorBar(QWidget* parent) : QWidget(parent){ 00019 //Set the size of the color bar 00020 setMinimumSize(400, 20); 00021 setMaximumSize(400, 20); 00022 00023 //Set the colors 00024 color0.setRgbF(HEAT_COLOR_0); 00025 color1.setRgbF(HEAT_COLOR_1); 00026 color2.setRgbF(HEAT_COLOR_2); 00027 color3.setRgbF(HEAT_COLOR_3); 00028 color4.setRgbF(HEAT_COLOR_4); 00029 color5.setRgbF(HEAT_COLOR_5); 00030 color6.setRgbF(HEAT_COLOR_6); 00031 color7.setRgbF(HEAT_COLOR_7); 00032 color8.setRgbF(HEAT_COLOR_8); 00033 color9.setRgbF(HEAT_COLOR_9); 00034 color10.setRgbF(HEAT_COLOR_10); 00035 00036 //Set up font colours 00037 fontColor.setRgb(0,255,0); 00038 00039 //Default max value of the bar 00040 maxValue = DEFAULT_MAX_HEAT_COLOR_VALUE; 00041 } 00042 00043 00045 HeatColorBar::~HeatColorBar(){ 00046 } 00047 00048 00049 /*----------------------------------------------------------*/ 00050 /*------ PUBLIC METHODS ------*/ 00051 /*----------------------------------------------------------*/ 00052 00054 void HeatColorBar::setMaxValue(double maxValue){ 00055 this->maxValue = maxValue; 00056 update(); 00057 } 00058 00059 00060 /*----------------------------------------------------------*/ 00061 /*------ PROTECTED METHODS ------*/ 00062 /*----------------------------------------------------------*/ 00063 00065 void HeatColorBar::paintEvent(QPaintEvent*){ 00066 QPainter painter(this); 00067 int areaWidth = width()/11; 00068 int areaHeight = height(); 00069 00070 //Paint the colour bars 00071 painter.fillRect(areaWidth * 0, 0, areaWidth, areaHeight, color0); 00072 painter.fillRect(areaWidth * 1, 0, areaWidth, areaHeight, color1); 00073 painter.fillRect(areaWidth * 2, 0, areaWidth, areaHeight, color2); 00074 painter.fillRect(areaWidth * 3, 0, areaWidth, areaHeight, color3); 00075 painter.fillRect(areaWidth * 4, 0, areaWidth, areaHeight, color4); 00076 painter.fillRect(areaWidth * 5, 0, areaWidth, areaHeight, color5); 00077 painter.fillRect(areaWidth * 6, 0, areaWidth, areaHeight, color6); 00078 painter.fillRect(areaWidth * 7, 0, areaWidth, areaHeight, color7); 00079 painter.fillRect(areaWidth * 8, 0, areaWidth, areaHeight, color8); 00080 painter.fillRect(areaWidth * 9, 0, areaWidth, areaHeight, color9); 00081 painter.fillRect(areaWidth * 10, 0, areaWidth, areaHeight, color10); 00082 00083 //Write the values associated with the colours 00084 QRectF fontRect(0, 0, areaWidth, areaHeight); 00085 painter.setPen(fontColor); 00086 painter.setFont(QFont("Arial", 10)); 00087 painter.drawText(fontRect, Qt::AlignCenter, "0"); 00088 00089 fontRect.moveTopLeft( QPointF(areaWidth * 1, 0) ); 00090 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 1*(maxValue/10.0), 1 ) ) ); 00091 fontRect.moveTopLeft( QPointF(areaWidth * 2, 0) ); 00092 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 2*(maxValue/10.0), 1 ) ) ); 00093 fontRect.moveTopLeft( QPointF(areaWidth * 3, 0) ); 00094 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 3*(maxValue/10.0), 1 ) ) ); 00095 fontRect.moveTopLeft( QPointF(areaWidth * 4, 0) ); 00096 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 4*(maxValue/10.0), 1 ) ) ); 00097 fontRect.moveTopLeft( QPointF(areaWidth * 5, 0) ); 00098 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 5*(maxValue/10.0), 1 ) ) ); 00099 fontRect.moveTopLeft( QPointF(areaWidth * 6, 0) ); 00100 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 6*(maxValue/10.0), 1 ) ) ); 00101 fontRect.moveTopLeft( QPointF(areaWidth * 7, 0) ); 00102 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 7*(maxValue/10.0), 1 ) ) ); 00103 fontRect.moveTopLeft( QPointF(areaWidth * 8, 0) ); 00104 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 8*(maxValue/10.0), 1 ) ) ); 00105 fontRect.moveTopLeft( QPointF(areaWidth * 9, 0) ); 00106 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( 9*(maxValue/10.0), 1 ) ) ); 00107 fontRect.moveTopLeft( QPointF(areaWidth * 10, 0) ); 00108 painter.drawText(fontRect, Qt::AlignCenter, QString::number( Util::rDouble( maxValue, 1 ) ) ); 00109 } 00110 00111