]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/ColorCache.cpp
dde6bc6368ba6df40afe7a8f46eb810de2c87599
[lyx.git] / src / frontends / qt4 / ColorCache.cpp
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.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ColorCache.h"
14
15 #include "Color.h"
16
17 #include <string>
18
19
20 namespace lyx {
21
22 void ColorCache::init()
23 {
24         for (int col = 0; col <= Color_ignore; ++col)
25                 lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
26         initialized_ = true;
27 }
28
29
30 /// get the given color
31 QColor ColorCache::get(Color color) const
32 {
33         if (!initialized_)
34                 const_cast<ColorCache *>(this)->init();
35         if (color <= Color_ignore && color.mergeColor == Color_ignore)
36                 return lcolors_[color.baseColor];
37         if (color.mergeColor != Color_ignore) {
38                 // FIXME: This would ideally be done in the Color class, but
39                 // that means that we'd have to use the Qt code in the core.
40                 QColor base_color = get(color.baseColor).toRgb();
41                 QColor merge_color = get(color.mergeColor).toRgb();
42                 return QColor(
43                         (base_color.red() + merge_color.red())/2,
44                         (base_color.green() + merge_color.green())/2,
45                         (base_color.blue() + merge_color.blue())/2);
46         }
47         // used by branches
48         return QColor(lcolor.getX11Name(color.baseColor).c_str()); 
49 }
50
51
52 QColor const rgb2qcolor(RGBColor const & rgb)
53 {
54         return QColor(rgb.r, rgb.g, rgb.b);
55 }
56
57
58 } // namespace lyx