From e19556263c3c62b6a24b920a102aed5523e166a0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Aug 2024 19:20:39 -0400 Subject: [PATCH] provide syntax highlighting color schemes for light and dark themes --- tools/lammps-gui/highlighter.cpp | 68 ++++++++++++++++++++++---------- tools/lammps-gui/lammpsgui.cpp | 6 ++- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/tools/lammps-gui/highlighter.cpp b/tools/lammps-gui/highlighter.cpp index 3f79c7a73e..9846011836 100644 --- a/tools/lammps-gui/highlighter.cpp +++ b/tools/lammps-gui/highlighter.cpp @@ -12,6 +12,7 @@ ------------------------------------------------------------------------- */ #include "highlighter.h" +#include "helpers.h" Highlighter::Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent), @@ -54,27 +55,54 @@ Highlighter::Highlighter(QTextDocument *parent) : isTriple(QStringLiteral("[^\"]*\"\"\"[^\"]*")), isString(QStringLiteral("(\".+?\"|'.+?'|\"\"\".*\"\"\")")), in_triple(false) { - formatNumber.setForeground(Qt::blue); - formatString.setForeground(Qt::darkGreen); - formatString.setFontWeight(QFont::Normal); - formatComment.setForeground(Qt::red); - formatSpecial.setForeground(Qt::darkMagenta); - formatSpecial.setFontWeight(QFont::Bold); - formatParticle.setForeground(Qt::darkRed); - formatParticle.setFontWeight(QFont::Bold); - formatRun.setForeground(Qt::darkBlue); - formatRun.setFontWeight(QFont::Bold); - formatVariable.setForeground(Qt::darkGray); - formatVariable.setFontWeight(QFont::Bold); + if (is_light_theme()) { + // syntax colors for light themes + formatNumber.setForeground(Qt::blue); + formatString.setForeground(Qt::darkGreen); + formatString.setFontWeight(QFont::Normal); + formatComment.setForeground(Qt::red); + formatSpecial.setForeground(Qt::darkMagenta); + formatSpecial.setFontWeight(QFont::Bold); + formatParticle.setForeground(Qt::darkRed); + formatParticle.setFontWeight(QFont::Bold); + formatRun.setForeground(Qt::darkBlue); + formatRun.setFontWeight(QFont::Bold); + formatVariable.setForeground(Qt::darkGray); + formatVariable.setFontWeight(QFont::Bold); - formatOutput.setForeground(Qt::darkYellow); - formatOutput.setFontWeight(QFont::Bold); - formatRead.setForeground(Qt::magenta); - formatRead.setFontWeight(QFont::Bold); - formatLattice.setForeground(Qt::darkGreen); - formatLattice.setFontWeight(QFont::Bold); - formatSetup.setForeground(Qt::darkCyan); - formatSetup.setFontWeight(QFont::Bold); + formatOutput.setForeground(Qt::darkYellow); + formatOutput.setFontWeight(QFont::Bold); + formatRead.setForeground(Qt::magenta); + formatRead.setFontWeight(QFont::Bold); + formatLattice.setForeground(Qt::darkGreen); + formatLattice.setFontWeight(QFont::Bold); + formatSetup.setForeground(Qt::darkCyan); + formatSetup.setFontWeight(QFont::Bold); + } else { + // syntax colors for dark themes + formatNumber.setForeground(QColorConstants::Svg::dodgerblue); + formatString.setForeground(QColorConstants::Green); + formatString.setFontWeight(QFont::Normal); + formatComment.setForeground(QColorConstants::Red); + formatComment.setFontWeight(QFont::Bold); + formatSpecial.setForeground(QColorConstants::Magenta); + formatSpecial.setFontWeight(QFont::Bold); + formatParticle.setForeground(QColorConstants::Svg::indianred); + formatParticle.setFontWeight(QFont::Bold); + formatRun.setForeground(QColorConstants::Svg::lightskyblue); + formatRun.setFontWeight(QFont::Bold); + formatVariable.setForeground(QColorConstants::Svg::lightgray); + formatVariable.setFontWeight(QFont::Bold); + + formatOutput.setForeground(QColorConstants::Yellow); + formatOutput.setFontWeight(QFont::Bold); + formatRead.setForeground(QColorConstants::Svg::lightcoral); + formatRead.setFontWeight(QFont::Bold); + formatLattice.setForeground(QColorConstants::Svg::lightgreen); + formatLattice.setFontWeight(QFont::Bold); + formatSetup.setForeground(QColorConstants::Cyan); + formatSetup.setFontWeight(QFont::Bold); + } } void Highlighter::highlightBlock(const QString &text) diff --git a/tools/lammps-gui/lammpsgui.cpp b/tools/lammps-gui/lammpsgui.cpp index 362a8f00cb..d75f97da7a 100644 --- a/tools/lammps-gui/lammpsgui.cpp +++ b/tools/lammps-gui/lammpsgui.cpp @@ -1431,7 +1431,11 @@ void LammpsGui::setFont(const QFont &newfont) void LammpsGui::about() { std::string version = "This is LAMMPS-GUI version " LAMMPS_GUI_VERSION; - version += " using Qt version " QT_VERSION_STR "\n"; + version += " using Qt version " QT_VERSION_STR; + if (is_light_theme()) + version += " using light theme\n"; + else + version += " using dark theme\n"; if (lammps.has_plugin()) { version += "LAMMPS library loaded as plugin"; if (!plugin_path.empty()) {