From 954531f247adee029c12713634a81717f87a2bcf Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 26 Feb 2019 16:37:41 +0100 Subject: [PATCH] Update screen as needed when preferences are changed This commit removes the adhoc code in GuiPrefs and moves it to LyXRC, so that it triggers in every preference change. The code has also been updated to trigger on more variables, e.g. font_*_foundry. Note that the actual function that are called have not been changed (addPreviews and LFUN_SCREEN_FONT_UPDATE), although there are doubts that they behave as needed (see FIXMEs). Fixes bug #11498. --- src/LyXRC.cpp | 25 ++++++++++++- src/frontends/qt4/GuiApplication.cpp | 3 ++ src/frontends/qt4/GuiPrefs.cpp | 54 +++------------------------- src/frontends/qt4/GuiPrefs.h | 9 ----- 4 files changed, 32 insertions(+), 59 deletions(-) diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 46d23f2f9c..b1936f0829 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -23,6 +23,8 @@ #include "Converter.h" #include "FontEnums.h" #include "Format.h" +#include "FuncCode.h" +#include "FuncRequest.h" #include "Lexer.h" #include "LyX.h" #include "Mover.h" @@ -2942,6 +2944,14 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) } // fall through case LyXRC::RC_PREVIEW: + if (lyxrc_orig.preview != lyxrc_new.preview) { + // Update all previews of all documents. + /* FIXME: this can be very expensive. It would be cheaper + * to kill all existing previews and update visible + * previews.*/ + theBufferList().updatePreviews(); + } + // fall through case LyXRC::RC_PREVIEW_HASHED_LABELS: case LyXRC::RC_PREVIEW_SCALE_FACTOR: case LyXRC::RC_PRINTLANDSCAPEFLAG: @@ -2950,6 +2960,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_SAVE_COMPRESSED: case LyXRC::RC_SAVE_ORIGIN: case LyXRC::RC_SCREEN_DPI: + case LyXRC::RC_SCREEN_FONT_ROMAN: case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY: case LyXRC::RC_SCREEN_FONT_SANS: @@ -2958,8 +2969,20 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_SCREEN_FONT_SIZES: case LyXRC::RC_SCREEN_FONT_TYPEWRITER: case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY: - case LyXRC::RC_GEOMETRY_SESSION: case LyXRC::RC_SCREEN_ZOOM: + if (lyxrc_orig.roman_font_name != lyxrc_new.roman_font_name + || lyxrc_orig.sans_font_name != lyxrc_new.sans_font_name + || lyxrc_orig.typewriter_font_name != lyxrc_new.typewriter_font_name + || lyxrc_orig.roman_font_foundry != lyxrc_new.roman_font_foundry + || lyxrc_orig.sans_font_foundry != lyxrc_new.sans_font_foundry + || lyxrc_orig.use_scalable_fonts != lyxrc_new.use_scalable_fonts + || lyxrc_orig.font_sizes != lyxrc_new.font_sizes + || lyxrc_orig.typewriter_font_foundry != lyxrc_new.typewriter_font_foundry + || lyxrc_orig.defaultZoom != lyxrc_new.defaultZoom) { + dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE)); + } + + case LyXRC::RC_GEOMETRY_SESSION: case LyXRC::RC_SERVERPIPE: case LyXRC::RC_SET_COLOR: case LyXRC::RC_SHOW_BANNER: diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 28b4da4fad..ac3e4e8f97 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1642,6 +1642,9 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_SCREEN_FONT_UPDATE: { // handle the screen font changes. + /* FIXME: this only updates the current document, whereas all + * documents should see their metrics updated. + */ d->font_loader_.update(); dr.screenUpdate(Update::Force | Update::FitCursor); break; diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 82cfd0a501..be9e981ca7 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1030,15 +1030,6 @@ void PrefScreenFonts::applyRC(LyXRC & rc) const rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED); rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED); rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED); - - if (rc.font_sizes != oldrc.font_sizes - || rc.roman_font_name != oldrc.roman_font_name - || rc.sans_font_name != oldrc.sans_font_name - || rc.typewriter_font_name != oldrc.typewriter_font_name - || rc.defaultZoom != oldrc.defaultZoom) { - guiApp->fontLoader().update(); - form_->updateScreenFonts(); - } } @@ -1366,16 +1357,10 @@ void PrefDisplay::applyRC(LyXRC & rc) const rc.preview = LyXRC::PREVIEW_OFF; break; case 1: - if (rc.preview != LyXRC::PREVIEW_NO_MATH) { - rc.preview = LyXRC::PREVIEW_NO_MATH; - form_->updatePreviews(); - } + rc.preview = LyXRC::PREVIEW_NO_MATH; break; case 2: - if (rc.preview != LyXRC::PREVIEW_ON) { - rc.preview = LyXRC::PREVIEW_ON; - form_->updatePreviews(); - } + rc.preview = LyXRC::PREVIEW_ON; break; } @@ -3456,8 +3441,7 @@ void PrefIdentity::updateRC(LyXRC const & rc) ///////////////////////////////////////////////////////////////////// GuiPreferences::GuiPreferences(GuiView & lv) - : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false), - update_previews_(false) + : GuiDialog(lv, "prefs", qt_("Preferences")) { setupUi(this); @@ -3560,8 +3544,6 @@ bool GuiPreferences::initialiseParams(string const &) converters_.update(formats_); movers_ = theMovers(); colors_.clear(); - update_screen_font_ = false; - update_previews_ = false; updateRC(rc_); // Make sure that the bc is in the INITIAL state @@ -3595,24 +3577,10 @@ void GuiPreferences::dispatchParams() theMovers() = movers_; - vector::const_iterator it = colors_.begin(); - vector::const_iterator const end = colors_.end(); - for (; it != end; ++it) - dispatch(FuncRequest(LFUN_SET_COLOR, *it)); + for (string const & color : colors_) + dispatch(FuncRequest(LFUN_SET_COLOR, color)); colors_.clear(); - if (update_screen_font_) { - dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE)); - // resets flag in case second apply in same dialog - update_screen_font_ = false; - } - - if (update_previews_) { - // resets flag in case second apply in same dialog - theBufferList().updatePreviews(); - update_previews_ = false; - } - // Save permanently if (!tempSaveCB->isChecked()) dispatch(FuncRequest(LFUN_PREFERENCES_SAVE)); @@ -3625,18 +3593,6 @@ void GuiPreferences::setColor(ColorCode col, QString const & hex) } -void GuiPreferences::updateScreenFonts() -{ - update_screen_font_ = true; -} - - -void GuiPreferences::updatePreviews() -{ - update_previews_ = true; -} - - QString GuiPreferences::browsebind(QString const & file) const { return browseLibFile("bind", file, "bind", qt_("Choose bind file"), diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index b498a4e82e..ebf7a53f02 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -98,12 +98,6 @@ public: /// set a color void setColor(ColorCode col, QString const & hex); - /// update the screen fonts after change - void updateScreenFonts(); - - /// update the previews after change - void updatePreviews(); - LyXRC & rc() { return rc_; } Converters & converters() { return converters_; } Formats & formats() { return formats_; } @@ -124,9 +118,6 @@ private: /// A list of colors to be dispatched std::vector colors_; - - bool update_screen_font_; - bool update_previews_; }; -- 2.39.5