Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | #include "signaldisplay.h" |
| 2 | #include <QtGui> |
| 3 | #include <QDebug> |
| 4 | |
| 5 | SignalDisplay::SignalDisplay(QWidget *&parent):QWidget(parent) |
| 6 | { |
| 7 | colorTrace1 = Qt::blue; |
| 8 | colorTrace2 = Qt::red; |
| 9 | secsPerDiv = 1.0/600.0; |
| 10 | voltsPerDiv = 20; |
| 11 | setPointsPerPlot(10); |
| 12 | } |
| 13 | |
| 14 | void SignalDisplay::setPointsPerPlot(int value) |
| 15 | { |
| 16 | pointsPerPlot = value; |
| 17 | wave1 = new QPoint[pointsPerPlot]; |
| 18 | wave2 = new QPoint[pointsPerPlot]; |
| 19 | secsIdx1 = 0; secsIdx2 = 0; |
| 20 | } |
| 21 | |
| 22 | void SignalDisplay::drawGrid(QPainter &p, QColor colorGrid, int x, int y, int w, int h, int nx, int ny){ |
| 23 | p.setPen(colorGrid); |
| 24 | for (int ix= 0; ix<nx; ix++){ |
| 25 | int x = ix*w/nx; |
| 26 | p.drawLine(x,0,x,h); |
| 27 | } |
| 28 | for (int iy = 0; iy < ny; iy++){ |
| 29 | int y = iy*h/ny; |
| 30 | p.drawLine(0,y,w,y); |
| 31 | } |
| 32 | } |
| 33 | void SignalDisplay::paintEvent(QPaintEvent *event){ |
| 34 | QPainter painter(this); |
| 35 | w = width(); |
| 36 | h = height(); |
| 37 | ox = w; |
| 38 | oy = h; |
| 39 | painter.fillRect(0,0,w,h,Qt::white); |
| 40 | drawGrid(painter, Qt::lightGray,0,0,w,h,5, 10); |
| 41 | painter.setPen(colorTrace1); |
| 42 | painter.drawPolyline(wave1,pointsPerPlot); |
| 43 | painter.setPen(colorTrace2); |
| 44 | painter.drawPolyline(wave2,pointsPerPlot); |
| 45 | } |
| 46 | |
| 47 | void SignalDisplay::addPoint1( int value) |
| 48 | { |
| 49 | wave1[secsIdx1] = QPoint(secsIdx1*w/10/60.0/pointsPerPlot/secsPerDiv+w/(2*pointsPerPlot), \ |
| 50 | oy-value*h/voltsPerDiv/10); |
| 51 | secsIdx1 = (secsIdx1+1) % pointsPerPlot; |
| 52 | } |
| 53 | |
| 54 | void SignalDisplay::addPoint2( int value) |
| 55 | { |
| 56 | wave2[secsIdx2] = QPoint(secsIdx2*w/10/60.0/pointsPerPlot/secsPerDiv+w/(2*pointsPerPlot), \ |
| 57 | oy-value*h/voltsPerDiv/10); |
| 58 | secsIdx2 = (secsIdx2+1) % pointsPerPlot; |
| 59 | } |
| 60 | |
| 61 | //EOF |
| 62 |
Branches:
master
