From baf1511f23ea0a43486fd2994e066bf5380dbf3c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Aug 2024 19:19:56 -0400 Subject: [PATCH] add light/dark mode detection --- tools/lammps-gui/helpers.cpp | 13 +++++++++++++ tools/lammps-gui/helpers.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/tools/lammps-gui/helpers.cpp b/tools/lammps-gui/helpers.cpp index 47d09f4515..cac5d86482 100644 --- a/tools/lammps-gui/helpers.cpp +++ b/tools/lammps-gui/helpers.cpp @@ -13,9 +13,12 @@ #include "helpers.h" +#include +#include #include #include #include +#include #include #include @@ -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: diff --git a/tools/lammps-gui/helpers.h b/tools/lammps-gui/helpers.h index b22b6e72c4..b3269e6d61 100644 --- a/tools/lammps-gui/helpers.h +++ b/tools/lammps-gui/helpers.h @@ -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