Style scintilla to work on dark as well as light themes. Refs #862

This commit is contained in:
baldurk
2018-02-09 17:24:26 +00:00
parent f6ccd537b6
commit b12475f808
2 changed files with 58 additions and 17 deletions
+55 -17
View File
@@ -228,8 +228,6 @@ uimage2DMSArray
void ConfigureSyntax(ScintillaEdit *scintilla, int language)
{
scintilla->setLexer(language);
bool hlsl = false;
bool glsl = false;
@@ -248,17 +246,55 @@ void ConfigureSyntax(ScintillaEdit *scintilla, int language)
scintilla->setLexer(language);
scintilla->styleSetSize(STYLE_DEFAULT, 10);
#define SC_COL(qcol) SCINTILLA_COLOUR(qcol.red(), qcol.green(), qcol.blue())
// set the default style to base/text
QColor base = scintilla->palette().color(QPalette::Base);
QColor text = scintilla->palette().color(QPalette::Text);
scintilla->styleSetBack(STYLE_DEFAULT, SC_COL(base));
scintilla->styleSetFore(STYLE_DEFAULT, SC_COL(text));
// default all lexer styles up to STYLE_DEFAULT as the same, then override per-colour below
for(sptr_t i = 0; i < STYLE_DEFAULT; i++)
{
scintilla->styleSetBack(i, SC_COL(base));
scintilla->styleSetFore(i, SC_COL(text));
}
// set highlight text colour
QColor highlight = scintilla->palette().color(QPalette::Highlight);
QColor highlightedText = scintilla->palette().color(QPalette::HighlightedText);
scintilla->setSelBack(true, SC_COL(highlight));
scintilla->setSelFore(true, SC_COL(highlightedText));
// set margin colours
QColor window = scintilla->palette().color(QPalette::Window);
QColor windowText = scintilla->palette().color(QPalette::WindowText);
for(sptr_t i = 0; i < 5; i++)
scintilla->setMarginBackN(i, SC_COL(window));
scintilla->styleSetBack(STYLE_LINENUMBER, SC_COL(window));
scintilla->styleSetFore(STYLE_LINENUMBER, SC_COL(windowText));
sptr_t blue = IsDarkTheme() ? SCINTILLA_COLOUR(105, 105, 255) : SCINTILLA_COLOUR(0, 0, 150);
sptr_t magenta = IsDarkTheme() ? SCINTILLA_COLOUR(255, 105, 255) : SCINTILLA_COLOUR(150, 0, 150);
sptr_t rouge = IsDarkTheme() ? SCINTILLA_COLOUR(255, 150, 150) : SCINTILLA_COLOUR(175, 70, 70);
// works for either dark or light
sptr_t green = SCINTILLA_COLOUR(0, 150, 0);
sptr_t teal = SCINTILLA_COLOUR(0, 150, 150);
sptr_t olive = SCINTILLA_COLOUR(150, 150, 0);
if(language == SCLEX_CPP)
{
scintilla->setProperty("lexer.cpp.track.preprocessor", "0");
scintilla->setProperty("styling.within.preprocessor", "1");
scintilla->styleSetFore(SCE_C_COMMENT, SCINTILLA_COLOUR(0, 150, 0));
scintilla->styleSetFore(SCE_C_COMMENTDOC, SCINTILLA_COLOUR(0, 150, 0));
scintilla->styleSetFore(SCE_C_COMMENTLINE, SCINTILLA_COLOUR(0, 150, 0));
scintilla->styleSetFore(SCE_C_WORD, SCINTILLA_COLOUR(0, 0, 150));
scintilla->styleSetFore(SCE_C_WORD2, SCINTILLA_COLOUR(0, 0, 150));
scintilla->styleSetFore(SCE_C_PREPROCESSOR, SCINTILLA_COLOUR(0, 0, 150));
scintilla->styleSetFore(SCE_C_COMMENT, green);
scintilla->styleSetFore(SCE_C_COMMENTDOC, green);
scintilla->styleSetFore(SCE_C_COMMENTLINE, green);
scintilla->styleSetFore(SCE_C_WORD, blue);
scintilla->styleSetFore(SCE_C_WORD2, blue);
scintilla->styleSetFore(SCE_C_PREPROCESSOR, blue);
scintilla->styleSetBold(SCE_C_PREPROCESSOR, true);
if(hlsl)
@@ -279,15 +315,17 @@ void ConfigureSyntax(ScintillaEdit *scintilla, int language)
scintilla->setKeyWords(0, python_keywords);
scintilla->styleSetFore(SCE_P_COMMENTLINE, SCINTILLA_COLOUR(0, 150, 0));
scintilla->styleSetFore(SCE_P_COMMENTBLOCK, SCINTILLA_COLOUR(0, 150, 0));
scintilla->styleSetFore(SCE_P_NUMBER, SCINTILLA_COLOUR(0, 150, 150));
scintilla->styleSetFore(SCE_P_STRING, SCINTILLA_COLOUR(150, 0, 150));
scintilla->styleSetFore(SCE_P_CHARACTER, SCINTILLA_COLOUR(150, 0, 150));
scintilla->styleSetFore(SCE_P_DEFNAME, SCINTILLA_COLOUR(150, 150, 0));
scintilla->styleSetFore(SCE_P_CLASSNAME, SCINTILLA_COLOUR(150, 0, 150));
scintilla->styleSetFore(SCE_P_WORD, SCINTILLA_COLOUR(0, 0, 150));
scintilla->styleSetFore(SCE_P_WORD2, SCINTILLA_COLOUR(0, 0, 150));
scintilla->styleSetFore(SCE_P_COMMENTLINE, green);
scintilla->styleSetFore(SCE_P_COMMENTBLOCK, green);
scintilla->styleSetFore(SCE_P_NUMBER, teal);
scintilla->styleSetFore(SCE_P_STRING, magenta);
scintilla->styleSetFore(SCE_P_TRIPLE, rouge);
scintilla->styleSetFore(SCE_P_TRIPLEDOUBLE, rouge);
scintilla->styleSetFore(SCE_P_CHARACTER, magenta);
scintilla->styleSetFore(SCE_P_DEFNAME, olive);
scintilla->styleSetFore(SCE_P_CLASSNAME, magenta);
scintilla->styleSetFore(SCE_P_WORD, blue);
scintilla->styleSetFore(SCE_P_WORD2, blue);
scintilla->styleSetBold(SCE_P_WORD, true);
scintilla->styleSetBold(SCE_P_WORD2, true);
}
+3
View File
@@ -26,6 +26,7 @@
#include <QFontDatabase>
#include "3rdparty/scintilla/include/SciLexer.h"
#include "3rdparty/scintilla/include/qt/ScintillaEdit.h"
#include "Code/ScintillaSyntax.h"
#include "ui_CommentView.h"
CommentView::CommentView(ICaptureContext &ctx, QWidget *parent)
@@ -39,6 +40,8 @@ CommentView::CommentView(ICaptureContext &ctx, QWidget *parent)
STYLE_DEFAULT, QFontDatabase::systemFont(QFontDatabase::FixedFont).family().toUtf8().data());
m_commentsEditor->setTabWidth(4);
ConfigureSyntax(m_commentsEditor, SCLEX_PYTHON);
QObject::connect(m_commentsEditor, &ScintillaEdit::modified, [this](int type, int, int, int,
const QByteArray &, int, int,
int) {