3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "ColorCache.h"
18 void ColorCache::init()
20 for (int col = 0; col <= Color_ignore; ++col)
21 lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
26 /// get the given color
27 QColor ColorCache::get(Color color) const
30 const_cast<ColorCache *>(this)->init();
31 if (color <= Color_ignore && color.mergeColor == Color_ignore)
32 return lcolors_[color.baseColor];
33 if (color.mergeColor != Color_ignore) {
34 // FIXME: This would ideally be done in the Color class, but
35 // that means that we'd have to use the Qt code in the core.
36 QColor base_color = get(color.baseColor).toRgb();
37 QColor merge_color = get(color.mergeColor).toRgb();
39 (base_color.red() + merge_color.red()) / 2,
40 (base_color.green() + merge_color.green()) / 2,
41 (base_color.blue() + merge_color.blue()) / 2);
44 return QColor(lcolor.getX11Name(color.baseColor).c_str());
48 QColor const rgb2qcolor(RGBColor const & rgb)
50 return QColor(rgb.r, rgb.g, rgb.b);