Commit 6e5f9091 authored by Marco Bubke's avatar Marco Bubke

Use text settings instead of hard coded diagnostic text formats

Change-Id: Id51d03a46b4403d9224508ff3c7647b829ee69cd
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 4453ed4f
......@@ -34,6 +34,9 @@
#include "cpptoolsreuse.h"
#include "editordocumenthandle.h"
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <utils/qtcassert.h>
#include <QTextBlock>
......@@ -82,15 +85,10 @@ QList<QTextEdit::ExtraSelection> BaseEditorDocumentProcessor::toTextEditorSelect
const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics,
QTextDocument *textDocument)
{
// Format for errors
QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
errorFormat.setUnderlineColor(Qt::red);
// Format for warnings
QTextCharFormat warningFormat;
warningFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
warningFormat.setUnderlineColor(Qt::darkYellow);
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
QTextCharFormat warningFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
QList<QTextEdit::ExtraSelection> result;
foreach (const CPlusPlus::Document::DiagnosticMessage &m, diagnostics) {
......
......@@ -36,8 +36,10 @@
#include <coreplugin/editormanager/documentmodel.h>
#include <texteditor/fontsettings.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditorsettings.h>
#include <QTextBlock>
......@@ -248,10 +250,8 @@ QStringList highlightExceptionCode(int lineNumber, const QString &filePath, cons
QStringList messages;
QList<IEditor *> editors = DocumentModel::editorsForFilePath(filePath);
// set up the format for the errors
QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
errorFormat.setUnderlineColor(Qt::red);
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
foreach (IEditor *editor, editors) {
TextEditorWidget *ed = qobject_cast<TextEditorWidget *>(editor->widget());
......
......@@ -53,6 +53,7 @@
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h>
#include <texteditor/fontsettings.h>
#include <texteditor/refactoroverlay.h>
#include <texteditor/textdocument.h>
#include <texteditor/syntaxhighlighter.h>
......@@ -236,13 +237,10 @@ void GlslEditorWidget::updateDocumentNow()
CreateRanges createRanges(document(), doc);
createRanges(ast);
QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
errorFormat.setUnderlineColor(Qt::red);
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
QTextCharFormat warningFormat;
warningFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
warningFormat.setUnderlineColor(Qt::darkYellow);
QTextCharFormat warningFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
QList<QTextEdit::ExtraSelection> sels;
QSet<int> errors;
......
......@@ -66,6 +66,7 @@
#include <texteditor/fontsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/refactoroverlay.h>
#include <texteditor/codeassist/genericproposal.h>
......@@ -194,12 +195,13 @@ static void appendExtraSelectionsForMessages(
sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.loc.length);
}
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
if (d.isWarning())
sel.format.setUnderlineColor(Qt::darkYellow);
sel.format = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
else
sel.format.setUnderlineColor(Qt::red);
sel.format = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
sel.format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
sel.format.setToolTip(d.message);
selections->append(sel);
......
......@@ -45,6 +45,7 @@
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
......@@ -385,13 +386,14 @@ protected:
length = end-begin;
}
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
QTextCharFormat format;
if (d.isWarning())
format.setUnderlineColor(Qt::darkYellow);
format = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
else
format.setUnderlineColor(Qt::red);
format = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
format.setToolTip(d.message);
collectRanges(begin, length, format);
......@@ -420,15 +422,19 @@ protected:
column += begin - d.location.begin();
length = end-begin;
}
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
QTextCharFormat format;
if (d.severity == Severity::Warning || d.severity == Severity::MaybeWarning)
format.setUnderlineColor(Qt::darkYellow);
else if (d.severity == Severity::Error || d.severity == Severity::MaybeError)
format.setUnderlineColor(Qt::red);
else if (d.severity == Severity::Hint)
if (d.severity == Severity::Warning || d.severity == Severity::MaybeWarning) {
format = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
} else if (d.severity == Severity::Error || d.severity == Severity::MaybeError) {
format = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
} else if (d.severity == Severity::Hint) {
format = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
format.setUnderlineColor(Qt::darkGreen);
}
format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
format.setToolTip(d.message);
collectRanges(begin, length, format);
......
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