diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2014-11-04 22:46:57 +0200 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2014-11-05 09:47:34 +0100 |
commit | f0a6345fdeed44336932389189749b94188566ce (patch) | |
tree | d093ddfae1faa71166d113f97d6ed7faf286891d /src/plugins/mercurial | |
parent | 697f70cb33ddb36403d941dac1487491f6100d68 (diff) |
Mercurial: Use TextEditor::SyntaxHighlighter
Change-Id: Ic215b778a6365d8bce5cb8eeb0d016d8ce80e476
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Diffstat (limited to 'src/plugins/mercurial')
-rw-r--r-- | src/plugins/mercurial/mercurialcommitwidget.cpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/plugins/mercurial/mercurialcommitwidget.cpp b/src/plugins/mercurial/mercurialcommitwidget.cpp index 272a811235..1d3a683012 100644 --- a/src/plugins/mercurial/mercurialcommitwidget.cpp +++ b/src/plugins/mercurial/mercurialcommitwidget.cpp @@ -32,6 +32,7 @@ #include <texteditor/texteditorsettings.h> #include <texteditor/fontsettings.h> +#include <texteditor/syntaxhighlighter.h> #include <texteditor/texteditorconstants.h> #include <utils/qtcassert.h> @@ -43,21 +44,13 @@ //see the git submit widget for details of the syntax Highlighter -//TODO Check to see when the Highlighter has been moved to a base class and use that instead - namespace Mercurial { namespace Internal { -// Retrieve the comment char format from the text editor. -static QTextCharFormat commentFormat() -{ - return TextEditor::TextEditorSettings::fontSettings().toTextCharFormat(TextEditor::C_COMMENT); -} - // Highlighter for Mercurial submit messages. Make the first line bold, indicates // comments as such (retrieving the format from the text editor) and marks up // keywords (words in front of a colon as in 'Task: <bla>'). -class MercurialSubmitHighlighter : QSyntaxHighlighter +class MercurialSubmitHighlighter : TextEditor::SyntaxHighlighter { public: explicit MercurialSubmitHighlighter(QTextEdit *parent); @@ -65,17 +58,21 @@ public: private: enum State { Header, Comment, Other }; - const QTextCharFormat m_commentFormat; + enum Format { Format_Comment }; QRegExp m_keywordPattern; const QChar m_hashChar; }; MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) : - QSyntaxHighlighter(parent), - m_commentFormat(commentFormat()), + TextEditor::SyntaxHighlighter(parent), m_keywordPattern(QLatin1String("^\\w+:")), m_hashChar(QLatin1Char('#')) { + static QVector<TextEditor::TextStyle> categories; + if (categories.isEmpty()) + categories << TextEditor::C_COMMENT; + + setTextFormatCategories(categories); QTC_CHECK(m_keywordPattern.isValid()); } @@ -93,13 +90,13 @@ void MercurialSubmitHighlighter::highlightBlock(const QString &text) // Apply format. switch (state) { case Header: { - QTextCharFormat charFormat = format(0); - charFormat.setFontWeight(QFont::Bold); - setFormat(0, text.size(), charFormat); - } + QTextCharFormat charFormat = format(0); + charFormat.setFontWeight(QFont::Bold); + setFormat(0, text.size(), charFormat); break; + } case Comment: - setFormat(0, text.size(), m_commentFormat); + setFormat(0, text.size(), formatForCategory(Format_Comment)); break; case Other: // Format key words ("Task:") italic |