GuiPrintNomencl.{cpp,h}:
[lyx.git] / src / frontends / qt4 / ColorCache.cpp
blob5b7a416afcc38d7bd5d8a3ebd53718da16bb9060
1 /**
2 * \file ColorCache.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author John Levon
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "ColorCache.h"
14 #include "ColorSet.h"
16 namespace lyx {
18 void ColorCache::init()
20 for (int col = 0; col <= Color_ignore; ++col)
21 lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
22 initialized_ = true;
26 /// get the given color
27 QColor ColorCache::get(Color color) const
29 if (!initialized_)
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();
38 return QColor(
39 (base_color.red() + merge_color.red()) / 2,
40 (base_color.green() + merge_color.green()) / 2,
41 (base_color.blue() + merge_color.blue()) / 2);
43 // used by branches
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);
54 } // namespace lyx