From 8c4127ebacd0508f12db79689ef976a814729d91 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 19 Jul 2017 09:19:29 +0200 Subject: 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(-) (limited to 'src/plugins/texteditor/textmark.cpp') 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 @@ -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" -- cgit v1.2.1 From c2ecee517ecfbb5022149ee639d79e3dc5760e45 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 19 Jul 2017 12:56:17 +0300 Subject: TextEditor: Avoid removing text marks that were not added to hash TextMarks with empty file names are not added, no reason to remove them. Change-Id: I8647deaa1136294d2f7c3c63337d967afea675c2 Reviewed-by: David Schulz --- src/plugins/texteditor/textmark.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/texteditor/textmark.cpp') diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index 0a390837ea..76050e1902 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -88,7 +88,8 @@ TextMark::TextMark(const QString &fileName, int lineNumber, Id category, double TextMark::~TextMark() { - TextMarkRegistry::remove(this); + if (!m_fileName.isEmpty()) + TextMarkRegistry::remove(this); if (m_baseTextDocument) m_baseTextDocument->removeMark(this); m_baseTextDocument = 0; -- cgit v1.2.1