add light/dark mode detection

This commit is contained in:
Axel Kohlmeyer
2024-08-24 19:19:56 -04:00
parent 217546ed3b
commit baf1511f23
2 changed files with 16 additions and 0 deletions

View File

@ -13,9 +13,12 @@
#include "helpers.h"
#include <QBrush>
#include <QColor>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QPalette>
#include <QProcess>
#include <QStringList>
@ -84,6 +87,16 @@ void purge_directory(const QString &dir)
}
}
// compare black level of foreground and background color
bool is_light_theme()
{
QPalette p;
int fg = p.brush(QPalette::Active, QPalette::WindowText).color().black();
int bg = p.brush(QPalette::Active, QPalette::Window).color().black();
return (fg > bg);
}
// Local Variables:
// c-basic-offset: 4
// End:

View File

@ -28,6 +28,9 @@ extern bool has_exe(const QString &exe);
// recursively purge a directory
extern void purge_directory(const QString &dir);
// flag if light or dark theme
extern bool is_light_theme();
#endif
// Local Variables:
// c-basic-offset: 4