From 5bb041deaa12a8a8a4f62e6ca8b229298e5667a6 Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Mon, 3 Oct 2022 17:52:45 +0200 Subject: [PATCH] Gui: use default app text color for Python code instuctions highlighting This allows to deal with OS native dark themes In such cases, Python instructions were black on a dark background --- src/Gui/DlgEditorImp.cpp | 2 +- src/Gui/PythonConsole.cpp | 4 ++-- src/Gui/SyntaxHighlighter.cpp | 18 +++++++++++++----- src/Gui/TextEdit.cpp | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Gui/DlgEditorImp.cpp b/src/Gui/DlgEditorImp.cpp index f9f29e02ba..d5056d56fd 100644 --- a/src/Gui/DlgEditorImp.cpp +++ b/src/Gui/DlgEditorImp.cpp @@ -68,7 +68,7 @@ DlgSettingsEditorImp::DlgSettingsEditorImp( QWidget* parent ) d = new DlgSettingsEditorP(); QColor col; - col = Qt::black; + col = qApp->palette().windowText().color(); unsigned int lText = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Text")), lText)); diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index a0506cd1f4..235f5def7d 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -100,7 +100,7 @@ struct PythonConsoleP callTipsList = nullptr; interactive = false; historyFile = QString::fromUtf8((App::Application::getUserAppDataDir() + "PythonHistory.log").c_str()); - colormap[QLatin1String("Text")] = Qt::black; + colormap[QLatin1String("Text")] = qApp->palette().windowText().color(); colormap[QLatin1String("Bookmark")] = Qt::cyan; colormap[QLatin1String("Breakpoint")] = Qt::red; colormap[QLatin1String("Keyword")] = Qt::blue; @@ -932,7 +932,7 @@ void PythonConsole::changeEvent(QEvent *e) } } else if (e->type() == QEvent::StyleChange) { - QPalette pal = palette(); + QPalette pal = qApp->palette(); QColor color = pal.windowText().color(); unsigned int text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8); auto value = static_cast(text); diff --git a/src/Gui/SyntaxHighlighter.cpp b/src/Gui/SyntaxHighlighter.cpp index 6a8e1ef4fb..034807b51f 100644 --- a/src/Gui/SyntaxHighlighter.cpp +++ b/src/Gui/SyntaxHighlighter.cpp @@ -22,6 +22,9 @@ #include "PreCompiled.h" +#include +#include + #include "SyntaxHighlighter.h" @@ -33,11 +36,16 @@ class SyntaxHighlighterP public: SyntaxHighlighterP() { - cNormalText.setRgb(0, 0, 0); cComment.setRgb(0, 170, 0); - cBlockcomment.setRgb(160, 160, 164); cLiteral.setRgb(255, 0, 0); - cNumber.setRgb(0, 0, 255); cOperator.setRgb(160, 160, 164); - cKeyword.setRgb(0, 0, 255); cClassName.setRgb(255, 170, 0); - cDefineName.setRgb(255, 170, 0); cOutput.setRgb(170, 170, 127); + cNormalText = qApp->palette().windowText().color(); + cComment.setRgb(0, 170, 0); + cBlockcomment.setRgb(160, 160, 164); + cLiteral.setRgb(255, 0, 0); + cNumber.setRgb(0, 0, 255); + cOperator.setRgb(160, 160, 164); + cKeyword.setRgb(0, 0, 255); + cClassName.setRgb(255, 170, 0); + cDefineName.setRgb(255, 170, 0); + cOutput.setRgb(170, 170, 127); cError.setRgb(255, 0, 0); } diff --git a/src/Gui/TextEdit.cpp b/src/Gui/TextEdit.cpp index 10e603dbf5..f352768042 100644 --- a/src/Gui/TextEdit.cpp +++ b/src/Gui/TextEdit.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include # include # include @@ -197,7 +198,7 @@ struct TextEditorP QMap colormap; // Color map TextEditorP() { - colormap[QLatin1String("Text")] = Qt::black; + colormap[QLatin1String("Text")] = qApp->palette().windowText().color(); colormap[QLatin1String("Bookmark")] = Qt::cyan; colormap[QLatin1String("Breakpoint")] = Qt::red; colormap[QLatin1String("Keyword")] = Qt::blue;