highlighting and background color set

master
shaina7837 2014-06-20 12:07:40 +05:30
parent 0b6814f253
commit 6a67c0b6bb
4 changed files with 69 additions and 38 deletions

View File

@ -18,15 +18,28 @@ const char *ScadLexer::keywords(int set) const
{
if (set == 1)
return "module function intersection_for assign echo search str"
"let"; // -> Style: Keyword
return "and and_eq asm auto bitand bitor bool break case "
"catch char class compl const const_cast continue "
"default delete do double dynamic_cast else enum "
"explicit export extern float for friend goto if "
"inline int long mutable namespace new not not_eq "
"operator or or_eq private protected public register "
"reinterpret_cast return short signed sizeof static "
"static_cast struct switch template this throw "
"try typedef typeid typename unsigned using "
" void volatile wchar_t while xor xor_eq "
" module function intersection_for assign echo search "
" str let true false "; // -> Style: Keyword
if (set == 2)
return "difference union intersection render translate rotate scale projection"
"hull resize mirror minkowski"; // -> Style: KeywordSet2
return " abs sign acos asin atan atan2 sin cos floor round ceil ln "
" log lookup min max pow sqrt exp rands difference union intersection "
" render translate rotate scale projection hull resize mirror minkowski "
" include use import_stl import import_dxf dxf_dim dxf_cross surface "
" linear_extrude rotate_extrude "; // -> Style: KeywordSet2
if (set == 3)
return "param author"; // -> used in comments only like /*! \cube */
return " param author "; // -> used in comments only like /*! \cube */
if (set == 4)
return "cube circle cylinder polygon polyhedron square sphere"; // -> Style: GlobalClass

View File

@ -12,8 +12,7 @@ public:
ScadLexer(QObject *parent);
virtual ~ScadLexer();
const char *language() const;
const char *keywords(int set) const;
// QColor defaultColor(int style) const;
const char *keywords(int set) const;
private:
ScadLexer(const ScadLexer &);

View File

@ -15,18 +15,15 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
qsci->setAutoIndent(true);
qsci->indicatorDefine(QsciScintilla::RoundBoxIndicator, indicatorNumber);
qsci->markerDefine(QsciScintilla::Circle, markerNumber);
qsci->setUtf8(true);
preferenceEditorOption = Preferences::inst()->getValue("editor/syntaxhighlight").toString();
lexer = new ScadLexer(this);
if(preferenceEditorOption == "For Light Background")
forLightBackground();
if(preferenceEditorOption == "For Dark Background")
forDarkBackground();
qsci->setCaretLineVisible(true);
initFont();
initMargin();
initLexer();
initLexer();
initMargin();
qsci->setCaretLineVisible(true);
this->setHighlightScheme(preferenceEditorOption);
}
void ScintillaEditor::indentSelection()
{
@ -74,30 +71,50 @@ void ScintillaEditor::unhighlightLastError()
void ScintillaEditor::forLightBackground()
{
lexer->setPaper(Qt::white);
lexer->setPaper("#fff");
lexer->setColor(QColor("#272822")); // -> Style: Default text
lexer->setColor(Qt::red, QsciLexerCPP::Keyword); // -> Style: Keyword
lexer->setColor(Qt::green, QsciLexerCPP::KeywordSet2); // -> Style: KeywordSet2
lexer->setColor(QColor("#ff00ff"), QsciLexerCPP::Keyword); // -> Style: Keyword
lexer->setColor(QColor("#00f0f0"), QsciLexerCPP::KeywordSet2); // -> Style: KeywordSet2
lexer->setColor(Qt::blue, QsciLexerCPP::CommentDocKeyword); // -> used in comments only like /*! \cube */
lexer->setColor(Qt::blue, QsciLexerCPP::GlobalClass); // -> Style: GlobalClass
lexer->setColor(QColor("#00d000"), QsciLexerCPP::GlobalClass); // -> Style: GlobalClass
lexer->setColor(QColor("#111111"), QsciLexerCPP::Operator);
lexer->setColor(QColor("#808000"), QsciLexerCPP::DoubleQuotedString);
lexer->setColor(QColor("#0000d0"), QsciLexerCPP::CommentLine);
lexer->setColor(QColor("#800080"), QsciLexerCPP::Number);
qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber);
qsci->setCaretLineBackgroundColor(QColor("#ffe4e4"));
qsci->setMarginsBackgroundColor(QColor("#ccc"));
qsci->setMarginsForegroundColor(QColor("#111"));
}
void ScintillaEditor::forDarkBackground()
{
lexer->setPaper(QColor("#272822"));
lexer->setColor(QColor(Qt::white)); // -> Style: Default text
lexer->setColor(QColor("#66d9ef"), QsciLexerCPP::Keyword); // -> Style: Keyword
lexer->setColor(QColor("#f92672"),QsciLexerCPP::KeywordSet2); // -> Style: KeywordSet2
lexer->setColor(Qt::blue, QsciLexerCPP::CommentDocKeyword); // -> used in comments only like /*! \cube */
lexer->setColor(QColor("#fd9715"), QsciLexerCPP::GlobalClass); // -> Style: GlobalClass
qsci->setCaretLineBackgroundColor(QColor("#eee"));
}
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"));
}
void ScintillaEditor::noColor()
{
lexer->setPaper(Qt::white);
lexer->setColor(Qt::black);
qsci->setMarginsBackgroundColor(QColor("#ccc"));
qsci->setMarginsForegroundColor(QColor("#111"));
}
void ScintillaEditor::setHighlightScheme(const QString &name)
{
@ -109,8 +126,10 @@ void ScintillaEditor::setHighlightScheme(const QString &name)
{
forDarkBackground();
}
else
return;
else if(name == "Off")
{
noColor();
}
}
void ScintillaEditor::insertPlainText(const QString &text)
@ -155,18 +174,22 @@ void ScintillaEditor::zoomOut()
void ScintillaEditor::initFont()
{
QFont font("Courier", 12);
QFont font("inconsolata", 12);
font.setFixedPitch(true);
qsci->setFont(font);
}
void ScintillaEditor::initLexer()
{
lexer->setFont(qsci->font());
qsci->setLexer(lexer);
}
void ScintillaEditor::initMargin()
{
QFontMetrics fontmetrics = QFontMetrics(qsci->font());
qsci->setMarginsFont(qsci->font());
qsci->setMarginWidth(0, fontmetrics.width(QString::number(qsci->lines())) + 6);
qsci->setMarginLineNumbers(0, true);
qsci->setMarginsBackgroundColor(QColor("#cccccc"));
connect(qsci, SIGNAL(textChanged()), this, SLOT(onTextChanged()));
}
@ -177,8 +200,3 @@ void ScintillaEditor::onTextChanged()
qsci->setMarginWidth(0, fontmetrics.width(QString::number(qsci->lines())) + 6);
}
void ScintillaEditor::initLexer()
{
lexer->setDefaultFont(qsci->font());
qsci->setLexer(lexer);
}

View File

@ -20,6 +20,7 @@ public:
void initLexer();
void forLightBackground();
void forDarkBackground();
void noColor();
public slots:
void zoomIn();