1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-01-10 16:40:16 +02:00
nn-usb-fpga/Examples/ADC/QT_src/signaldisplay.cpp
2010-04-05 14:06:50 -05:00

61 lines
1.4 KiB
C++
Executable File

#include "signaldisplay.h"
#include <QtGui>
#include <QDebug>
SignalDisplay::SignalDisplay(QWidget *&parent):QWidget(parent)
{
colorTrace = Qt::blue;
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;
painter.fillRect(0,0,w,h,Qt::gray);
painter.setPen(Qt::white);
//painter.drawLine(secsIdx*w/10/60.0/pointsPerPlot/secsPerDiv,0, \
// secsIdx*w/10/60.0/pointsPerPlot/secsPerDiv,h);
drawGrid(painter, Qt::darkGray,0,0,w,h,4, 10);
/*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