2015-08-20 00:49:03 +01:00
|
|
|
#include "ColorCache.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blend the color with the front color, adapting to the back color
|
|
|
|
*/
|
|
|
|
QColor ColorCache::blend(QColor color)
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (Rainbow::luma(m_front) > Rainbow::luma(m_back)) {
|
2015-08-20 00:49:03 +01:00
|
|
|
// for dark color schemes, produce a fitting color first
|
|
|
|
color = Rainbow::tint(m_front, color, 0.5);
|
|
|
|
}
|
|
|
|
// adapt contrast
|
|
|
|
return Rainbow::mix(m_front, color, m_bias);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blend the color with the back color
|
|
|
|
*/
|
|
|
|
QColor ColorCache::blendBackground(QColor color)
|
|
|
|
{
|
|
|
|
// adapt contrast
|
|
|
|
return Rainbow::mix(m_back, color, m_bias);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorCache::recolorAll()
|
|
|
|
{
|
|
|
|
auto iter = m_colors.begin();
|
2023-08-02 17:35:35 +01:00
|
|
|
while (iter != m_colors.end()) {
|
2015-08-20 00:49:03 +01:00
|
|
|
iter->front = blend(iter->original);
|
|
|
|
iter->back = blendBackground(iter->original);
|
|
|
|
}
|
|
|
|
}
|