X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FColorCache.cpp;h=5b7a416afcc38d7bd5d8a3ebd53718da16bb9060;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=bfccf7a6f60a9a8473055f042a1bb270ab5805aa;hpb=a5263e0f927034885870a65053ef3908d1c6f885;p=lyx.git diff --git a/src/frontends/qt4/ColorCache.cpp b/src/frontends/qt4/ColorCache.cpp index bfccf7a6f6..5b7a416afc 100644 --- a/src/frontends/qt4/ColorCache.cpp +++ b/src/frontends/qt4/ColorCache.cpp @@ -11,45 +11,37 @@ #include #include "ColorCache.h" - -#include "Color.h" - -#include +#include "ColorSet.h" namespace lyx { -const QColor grey40(0x66, 0x66, 0x66); -const QColor grey60(0x99, 0x99, 0x99); -const QColor grey80(0xcc, 0xcc, 0xcc); -const QColor grey90(0xe5, 0xe5, 0xe5); -const QColor none = Qt::black; - -QColor const & ColorCache::get(ColorCode col) const +void ColorCache::init() { - lcolor_map::const_iterator cit = colormap.find(col); - if (cit != colormap.end()) - return cit->second; - - if (lcolor.getX11Name(col) == "grey40") - colormap[col] = grey40; - else if (lcolor.getX11Name(col) == "grey60") - colormap[col] = grey60; - else if (lcolor.getX11Name(col) == "grey80") - colormap[col] = grey80; - else if (lcolor.getX11Name(col) == "grey90") - colormap[col] = grey90; - else if (lcolor.getX11Name(col) == "none") - colormap[col] = none; - else - colormap[col] = QColor(lcolor.getX11Name(col).c_str()); - - return colormap[col]; + for (int col = 0; col <= Color_ignore; ++col) + lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str()); + initialized_ = true; } -void ColorCache::clear() +/// get the given color +QColor ColorCache::get(Color color) const { - colormap.clear(); + if (!initialized_) + const_cast(this)->init(); + if (color <= Color_ignore && color.mergeColor == Color_ignore) + return lcolors_[color.baseColor]; + if (color.mergeColor != Color_ignore) { + // FIXME: This would ideally be done in the Color class, but + // that means that we'd have to use the Qt code in the core. + QColor base_color = get(color.baseColor).toRgb(); + QColor merge_color = get(color.mergeColor).toRgb(); + return QColor( + (base_color.red() + merge_color.red()) / 2, + (base_color.green() + merge_color.green()) / 2, + (base_color.blue() + merge_color.blue()) / 2); + } + // used by branches + return QColor(lcolor.getX11Name(color.baseColor).c_str()); }