]> git.lyx.org Git - features.git/commitdiff
Update screen as needed when preferences are changed
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 26 Feb 2019 15:37:41 +0000 (16:37 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 12:39:58 +0000 (14:39 +0200)
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
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrefs.h

index 46d23f2f9c00ad11fae48cbe9211dc5a0422c3aa..b1936f08296d16254adb38d615299d2cff9f01eb 100644 (file)
@@ -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:
index 28b4da4fadb281576ea770f2c7e1bb8c6cedc36f..ac3e4e8f97678788b3718977f37c804a44dc8dd6 100644 (file)
@@ -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;
index 82cfd0a5010d85b35bd33bcd00d944f910a700e2..be9e981ca7a1ea6eeaa2372daff385f65a5af431 100644 (file)
@@ -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<string>::const_iterator it = colors_.begin();
-       vector<string>::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"),
index b498a4e82e4709e2fc24b5291ea407aeb7b5ac24..ebf7a53f02e5dcd32b1db2dcd763f55a5c9b57fb 100644 (file)
@@ -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<std::string> colors_;
-
-       bool update_screen_font_;
-       bool update_previews_;
 };