00001 #include "QtMarPlot.h"
00002
00003 namespace MarsyasQt
00004 {
00005 QtMarPlot::QtMarPlot(QWidget *parent)
00006 : QWidget(parent)
00007 {
00008
00009 plotName_ = "";
00010 minVal_ = -1;
00011 highVal_ = 1;
00012 pixelWidth_ = 1;
00013 startOffset_ = 0;
00014 endOffset_ = -1;
00015 drawCenter_ = false;
00016 drawImpulses_ = false;
00017 setAutoFillBackground(true);
00018 setBackgroundColor(QColor(255,255,255));
00019 }
00020
00021 QtMarPlot::~QtMarPlot()
00022 {
00023 }
00024
00025 void
00026 QtMarPlot::paintEvent(QPaintEvent *)
00027 {
00028 if (data_.getSize()==0)
00029 return;
00030
00031 QPainter painter(this);
00032
00033 painter.drawText( 4, 14, plotName_);
00034
00035
00036 QPen pen(Qt::SolidPattern, 1, Qt::DashLine);
00037 painter.setPen(pen);
00038 if (drawCenter_)
00039 painter.drawLine( 0, height()/2, width(), height()/2);
00040
00041 pen.setWidth(pixelWidth_);
00042 pen.setStyle(Qt::SolidLine);
00043 pen.setCapStyle(Qt::RoundCap);
00044 pen.setJoinStyle(Qt::RoundJoin);
00045 painter.setPen(pen);
00046
00047 mrs_natural i;
00048 mrs_natural x,y;
00049 mrs_real hScale = width() / (mrs_real) (endOffset_ - startOffset_);
00050 mrs_real vScale = height() / (highVal_ - minVal_);
00051 mrs_real vMean = (minVal_+highVal_)/2;
00052 mrs_natural midY = height()/2;
00053
00054
00055 for (i=0; i<data_.getSize(); i++)
00056 {
00057 x = mrs_natural (i * hScale);
00058 y = mrs_natural ( (data_(i)-vMean) * vScale );
00059 if ( (y>-midY) && (y<midY))
00060 painter.drawPoint( x, -y+midY);
00061 if (drawImpulses_)
00062 {
00063 for (y=y; y>-height()/2; y--)
00064 painter.drawPoint( x, -y+midY);
00065 }
00066 }
00067 }
00068
00069 }
00070