diff options
author | Marco Bubke <marco.bubke@theqtcompany.com> | 2015-09-10 14:18:09 +0200 |
---|---|---|
committer | David Schulz <david.schulz@theqtcompany.com> | 2015-09-10 13:39:43 +0000 |
commit | 0d20d5618387a57bcbc667e9dd792bc4bd50bc58 (patch) | |
tree | 0f71c13d3ff4bb945a20295d84f55ebaa3c7c082 | |
parent | 408ac55741a09df1f3e8db651d2574b594b9b313 (diff) | |
download | qt-creator-0d20d5618387a57bcbc667e9dd792bc4bd50bc58.tar.gz |
TextEditor/Clang: Add font settings for clang diagnostics
Change-Id: Iea2b4fabf0f4620b12f88b108eb59c160945c8d8
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
-rw-r--r-- | src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp | 36 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettings.cpp | 26 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditorconstants.cpp | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditorconstants.h | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditorsettings.cpp | 18 |
5 files changed, 71 insertions, 19 deletions
diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 03cff462f0..8467c447fa 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -42,7 +42,10 @@ #include <cpptools/cpptoolsplugin.h> #include <cpptools/cppworkingcopy.h> +#include <texteditor/fontsettings.h> #include <texteditor/texteditor.h> +#include <texteditor/texteditorconstants.h> +#include <texteditor/texteditorsettings.h> #include <cplusplus/CppDocument.h> @@ -389,34 +392,31 @@ void addSelections(const std::vector<ClangBackEnd::DiagnosticContainer> &diagnos } } +QTextCharFormat fontsettingsTextFormat(TextEditor::TextStyle textStyle) +{ + return TextEditor::TextEditorSettings::fontSettings().toTextCharFormat(textStyle); +} + void addWarningSelections(const std::vector<ClangBackEnd::DiagnosticContainer> &diagnostics, QTextDocument *textDocument, QList<QTextEdit::ExtraSelection> &extraSelections) { - QTextCharFormat warningFormat; - warningFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); - warningFormat.setUnderlineColor(QColor(180, 180, 0, 255)); - - QTextCharFormat warningRangeFormat; - warningRangeFormat.setUnderlineStyle(QTextCharFormat::DotLine); - warningRangeFormat.setUnderlineColor(QColor(180, 180, 0, 255)); - - addSelections(diagnostics, textDocument, warningFormat, warningRangeFormat, extraSelections); + addSelections(diagnostics, + textDocument, + fontsettingsTextFormat(TextEditor::C_WARNING), + fontsettingsTextFormat(TextEditor::C_WARNING_CONTEXT), + extraSelections); } void addErrorSelections(const std::vector<ClangBackEnd::DiagnosticContainer> &diagnostics, QTextDocument *textDocument, QList<QTextEdit::ExtraSelection> &extraSelections) { - QTextCharFormat errorFormat; - errorFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); - errorFormat.setUnderlineColor(QColor(255, 0, 0, 255)); - - QTextCharFormat errorRangeFormat; - errorRangeFormat.setUnderlineStyle(QTextCharFormat::DotLine); - errorRangeFormat.setUnderlineColor(QColor(255, 0, 0, 255)); - - addSelections(diagnostics, textDocument, errorFormat, errorRangeFormat, extraSelections); + addSelections(diagnostics, + textDocument, + fontsettingsTextFormat(TextEditor::C_ERROR), + fontsettingsTextFormat(TextEditor::C_ERROR_CONTEXT), + extraSelections); } } // anonymous namespace diff --git a/src/plugins/texteditor/fontsettings.cpp b/src/plugins/texteditor/fontsettings.cpp index ef8933ac62..723c919ab8 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -152,6 +152,19 @@ bool FontSettings::equals(const FontSettings &f) const && m_scheme == f.m_scheme; } +static bool isDiagnostic(TextStyle textStyle) +{ + switch (textStyle) { + case C_ERROR: + case C_ERROR_CONTEXT: + case C_WARNING: + case C_WARNING_CONTEXT: return true; + default: return false; + } + + Q_UNREACHABLE(); +} + /** * Returns the QTextCharFormat of the given format category. */ @@ -175,12 +188,23 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const tf.setToolTip(QCoreApplication::translate("FontSettings_C_OCCURRENCES_UNUSED", "Unused variable")); } + + if (isDiagnostic(category)) { + if (category == C_ERROR || category == C_WARNING) + tf.setUnderlineStyle(QTextCharFormat::SingleUnderline); + else + tf.setUnderlineStyle(QTextCharFormat::DotLine); + + tf.setUnderlineColor(f.foreground()); + } + if (f.foreground().isValid() && category != C_OCCURRENCES && category != C_OCCURRENCES_RENAME && category != C_OCCURRENCES_UNUSED && category != C_SEARCH_RESULT - && category != C_PARENTHESES_MISMATCH) + && category != C_PARENTHESES_MISMATCH + && !isDiagnostic(category)) tf.setForeground(f.foreground()); if (f.background().isValid() && (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background())) tf.setBackground(f.background()); diff --git a/src/plugins/texteditor/texteditorconstants.cpp b/src/plugins/texteditor/texteditorconstants.cpp index 71f6aa3583..540eb8f791 100644 --- a/src/plugins/texteditor/texteditorconstants.cpp +++ b/src/plugins/texteditor/texteditorconstants.cpp @@ -99,6 +99,11 @@ const char *nameForStyle(TextStyle style) case C_LOG_CHANGE_LINE: return "LogChangeLine"; + case C_ERROR: return "Error"; + case C_ERROR_CONTEXT: return "ErrorContext"; + case C_WARNING: return "Warning"; + case C_WARNING_CONTEXT: return "WarningContext"; + case C_LAST_STYLE_SENTINEL: return "LastStyleSentinel"; } diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 17ea0d5684..b8214f2de9 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -98,6 +98,11 @@ enum TextStyle { C_LOG_CHANGE_LINE, + C_WARNING, + C_WARNING_CONTEXT, + C_ERROR, + C_ERROR_CONTEXT, + C_LAST_STYLE_SENTINEL }; diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp index 70ced81325..73e8abeec3 100644 --- a/src/plugins/texteditor/texteditorsettings.cpp +++ b/src/plugins/texteditor/texteditorsettings.cpp @@ -276,6 +276,24 @@ TextEditorSettings::TextEditorSettings(QObject *parent) tr("Applied to lines describing changes in VCS log."), Format(QColor(192, 0, 0), QColor()))); + formatDescr.append(FormatDescription(C_ERROR, + tr("Error"), + tr("Underline color of error diagnostics."), + {{255,0, 0}, QColor()})); + formatDescr.append(FormatDescription(C_ERROR_CONTEXT, + tr("Error Context"), + tr("Underline color of the contexts of error diagnostics."), + {{255,0, 0}, QColor()})); + formatDescr.append(FormatDescription(C_WARNING, + tr("Warning"), + tr("Underline color of warning diagnostics."), + {{255, 190, 0}, QColor()})); + formatDescr.append(FormatDescription(C_WARNING_CONTEXT, + tr("Warning Context"), + tr("Underline color of the contexts of warning diagnostics."), + {{255, 190, 0}, QColor()})); + + d->m_fontSettingsPage = new FontSettingsPage(formatDescr, Constants::TEXT_EDITOR_FONT_SETTINGS, this); |