From 3192366b44e74c0d2e67ec924cc75644ed8beb75 Mon Sep 17 00:00:00 2001 From: Hugo Holgersson Date: Thu, 30 Nov 2017 11:39:05 +0100 Subject: [PATCH] TextEditor: Implement color overriding mixins This is the first implementation of "color overriding mixins". Mixins are already initialized with fore/background color = QColor() = "invalid color" (see Format::createMixinFormat). This patch uses above contract in FontSettings::addMixinStyle. Only mixins with a valid fore- or background color can override other style options' colors. Unset mixins will have no effect. TEST=No functional change (will be enabled in a follow-up). Requires Clang. Task-number: QTCREATORBUG-16625 Change-Id: I983bb876c060963f6d66cc64881bc138e384f5e5 Reviewed-by: David Schulz --- src/plugins/texteditor/fontsettings.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/plugins/texteditor/fontsettings.cpp b/src/plugins/texteditor/fontsettings.cpp index b1db84be748..e1ebc812ee3 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -229,17 +229,21 @@ void FontSettings::addMixinStyle(QTextCharFormat &textCharFormat, const Format &format = m_scheme.formatFor(mixinStyle); if (textCharFormat.hasProperty(QTextFormat::ForegroundBrush)) { - textCharFormat.setForeground(mixBrush(textCharFormat.foreground(), - format.relativeForegroundSaturation(), - format.relativeForegroundLightness())); + if (format.foreground().isValid()) + textCharFormat.setForeground(format.foreground()); + else + textCharFormat.setForeground(mixBrush(textCharFormat.foreground(), + format.relativeForegroundSaturation(), + format.relativeForegroundLightness())); } - if (textCharFormat.hasProperty(QTextFormat::BackgroundBrush)) { - textCharFormat.setBackground(mixBrush(textCharFormat.background(), - format.relativeBackgroundSaturation(), - format.relativeBackgroundLightness())); + if (format.background().isValid()) + textCharFormat.setBackground(format.background()); + else + textCharFormat.setBackground(mixBrush(textCharFormat.background(), + format.relativeBackgroundSaturation(), + format.relativeBackgroundLightness())); } - if (!textCharFormat.fontItalic()) textCharFormat.setFontItalic(format.italic());