diff options
author | jkobus <jaroslaw.kobus@digia.com> | 2013-08-13 12:57:31 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@digia.com> | 2013-08-26 13:39:40 +0200 |
commit | e8801167aa7a0047c9c9be0942ed0b368e5b5aa4 (patch) | |
tree | eb1dcf7998b0457518681126ddf9b49f198dd2d4 /src/plugins/texteditor/syntaxhighlighter.cpp | |
parent | 760aa0f8bce34e094abecdd99c77c359fb96bb67 (diff) |
Add common interface for text formats inside syntax highlighter
Change-Id: I87f64446161a57aea0896f68e4eafacef791969b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/texteditor/syntaxhighlighter.cpp')
-rw-r--r-- | src/plugins/texteditor/syntaxhighlighter.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index de9c5acd092..0ad601f162e 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -30,6 +30,10 @@ #include "syntaxhighlighter.h" #include "basetextdocument.h" #include "basetextdocumentlayout.h" +#include "texteditorsettings.h" +#include "fontsettings.h" + +#include <utils/qtcassert.h> #include <qtimer.h> @@ -70,12 +74,15 @@ public: } void applyFormatChanges(int from, int charsRemoved, int charsAdded); + void updateFormatsForCategories(const TextEditor::FontSettings &fontSettings); QVector<QTextCharFormat> formatChanges; QTextBlock currentBlock; bool rehighlightPending; bool inReformatBlocks; BaseTextDocumentLayout::FoldValidator foldValidator; + QVector<QTextCharFormat> formats; + QVector<TextEditor::TextStyle> formatCategories; }; static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsRemoved, int charsAdded) { @@ -784,4 +791,31 @@ QList<QColor> SyntaxHighlighter::generateColors(int n, const QColor &background) return result; } +void SyntaxHighlighter::setFontSettings(const TextEditor::FontSettings &fontSettings) +{ + Q_D(SyntaxHighlighter); + d->updateFormatsForCategories(fontSettings); +} + +void SyntaxHighlighter::setTextFormatCategories(const QVector<TextEditor::TextStyle> &categories) +{ + Q_D(SyntaxHighlighter); + d->formatCategories = categories; + d->updateFormatsForCategories(TextEditorSettings::instance()->fontSettings()); +} + +QTextCharFormat SyntaxHighlighter::formatForCategory(int category) const +{ + Q_D(const SyntaxHighlighter); + QTC_ASSERT(d->formats.size() > category, return QTextCharFormat()); + + return d->formats.at(category); +} + +void SyntaxHighlighterPrivate::updateFormatsForCategories(const TextEditor::FontSettings &fontSettings) +{ + formats = fontSettings.toTextCharFormats(formatCategories); +} + + #include "moc_syntaxhighlighter.cpp" |