diff --git a/src/barplot.cpp b/src/barplot.cpp --- a/src/barplot.cpp +++ b/src/barplot.cpp @@ -19,9 +19,10 @@ #include "barplot.h" #include "barscaledraw.h" +#include "utils.h" -BarPlot::BarPlot(ChannelManager* channelMan, QWidget* parent) : - QwtPlot(parent), barChart(channelMan) +BarPlot::BarPlot(ChannelManager* channelMan, PlotMenu* menu, QWidget* parent) : + QwtPlot(parent), _menu(menu), barChart(channelMan) { _channelMan = channelMan; barChart.attach(this); @@ -31,6 +32,11 @@ BarPlot::BarPlot(ChannelManager* channel update(); connect(_channelMan, &ChannelManager::dataAdded, this, &BarPlot::update); connect(_channelMan, &ChannelManager::numOfChannelsChanged, this, &BarPlot::update); + + // connect to menu + connect(&menu->darkBackgroundAction, SELECT::OVERLOAD_OF(&QAction::toggled), + this, &BarPlot::darkBackground); + darkBackground(menu->darkBackgroundAction.isChecked()); } void BarPlot::update() @@ -52,3 +58,17 @@ void BarPlot::setYAxis(bool autoScaled, setAxisScale(QwtPlot::yLeft, yMin, yMax); } } + + +void BarPlot::darkBackground(bool enabled) +{ + if (enabled) + { + setCanvasBackground(QBrush(Qt::black)); + } + else + { + setCanvasBackground(QBrush(Qt::white)); + } + replot(); +} diff --git a/src/barplot.h b/src/barplot.h --- a/src/barplot.h +++ b/src/barplot.h @@ -23,6 +23,7 @@ #include #include "channelmanager.h" +#include "plotmenu.h" #include "barchart.h" class BarPlot : public QwtPlot @@ -30,14 +31,19 @@ class BarPlot : public QwtPlot Q_OBJECT public: - explicit BarPlot(ChannelManager* channelMan, QWidget* parent = 0); + explicit BarPlot(ChannelManager* channelMan, + PlotMenu* menu, + QWidget* parent = 0); public slots: /// Set the Y axis void setYAxis(bool autoScaled, double yMin = 0, double yMax = 1); + /// Enable/disable dark background + void darkBackground(bool enabled); private: ChannelManager* _channelMan; + PlotMenu* _menu; BarChart barChart; QVector chartData() const; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -508,7 +508,7 @@ void MainWindow::showBarPlot(bool show) { if (show) { - auto plot = new BarPlot(&channelMan); + auto plot = new BarPlot(&channelMan, &plotMenu); plot->setYAxis(plotControlPanel.autoScale(), plotControlPanel.yMin(), plotControlPanel.yMax());