forked from qt-creator/qt-creator
TextEditor: Improve readability of text annotation
Change-Id: Iddcf6951b44a73cd3e9d740d9aba725fa4d7d663 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -69,9 +69,6 @@ public:
|
||||
QColor rectColor;
|
||||
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"
|
||||
|
Reference in New Issue
Block a user