Move color scheme values into resource files.
This commit is contained in:
parent
5078f401e9
commit
395795949e
6 changed files with 212 additions and 99 deletions
29
color-schemes/editor/dark-background.json
Normal file
29
color-schemes/editor/dark-background.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"paper" : "#272822",
|
||||
"text" : "#ffffff",
|
||||
"caret" : {
|
||||
"width" : 2,
|
||||
"foreground" : "#ffff00",
|
||||
"line-background" : "#68e1687f"
|
||||
},
|
||||
"colors" : {
|
||||
"keyword1" : "#f12971",
|
||||
"keyword2" : "#56dbf0",
|
||||
"keyword3" : "#56d8f0",
|
||||
"comment" : "#ccdf32",
|
||||
"number" : "#af7dff",
|
||||
"string" : "#e6db74",
|
||||
"operator" : "#d8d8d8",
|
||||
"commentline" : "#e6db74",
|
||||
"selection-foreground" : "#ffff00",
|
||||
"selection-background" : "#a0a0ff",
|
||||
"margin-background" : "#14141496",
|
||||
"margin-foreground" : "#fff",
|
||||
"matched-brace-background" : "#333",
|
||||
"matched-brace-foreground" : "#fff",
|
||||
"unmatched-brace-background" : "#333",
|
||||
"unmatched-brace-foreground" : "#fff",
|
||||
"error-marker" : "#ff0000",
|
||||
"edge" : "#ffffff"
|
||||
}
|
||||
}
|
||||
29
color-schemes/editor/light-background.json
Normal file
29
color-schemes/editor/light-background.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"paper" : "#fff",
|
||||
"text" : "#272822",
|
||||
"caret" : {
|
||||
"width" : 2,
|
||||
"foreground" : "#000000",
|
||||
"line-background" : "#ffe4e4"
|
||||
},
|
||||
"colors" : {
|
||||
"keyword1" : "Green",
|
||||
"keyword2" : "Green",
|
||||
"keyword3" : "DarkBlue",
|
||||
"comment" : "DarkCyan",
|
||||
"number" : "DarkRed",
|
||||
"string" : "DarkMagenta",
|
||||
"operator" : "Blue",
|
||||
"commentline" : "DarkCyan",
|
||||
"selection-foreground" : "#ffff00",
|
||||
"selection-background" : "#a0a0ff",
|
||||
"margin-background" : "#ccc",
|
||||
"margin-foreground" : "#111",
|
||||
"matched-brace-background" : "#333",
|
||||
"matched-brace-foreground" : "#fff",
|
||||
"unmatched-brace-background" : "#333",
|
||||
"unmatched-brace-foreground" : "#fff",
|
||||
"error-marker" : "#ff0000",
|
||||
"edge" : "#ffffff"
|
||||
}
|
||||
}
|
||||
29
color-schemes/editor/monokai.json
Normal file
29
color-schemes/editor/monokai.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"paper" : "#272822",
|
||||
"text" : "#f8f8f2",
|
||||
"caret" : {
|
||||
"width" : 2,
|
||||
"foreground" : "#ffff00",
|
||||
"line-background" : "#3e3d32"
|
||||
},
|
||||
"colors" : {
|
||||
"keyword1" : "#66c3b3",
|
||||
"keyword2" : "#79abff",
|
||||
"keyword3" : "#ffffff",
|
||||
"comment" : "#ccdf32",
|
||||
"number" : "#7fb347",
|
||||
"string" : "#e6db74",
|
||||
"operator" : "#d8d8d8",
|
||||
"commentline" : "#75715e",
|
||||
"selection-foreground" : "#ffff00",
|
||||
"selection-background" : "#a0a0ff",
|
||||
"margin-background" : "#757575",
|
||||
"margin-foreground" : "#f8f8f2",
|
||||
"matched-brace-background" : "#333",
|
||||
"matched-brace-foreground" : "#fff",
|
||||
"unmatched-brace-background" : "#333",
|
||||
"unmatched-brace-foreground" : "#fff",
|
||||
"error-marker" : "#ff0000",
|
||||
"edge" : "#ffffff"
|
||||
}
|
||||
}
|
||||
29
color-schemes/editor/solarized.json
Normal file
29
color-schemes/editor/solarized.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"paper" : "#fdf6e3",
|
||||
"text" : "#657b83",
|
||||
"caret" : {
|
||||
"width" : 2,
|
||||
"foreground" : "#0000ff",
|
||||
"line-background" : "#eeead5"
|
||||
},
|
||||
"colors" : {
|
||||
"keyword1" : "#268ad1",
|
||||
"keyword2" : "#6c71c4",
|
||||
"keyword3" : "#b58800",
|
||||
"comment" : "#b58900",
|
||||
"number" : "#cb4b16",
|
||||
"string" : "#2aa198",
|
||||
"operator" : "#859900",
|
||||
"commentline" : "#b58800",
|
||||
"selection-foreground" : "#fdf6e3",
|
||||
"selection-background" : "#657b83",
|
||||
"margin-background" : "#eee8d5",
|
||||
"margin-foreground" : "#93a1a1",
|
||||
"matched-brace-background" : "#333",
|
||||
"matched-brace-foreground" : "#fff",
|
||||
"unmatched-brace-background" : "#333",
|
||||
"unmatched-brace-foreground" : "#fff",
|
||||
"error-marker" : "#ff0000",
|
||||
"edge" : "#ffffff"
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "scintillaeditor.h"
|
||||
#include <Qsci/qscicommandset.h>
|
||||
#include "Preferences.h"
|
||||
#include "PlatformUtils.h"
|
||||
|
||||
ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
|
||||
{
|
||||
|
|
@ -51,7 +52,6 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
|
|||
initMargin();
|
||||
qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4);
|
||||
qsci->setCaretLineVisible(true);
|
||||
this->setHighlightScheme(Preferences::inst()->getValue("editor/syntaxhighlight").toString());
|
||||
|
||||
connect(qsci, SIGNAL(textChanged()), this, SIGNAL(contentsChanged()));
|
||||
connect(qsci, SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool)));
|
||||
|
|
@ -87,7 +87,6 @@ void ScintillaEditor::highlightError(int error_pos)
|
|||
int line, index;
|
||||
qsci->lineIndexFromPosition(error_pos, &line, &index);
|
||||
qsci->fillIndicatorRange(line, index, line, index+1, indicatorNumber);
|
||||
qsci->setIndicatorForegroundColor(QColor(255,0,0,100));
|
||||
qsci->markerAdd(line, markerNumber);
|
||||
}
|
||||
|
||||
|
|
@ -100,115 +99,110 @@ void ScintillaEditor::unhighlightLastError()
|
|||
qsci->markerDeleteAll(markerNumber);
|
||||
}
|
||||
|
||||
//Editor themes
|
||||
void ScintillaEditor::forLightBackground()
|
||||
QColor ScintillaEditor::read_color(boost::property_tree::ptree &pt, const std::string name, const QColor defaultColor)
|
||||
{
|
||||
lexer->setPaper("#fff");
|
||||
lexer->setColor(QColor("#272822")); // -> Style: Default text
|
||||
lexer->setColor(QColor("Green"), QsciLexerCPP::Keyword); // -> Style: Keyword
|
||||
lexer->setColor(QColor("Green"), QsciLexerCPP::KeywordSet2); // -> Style: KeywordSet2
|
||||
lexer->setColor(Qt::blue, QsciLexerCPP::CommentDocKeyword); // -> used in comments only like /*! \cube */
|
||||
lexer->setColor(QColor("DarkBlue"), QsciLexerCPP::GlobalClass); // -> Style: GlobalClass
|
||||
lexer->setColor(Qt::blue, QsciLexerCPP::Operator);
|
||||
lexer->setColor(Qt::darkMagenta, QsciLexerCPP::DoubleQuotedString);
|
||||
lexer->setColor(Qt::darkCyan, QsciLexerCPP::Comment);
|
||||
lexer->setColor(Qt::darkCyan, QsciLexerCPP::CommentLine);
|
||||
lexer->setColor(QColor("DarkRed"), QsciLexerCPP::Number);
|
||||
qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber);
|
||||
qsci->setCaretLineBackgroundColor(QColor("#ffe4e4"));
|
||||
qsci->setMarginsBackgroundColor(QColor("#ccc"));
|
||||
qsci->setMarginsForegroundColor(QColor("#111"));
|
||||
qsci->setMatchedBraceBackgroundColor(QColor("#333"));
|
||||
qsci->setMatchedBraceForegroundColor(QColor("#fff"));
|
||||
try {
|
||||
const std::string val = pt.get<std::string>(name);
|
||||
return QColor(val.c_str());
|
||||
} catch (std::exception e) {
|
||||
//std::cout << "read_color('" << name << "') failed" << std::endl;
|
||||
return defaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
void ScintillaEditor::forDarkBackground()
|
||||
int ScintillaEditor::read_int(boost::property_tree::ptree &pt, const std::string name, const int defaultValue)
|
||||
{
|
||||
lexer->setPaper(QColor("#272822"));
|
||||
lexer->setColor(QColor(Qt::white));
|
||||
lexer->setColor(QColor("#f12971"), QsciLexerCPP::Keyword);
|
||||
lexer->setColor(QColor("#56dbf0"),QsciLexerCPP::KeywordSet2);
|
||||
lexer->setColor(QColor("#ccdf32"), QsciLexerCPP::CommentDocKeyword);
|
||||
lexer->setColor(QColor("#56d8f0"), QsciLexerCPP::GlobalClass);
|
||||
lexer->setColor(QColor("#d8d8d8"), QsciLexerCPP::Operator);
|
||||
lexer->setColor(QColor("#e6db74"), QsciLexerCPP::DoubleQuotedString);
|
||||
lexer->setColor(QColor("#e6db74"), QsciLexerCPP::CommentLine);
|
||||
lexer->setColor(QColor("#af7dff"), QsciLexerCPP::Number);
|
||||
qsci->setCaretLineBackgroundColor(QColor(104,225,104, 127));
|
||||
qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber);
|
||||
qsci->setMarginsBackgroundColor(QColor("20,20,20,150"));
|
||||
qsci->setMarginsForegroundColor(QColor("#fff"));
|
||||
qsci->setCaretWidth(2);
|
||||
qsci->setCaretForegroundColor(QColor("#ffff00"));
|
||||
try {
|
||||
const int val = pt.get<int>(name);
|
||||
return val;
|
||||
} catch (std::exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
void ScintillaEditor::Monokai()
|
||||
void ScintillaEditor::read_colormap(const fs::path path)
|
||||
{
|
||||
lexer->setPaper("#272822");
|
||||
lexer->setColor(QColor("#f8f8f2")); // -> Style: Default text
|
||||
lexer->setColor(QColor("#66c3b3"), QsciLexerCPP::Keyword); // -> Style: Keyword
|
||||
lexer->setColor(QColor("#79abff"), QsciLexerCPP::KeywordSet2); // -> Style: KeywordSet2
|
||||
lexer->setColor(QColor("#ccdf32"), QsciLexerCPP::CommentDocKeyword); // -> used in comments only like /*! \cube */
|
||||
lexer->setColor(QColor("#ffffff"), QsciLexerCPP::GlobalClass); // -> Style: GlobalClass
|
||||
lexer->setColor(QColor("#d8d8d8"), QsciLexerCPP::Operator);
|
||||
lexer->setColor(QColor("#e6db74"), QsciLexerCPP::DoubleQuotedString);
|
||||
lexer->setColor(QColor("#75715e"), QsciLexerCPP::CommentLine);
|
||||
lexer->setColor(QColor("#7fb347"), QsciLexerCPP::Number);
|
||||
qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber);
|
||||
qsci->setCaretLineBackgroundColor(QColor("#3e3d32"));
|
||||
qsci->setMarginsBackgroundColor(QColor("#757575"));
|
||||
qsci->setMarginsForegroundColor(QColor("#f8f8f2"));
|
||||
qsci->setCaretWidth(2);
|
||||
qsci->setCaretForegroundColor(QColor("#ffff00"));
|
||||
}
|
||||
boost::property_tree::ptree pt;
|
||||
|
||||
void ScintillaEditor::Solarized_light()
|
||||
{
|
||||
lexer->setPaper("#fdf6e3");
|
||||
lexer->setColor(QColor("#657b83")); // -> Style: Default text
|
||||
lexer->setColor(QColor("#268ad1"), QsciLexerCPP::Keyword); // -> Style: Keyword
|
||||
lexer->setColor(QColor("#6c71c4"), QsciLexerCPP::KeywordSet2); // -> Style: KeywordSet2
|
||||
lexer->setColor(QColor("#b58900"), QsciLexerCPP::CommentDocKeyword); // -> used in comments only like /*! \cube */
|
||||
lexer->setColor(QColor("#b58800"), QsciLexerCPP::GlobalClass); // -> Style: GlobalClass
|
||||
lexer->setColor(QColor("#859900"), QsciLexerCPP::Operator);
|
||||
lexer->setColor(QColor("#2aa198"), QsciLexerCPP::DoubleQuotedString);
|
||||
lexer->setColor(QColor("#b58800"), QsciLexerCPP::CommentLine);
|
||||
lexer->setColor(QColor("#cb4b16"), QsciLexerCPP::Number);
|
||||
qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber);
|
||||
qsci->setCaretLineBackgroundColor(QColor("#eeead5"));
|
||||
qsci->setMarginsBackgroundColor(QColor("#eee8d5"));
|
||||
qsci->setMarginsForegroundColor(QColor("#93a1a1"));
|
||||
qsci->setMatchedBraceBackgroundColor(QColor("#0000ff"));
|
||||
qsci->setMatchedBraceBackgroundColor(QColor("#333"));
|
||||
qsci->setMatchedBraceForegroundColor(QColor("#fff"));
|
||||
try {
|
||||
boost::property_tree::read_json(boosty::stringy(path).c_str(), pt);
|
||||
const QColor textColor(pt.get<std::string>("text").c_str());
|
||||
const QColor paperColor(pt.get<std::string>("paper").c_str());
|
||||
|
||||
lexer->setColor(textColor);
|
||||
lexer->setPaper(paperColor);
|
||||
|
||||
boost::property_tree::ptree& colors = pt.get_child("colors");
|
||||
lexer->setColor(read_color(colors, "keyword1", textColor), QsciLexerCPP::Keyword);
|
||||
lexer->setColor(read_color(colors, "keyword2", textColor), QsciLexerCPP::KeywordSet2);
|
||||
lexer->setColor(read_color(colors, "keyword3", textColor), QsciLexerCPP::GlobalClass);
|
||||
lexer->setColor(read_color(colors, "comment", textColor), QsciLexerCPP::CommentDocKeyword);
|
||||
lexer->setColor(read_color(colors, "number", textColor), QsciLexerCPP::Number);
|
||||
lexer->setColor(read_color(colors, "string", textColor), QsciLexerCPP::DoubleQuotedString);
|
||||
lexer->setColor(read_color(colors, "operator", textColor), QsciLexerCPP::Operator);
|
||||
lexer->setColor(read_color(colors, "commentline", textColor), QsciLexerCPP::CommentLine);
|
||||
|
||||
boost::property_tree::ptree& caret = pt.get_child("caret");
|
||||
|
||||
qsci->setCaretWidth(read_int(caret, "width", 1));
|
||||
qsci->setCaretForegroundColor(read_color(caret, "foreground", textColor));
|
||||
qsci->setCaretLineBackgroundColor(read_color(caret, "line-background", paperColor));
|
||||
|
||||
qsci->setMarkerBackgroundColor(read_color(colors, "error-marker", QColor(255, 0, 0, 100)), markerNumber);
|
||||
qsci->setMarginsBackgroundColor(read_color(colors, "margin-background", paperColor));
|
||||
qsci->setMarginsForegroundColor(read_color(colors, "margin-foreground", textColor));
|
||||
qsci->setMatchedBraceBackgroundColor(read_color(colors, "matched-brace-background", paperColor));
|
||||
qsci->setMatchedBraceForegroundColor(read_color(colors, "matched-brace-foreground", textColor));
|
||||
qsci->setUnmatchedBraceBackgroundColor(read_color(colors, "unmatched-brace-background", paperColor));
|
||||
qsci->setUnmatchedBraceForegroundColor(read_color(colors, "unmatched-brace-foreground", textColor));
|
||||
qsci->setSelectionForegroundColor(read_color(colors, "selection-foreground", paperColor));
|
||||
qsci->setSelectionBackgroundColor(read_color(colors, "selection-background", textColor));
|
||||
qsci->setFoldMarginColors(read_color(colors, "margin-foreground", textColor),
|
||||
read_color(colors, "margin-background", paperColor));
|
||||
qsci->setEdgeColor(read_color(colors, "edge", textColor));
|
||||
} catch (std::exception e) {
|
||||
noColor();
|
||||
}
|
||||
}
|
||||
|
||||
void ScintillaEditor::noColor()
|
||||
{
|
||||
lexer->setPaper(Qt::white);
|
||||
lexer->setColor(Qt::black);
|
||||
qsci->setMarginsBackgroundColor(QColor("#ccc"));
|
||||
qsci->setMarginsForegroundColor(QColor("#111"));
|
||||
|
||||
lexer->setPaper(Qt::white);
|
||||
lexer->setColor(Qt::black);
|
||||
qsci->setCaretWidth(2);
|
||||
qsci->setCaretForegroundColor(Qt::black);
|
||||
qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber);
|
||||
qsci->setCaretLineBackgroundColor(Qt::white);
|
||||
qsci->setMarginsBackgroundColor(Qt::white);
|
||||
qsci->setMarginsForegroundColor(Qt::black);
|
||||
qsci->setSelectionForegroundColor(Qt::white);
|
||||
qsci->setSelectionBackgroundColor(Qt::black);
|
||||
qsci->setMatchedBraceBackgroundColor(Qt::white);
|
||||
qsci->setMatchedBraceForegroundColor(Qt::black);
|
||||
qsci->setUnmatchedBraceBackgroundColor(Qt::white);
|
||||
qsci->setUnmatchedBraceForegroundColor(Qt::black);
|
||||
qsci->setMarginsBackgroundColor(Qt::lightGray);
|
||||
qsci->setMarginsForegroundColor(Qt::black);
|
||||
qsci->setFoldMarginColors(Qt::black, Qt::lightGray);
|
||||
qsci->setEdgeColor(Qt::black);
|
||||
}
|
||||
|
||||
void ScintillaEditor::setHighlightScheme(const QString &name)
|
||||
{
|
||||
if(name == "For Light Background") {
|
||||
forLightBackground();
|
||||
}
|
||||
else if(name == "For Dark Background") {
|
||||
forDarkBackground();
|
||||
}
|
||||
else if(name == "Monokai") {
|
||||
Monokai();
|
||||
}
|
||||
else if(name == "Solarized") {
|
||||
Solarized_light();
|
||||
}
|
||||
else if(name == "Off") {
|
||||
noColor();
|
||||
}
|
||||
fs::path resources = PlatformUtils::resourcesPath();
|
||||
fs::path color_schemes = resources / "color-schemes" / "editor";
|
||||
|
||||
if (name == "For Light Background") {
|
||||
read_colormap(color_schemes / "light-background.json");
|
||||
} else if (name == "For Dark Background") {
|
||||
read_colormap(color_schemes / "dark-background.json");
|
||||
} else if (name == "Monokai") {
|
||||
read_colormap(color_schemes / "monokai.json");
|
||||
} else if (name == "Solarized") {
|
||||
read_colormap(color_schemes / "solarized.json");
|
||||
} else if (name == "Off") {
|
||||
noColor();
|
||||
}
|
||||
}
|
||||
|
||||
void ScintillaEditor::insert(const QString &text)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
#include <QVBoxLayout>
|
||||
#include "editor.h"
|
||||
#include "scadlexer.h"
|
||||
#include "parsersettings.h"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
class ScintillaEditor : public EditorInterface
|
||||
{
|
||||
|
|
@ -18,10 +22,6 @@ public:
|
|||
QString toPlainText();
|
||||
void initMargin();
|
||||
void initLexer();
|
||||
void forLightBackground();
|
||||
void forDarkBackground();
|
||||
void Monokai();
|
||||
void Solarized_light();
|
||||
void noColor();
|
||||
QString selectedText();
|
||||
bool find(const QString &, bool findNext = false, bool findBackwards = false);
|
||||
|
|
@ -29,6 +29,9 @@ public:
|
|||
|
||||
private:
|
||||
void get_range(int *lineFrom, int *lineTo);
|
||||
void read_colormap(const boost::filesystem::path path);
|
||||
int read_int(boost::property_tree::ptree &pt, const std::string name, const int defaultValue);
|
||||
QColor read_color(boost::property_tree::ptree &pt, const std::string name, const QColor defaultColor);
|
||||
|
||||
public slots:
|
||||
void zoomIn();
|
||||
|
|
|
|||
Loading…
Reference in a new issue