00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "mgraph.h"
00021 #include "graphbackground.xpm"
00022 #include <qpainter.h>
00023 #include <qpixmap.h>
00024
00025
00026
00027 MGraph::MGraph( QWidget *parent, const char *name, WFlags f )
00028 : QFrame( parent, name, f ), min( 0 ), max( 0), values( 0 )
00029 {
00030 background = new QPixmap( (const char** ) graphbackground_xpm );
00031 values = new ValueList();
00032 }
00033
00034 void MGraph::setFrameStyle( int style )
00035 {
00036 QFrame::setFrameStyle( style );
00037 setFixedSize( background->width() + frameWidth()*2, background->height() + frameWidth()*2 );
00038 }
00039
00040 void MGraph::addValue( int value, bool followMax )
00041 {
00042 values->append( value );
00043 if ( followMax && (value > max) )
00044 setMax( value );
00045 if ( values->count() == background->width()-2 )
00046 values->remove( values->begin() );
00047 repaint( false );
00048 }
00049
00050 void MGraph::drawContents( QPainter* p )
00051 {
00052 p->drawPixmap( frameWidth(), frameWidth(), (const QPixmap&) *background );
00053 p->setPen( QColor( 40, 235, 40 ) );
00054
00055 int x = frameWidth() + 2;
00056 int y = 0;
00057
00058 ValueList::ConstIterator it;
00059 for ( it = values->begin(); it != values->end(); ++it )
00060 {
00061 y = frameWidth() + background->height() -3 - ( ( *(it)*(background->height()-4 ) /max ) );
00062 p->drawPoint( x++, y );
00063 }
00064 }
00065
00066 MGraph::~MGraph()
00067 {
00068 delete background;
00069 delete values;
00070 }
00071