From 25e4655d909de21b98376f46cad3e7ae04024f3b Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Tue, 12 Oct 2010 13:09:29 +0200 Subject: [PATCH] Generic highlighter: Apply format only if it's a configured one; Remove hard-coded colors. Reviewed-by: con --- .../texteditor/generichighlighter/highlighter.cpp | 47 ++++++++++++---------- src/plugins/texteditor/plaintexteditor.cpp | 14 ------- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp index 3775a63d51..76471dc9d1 100644 --- a/src/plugins/texteditor/generichighlighter/highlighter.cpp +++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp @@ -382,29 +382,32 @@ void Highlighter::applyFormat(int offset, TextFormatId formatId = m_kateFormats.m_ids.value(itemData->style()); if (formatId != Normal) { - QTextCharFormat format = m_creatorFormats.value(formatId); - - if (itemData->isCustomized()) { - // Please notice that the following are applied every time for item datas which have - // customizations. The configureFormats method could be used to provide a "one time" - // configuration, but it would probably require to traverse all item datas from all - // definitions available/loaded (either to set the values or for some "notifying" - // strategy). This is because the highlighter does not really know on which - // definition(s) it is working. Since not many item datas specify customizations I - // think this approach would fit better. If there are other ideas... - if (itemData->color().isValid()) - format.setForeground(itemData->color()); - if (itemData->isItalicSpecified()) - format.setFontItalic(itemData->isItalic()); - if (itemData->isBoldSpecified()) - format.setFontWeight(toFontWeight(itemData->isBold())); - if (itemData->isUnderlinedSpecified()) - format.setFontUnderline(itemData->isUnderlined()); - if (itemData->isStrikedOutSpecified()) - format.setFontStrikeOut(itemData->isStrikedOut()); - } + QHash::const_iterator cit = + m_creatorFormats.constFind(formatId); + if (cit != m_creatorFormats.constEnd()) { + QTextCharFormat format = cit.value(); + if (itemData->isCustomized()) { + // Please notice that the following are applied every time for item datas which have + // customizations. The configureFormats method could be used to provide a "one time" + // configuration, but it would probably require to traverse all item datas from all + // definitions available/loaded (either to set the values or for some "notifying" + // strategy). This is because the highlighter does not really know on which + // definition(s) it is working. Since not many item datas specify customizations I + // think this approach would fit better. If there are other ideas... + if (itemData->color().isValid()) + format.setForeground(itemData->color()); + if (itemData->isItalicSpecified()) + format.setFontItalic(itemData->isItalic()); + if (itemData->isBoldSpecified()) + format.setFontWeight(toFontWeight(itemData->isBold())); + if (itemData->isUnderlinedSpecified()) + format.setFontUnderline(itemData->isUnderlined()); + if (itemData->isStrikedOutSpecified()) + format.setFontStrikeOut(itemData->isStrikedOut()); + } - setFormat(offset, count, format); + setFormat(offset, count, format); + } } } diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp index 5d169aae71..74060a2e2e 100644 --- a/src/plugins/texteditor/plaintexteditor.cpp +++ b/src/plugins/texteditor/plaintexteditor.cpp @@ -134,20 +134,6 @@ void PlainTextEditor::setFontSettings(const FontSettings &fs) highlighter->configureFormat(Highlighter::String, fs.toTextCharFormat( QLatin1String(Constants::C_STRING))); - // Creator does not have corresponding formats for the following ones. Implement them? - // For now I will leave hardcoded values. - QTextCharFormat format; - format.setForeground(Qt::blue); - highlighter->configureFormat(Highlighter::Others, format); - format.setForeground(Qt::red); - highlighter->configureFormat(Highlighter::Alert, format); - format.setForeground(Qt::darkBlue); - highlighter->configureFormat(Highlighter::Function, format); - format.setForeground(Qt::darkGray); - highlighter->configureFormat(Highlighter::RegionMarker, format); - format.setForeground(Qt::darkRed); - highlighter->configureFormat(Highlighter::Error, format); - highlighter->rehighlight(); } } -- 2.11.0