From 8c4127ebacd0508f12db79689ef976a814729d91 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 19 Jul 2017 09:19:29 +0200 Subject: [PATCH] TextEditor: Improve readability of text annotation Change-Id: Iddcf6951b44a73cd3e9d740d9aba725fa4d7d663 Reviewed-by: Nikolai Kosjar --- src/plugins/texteditor/textmark.cpp | 30 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index 254999f1b31..0a390837ea5 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -69,9 +69,6 @@ public: QColor rectColor; QColor textColor; -private: - static double clipHsl(double value); - private: static QHash m_colorCache; }; @@ -376,16 +373,22 @@ QHash AnnotationColors::m_colo AnnotationColors &AnnotationColors::getAnnotationColors(const QColor &markColor, const QColor &backgroundColor) { + auto highClipHsl = [](qreal value) { + return std::max(0.7, std::min(0.9, value)); + }; + auto lowClipHsl = [](qreal value) { + return std::max(0.1, std::min(0.3, value)); + }; AnnotationColors &colors = m_colorCache[{markColor, backgroundColor}]; if (!colors.rectColor.isValid() || !colors.textColor.isValid()) { - const double backgroundSaturation = clipHsl(markColor.hslSaturationF() / 2); - const double backgroundLightness = clipHsl(backgroundColor.lightnessF()); - const double foregroundLightness = clipHsl(backgroundLightness > 0.5 - ? backgroundLightness - 0.5 - : backgroundLightness + 0.5); - colors.rectColor.setHslF(markColor.hslHueF(), - backgroundSaturation, - backgroundLightness); + const double backgroundLightness = backgroundColor.lightnessF(); + const double foregroundLightness = backgroundLightness > 0.5 + ? lowClipHsl(backgroundLightness - 0.5) + : highClipHsl(backgroundLightness + 0.5); + + colors.rectColor = markColor; + colors.rectColor.setAlphaF(0.15); + colors.textColor.setHslF(markColor.hslHueF(), markColor.hslSaturationF(), foregroundLightness); @@ -393,11 +396,6 @@ AnnotationColors &AnnotationColors::getAnnotationColors(const QColor &markColor, return colors; } -double AnnotationColors::clipHsl(double value) -{ - return std::max(0.15, std::min(0.85, value)); -} - } // namespace TextEditor #include "textmark.moc"