Skip to content

Commit c334fff

Browse files
committed
Add dark mode for plot
1 parent 885a8c9 commit c334fff

File tree

6 files changed

+105
-38
lines changed

6 files changed

+105
-38
lines changed

src/config/AppConfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class AppConfig :
6969
AudioOutputUseDefault,
7070
AudioOutputDevice,
7171
AudioAppBlocklist,
72-
AudioAppBlocklistInvert
72+
AudioAppBlocklistInvert,
73+
74+
AeqPlotDarkMode
7375
};
7476
Q_ENUM(Key);
7577

src/subprojects/AutoEqIntegration/AeqPreviewPlot.cpp

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
4556
void 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

150152
void 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+
191189
void 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+
}

src/subprojects/AutoEqIntegration/AeqPreviewPlot.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ private slots:
1818
void moveLegend();
1919
void onLegendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
2020
void onLegendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
21+
2122
private:
22-
bool useGraphicEq = false;
23+
void updateBaseColors(bool dark);
2324

2425
QCPTextElement* titleElement;
26+
2527
};
2628

2729
#endif // AEQPREVIEWPLOT_H

src/subprojects/AutoEqIntegration/AeqSelector.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "AeqMeasurementItem.h"
88
#include "AeqMeasurementModel.h"
99

10+
#include "config/AppConfig.h"
11+
1012
#include <QListWidget>
1113
#include <QMessageBox>
1214
#include <QBitmap>
@@ -35,13 +37,17 @@ AeqSelector::AeqSelector(QWidget *parent) :
3537
ui->list->setModel(proxyModel);
3638
ui->list->setItemDelegate(new AeqItemDelegate(ui->list));
3739

38-
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AeqSelector::accept);
39-
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &AeqSelector::reject);
40+
ui->darkMode->setChecked(AppConfig::instance().get<bool>(AppConfig::AeqPlotDarkMode));
41+
42+
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AeqSelector::accept);
43+
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &AeqSelector::reject);
4044

41-
connect(ui->searchInput, &QLineEdit::textChanged, proxyModel, &QSortFilterProxyModel::setFilterWildcard);
42-
connect(ui->manageDatabase, &QPushButton::clicked, this, &AeqSelector::switchPane);
43-
connect(ui->updateButton, &QPushButton::clicked, this, &AeqSelector::updateDatabase);
44-
connect(ui->deleteButton, &QPushButton::clicked, this, &AeqSelector::deleteDatabase);
45+
connect(ui->searchInput, &QLineEdit::textChanged, proxyModel, &QSortFilterProxyModel::setFilterWildcard);
46+
connect(ui->manageDatabase, &QPushButton::clicked, this, &AeqSelector::switchPane);
47+
connect(ui->updateButton, &QPushButton::clicked, this, &AeqSelector::updateDatabase);
48+
connect(ui->deleteButton, &QPushButton::clicked, this, &AeqSelector::deleteDatabase);
49+
50+
connect(ui->darkMode, &QCheckBox::stateChanged, this, &AeqSelector::onDarkModeToggled);
4551

4652
connect(ui->list->selectionModel(), &QItemSelectionModel::selectionChanged, this, &AeqSelector::onSelectionChanged);
4753

@@ -110,7 +116,6 @@ void AeqSelector::updateDatabase()
110116
});
111117
};
112118

113-
114119
pkgManager->isUpdateAvailable().then([&](AeqVersion remote)
115120
{
116121
doInstallation(remote);
@@ -185,6 +190,13 @@ void AeqSelector::onSelectionChanged(const QItemSelection &selected, const QItem
185190
}
186191
}
187192

193+
void AeqSelector::onDarkModeToggled(int state)
194+
{
195+
AppConfig::instance().set(AppConfig::AeqPlotDarkMode, (bool)state);
196+
// Reload plot
197+
onSelectionChanged(ui->list->selectionModel()->selection(), QItemSelection());
198+
}
199+
188200
QString AeqSelector::selection(DataFormat format, bool silent)
189201
{
190202
if (ui->list->selectionModel()->selectedRows().isEmpty())

src/subprojects/AutoEqIntegration/AeqSelector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private slots:
3838
void deleteDatabase();
3939
void updateDatabaseInfo();
4040
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
41+
void onDarkModeToggled(int state);
4142

4243
private:
4344
Ui::AeqSelector *ui;

src/subprojects/AutoEqIntegration/AeqSelector.ui

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<enum>QFrame::Plain</enum>
2626
</property>
2727
<property name="currentIndex">
28-
<number>0</number>
28+
<number>1</number>
2929
</property>
3030
<widget class="QWidget" name="stackedWidgetPage1">
3131
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -172,6 +172,22 @@
172172
</layout>
173173
</widget>
174174
</item>
175+
<item>
176+
<widget class="QGroupBox" name="groupBox_2">
177+
<property name="title">
178+
<string>Display settings</string>
179+
</property>
180+
<layout class="QVBoxLayout" name="verticalLayout_9">
181+
<item>
182+
<widget class="QCheckBox" name="darkMode">
183+
<property name="text">
184+
<string>Dark mode</string>
185+
</property>
186+
</widget>
187+
</item>
188+
</layout>
189+
</widget>
190+
</item>
175191
<item>
176192
<spacer name="verticalSpacer">
177193
<property name="orientation">
@@ -295,16 +311,14 @@ This will override your current GraphicEQ configuration.</string>
295311
</widget>
296312
<widget class="QWidget" name="page_2">
297313
<property name="styleSheet">
298-
<string notr="true">#page_2 {
299-
background-color: white;
300-
}</string>
314+
<string notr="true"/>
301315
</property>
302316
<layout class="QVBoxLayout" name="verticalLayout_8">
303317
<property name="leftMargin">
304318
<number>0</number>
305319
</property>
306320
<property name="topMargin">
307-
<number>4</number>
321+
<number>0</number>
308322
</property>
309323
<property name="rightMargin">
310324
<number>0</number>

0 commit comments

Comments
 (0)