diff --git a/src/plugins/genericeditor/highlighter.cpp b/src/plugins/genericeditor/highlighter.cpp index 416ee87214176c38206156e7b1c95264df6adee7..deac818bff3e67b791422cbc6ed7eb7f840c8564 100644 --- a/src/plugins/genericeditor/highlighter.cpp +++ b/src/plugins/genericeditor/highlighter.cpp @@ -308,18 +308,25 @@ void Highlighter::applyFormat(int offset, QTextCharFormat format = m_genericFormats.value(itemData->style()); - // Apply personalizations (if specified) for this particular item data from the current - // definition only. - 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()); + 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); } @@ -424,7 +431,7 @@ void Highlighter::setCurrentContext() { if (m_contexts.isEmpty()) { // This is not supposed to happen. However, there might be broken files (for example, the - // PHP definition) which will cause this behaviour. In such cases just pushing the default + // php.xml) which will cause this behaviour. In such cases just pushing the default // context is enough to keep highlighter working. m_contexts.push_back(m_defaultContext); } diff --git a/src/plugins/genericeditor/itemdata.cpp b/src/plugins/genericeditor/itemdata.cpp index b7e4298045405f8104a8639a9a73316dac17f8e8..2511734eb795f0cea1407ad68e7f0ed2a6365da1 100644 --- a/src/plugins/genericeditor/itemdata.cpp +++ b/src/plugins/genericeditor/itemdata.cpp @@ -52,7 +52,8 @@ ItemData::ItemData() : m_italicSpecified(false), m_boldSpecified(false), m_underlinedSpecified(false), - m_strikedOutSpecified(false) + m_strikedOutSpecified(false), + m_isCustomized(false) {} void ItemData::setStyle(const QString &style) @@ -62,13 +63,23 @@ const QString &ItemData::style() const { return m_style; } void ItemData::setColor(const QString &color) -{ m_color.setNamedColor(color); } +{ + if (!color.isEmpty()) { + m_color.setNamedColor(color); + m_isCustomized = true; + } +} const QColor &ItemData::color() const { return m_color; } void ItemData::setSelectionColor(const QString &color) -{ m_selectionColor.setNamedColor(color); } +{ + if (!color.isEmpty()) { + m_selectionColor.setNamedColor(color); + m_isCustomized = true; + } +} const QColor &ItemData::selectionColor() const { return m_selectionColor; } @@ -78,6 +89,7 @@ void ItemData::setItalic(const QString &italic) if (!italic.isEmpty()) { m_italic = toBool(italic); m_italicSpecified = true; + m_isCustomized = true; } } @@ -92,6 +104,7 @@ void ItemData::setBold(const QString &bold) if (!bold.isEmpty()) { m_bold = toBool(bold); m_boldSpecified = true; + m_isCustomized = true; } } @@ -106,6 +119,7 @@ void ItemData::setUnderlined(const QString &underlined) if (!underlined.isEmpty()) { m_underlined = toBool(underlined); m_underlinedSpecified = true; + m_isCustomized = true; } } @@ -120,6 +134,7 @@ void ItemData::setStrikedOut(const QString &striked) if (!striked.isEmpty()) { m_strikedOut = toBool(striked); m_strikedOutSpecified = true; + m_isCustomized = true; } } @@ -128,3 +143,6 @@ bool ItemData::isStrikedOut() const bool ItemData::isStrikedOutSpecified() const { return m_strikedOutSpecified; } + +bool ItemData::isCustomized() const +{ return m_isCustomized; } diff --git a/src/plugins/genericeditor/itemdata.h b/src/plugins/genericeditor/itemdata.h index 62819acb21b245ae5dc016f49fe20b5a735be611..71e088f341298fcca65605985b42227f9f2624cc 100644 --- a/src/plugins/genericeditor/itemdata.h +++ b/src/plugins/genericeditor/itemdata.h @@ -69,6 +69,8 @@ public: bool isStrikedOut() const; bool isStrikedOutSpecified() const; + bool isCustomized() const; + static const QLatin1String kDsNormal; static const QLatin1String kDsKeyword; static const QLatin1String kDsDataType; @@ -96,6 +98,7 @@ private: bool m_underlinedSpecified; bool m_strikedOut; bool m_strikedOutSpecified; + bool m_isCustomized; }; } // namespace Internal