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 rectColor;
|
||||||
QColor textColor;
|
QColor textColor;
|
||||||
|
|
||||||
private:
|
|
||||||
static double clipHsl(double value);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QHash<SourceColors, AnnotationColors> m_colorCache;
|
static QHash<SourceColors, AnnotationColors> m_colorCache;
|
||||||
};
|
};
|
||||||
@@ -376,16 +373,22 @@ QHash<AnnotationColors::SourceColors, AnnotationColors> AnnotationColors::m_colo
|
|||||||
AnnotationColors &AnnotationColors::getAnnotationColors(const QColor &markColor,
|
AnnotationColors &AnnotationColors::getAnnotationColors(const QColor &markColor,
|
||||||
const QColor &backgroundColor)
|
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}];
|
AnnotationColors &colors = m_colorCache[{markColor, backgroundColor}];
|
||||||
if (!colors.rectColor.isValid() || !colors.textColor.isValid()) {
|
if (!colors.rectColor.isValid() || !colors.textColor.isValid()) {
|
||||||
const double backgroundSaturation = clipHsl(markColor.hslSaturationF() / 2);
|
const double backgroundLightness = backgroundColor.lightnessF();
|
||||||
const double backgroundLightness = clipHsl(backgroundColor.lightnessF());
|
const double foregroundLightness = backgroundLightness > 0.5
|
||||||
const double foregroundLightness = clipHsl(backgroundLightness > 0.5
|
? lowClipHsl(backgroundLightness - 0.5)
|
||||||
? backgroundLightness - 0.5
|
: highClipHsl(backgroundLightness + 0.5);
|
||||||
: backgroundLightness + 0.5);
|
|
||||||
colors.rectColor.setHslF(markColor.hslHueF(),
|
colors.rectColor = markColor;
|
||||||
backgroundSaturation,
|
colors.rectColor.setAlphaF(0.15);
|
||||||
backgroundLightness);
|
|
||||||
colors.textColor.setHslF(markColor.hslHueF(),
|
colors.textColor.setHslF(markColor.hslHueF(),
|
||||||
markColor.hslSaturationF(),
|
markColor.hslSaturationF(),
|
||||||
foregroundLightness);
|
foregroundLightness);
|
||||||
@@ -393,11 +396,6 @@ AnnotationColors &AnnotationColors::getAnnotationColors(const QColor &markColor,
|
|||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
double AnnotationColors::clipHsl(double value)
|
|
||||||
{
|
|
||||||
return std::max(0.15, std::min(0.85, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
#include "textmark.moc"
|
#include "textmark.moc"
|
||||||
|
Reference in New Issue
Block a user