11#include " AeqPreviewPlot.h"
22
3+ #include " config/AppConfig.h"
4+
35#include < qtcsv/reader.h>
46#include < qtcsv/variantdata.h>
57#include < QBuffer>
@@ -42,10 +44,17 @@ AeqPreviewPlot::AeqPreviewPlot(QWidget* parent) : QCustomPlot(parent)
4244
4345}
4446
47+ #define ADD (name,label,color_light,width ) \
48+ auto name = addGraph(); \
49+ name->setName (label); \
50+ QPen name##_pen; \
51+ name##_pen.setColor(dark ? \
52+ QColor::fromHslF (color_light.hslHueF(), color_light.hslSaturationF(), fabs(color_light.lightnessF() - 1.0f)) : color_light); \
53+ name##_pen.setWidthF(width); \
54+ name->setPen (name##_pen);
55+
4556void AeqPreviewPlot::importCsv (const QString &csv, const QString& title)
4657{
47- useGraphicEq = false ;
48-
4958 clearItems ();
5059 clearGraphs ();
5160
@@ -69,13 +78,8 @@ void AeqPreviewPlot::importCsv(const QString &csv, const QString& title)
6978 return ;
7079 }
7180
72- #define ADD (name,label,color,width ) \
73- auto name = addGraph (); \
74- name->setName (label); \
75- QPen name##_pen; \
76- name##_pen.setColor (color); \
77- name##_pen.setWidthF (width); \
78- name->setPen (name##_pen);
81+ bool dark = AppConfig::instance ().get <bool >(AppConfig::AeqPlotDarkMode);
82+ updateBaseColors (dark);
7983
8084 ADD (target, " Target" , QColor (173 ,216 ,230 ) /* light blue */ ,4 )
8185 ADD (smoothed, " Raw (smoothed)" , QColor (Qt::lightGray), 4 )
@@ -97,8 +101,6 @@ void AeqPreviewPlot::importCsv(const QString &csv, const QString& title)
97101 equalization->addToLegend (legend);
98102 equalized_raw->addToLegend (legend);
99103
100- #undef ADD
101-
102104 double minY = -10 , maxY = 2 ;
103105 for (int row = 1 ; row < variant.rowCount (); row++)
104106 {
@@ -149,21 +151,15 @@ void AeqPreviewPlot::importCsv(const QString &csv, const QString& title)
149151
150152void AeqPreviewPlot::importGraphicEq (const QString &graphic, const QString& title)
151153{
152- useGraphicEq = true ;
153-
154154 clearItems ();
155155 clearGraphs ();
156156
157157 titleElement->setText (title);
158158
159- auto g = addGraph (xAxis, yAxis);
160- g->setName (" Equalization (normalized)" );
161- g->addToLegend (legend);
159+ bool dark = AppConfig::instance ().get <bool >(AppConfig::AeqPlotDarkMode);
160+ updateBaseColors (dark);
162161
163- QPen pen; \
164- pen.setColor (QColor (119 , 194 , 119 ) /* green */ );
165- pen.setWidthF (4 );
166- g->setPen (pen);
162+ ADD (graph, " Equalization (normalized)" , QColor (119 , 194 , 119 ) /* green */ ,4 )
167163
168164 auto dataset = graphic;
169165 dataset.replace (" GraphicEQ: " , " " );
@@ -180,14 +176,16 @@ void AeqPreviewPlot::importGraphicEq(const QString &graphic, const QString& titl
180176 if (y < minY)
181177 minY = y;
182178
183- g ->addData (set[0 ].toDouble (), y);
179+ graph ->addData (set[0 ].toDouble (), y);
184180 }
185181 }
186182
187183 yAxis->setRange (QCPRange (minY - 3 , maxY + 3 ));
188184 replot (QCustomPlot::rpQueuedReplot);
189185}
190186
187+ #undef ADD
188+
191189void AeqPreviewPlot::onHover (QMouseEvent *event)
192190{
193191 int x = (int ) xAxis->pixelToCoord (event->pos ().x ());
@@ -238,10 +236,20 @@ void AeqPreviewPlot::onLegendClick(QCPLegend *legend, QCPAbstractLegendItem *ite
238236
239237 if (item)
240238 {
239+ bool dark = AppConfig::instance ().get <bool >(AppConfig::AeqPlotDarkMode);
240+
241241 QCPPlottableLegendItem *plItem = qobject_cast<QCPPlottableLegendItem*>(item);
242242 bool visible = plItem->plottable ()->visible ();
243243 plItem->plottable ()->setVisible (!visible);
244- plItem->setTextColor (!visible ? QColor (Qt::black) : QColor (Qt::gray));
244+
245+ if (dark)
246+ {
247+ plItem->setTextColor (!visible ? QColor (Qt::white) : QColor (Qt::darkGray));
248+ }
249+ else
250+ {
251+ plItem->setTextColor (!visible ? QColor (Qt::black) : QColor (Qt::gray));
252+ }
245253 replot ();
246254 }
247255}
@@ -255,18 +263,46 @@ void AeqPreviewPlot::onLegendDoubleClick(QCPLegend *legend, QCPAbstractLegendIte
255263 QCPPlottableLegendItem *plItem = qobject_cast<QCPPlottableLegendItem*>(item);
256264 for (int i = 0 ; i < legend->itemCount (); i++)
257265 {
266+ bool dark = AppConfig::instance ().get <bool >(AppConfig::AeqPlotDarkMode);
267+
258268 auto it = qobject_cast<QCPPlottableLegendItem*>(legend->item (i));
259269 if (it && it == plItem)
260270 {
261271 it->plottable ()->setVisible (true );
262- it->setTextColor (QColor (Qt::black));
272+ it->setTextColor (QColor (dark ? Qt::white : Qt::black));
263273 }
264274 else if (it && it != plItem)
265275 {
266276 it->plottable ()->setVisible (false );
267- it->setTextColor (QColor (Qt::gray));
277+ it->setTextColor (QColor (dark ? Qt::darkGray : Qt::gray));
268278 }
269279 }
270280 replot ();
271281 }
272282}
283+
284+ void AeqPreviewPlot::updateBaseColors (bool dark)
285+ {
286+ QColor text = dark ? QColor (222 , 222 , 222 ) : Qt::black;
287+ QColor base = dark ? Qt::black : Qt::white;
288+ QColor window = dark ? QColor (28 , 28 , 28 ) : Qt::black;
289+
290+ this ->setBackground (base);
291+ this ->titleElement ->setTextColor (text);
292+
293+ this ->yAxis ->setLabelColor (text);
294+ this ->yAxis ->setTickLabelColor (text);
295+ this ->yAxis ->setBasePen (text);
296+ this ->yAxis ->setTickPen (text);
297+ this ->yAxis ->setSubTickPen (text);
298+
299+ this ->xAxis ->setLabelColor (text);
300+ this ->xAxis ->setTickLabelColor (text);
301+ this ->xAxis ->setBasePen (text);
302+ this ->xAxis ->setTickPen (text);
303+ this ->xAxis ->setSubTickPen (text);
304+
305+ this ->legend ->setBrush (base);
306+ this ->legend ->setBorderPen (window);
307+ this ->legend ->setTextColor (text);
308+ }
0 commit comments