]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/ColorCache.cpp
* fix spelling in comments to please John.
[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 #include "ColorSet.h"
15
16 namespace lyx {
17
18 void ColorCache::init()
19 {
20         for (int col = 0; col <= Color_ignore; ++col)
21                 lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
22         initialized_ = true;
23 }
24
25
26 /// get the given color
27 QColor ColorCache::get(Color color) const
28 {
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);
42         }
43         // used by branches
44         return QColor(lcolor.getX11Name(color.baseColor).c_str()); 
45 }
46
47
48 QColor const rgb2qcolor(RGBColor const & rgb)
49 {
50         return QColor(rgb.r, rgb.g, rgb.b);
51 }
52
53
54 } // namespace lyx