diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 03cff462f0a..8467c447fa8 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -42,7 +42,10 @@ #include #include +#include #include +#include +#include #include @@ -389,34 +392,31 @@ void addSelections(const std::vector &diagnos } } +QTextCharFormat fontsettingsTextFormat(TextEditor::TextStyle textStyle) +{ + return TextEditor::TextEditorSettings::fontSettings().toTextCharFormat(textStyle); +} + void addWarningSelections(const std::vector &diagnostics, QTextDocument *textDocument, QList &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 &diagnostics, QTextDocument *textDocument, QList &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 ef8933ac62f..723c919ab8f 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 71f6aa3583f..540eb8f791e 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 17ea0d56849..b8214f2de93 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 70ced813250..73e8abeec33 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);