From: Shamus Hammons Date: Mon, 7 Jan 2019 13:35:40 +0000 (-0600) Subject: Collapse redundant code down to a callable function in waveformwidget. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63b57805e230dea14545298bb8264a3680a21e65;p=wozmaker Collapse redundant code down to a callable function in waveformwidget. --- diff --git a/src/waveformwidget.cpp b/src/waveformwidget.cpp index 5368a8b..c00bc77 100644 --- a/src/waveformwidget.cpp +++ b/src/waveformwidget.cpp @@ -279,17 +279,7 @@ void WaveformWidget::paintEvent(QPaintEvent * event) { for(uint32_t i=0; idata[offset + i]; - - while (Global::stream[j]->data[offset + i] == 0xFF) - { - i++; - timeToNext += Global::stream[j]->data[offset + i]; - } -#else uint32_t timeToNext = Global::wave[j][offset + i]; -#endif // if (i > 0) // x += timeToNext / 2; @@ -299,16 +289,11 @@ void WaveformWidget::paintEvent(QPaintEvent * event) { if (x >= drawXPos) { - painter.setPen(bluePen); - - if (x >= ((estSplice / 2) /* * ratio[wfNum]*/)) - painter.setPen(Qt::magenta); + if (x < (estSplice / 2)) + DrawPulse(&painter, &bluePen, lastx, x, y); + else + DrawPulse(&painter, Qt::magenta, lastx, x, y); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4.0, y); - painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0); - painter.drawLine(x + 4.0, y - 17.0, x + 8.0, y - 17.0); - painter.drawLine(x + 8.0, y - 17.0, x + 8.0, y); lastx = x + 8.0; } @@ -402,12 +387,7 @@ x positions are 16 pix apart, ideally. So to get the # of bits, we need to divi { if (Global::stream[j]->data[i / 8] & Global::bit[i % 8]) { - painter.setPen(Qt::cyan); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4, y); - painter.drawLine(x + 4, y, x + 4, y - 17); - painter.drawLine(x + 4, y - 17, x + 8, y - 17); - painter.drawLine(x + 8, y - 17, x + 8, y); + DrawPulse(&painter, Qt::cyan, lastx, x, y); lastx = x + 8.0; } @@ -430,32 +410,20 @@ x positions are 16 pix apart, ideally. So to get the # of bits, we need to divi uint32_t byte = 1; uint32_t bytePos = x; uint32_t bitCount = 1; - float hgt = 17.0f * 1.0f; - - painter.setPen(greenPen); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4.0, y); - painter.drawLine(x + 4.0, y, x + 4.0, y - hgt); - painter.drawLine(x + 4.0, y - hgt, x + 8.0, y - hgt); - painter.drawLine(x + 8.0, y - hgt, x + 8.0, y); + + DrawPulse(&painter, &greenPen, lastx, x, y); lastx = x + 8.0; for(uint32_t i=0; i 0) || (i == 0)) { if (x >= drawXPos) { - painter.setPen(greenPen); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4.0, y); - painter.drawLine(x + 4.0, y, x + 4.0, y - hgt); - painter.drawLine(x + 4.0, y - hgt, x + 8.0, y - hgt); - painter.drawLine(x + 8.0, y - hgt, x + 8.0, y); + DrawPulse(&painter, &greenPen, lastx, x, y, Global::swAmplitude[i]); lastx = x + 8.0; } @@ -535,12 +503,7 @@ x positions are 16 pix apart, ideally. So to get the # of bits, we need to divi x = 0; lastx = 0; - painter.setPen(orangePen); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4.0, y); - painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f); - painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f); - painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y); + DrawPulse(&painter, &orangePen, lastx, x, y); lastx = x + 8.0; for(uint32_t i=0; i= drawXPos) { - painter.setPen(orangePen); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4.0, y); - painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f); - painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f); - painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y); + DrawPulse(&painter, &orangePen, lastx, x, y); lastx = x + 8.0; } @@ -576,12 +534,7 @@ x positions are 16 pix apart, ideally. So to get the # of bits, we need to divi x = 0; lastx = 0; - painter.setPen(orangePen); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4.0, y); - painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f); - painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f); - painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y); + DrawPulse(&painter, &orangePen, lastx, x, y); lastx = x + 8.0; for(uint32_t i=Global::waveSync; i= drawXPos) { - painter.setPen(orangePen); - painter.drawLine(lastx, y, x, y); - painter.drawLine(x, y, x + 4.0, y); - painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f); - painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f); - painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y); + DrawPulse(&painter, &orangePen, lastx, x, y); lastx = x + 8.0; } @@ -615,6 +563,25 @@ x positions are 16 pix apart, ideally. So to get the # of bits, we need to divi } +void WaveformWidget::DrawPulse(QPainter * painter, QPen * pen, float lastx, float x, float y, float height/*= 1.0*/) +{ + float yHeight = y - (17.0 * height); + painter->setPen(*pen); + painter->drawLine(lastx, y, x, y); + painter->drawLine(x, y, x + 4.0, y); + painter->drawLine(x + 4.0, y, x + 4.0, yHeight); + painter->drawLine(x + 4.0, yHeight, x + 8.0, yHeight); + painter->drawLine(x + 8.0, yHeight, x + 8.0, y); +} + + +void WaveformWidget::DrawPulse(QPainter * painter, Qt::GlobalColor color, float lastx, float x, float y, float height/*= 1.0*/) +{ + QPen pen(color); + DrawPulse(painter, &pen, lastx, x, y, height); +} + + void WaveformWidget::mousePressEvent(QMouseEvent * event) { if (event->button() == Qt::LeftButton) diff --git a/src/waveformwidget.h b/src/waveformwidget.h index 19ccbf3..0a3cf5d 100644 --- a/src/waveformwidget.h +++ b/src/waveformwidget.h @@ -14,6 +14,8 @@ class WaveformWidget: public QWidget protected: void paintEvent(QPaintEvent * event); + void DrawPulse(QPainter * painter, QPen * pen, float lastx, float x, float y, float height = 1.0); + void DrawPulse(QPainter * painter, Qt::GlobalColor color, float lastx, float x, float y, float height = 1.0); void mousePressEvent(QMouseEvent * event); void mouseMoveEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent * event);