Make the session zoom relative to the default zoom

Also rename lyxrc.zoom to lyxrc.defaultZoom

Fixes: #10455
This commit is contained in:
Juergen Spitzmueller 2017-09-06 18:11:31 +02:00
parent a034af5d5f
commit e96c5c8f96
6 changed files with 40 additions and 27 deletions

View File

@ -892,7 +892,8 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM * \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM
* \li Action: Sets the zoom of the screen fonts. * \li Action: Sets the zoom of the screen fonts.
* \li Syntax: buffer-zoom [<ZOOM>] * \li Syntax: buffer-zoom [<ZOOM>]
* \li Params: <ZOOM>: The zoom in % points (neg. or pos.), the default is to reset to zoom savd in preferences. * \li Params: <ZOOM>: The target zoom value in %;
* the default is the default zoom as saved in preferences.
* \li Origin: daniel, 28 Oct 2016 * \li Origin: daniel, 28 Oct 2016
* \endvar * \endvar
*/ */
@ -902,7 +903,8 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM_IN * \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM_IN
* \li Action: Increases the zoom of the screen fonts. * \li Action: Increases the zoom of the screen fonts.
* \li Syntax: buffer-zoom-in [<ZOOM>] * \li Syntax: buffer-zoom-in [<ZOOM>]
* \li Params: <ZOOM>: The zoom in % points (neg. or pos.), the default is 20. * \li Params: <ZOOM>: 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 * \li Origin: vfr, 30 Mar 2009
* \endvar * \endvar
*/ */
@ -913,7 +915,8 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM_OUT * \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM_OUT
* \li Action: Decreases the zoom of the screen fonts. * \li Action: Decreases the zoom of the screen fonts.
* \li Syntax: buffer-zoom-out [<ZOOM>] * \li Syntax: buffer-zoom-out [<ZOOM>]
* \li Params: <ZOOM>: The zoom in % points (neg. or pos.), the default is -20. * \li Params: <ZOOM>: 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 * \li Origin: vfr, 30 Mar 2009
* \endvar * \endvar
*/ */

View File

@ -245,8 +245,8 @@ void LyXRC::setDefaults()
pygmentize_command = string(); pygmentize_command = string();
dpi = 75; dpi = 75;
// Because a screen is typically wider than a piece of paper: // Because a screen is typically wider than a piece of paper:
zoom = 150; defaultZoom = 150;
currentZoom = zoom; currentZoom = defaultZoom;
allow_geometry_session = true; allow_geometry_session = true;
// Default LaTeX font size: // Default LaTeX font size:
font_sizes[FONT_SIZE_TINY] = "5.0"; font_sizes[FONT_SIZE_TINY] = "5.0";
@ -624,9 +624,9 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
break; break;
case RC_SCREEN_ZOOM: case RC_SCREEN_ZOOM:
lexrc >> zoom; lexrc >> defaultZoom;
if (zoom < 10) if (defaultZoom < 10)
zoom = 10; defaultZoom = 10;
break; break;
case RC_GEOMETRY_SESSION: case RC_GEOMETRY_SESSION:
@ -1724,8 +1724,8 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
// fall through // fall through
case RC_SCREEN_ZOOM: case RC_SCREEN_ZOOM:
if (ignore_system_lyxrc || if (ignore_system_lyxrc ||
zoom != system_lyxrc.zoom) { defaultZoom != system_lyxrc.defaultZoom) {
os << "\\screen_zoom " << zoom << '\n'; os << "\\screen_zoom " << defaultZoom << '\n';
} }
if (tag != RC_LAST) if (tag != RC_LAST)
break; break;

View File

@ -295,9 +295,10 @@ public:
bool allow_geometry_session; bool allow_geometry_session;
/// Scrolling speed of the mouse wheel /// Scrolling speed of the mouse wheel
double mouse_wheel_speed; double mouse_wheel_speed;
/// Zoom factor for screen fonts /// Default zoom factor for screen fonts
int zoom; int defaultZoom;
/// Current zoom factor for screen fonts /// Actual zoom factor for screen fonts
/// (default zoom plus buffer zoom factor)
int currentZoom; int currentZoom;
/// Screen font sizes in points for each font size /// Screen font sizes in points for each font size
std::string font_sizes[10]; std::string font_sizes[10];

View File

