Commit 0d20d561 authored by Marco Bubke's avatar Marco Bubke Committed by David Schulz

TextEditor/Clang: Add font settings for clang diagnostics

Change-Id: Iea2b4fabf0f4620b12f88b108eb59c160945c8d8
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 408ac557
......@@ -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
......
......@@ -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());
......
......@@ -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";
}
......
......@@ -98,6 +98,11 @@ enum TextStyle {
C_LOG_CHANGE_LINE,
C_WARNING,
C_WARNING_CONTEXT,
C_ERROR,
C_ERROR_CONTEXT,
C_LAST_STYLE_SENTINEL
};
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment