1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-01-10 12:30:16 +02:00
nn-usb-fpga/Examples/ADC/QT_src/signaldisplay.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

2010-04-05 22:06:50 +03:00
#include "signaldisplay.h"
#include <QtGui>
#include <QDebug>
SignalDisplay::SignalDisplay(QWidget *&parent):QWidget(parent)
{
2010-04-08 05:59:30 +03:00
colorTrace = Qt::black;
2010-04-05 22:06:50 +03:00
secsPerDiv = 1.0/600.0;
voltsPerDiv = 20;
setPointsPerPlot(10);
}
void SignalDisplay::setPointsPerPlot(int value)
{
pointsPerPlot = value;
waves = new QPoint[pointsPerPlot];
secsIdx = 0;
}
void SignalDisplay::drawGrid(QPainter &p, QColor colorGrid, int x, int y, int w, int h, int nx, int ny){
p.setPen(colorGrid);
for (int ix= 0; ix<nx; ix++){
int x = ix*w/nx;
p.drawLine(x,0,x,h);
}
for (int iy = 0; iy < ny; iy++){
int y = iy*h/ny;
p.drawLine(0,y,w,y);
}
}
void SignalDisplay::paintEvent(QPaintEvent *event){
QPainter painter(this);
w = width();
h = height();
ox = w;
oy = h;
2010-04-08 05:59:30 +03:00
painter.fillRect(0,0,w,h,Qt::white);
//painter.setPen(Qt::white);
2010-04-05 22:06:50 +03:00
//painter.drawLine(secsIdx*w/10/60.0/pointsPerPlot/secsPerDiv,0, \
// secsIdx*w/10/60.0/pointsPerPlot/secsPerDiv,h);
2010-04-08 05:59:30 +03:00
drawGrid(painter, Qt::lightGray,0,0,w,h,5, 10);
2010-04-05 22:06:50 +03:00
/*for(int i = 0; i < pointsPerPlot; i++)
{
painter.fillRect(waves[i].x()-w/pointsPerPlot/2,waves[i].y(), \
w/pointsPerPlot,h-waves[i].y(), Qt::blue);
}*/
painter.setPen(colorTrace);
painter.drawPolyline(waves,pointsPerPlot);
}
void SignalDisplay::addPoint( int value1)
{
waves[secsIdx] = QPoint(secsIdx*w/10/60.0/pointsPerPlot/secsPerDiv+w/(2*pointsPerPlot), \
oy-value1*h/voltsPerDiv/10);
secsIdx = (secsIdx+1) % pointsPerPlot;
}
//EOF