+ }
+
+ initialized_ = true;
+}
+
+
+/// get the given color
+QColor ColorCache::get(Color const & color) const
+{
+ return get(color, lyxrc.use_system_colors);
+}
+
+
+/// get the given color
+QColor ColorCache::get(Color const & color, bool syscolors) const
+{
+ if (!initialized_)
+ const_cast<ColorCache *>(this)->init();
+ if (color <= Color_ignore && color.mergeColor == Color_ignore) {
+ QPalette::ColorRole const cr = role(color.baseColor);
+ if (syscolors && cr != QPalette::NoRole) {
+ static QColor const white = Qt::white;
+ QColor const c = pal_.brush(QPalette::Active, cr).color();
+ if (cr == QPalette::Base && c == white)
+ return lcolors_[color.baseColor];
+ else
+ return c;
+ } else
+ 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, syscolors).toRgb();
+ QColor merge_color = get(color.mergeColor, syscolors).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());
+}
+
+
+bool ColorCache::isSystem(ColorCode const color) const
+{
+ QPalette::ColorRole const cr = role(color);
+ if (cr == QPalette::Base) {
+ static QColor const white = Qt::white;
+ return pal_.brush(QPalette::Active, cr).color() != white;
+ } else
+ return cr != QPalette::NoRole;