@ -1089,7 +1089,7 @@ void PrefScreenFonts::applyRC(LyXRC & rc) const
parseFontName(screenTypewriterCO->currentText(), parseFontName(screenTypewriterCO->currentText(),
rc.typewriter_font_name, rc.typewriter_font_foundry); 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_TINY] = widgetToDoubleStr(screenTinyED);
rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED); rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED); 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.roman_font_name != oldrc.roman_font_name
|| rc.sans_font_name != oldrc.sans_font_name || rc.sans_font_name != oldrc.sans_font_name
|| rc.typewriter_font_name != oldrc.typewriter_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 // The global QPixmapCache is used in GuiPainter to cache text
// painting so we must reset it in case any of the above // painting so we must reset it in case any of the above
// parameter is changed. // parameter is changed.
@ -1130,7 +1130,7 @@ void PrefScreenFonts::updateRC(LyXRC const & rc)
selectSans(screenSansCO->currentText()); selectSans(screenSansCO->currentText());
selectTypewriter(screenTypewriterCO->currentText()); selectTypewriter(screenTypewriterCO->currentText());
screenZoomSB->setValue(rc.zoom); screenZoomSB->setValue(rc.defaultZoom);
updateScreenFontSizes(rc); updateScreenFontSizes(rc);
pixmapCacheCB->setChecked(rc.use_pixmap_cache); pixmapCacheCB->setChecked(rc.use_pixmap_cache);

View File

@ -741,7 +741,7 @@ void GuiView::autoSaveThreadFinished()
void GuiView::saveLayout() const void GuiView::saveLayout() const
{ {
QSettings settings; QSettings settings;
settings.setValue("zoom", lyxrc.currentZoom); settings.setValue("zoom_ratio", zoom_ratio_);
settings.setValue("devel_mode", devel_mode_); settings.setValue("devel_mode", devel_mode_);
settings.beginGroup("views"); settings.beginGroup("views");
settings.beginGroup(QString::number(id_)); settings.beginGroup(QString::number(id_));
@ -772,7 +772,12 @@ void GuiView::saveUISettings() const
bool GuiView::restoreLayout() bool GuiView::restoreLayout()
{ {
QSettings settings; 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<int>(zoom_min_))
zoom = zoom_min_;
lyxrc.currentZoom = zoom;
devel_mode_ = settings.value("devel_mode", devel_mode_).toBool(); devel_mode_ = settings.value("devel_mode", devel_mode_).toBool();
settings.beginGroup("views"); settings.beginGroup("views");
settings.beginGroup(QString::number(id_)); 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_IN:
case LFUN_BUFFER_ZOOM_OUT: case LFUN_BUFFER_ZOOM_OUT:
case LFUN_BUFFER_ZOOM: { case LFUN_BUFFER_ZOOM: {
// use a signed temp to avoid overflow
int zoom = lyxrc.currentZoom;
if (cmd.argument().empty()) { if (cmd.argument().empty()) {
if (cmd.action() == LFUN_BUFFER_ZOOM) if (cmd.action() == LFUN_BUFFER_ZOOM)
zoom = lyxrc.zoom; zoom_ratio_ = 1.0;
else if (cmd.action() == LFUN_BUFFER_ZOOM_IN) else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
zoom += 20; zoom_ratio_ += 0.1;
else else
zoom -= 20; zoom_ratio_ -= 0.1;
} else { } else {
if (cmd.action() == LFUN_BUFFER_ZOOM) if (cmd.action() == LFUN_BUFFER_ZOOM)
zoom = convert<int>(cmd.argument()); zoom_ratio_ = convert<int>(cmd.argument()) / double(lyxrc.defaultZoom);
else if (cmd.action() == LFUN_BUFFER_ZOOM_IN) else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
zoom += convert<int>(cmd.argument()); zoom_ratio_ += convert<int>(cmd.argument()) / 100.0;
else else
zoom -= convert<int>(cmd.argument()); zoom_ratio_ -= convert<int>(cmd.argument()) / 100.0;
} }
// Actual zoom value: default zoom + fractional extra value
int zoom = lyxrc.defaultZoom * zoom_ratio_;
if (zoom < static_cast<int>(zoom_min_)) if (zoom < static_cast<int>(zoom_min_))
zoom = zoom_min_; zoom = zoom_min_;
lyxrc.currentZoom = zoom; 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 // The global QPixmapCache is used in GuiPainter to cache text
// painting so we must reset it. // painting so we must reset it.

View File

@ -470,6 +470,9 @@ private:
/// Statusbar widget that shows version control status /// Statusbar widget that shows version control status
QLabel * version_control_; 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 /// Minimum zoom percentage
static int const zoom_min_ = 10; static int const zoom_min_ = 10;