mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
Finish implementation of "use system colors" checkbox.
ColorCache: * method isSystem() allows to know whether a color can be overridden by system colors * method get() has a variant that accepts a bool (system color or not) * code simplifications GuiPrefs: * hide colors set from the system when they are inherited * syncronize list of colors and checkbox git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35101 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
aba279a928
commit
b01fcee92d
@ -17,65 +17,79 @@
|
||||
|
||||
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,
|
||||
@ -86,6 +100,12 @@ QColor ColorCache::get(Color color) const
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
@ -30,11 +30,17 @@ public:
|
||||
///
|
||||
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; }
|
||||
@ -43,8 +49,6 @@ private:
|
||||
///
|
||||
void init();
|
||||
///
|
||||
void setColor(int col, QPalette::ColorRole cr);
|
||||
///
|
||||
QColor lcolors_[Color_ignore + 1];
|
||||
///
|
||||
bool initialized_;
|
||||
|
@ -1090,6 +1090,8 @@ PrefColors::PrefColors(GuiPreferences * form)
|
||||
this, SLOT(changeColor()));
|
||||
connect(syscolorsCB, SIGNAL(toggled(bool)),
|
||||
this, SIGNAL(changed()));
|
||||
connect(syscolorsCB, SIGNAL(toggled(bool)),
|
||||
this, SLOT(changeSysColor()));
|
||||
}
|
||||
|
||||
|
||||
@ -1110,7 +1112,7 @@ void PrefColors::apply(LyXRC & rc) const
|
||||
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));
|
||||
@ -1142,6 +1144,18 @@ void PrefColors::changeColor()
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -254,6 +254,7 @@ public:
|
||||
|
||||
private Q_SLOTS:
|
||||
void changeColor();
|
||||
void changeSysColor();
|
||||
void changeLyxObjectsSelection();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user