diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -32,6 +32,7 @@ #include #include +#include #include "utils.h" #include "version.h" @@ -157,7 +158,7 @@ MainWindow::MainWindow(QWidget *parent) channelBuffers.append(new FrameBuffer(numOfSamples)); curves.append(new QwtPlotCurve()); curves[i]->setSamples(channelBuffers[i]); - curves[i]->setPen(makeColor(i)); + curves[i]->setPen(Plot::makeColor(i)); curves[i]->attach(ui->plot); } @@ -471,7 +472,7 @@ void MainWindow::onNumOfChannelsChanged( channelBuffers.append(new FrameBuffer(numOfSamples)); curves.append(new QwtPlotCurve()); curves.last()->setSamples(channelBuffers.last()); - curves.last()->setPen(makeColor(curves.length()-1)); + curves.last()->setPen(Plot::makeColor(curves.length()-1)); curves.last()->attach(ui->plot); } } @@ -653,37 +654,6 @@ void MainWindow::enableDemo(bool enabled } } -/* - Below crude drawing demostrates how color selection occurs for - given channel index - - 0° <--Hue Value--> 360° - |* . o . + . o . * . o . + . o . * . o . + . o . * . o . + . o . | - - * -> 0-3 - + -> 4-7 - o -> 8-15 - . -> 16-31 - - */ - -QColor MainWindow::makeColor(unsigned int channelIndex) -{ - auto i = channelIndex; - - if (i < 4) - { - return QColor::fromHsv(360*i/4, 255, 230); - } - else - { - double p = floor(log2(i)); - double n = pow(2, p); - i = i - n; - return QColor::fromHsv(360*i/n + 360/pow(2,p+1), 255, 230); - } -} - void MainWindow::onExportCsv() { bool wasPaused = ui->actionPause->isChecked(); diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -109,8 +109,6 @@ private: bool isDemoRunning(); QwtPlotTextLabel demoIndicator; - QColor makeColor(unsigned int channelIndex); - private slots: void onPortToggled(bool open); void onDataReady(); // used with binary number formats diff --git a/plot.cpp b/plot.cpp --- a/plot.cpp +++ b/plot.cpp @@ -110,3 +110,33 @@ void Plot::darkBackground(bool enabled) } replot(); } + +/* + Below crude drawing demostrates how color selection occurs for + given channel index + + 0° <--Hue Value--> 360° + |* . o . + . o . * . o . + . o . * . o . + . o . * . o . + . o . | + + * -> 0-3 + + -> 4-7 + o -> 8-15 + . -> 16-31 + + */ +QColor Plot::makeColor(unsigned int channelIndex) +{ + auto i = channelIndex; + + if (i < 4) + { + return QColor::fromHsv(360*i/4, 255, 230); + } + else + { + double p = floor(log2(i)); + double n = pow(2, p); + i = i - n; + return QColor::fromHsv(360*i/n + 360/pow(2,p+1), 255, 230); + } +} diff --git a/plot.h b/plot.h --- a/plot.h +++ b/plot.h @@ -20,6 +20,7 @@ #ifndef PLOT_H #define PLOT_H +#include #include #include #include @@ -34,6 +35,8 @@ public: Plot(QWidget* parent = 0); void setAxis(bool autoScaled, double yMin = 0, double yMax = 1); + static QColor makeColor(unsigned int channelIndex); + private: bool isAutoScaled; double yMin, yMax; diff --git a/snapshotview.cpp b/snapshotview.cpp --- a/snapshotview.cpp +++ b/snapshotview.cpp @@ -14,6 +14,7 @@ SnapShotView::SnapShotView(QWidget *pare QwtPlotCurve* curve = new QwtPlotCurve(); curves.append(curve); curve->setSamples(snapShot->data[ci]); + curve->setPen(Plot::makeColor(ci)); curve->attach(ui->plot); } diff --git a/snapshotview.h b/snapshotview.h --- a/snapshotview.h +++ b/snapshotview.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "plot.h"