From 6e5f90917f4cbe092816ac82434f827f67082f4d Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 9 Dec 2015 12:24:53 +0100 Subject: [PATCH] Use text settings instead of hard coded diagnostic text formats Change-Id: Id51d03a46b4403d9224508ff3c7647b829ee69cd Reviewed-by: Nikolai Kosjar --- .../cpptools/baseeditordocumentprocessor.cpp | 14 ++++------ src/plugins/debugger/qml/qmlengineutils.cpp | 8 +++--- src/plugins/glsleditor/glsleditor.cpp | 10 +++---- src/plugins/qmljseditor/qmljseditor.cpp | 12 ++++---- .../qmljseditor/qmljssemantichighlighter.cpp | 28 +++++++++++-------- 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/plugins/cpptools/baseeditordocumentprocessor.cpp b/src/plugins/cpptools/baseeditordocumentprocessor.cpp index 43f5fb9029d..33e9887756e 100644 --- a/src/plugins/cpptools/baseeditordocumentprocessor.cpp +++ b/src/plugins/cpptools/baseeditordocumentprocessor.cpp @@ -34,6 +34,9 @@ #include "cpptoolsreuse.h" #include "editordocumenthandle.h" +#include +#include + #include #include @@ -82,15 +85,10 @@ QList BaseEditorDocumentProcessor::toTextEditorSelect const QList &diagnostics, QTextDocument *textDocument) { - // Format for errors - QTextCharFormat errorFormat; - errorFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); - errorFormat.setUnderlineColor(Qt::red); + const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings(); - // Format for warnings - 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 result; foreach (const CPlusPlus::Document::DiagnosticMessage &m, diagnostics) { diff --git a/src/plugins/debugger/qml/qmlengineutils.cpp b/src/plugins/debugger/qml/qmlengineutils.cpp index 50f707d0056..684d7b69b22 100644 --- a/src/plugins/debugger/qml/qmlengineutils.cpp +++ b/src/plugins/debugger/qml/qmlengineutils.cpp @@ -36,8 +36,10 @@ #include +#include #include #include +#include #include @@ -248,10 +250,8 @@ QStringList highlightExceptionCode(int lineNumber, const QString &filePath, cons QStringList messages; QList 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(editor->widget()); diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index b7fac825e0d..3a35ccadf74 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -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 sels; QSet errors; diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index df7f849cb93..d377095f8e0 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -194,12 +195,13 @@ static void appendExtraSelectionsForMessages( sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.loc.length); } - if (d.isWarning()) - sel.format.setUnderlineColor(Qt::darkYellow); - else - sel.format.setUnderlineColor(Qt::red); + const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings(); + + if (d.isWarning()) + sel.format = fontSettings.toTextCharFormat(TextEditor::C_WARNING); + else + sel.format = fontSettings.toTextCharFormat(TextEditor::C_ERROR); - sel.format.setUnderlineStyle(QTextCharFormat::SingleUnderline); sel.format.setToolTip(d.message); selections->append(sel); diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp index fb5900548e4..1ba2e6a8ca0 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -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; } - 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) - format.setUnderlineColor(Qt::darkGreen); - format.setUnderlineStyle(QTextCharFormat::SingleUnderline); + const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings(); + + QTextCharFormat format; + 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.setToolTip(d.message); collectRanges(begin, length, format);