From e96c5c8f96369b256ebb69ccefe3c424de6090bc Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 6 Sep 2017 18:11:31 +0200 Subject: [PATCH] Make the session zoom relative to the default zoom Also rename lyxrc.zoom to lyxrc.defaultZoom Fixes: #10455 --- src/LyXAction.cpp | 9 ++++++--- src/LyXRC.cpp | 14 +++++++------- src/LyXRC.h | 7 ++++--- src/frontends/qt4/GuiPrefs.cpp | 6 +++--- src/frontends/qt4/GuiView.cpp | 28 +++++++++++++++++----------- src/frontends/qt4/GuiView.h | 3 +++ 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 6aaec92428..74031c70fd 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -892,7 +892,8 @@ void LyXAction::init() * \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM * \li Action: Sets the zoom of the screen fonts. * \li Syntax: buffer-zoom [] -* \li Params: : The zoom in % points (neg. or pos.), the default is to reset to zoom savd in preferences. +* \li Params: : The target zoom value in %; +* the default is the default zoom as saved in preferences. * \li Origin: daniel, 28 Oct 2016 * \endvar */ @@ -902,7 +903,8 @@ void LyXAction::init() * \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM_IN * \li Action: Increases the zoom of the screen fonts. * \li Syntax: buffer-zoom-in [] - * \li Params: : The zoom in % points (neg. or pos.), the default is 20. + * \li Params: : The zoom value addition in % (neg. or pos.); + * the default is 10% of the default zoom as saved in preferences. * \li Origin: vfr, 30 Mar 2009 * \endvar */ @@ -913,7 +915,8 @@ void LyXAction::init() * \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM_OUT * \li Action: Decreases the zoom of the screen fonts. * \li Syntax: buffer-zoom-out [] - * \li Params: : The zoom in % points (neg. or pos.), the default is -20. + * \li Params: : The zoom value abstraction in % (neg. or pos.); + * the default is 10% of the default zoom as saved in preferences. * \li Origin: vfr, 30 Mar 2009 * \endvar */ diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 315495f85c..431f4a40d6 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -245,8 +245,8 @@ void LyXRC::setDefaults() pygmentize_command = string(); dpi = 75; // Because a screen is typically wider than a piece of paper: - zoom = 150; - currentZoom = zoom; + defaultZoom = 150; + currentZoom = defaultZoom; allow_geometry_session = true; // Default LaTeX font size: font_sizes[FONT_SIZE_TINY] = "5.0"; @@ -624,9 +624,9 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format) break; case RC_SCREEN_ZOOM: - lexrc >> zoom; - if (zoom < 10) - zoom = 10; + lexrc >> defaultZoom; + if (defaultZoom < 10) + defaultZoom = 10; break; case RC_GEOMETRY_SESSION: @@ -1724,8 +1724,8 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c // fall through case RC_SCREEN_ZOOM: if (ignore_system_lyxrc || - zoom != system_lyxrc.zoom) { - os << "\\screen_zoom " << zoom << '\n'; + defaultZoom != system_lyxrc.defaultZoom) { + os << "\\screen_zoom " << defaultZoom << '\n'; } if (tag != RC_LAST) break; diff --git a/src/LyXRC.h b/src/LyXRC.h index 38fcd37394..8ac70c1bca 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -295,9 +295,10 @@ public: bool allow_geometry_session; /// Scrolling speed of the mouse wheel double mouse_wheel_speed; - /// Zoom factor for screen fonts - int zoom; - /// Current zoom factor for screen fonts + /// Default zoom factor for screen fonts + int defaultZoom; + /// Actual zoom factor for screen fonts + /// (default zoom plus buffer zoom factor) int currentZoom; /// Screen font sizes in points for each font size std::string font_sizes[10]; diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 891970b694..212d19f601 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1089,7 +1089,7 @@ void PrefScreenFonts::applyRC(LyXRC & rc) const parseFontName(screenTypewriterCO->currentText(), rc.typewriter_font_name, rc.typewriter_font_foundry); - rc.zoom = screenZoomSB->value(); + rc.defaultZoom = screenZoomSB->value(); rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED); rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED); rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED); @@ -1106,7 +1106,7 @@ void PrefScreenFonts::applyRC(LyXRC & rc) const || 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.zoom != oldrc.zoom) { + || rc.defaultZoom != oldrc.defaultZoom) { // The global QPixmapCache is used in GuiPainter to cache text // painting so we must reset it in case any of the above // parameter is changed. @@ -1130,7 +1130,7 @@ void PrefScreenFonts::updateRC(LyXRC const & rc) selectSans(screenSansCO->currentText()); selectTypewriter(screenTypewriterCO->currentText()); - screenZoomSB->setValue(rc.zoom); + screenZoomSB->setValue(rc.defaultZoom); updateScreenFontSizes(rc); pixmapCacheCB->setChecked(rc.use_pixmap_cache); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index b325e4b225..e48d6db1af 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -741,7 +741,7 @@ void GuiView::autoSaveThreadFinished() void GuiView::saveLayout() const { QSettings settings; - settings.setValue("zoom", lyxrc.currentZoom); + settings.setValue("zoom_ratio", zoom_ratio_); settings.setValue("devel_mode", devel_mode_); settings.beginGroup("views"); settings.beginGroup(QString::number(id_)); @@ -772,7 +772,12 @@ void GuiView::saveUISettings() const bool GuiView::restoreLayout() { QSettings settings; - lyxrc.currentZoom = settings.value("zoom", lyxrc.zoom).toInt(); + zoom_ratio_ = settings.value("zoom_ratio", 1.0).toDouble(); + // Actual zoom value: default zoom + fractional offset + int zoom = lyxrc.defaultZoom * zoom_ratio_; + if (zoom < static_cast(zoom_min_)) + zoom = zoom_min_; + lyxrc.currentZoom = zoom; devel_mode_ = settings.value("devel_mode", devel_mode_).toBool(); settings.beginGroup("views"); settings.beginGroup(QString::number(id_)); @@ -4114,30 +4119,31 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_BUFFER_ZOOM_IN: case LFUN_BUFFER_ZOOM_OUT: case LFUN_BUFFER_ZOOM: { - // use a signed temp to avoid overflow - int zoom = lyxrc.currentZoom; if (cmd.argument().empty()) { if (cmd.action() == LFUN_BUFFER_ZOOM) - zoom = lyxrc.zoom; + zoom_ratio_ = 1.0; else if (cmd.action() == LFUN_BUFFER_ZOOM_IN) - zoom += 20; + zoom_ratio_ += 0.1; else - zoom -= 20; + zoom_ratio_ -= 0.1; } else { if (cmd.action() == LFUN_BUFFER_ZOOM) - zoom = convert(cmd.argument()); + zoom_ratio_ = convert(cmd.argument()) / double(lyxrc.defaultZoom); else if (cmd.action() == LFUN_BUFFER_ZOOM_IN) - zoom += convert(cmd.argument()); + zoom_ratio_ += convert(cmd.argument()) / 100.0; else - zoom -= convert(cmd.argument()); + zoom_ratio_ -= convert(cmd.argument()) / 100.0; } + // Actual zoom value: default zoom + fractional extra value + int zoom = lyxrc.defaultZoom * zoom_ratio_; if (zoom < static_cast(zoom_min_)) zoom = zoom_min_; lyxrc.currentZoom = zoom; - dr.setMessage(bformat(_("Zoom level is now %1$d%"), lyxrc.currentZoom)); + dr.setMessage(bformat(_("Zoom level is now %1$d% (default value: %2$d%)"), + lyxrc.currentZoom, lyxrc.defaultZoom)); // The global QPixmapCache is used in GuiPainter to cache text // painting so we must reset it. diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index dd6fb9bd6e..ecf4e446c6 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -470,6 +470,9 @@ private: /// Statusbar widget that shows version control status QLabel * version_control_; + /// The rate from which the actual zoom value is calculated + /// from the default zoom pref + double zoom_ratio_ = 1.0; /// Minimum zoom percentage static int const zoom_min_ = 10; -- 2.39.5