provide syntax highlighting color schemes for light and dark themes

This commit is contained in:
Axel Kohlmeyer
2024-08-24 19:20:39 -04:00
parent baf1511f23
commit e19556263c
2 changed files with 53 additions and 21 deletions

View File

@ -12,6 +12,7 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "highlighter.h" #include "highlighter.h"
#include "helpers.h"
Highlighter::Highlighter(QTextDocument *parent) : Highlighter::Highlighter(QTextDocument *parent) :
QSyntaxHighlighter(parent), QSyntaxHighlighter(parent),
@ -54,27 +55,54 @@ Highlighter::Highlighter(QTextDocument *parent) :
isTriple(QStringLiteral("[^\"]*\"\"\"[^\"]*")), isTriple(QStringLiteral("[^\"]*\"\"\"[^\"]*")),
isString(QStringLiteral("(\".+?\"|'.+?'|\"\"\".*\"\"\")")), in_triple(false) isString(QStringLiteral("(\".+?\"|'.+?'|\"\"\".*\"\"\")")), in_triple(false)
{ {
formatNumber.setForeground(Qt::blue); if (is_light_theme()) {
formatString.setForeground(Qt::darkGreen); // syntax colors for light themes
formatString.setFontWeight(QFont::Normal); formatNumber.setForeground(Qt::blue);
formatComment.setForeground(Qt::red); formatString.setForeground(Qt::darkGreen);
formatSpecial.setForeground(Qt::darkMagenta); formatString.setFontWeight(QFont::Normal);
formatSpecial.setFontWeight(QFont::Bold); formatComment.setForeground(Qt::red);
formatParticle.setForeground(Qt::darkRed); formatSpecial.setForeground(Qt::darkMagenta);
formatParticle.setFontWeight(QFont::Bold); formatSpecial.setFontWeight(QFont::Bold);
formatRun.setForeground(Qt::darkBlue); formatParticle.setForeground(Qt::darkRed);
formatRun.setFontWeight(QFont::Bold); formatParticle.setFontWeight(QFont::Bold);
formatVariable.setForeground(Qt::darkGray); formatRun.setForeground(Qt::darkBlue);
formatVariable.setFontWeight(QFont::Bold); formatRun.setFontWeight(QFont::Bold);
formatVariable.setForeground(Qt::darkGray);
formatVariable.setFontWeight(QFont::Bold);
formatOutput.setForeground(Qt::darkYellow); formatOutput.setForeground(Qt::darkYellow);
formatOutput.setFontWeight(QFont::Bold); formatOutput.setFontWeight(QFont::Bold);
formatRead.setForeground(Qt::magenta); formatRead.setForeground(Qt::magenta);
formatRead.setFontWeight(QFont::Bold); formatRead.setFontWeight(QFont::Bold);
formatLattice.setForeground(Qt::darkGreen); formatLattice.setForeground(Qt::darkGreen);
formatLattice.setFontWeight(QFont::Bold); formatLattice.setFontWeight(QFont::Bold);
formatSetup.setForeground(Qt::darkCyan); formatSetup.setForeground(Qt::darkCyan);
formatSetup.setFontWeight(QFont::Bold); 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) void Highlighter::highlightBlock(const QString &text)

View File

@ -1431,7 +1431,11 @@ void LammpsGui::setFont(const QFont &newfont)
void LammpsGui::about() void LammpsGui::about()
{ {
std::string version = "This is LAMMPS-GUI version " LAMMPS_GUI_VERSION; 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()) { if (lammps.has_plugin()) {
version += "LAMMPS library loaded as plugin"; version += "LAMMPS library loaded as plugin";
if (!plugin_path.empty()) { if (!plugin_path.empty()) {