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/git | |
parent | 760aa0f8bce34e094abecdd99c77c359fb96bb67 (diff) | |
download | qt-creator-e8801167aa7a0047c9c9be0942ed0b368e5b5aa4.tar.gz |
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/git')
-rw-r--r-- | src/plugins/git/annotationhighlighter.cpp | 3 | ||||
-rw-r--r-- | src/plugins/git/annotationhighlighter.h | 2 | ||||
-rw-r--r-- | src/plugins/git/giteditor.cpp | 5 | ||||
-rw-r--r-- | src/plugins/git/giteditor.h | 2 | ||||
-rw-r--r-- | src/plugins/git/githighlighters.cpp | 64 | ||||
-rw-r--r-- | src/plugins/git/githighlighters.h | 25 |
6 files changed, 55 insertions, 46 deletions
diff --git a/src/plugins/git/annotationhighlighter.cpp b/src/plugins/git/annotationhighlighter.cpp index 9b19420eb4..4e91ca0882 100644 --- a/src/plugins/git/annotationhighlighter.cpp +++ b/src/plugins/git/annotationhighlighter.cpp @@ -35,9 +35,8 @@ namespace Git { namespace Internal { GitAnnotationHighlighter::GitAnnotationHighlighter(const ChangeNumbers &changeNumbers, - const QColor &bg, QTextDocument *document) : - VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document), + VcsBase::BaseAnnotationHighlighter(changeNumbers, document), m_blank(QLatin1Char(' ')) { } diff --git a/src/plugins/git/annotationhighlighter.h b/src/plugins/git/annotationhighlighter.h index 6c2539b6fb..73f5985126 100644 --- a/src/plugins/git/annotationhighlighter.h +++ b/src/plugins/git/annotationhighlighter.h @@ -40,7 +40,7 @@ class GitAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter { Q_OBJECT public: - explicit GitAnnotationHighlighter(const ChangeNumbers &changeNumbers, const QColor &bg, + explicit GitAnnotationHighlighter(const ChangeNumbers &changeNumbers, QTextDocument *document = 0); private: diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index cdc4746055..2baf17ddef 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -107,10 +107,9 @@ QString GitEditor::changeUnderCursor(const QTextCursor &c) const return QString(); } -VcsBase::BaseAnnotationHighlighter *GitEditor::createAnnotationHighlighter(const QSet<QString> &changes, - const QColor &bg) const +VcsBase::BaseAnnotationHighlighter *GitEditor::createAnnotationHighlighter(const QSet<QString> &changes) const { - return new GitAnnotationHighlighter(changes, bg); + return new GitAnnotationHighlighter(changes); } /* Remove the date specification from annotation, which is tabular: diff --git a/src/plugins/git/giteditor.h b/src/plugins/git/giteditor.h index 47f79e07e8..648a2fa4ec 100644 --- a/src/plugins/git/giteditor.h +++ b/src/plugins/git/giteditor.h @@ -63,7 +63,7 @@ private: bool open(QString *errorString, const QString &fileName, const QString &realFileName); QSet<QString> annotationChanges() const; QString changeUnderCursor(const QTextCursor &) const; - VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const; + VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const; QString decorateVersion(const QString &revision) const; QStringList annotationPreviousVersions(const QString &revision) const; bool isValidRevision(const QString &revision) const; diff --git a/src/plugins/git/githighlighters.cpp b/src/plugins/git/githighlighters.cpp index 2f00c9f2db..835b0f556d 100644 --- a/src/plugins/git/githighlighters.cpp +++ b/src/plugins/git/githighlighters.cpp @@ -27,9 +27,7 @@ ** ****************************************************************************/ -#include <texteditor/fontsettings.h> #include <texteditor/texteditorconstants.h> -#include <texteditor/texteditorsettings.h> #include <utils/qtcassert.h> @@ -40,13 +38,6 @@ namespace Internal { static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b"; -// Retrieve the comment char format from the text editor. -static QTextCharFormat commentFormat() -{ - const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings(); - return settings.toTextCharFormat(TextEditor::C_COMMENT); -} - GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) : TextEditor::SyntaxHighlighter(parent) { @@ -61,7 +52,11 @@ GitSubmitHighlighter::GitSubmitHighlighter(TextEditor::BaseTextDocument *parent) void GitSubmitHighlighter::initialize() { - m_commentFormat = commentFormat(); + static QVector<TextEditor::TextStyle> categories; + if (categories.isEmpty()) + categories << TextEditor::C_COMMENT; + + setTextFormatCategories(categories); m_keywordPattern.setPattern(QLatin1String("^[\\w-]+:")); m_hashChar = QLatin1Char('#'); QTC_CHECK(m_keywordPattern.isValid()); @@ -77,7 +72,7 @@ void GitSubmitHighlighter::highlightBlock(const QString &text) setCurrentBlockState(state); return; } else if (text.startsWith(m_hashChar)) { - setFormat(0, text.size(), m_commentFormat); + setFormat(0, text.size(), formatForCategory(Format_Comment)); setCurrentBlockState(state); return; } else if (state == None) { @@ -107,11 +102,10 @@ void GitSubmitHighlighter::highlightBlock(const QString &text) } GitRebaseHighlighter::RebaseAction::RebaseAction(const QString ®exp, - const TextEditor::FontSettings &settings, - TextEditor::TextStyle category) - : exp(regexp) + const Format formatCategory) + : exp(regexp), + formatCategory(formatCategory) { - format = settings.toTextCharFormat(category); } GitRebaseHighlighter::GitRebaseHighlighter(TextEditor::BaseTextDocument *parent) : @@ -119,26 +113,36 @@ GitRebaseHighlighter::GitRebaseHighlighter(TextEditor::BaseTextDocument *parent) m_hashChar(QLatin1Char('#')), m_changeNumberPattern(QLatin1String(CHANGE_PATTERN)) { - const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings(); - m_commentFormat = settings.toTextCharFormat(TextEditor::C_COMMENT); - m_changeFormat = settings.toTextCharFormat(TextEditor::C_DOXYGEN_COMMENT); - m_descFormat = settings.toTextCharFormat(TextEditor::C_STRING); - m_actions << RebaseAction(QLatin1String("^(p|pick)\\b"), settings, TextEditor::C_KEYWORD); - m_actions << RebaseAction(QLatin1String("^(r|reword)\\b"), settings, TextEditor::C_FIELD); - m_actions << RebaseAction(QLatin1String("^(e|edit)\\b"), settings, TextEditor::C_TYPE); - m_actions << RebaseAction(QLatin1String("^(s|squash)\\b"), settings, TextEditor::C_ENUMERATION); - m_actions << RebaseAction(QLatin1String("^(f|fixup)\\b"), settings, TextEditor::C_NUMBER); - m_actions << RebaseAction(QLatin1String("^(x|exec)\\b"), settings, TextEditor::C_LABEL); + static QVector<TextEditor::TextStyle> categories; + if (categories.isEmpty()) { + categories << TextEditor::C_COMMENT + << TextEditor::C_DOXYGEN_COMMENT + << TextEditor::C_STRING + << TextEditor::C_KEYWORD + << TextEditor::C_FIELD + << TextEditor::C_TYPE + << TextEditor::C_ENUMERATION + << TextEditor::C_NUMBER + << TextEditor::C_LABEL; + } + setTextFormatCategories(categories); + + m_actions << RebaseAction(QLatin1String("^(p|pick)\\b"), Format_Pick); + m_actions << RebaseAction(QLatin1String("^(r|reword)\\b"), Format_Reword); + m_actions << RebaseAction(QLatin1String("^(e|edit)\\b"), Format_Edit); + m_actions << RebaseAction(QLatin1String("^(s|squash)\\b"), Format_Squash); + m_actions << RebaseAction(QLatin1String("^(f|fixup)\\b"), Format_Fixup); + m_actions << RebaseAction(QLatin1String("^(x|exec)\\b"), Format_Exec); } void GitRebaseHighlighter::highlightBlock(const QString &text) { if (text.startsWith(m_hashChar)) { - setFormat(0, text.size(), m_commentFormat); + setFormat(0, text.size(), formatForCategory(Format_Comment)); int changeIndex = 0; while ((changeIndex = m_changeNumberPattern.indexIn(text, changeIndex)) != -1) { const int changeLen = m_changeNumberPattern.matchedLength(); - setFormat(changeIndex, changeLen, m_changeFormat); + setFormat(changeIndex, changeLen, formatForCategory(Format_Change)); changeIndex += changeLen; } return; @@ -147,13 +151,13 @@ void GitRebaseHighlighter::highlightBlock(const QString &text) foreach (const RebaseAction &action, m_actions) { if (action.exp.indexIn(text) != -1) { const int len = action.exp.matchedLength(); - setFormat(0, len, action.format); + setFormat(0, len, formatForCategory(action.formatCategory)); const int changeIndex = m_changeNumberPattern.indexIn(text, len); if (changeIndex != -1) { const int changeLen = m_changeNumberPattern.matchedLength(); const int descStart = changeIndex + changeLen + 1; - setFormat(changeIndex, changeLen, m_changeFormat); - setFormat(descStart, text.size() - descStart, m_descFormat); + setFormat(changeIndex, changeLen, formatForCategory(Format_Change)); + setFormat(descStart, text.size() - descStart, formatForCategory(Format_Description)); } break; } diff --git a/src/plugins/git/githighlighters.h b/src/plugins/git/githighlighters.h index 3d7f6e0621..888b615c72 100644 --- a/src/plugins/git/githighlighters.h +++ b/src/plugins/git/githighlighters.h @@ -31,7 +31,6 @@ #define GITHIGHLIGHTERS_H #include <texteditor/syntaxhighlighter.h> -#include <texteditor/texteditorconstants.h> namespace TextEditor { class FontSettings; @@ -40,6 +39,18 @@ class FontSettings; namespace Git { namespace Internal { +enum Format { + Format_Comment, + Format_Change, + Format_Description, + Format_Pick, + Format_Reword, + Format_Edit, + Format_Squash, + Format_Fixup, + Format_Exec +}; + // Highlighter for git 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>'). @@ -50,10 +61,10 @@ public: explicit GitSubmitHighlighter(TextEditor::BaseTextDocument *parent); void highlightBlock(const QString &text); - void initialize(); private: + void initialize(); + enum State { None = -1, Header, Other }; - QTextCharFormat m_commentFormat; QRegExp m_keywordPattern; QChar m_hashChar; }; @@ -71,13 +82,9 @@ private: { public: mutable QRegExp exp; - QTextCharFormat format; - RebaseAction(const QString ®exp, const TextEditor::FontSettings &settings, - TextEditor::TextStyle category); + Format formatCategory; + RebaseAction(const QString ®exp, const Format formatCategory); }; - QTextCharFormat m_commentFormat; - QTextCharFormat m_changeFormat; - QTextCharFormat m_descFormat; const QChar m_hashChar; QRegExp m_changeNumberPattern; QList<RebaseAction> m_actions; |