diff options
author | David Schulz <david.schulz@qt.io> | 2017-07-19 09:19:29 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2017-07-20 13:15:23 +0000 |
commit | 8c4127ebacd0508f12db79689ef976a814729d91 (patch) | |
tree | 3756df74b2f38650cfd0ffd78023e6a92fb2d4e1 /src/plugins/texteditor/textmark.cpp | |
parent | a8fa002c4a9218647f0d443e09b493d4208868bc (diff) |
TextEditor: Improve readability of text annotation
Change-Id: Iddcf6951b44a73cd3e9d740d9aba725fa4d7d663
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/texteditor/textmark.cpp')
-rw-r--r-- | src/plugins/texteditor/textmark.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index 254999f1b3..0a390837ea 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -70,9 +70,6 @@ public: QColor textColor; private: - static double clipHsl(double value); - -private: static QHash<SourceColors, AnnotationColors> m_colorCache; }; @@ -376,16 +373,22 @@ QHash<AnnotationColors::SourceColors, AnnotationColors> 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" |