diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 623df41a63..3e19dcc683 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -199,6 +199,7 @@ LexerKeyword lyxrcTags[] = { { "\\use_pixmap_cache", LyXRC::RC_USE_PIXMAP_CACHE }, // compatibility with versions older than 1.4.0 only { "\\use_pspell", LyXRC::RC_USE_SPELL_LIB }, + { "\\use_system_colors", LyXRC::RC_USE_SYSTEM_COLORS }, // compatibility with versions older than 1.4.0 only { "\\use_tempdir", LyXRC::RC_USETEMPDIR }, { "\\use_tooltip", LyXRC::RC_USE_TOOLTIP }, @@ -330,6 +331,7 @@ void LyXRC::setDefaults() preview_hashed_labels = false; preview_scale_factor = 1.0; use_converter_cache = true; + use_system_colors = true; use_tooltip = true; use_pixmap_cache = false; converter_cache_maxage = 6 * 30 * 24 * 3600; // 6 months @@ -914,6 +916,9 @@ int LyXRC::read(Lexer & lexrc) case RC_ACCEPT_COMPOUND: lexrc >> spellchecker_accept_compound; break; + case RC_USE_SYSTEM_COLORS: + lexrc >> use_system_colors; + break; case RC_USE_TOOLTIP: lexrc >> use_tooltip; break; @@ -2382,6 +2387,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c // obsoleted in 2.0 if (tag != RC_LAST) break; + case RC_USE_SYSTEM_COLORS: + if (ignore_system_lyxrc || + use_system_colors != system_lyxrc.use_system_colors) { + os << "\\use_system_colors " + << convert(use_system_colors) + << '\n'; + } + if (tag != RC_LAST) + break; case RC_USE_TOOLTIP: if (ignore_system_lyxrc || use_tooltip != system_lyxrc.use_tooltip) { @@ -2932,6 +2946,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_USE_ESC_CHARS: case LyXRC::RC_USE_INP_ENC: case LyXRC::RC_USE_PERS_DICT: + case LyXRC::RC_USE_SYSTEM_COLORS: case LyXRC::RC_USE_TOOLTIP: case LyXRC::RC_USE_PIXMAP_CACHE: case LyXRC::RC_USE_SPELL_LIB: @@ -3382,6 +3397,10 @@ string const LyXRC::getDescription(LyXRCTags tag) case RC_USETEMPDIR: break; + case RC_USE_TOOLTIP: + str = _("Enable use the system colors for some things like main window background and selection."); + break; + case RC_USE_TOOLTIP: str = _("Enable the automatic appearance of tool tips in the work area."); break; diff --git a/src/LyXRC.h b/src/LyXRC.h index 8be4aea19f..ffcf3f650c 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -182,6 +182,7 @@ public: RC_USE_ESC_CHARS, RC_USE_INP_ENC, RC_USE_PERS_DICT, + RC_USE_SYSTEM_COLORS, RC_USE_TOOLTIP, RC_USE_PIXMAP_CACHE, RC_USE_SPELL_LIB, @@ -351,6 +352,8 @@ public: bool paragraph_markers; /// Use tooltips? bool use_tooltip; + /// Use the colors from current system theme? + bool use_system_colors; /// Use pixmap cache? bool use_pixmap_cache; /// Spellchecker engine: aspell, hunspell, etc diff --git a/src/frontends/qt4/ColorCache.cpp b/src/frontends/qt4/ColorCache.cpp index 5b7a416afc..26ee11b279 100644 --- a/src/frontends/qt4/ColorCache.cpp +++ b/src/frontends/qt4/ColorCache.cpp @@ -10,15 +10,56 @@ #include +#include "LyXRC.h" + #include "ColorCache.h" #include "ColorSet.h" namespace lyx { +void ColorCache::setColor(int col, QPalette::ColorRole cr) +{ + lcolors_[col] = pal_.brush(QPalette::Active, cr).color(); +} + + void ColorCache::init() { - for (int col = 0; col <= Color_ignore; ++col) - lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str()); + 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()); + } initialized_ = true; } diff --git a/src/frontends/qt4/ColorCache.h b/src/frontends/qt4/ColorCache.h index 88db6bb565..af767c3420 100644 --- a/src/frontends/qt4/ColorCache.h +++ b/src/frontends/qt4/ColorCache.h @@ -15,6 +15,7 @@ #include "Color.h" #include +#include namespace lyx { @@ -26,11 +27,15 @@ struct RGBColor; class ColorCache { public: + /// ColorCache() : initialized_(false) {} /// get the given color QColor get(Color color) const; + /// change the undelying palette + void setPalette(QPalette const pal) { pal_ = pal; initialized_ = false; } + /// clear all colors void clear() { initialized_ = false; } @@ -38,9 +43,13 @@ private: /// void init(); /// + void setColor(int col, QPalette::ColorRole cr); + /// QColor lcolors_[Color_ignore + 1]; /// bool initialized_; + /// + QPalette pal_; }; /// diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 6047e55f57..9f5232f157 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -162,7 +162,11 @@ frontend::Application * createApplication(int & argc, char * argv[]) } } #endif - return new frontend::GuiApplication(argc, argv); + frontend::GuiApplication * guiApp = new frontend::GuiApplication(argc, argv); + // I'd rather do that in the constructor, but I do not think that + // the palette is accessible there. + guiApp->colorCache().setPalette(guiApp->palette()); + return guiApp; } namespace frontend { @@ -759,13 +763,6 @@ GuiApplication::~GuiApplication() } -namespace { -void setColor(ColorCode code, QPalette const & pal, QPalette::ColorRole cr) -{ - lcolor.setColor(code, fromqstr(pal.brush(QPalette::Active, cr).color().name())); -} -} - GuiApplication::GuiApplication(int & argc, char ** argv) : QApplication(argc, argv), current_view_(0), d(new GuiApplication::Private) @@ -827,24 +824,6 @@ GuiApplication::GuiApplication(int & argc, char ** argv) if (lyxrc.typewriter_font_name.empty()) lyxrc.typewriter_font_name = fromqstr(typewriterFontName()); - // initialize colors - setColor(Color_background, palette(), QPalette::Base); - setColor(Color_commentbg, palette(), QPalette::Base); - setColor(Color_greyedoutbg, palette(), QPalette::Base); - setColor(Color_mathbg, palette(), QPalette::Base); - setColor(Color_graphicsbg, palette(), QPalette::Base); - setColor(Color_mathmacrobg, palette(), QPalette::Base); - setColor(Color_mathcorners, palette(), QPalette::Base); - - setColor(Color_foreground, palette(), QPalette::Text); - setColor(Color_cursor, palette(), QPalette::Text); - setColor(Color_preview, palette(), QPalette::Text); - setColor(Color_tabularline, palette(), QPalette::Text); - setColor(Color_previewframe, palette(), QPalette::Text); - - setColor(Color_selection, palette(), QPalette::Highlight); - setColor(Color_selectiontext, palette(), QPalette::HighlightedText); - d->general_timer_.setInterval(500); connect(&d->general_timer_, SIGNAL(timeout()), this, SLOT(handleRegularEvents())); diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 932d0c1ad6..6bd55e86e5 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1088,18 +1088,26 @@ PrefColors::PrefColors(GuiPreferences * form) this, SLOT(changeLyxObjectsSelection())); connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(changeColor())); + connect(syscolorsCB, SIGNAL(toggled(bool)), + this, SIGNAL(changed())); } -void PrefColors::apply(LyXRC & /*rc*/) const +void PrefColors::apply(LyXRC & rc) const { + LyXRC oldrc = rc; + for (unsigned int i = 0; i < lcolors_.size(); ++i) if (curcolors_[i] != newcolors_[i]) form_->setColor(lcolors_[i], newcolors_[i]); + rc.use_system_colors = syscolorsCB->isChecked(); + + if (oldrc.use_system_colors != rc.use_system_colors) + guiApp->colorCache().clear(); } -void PrefColors::update(LyXRC const & /*rc*/) +void PrefColors::update(LyXRC const & rc) { for (unsigned int i = 0; i < lcolors_.size(); ++i) { QColor color = QColor(guiApp->colorCache().get(lcolors_[i])); @@ -1108,6 +1116,7 @@ void PrefColors::update(LyXRC const & /*rc*/) lyxObjectsLW->item(i)->setIcon(QIcon(coloritem)); newcolors_[i] = curcolors_[i] = color.name(); } + syscolorsCB->setChecked(rc.use_system_colors); changeLyxObjectsSelection(); } @@ -3081,6 +3090,7 @@ void GuiPreferences::applyView() apply(rc()); } + bool GuiPreferences::initialiseParams(string const &) { rc_ = lyxrc; diff --git a/src/frontends/qt4/ui/PrefColorsUi.ui b/src/frontends/qt4/ui/PrefColorsUi.ui index 10a6fe0c61..76461ed219 100644 --- a/src/frontends/qt4/ui/PrefColorsUi.ui +++ b/src/frontends/qt4/ui/PrefColorsUi.ui @@ -5,26 +5,18 @@ 0 0 - 199 - 226 + 231 + 254 - - 9 - - - 6 - - - 5 - 7 + 0 0 @@ -64,6 +56,13 @@ + + + + Use system colors + + +