namespace lyx {
-void ColorCache::setColor(int col, QPalette::ColorRole cr)
+namespace{
+// FIXME (later): Qt >= 4.4 has a proper QPalette::NoRole value.
+QPalette::ColorRole const NoRole = static_cast<QPalette::ColorRole>(-1);
+
+QPalette::ColorRole role(ColorCode col)
{
- lcolors_[col] = pal_.brush(QPalette::Active, cr).color();
+ switch (ColorCode(col)) {
+ case Color_background:
+ case Color_commentbg:
+ case Color_greyedoutbg:
+ case Color_mathbg:
+ case Color_graphicsbg:
+ case Color_mathmacrobg:
+ case Color_mathcorners:
+ return QPalette::Base;
+ break;
+
+ case Color_foreground:
+ case Color_cursor:
+ case Color_preview:
+ case Color_tabularline:
+ case Color_previewframe:
+ return QPalette::Text;
+ break;
+
+ case Color_selection:
+ return QPalette::Highlight;
+ break;
+ case Color_selectiontext:
+ return QPalette::HighlightedText;
+ break;
+ default:
+ return NoRole;
+ }
+}
+
}
void ColorCache::init()
{
- if (lyxrc.use_system_colors) {
- for (int col = 0; col <= Color_ignore; ++col) {
- switch (ColorCode(col)) {
- case Color_background:
- case Color_commentbg:
- case Color_greyedoutbg:
- case Color_mathbg:
- case Color_graphicsbg:
- case Color_mathmacrobg:
- case Color_mathcorners:
- setColor(col, QPalette::Base);
- break;
-
- case Color_foreground:
- case Color_cursor:
- case Color_preview:
- case Color_tabularline:
- case Color_previewframe:
- setColor(col, QPalette::Text);
- break;
-
- case Color_selection:
- setColor(col, QPalette::Highlight);
- break;
- case Color_selectiontext:
- setColor(col, QPalette::HighlightedText);
- break;
- default:
- lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
- }
- }
- } else {
- for (int col = 0; col <= Color_ignore; ++col)
- lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
+ for (int col = 0; col <= Color_ignore; ++col) {
+ lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
}
+
initialized_ = true;
}
/// get the given color
-QColor ColorCache::get(Color color) const
+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)
- return lcolors_[color.baseColor];
+ if (color <= Color_ignore && color.mergeColor == Color_ignore) {
+ QPalette::ColorRole cr = role(color.baseColor);
+ if (syscolors && cr != NoRole)
+ return pal_.brush(QPalette::Active, cr).color();
+ 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).toRgb();
- QColor merge_color = get(color.mergeColor).toRgb();
+ 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,
}
+bool ColorCache::isSystem(ColorCode const color) const
+{
+ return role(color) != NoRole;
+}
+
+
QColor const rgb2qcolor(RGBColor const & rgb)
{
return QColor(rgb.r, rgb.g, rgb.b);
///
ColorCache() : initialized_(false) {}
+ /// get the given color (depends on LyXRC::use_system_color)
+ QColor get(Color const & color) const;
+
/// get the given color
- QColor get(Color color) const;
+ QColor get(Color const & color, bool use_system_colors) const;
+
+ /// is this color replaced when LyXRC::use_system_color is true?
+ bool isSystem(ColorCode color) const;
/// change the undelying palette
- void setPalette(QPalette const pal) { pal_ = pal; initialized_ = false; }
+ void setPalette(QPalette const pal) { pal_ = pal; clear(); }
/// clear all colors
void clear() { initialized_ = false; }
///
void init();
///
- void setColor(int col, QPalette::ColorRole cr);
- ///
QColor lcolors_[Color_ignore + 1];
///
bool initialized_;
this, SLOT(changeColor()));
connect(syscolorsCB, SIGNAL(toggled(bool)),
this, SIGNAL(changed()));
+ connect(syscolorsCB, SIGNAL(toggled(bool)),
+ this, SLOT(changeSysColor()));
}
void PrefColors::update(LyXRC const & rc)
{
for (unsigned int i = 0; i < lcolors_.size(); ++i) {
- QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
+ QColor color = QColor(guiApp->colorCache().get(lcolors_[i], false));
QPixmap coloritem(32, 32);
coloritem.fill(color);
lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
}
}
+void PrefColors::changeSysColor()
+{
+ for (int row = 0 ; row < lyxObjectsLW->count() ; ++row) {
+ // skip colors that are taken from system palette
+ bool const hide = syscolorsCB->isChecked()
+ && guiApp->colorCache().isSystem(lcolors_[row]);
+
+ lyxObjectsLW->item(row)->setHidden(hide);
+ }
+
+}
+
void PrefColors::changeLyxObjectsSelection()
{
colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);