I am working on a patch for
http://www.lyx.org/trac/ticket/10455
Seemed to me like a good suggestion. Attached is a not yet working patch.
Unfortunately, I have no idea in which header to define the new
currentZoom variable. Any recommendations?
- It will be saved via QSettings (highest hirachy). The alternative to
save it to the preferences does not seem right since preferences are
normally only saved when the settings are manually saved. However, the
currentZoom should be saved whenever LyX is quit.
- Basically this variable is needed everywhere where now there is
lyxrc.zoom except for the preferences itself (and a new LFUN which
resets currentZoom to the default lyxrc.zoom). That is why still putting
it in LyXRC.h is tempting. This is what I did in the patch and what
seems to break it. Probably since the variable is somehow reset when
loading the preferences which happens after the currentZoom is loaded
via QSettings?
Daniel
From 985ed69a158f9efaf99ec5dd3d579ac335542d7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Ram=C3=83=C2=B6ller?= <d....@web.de>
Date: Sat, 29 Oct 2016 10:28:34 +0200
Subject: [PATCH] Fix for #10455: Preferences shows current zoom instead of
preference's default zoom - Adds a currentZoom variable which holds the
current zoom level and is stored via QSettings. - The zoom stored in
preferences is used as default zoom level.
---
src/Buffer.cpp | 2 +-
src/FuncCode.h | 1 +
src/Length.cpp | 2 +-
src/LyXAction.cpp | 9 ++++++
src/LyXRC.h | 2 ++
src/MetricsInfo.cpp | 8 +++---
src/frontends/qt4/GuiFontLoader.cpp | 2 +-
src/frontends/qt4/GuiView.cpp | 55 +++++++++++++++++++++++++++++--------
src/frontends/qt4/GuiWorkArea.cpp | 2 +-
src/tests/check_Length.cpp | 2 +-
10 files changed, 64 insertions(+), 21 deletions(-)
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 2dcdefe..edb87a3 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -705,7 +705,7 @@ BufferParams const & Buffer::masterParams() const
double Buffer::fontScalingFactor() const
{
return isExporting() ? 75.0 * params().html_math_img_scale
- : 0.01 * lyxrc.dpi * lyxrc.zoom * lyxrc.preview_scale_factor *
params().display_pixel_ratio;
+ : 0.01 * lyxrc.dpi * lyxrc.currentZoom *
lyxrc.preview_scale_factor * params().display_pixel_ratio;
}
diff --git a/src/FuncCode.h b/src/FuncCode.h
index c84f352..cbedd03 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -467,6 +467,7 @@ enum FuncCode
LFUN_TABULAR_FEATURE, // gm, 20151210
LFUN_BRANCH_INVERT, // rgheck, 20160712
LFUN_LYX_ACTIVATE, // skostysh, 20160804
+ LFUN_BUFFER_ZOOM, // daniel, 20161028
LFUN_LASTACTION // end of the table
};
diff --git a/src/Length.cpp b/src/Length.cpp
index a55d2ef..7e1de35 100644
--- a/src/Length.cpp
+++ b/src/Length.cpp
@@ -197,7 +197,7 @@ bool Length::empty() const
int Length::inPixels(int text_width, int em_width_base) const
{
// Zoom factor specified by user in percent
- double const zoom = lyxrc.zoom / 100.0; // [percent]
+ double const zoom = lyxrc.currentZoom / 100.0; // [percent]
// DPI setting for monitor: pixels/inch
double const dpi = lyxrc.dpi; // screen resolution [pixels/inch]
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 6674fec..b445418 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3754,6 +3754,15 @@ void LyXAction::init()
{ LFUN_LABEL_INSERT_AS_REFERENCE, "label-insert-as-reference",
Noop, Edit},
/*!
+* \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM
+* \li Action: Sets the zoom of the screen fonts.
+* \li Syntax: buffer-zoom [<ZOOM>]
+* \li Origin: daniel, 28 Oct 2016
+* \endvar
+*/
+ { LFUN_BUFFER_ZOOM, "buffer-zoom", ReadOnly, Buffer },
+
+/*!
* \var lyx::FuncCode lyx::LFUN_BUFFER_ZOOM_IN
* \li Action: Increases the zoom of the screen fonts.
* \li Syntax: buffer-zoom-in [<ZOOM>]
diff --git a/src/LyXRC.h b/src/LyXRC.h
index 7b50ce0..4ad1282 100644
--- a/src/LyXRC.h
+++ b/src/LyXRC.h
@@ -289,6 +289,8 @@ public:
double mouse_wheel_speed;
/// Zoom factor for screen fonts
unsigned int zoom;
+ /// Current zoom factor for screen fonts
+ unsigned int currentZoom;
/// Screen font sizes in points for each font size
std::string font_sizes[10];
/// Allow the use of scalable fonts? Default is yes.
diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp
index 589e924..8653b37 100644
--- a/src/MetricsInfo.cpp
+++ b/src/MetricsInfo.cpp
@@ -41,19 +41,19 @@ MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w)
textwidth(w), solid_line_thickness_(1), solid_line_offset_(1),
dotted_line_thickness_(1)
{
- if (lyxrc.zoom >= 200) {
+ if (lyxrc.currentZoom >= 200) {
// derive the line thickness from zoom factor
// the zoom is given in percent
// (increase thickness at 250%, 450% etc.)
- solid_line_thickness_ = (lyxrc.zoom + 150) / 200;
+ solid_line_thickness_ = (lyxrc.currentZoom + 150) / 200;
// adjust line_offset_ too
solid_line_offset_ = 1 + solid_line_thickness_ / 2;
}
- if (lyxrc.zoom >= 100) {
+ if (lyxrc.currentZoom >= 100) {
// derive the line thickness from zoom factor
// the zoom is given in percent
// (increase thickness at 150%, 250% etc.)
- dotted_line_thickness_ = (lyxrc.zoom + 50) / 100;
+ dotted_line_thickness_ = (lyxrc.currentZoom + 50) / 100;
}
}
diff --git a/src/frontends/qt4/GuiFontLoader.cpp
b/src/frontends/qt4/GuiFontLoader.cpp
index cc092f5..ef2f83f 100644
--- a/src/frontends/qt4/GuiFontLoader.cpp
+++ b/src/frontends/qt4/GuiFontLoader.cpp
@@ -356,7 +356,7 @@ QFont makeQFont(FontInfo const & f)
LYXERR(Debug::FONT, "XFLD: " << font.rawName());
font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
- * lyxrc.zoom / 100.0);
+ * lyxrc.currentZoom / 100.0);
LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF());
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 9c698cb..256aade 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -710,6 +710,7 @@ void GuiView::autoSaveThreadFinished()
void GuiView::saveLayout() const
{
QSettings settings;
+ settings.setValue("zoom", lyxrc.currentZoom);
settings.beginGroup("views");
settings.beginGroup(QString::number(id_));
#if defined(Q_WS_X11) || defined(QPA_XCB)
@@ -739,7 +740,10 @@ void GuiView::saveUISettings() const
bool GuiView::restoreLayout()
{
QSettings settings;
+ int zoom = settings.value("zoom").toInt();
settings.beginGroup("views");
+ lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM, convert<docstring>(zoom)));
+
settings.beginGroup(QString::number(id_));
QString const icon_key = "icon_size";
if (!settings.contains(icon_key))
@@ -2023,6 +2027,19 @@ bool GuiView::getStatus(FuncRequest const & cmd,
FuncStatus & flag)
enable = false;
break;
+ case LFUN_BUFFER_ZOOM: {
+ // disable zoom smaller than zoom_min_
+ if (!cmd.argument().empty() && convert<int>(cmd.argument()) <=
zoom_min_) {
+ docstring const msg =
+ bformat(_("Zoom level cannot be less than
%1$d%."), zoom_min_);
+ flag.message(msg);
+ enable = false;
+ }
+ else
+ enable = doc_buffer;
+ break;
+ }
+
case LFUN_BUFFER_ZOOM_OUT:
case LFUN_BUFFER_ZOOM_IN: {
// only diff between these two is that the default for ZOOM_OUT
@@ -3972,10 +3989,34 @@ void GuiView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
d.current_work_area_->completer().activate();
break;
+ case LFUN_BUFFER_ZOOM: {
+ // use a signed temp to avoid overflow
+ int zoom;
+ // if no argument provided
+ if (cmd.argument().empty())
+ // reset zoom to preferences default
+ zoom = lyxrc.zoom;
+ else
+ zoom = convert<int>(cmd.argument());
+ // zoom cannot be below zoom_min_
+ if (zoom < static_cast<int>(zoom_min_))
+ zoom = zoom_min_;
+ lyxrc.currentZoom = zoom;
+
+ dr.setMessage(bformat(_("Zoom level is now %1$d%"),
lyxrc.currentZoom));
+
+ // The global QPixmapCache is used in GuiPainter to
cache text
+ // painting so we must reset it.
+ QPixmapCache::clear();
+ guiApp->fontLoader().update();
+ lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+ break;
+ }
+
case LFUN_BUFFER_ZOOM_IN:
case LFUN_BUFFER_ZOOM_OUT: {
// use a signed temp to avoid overflow
- int zoom = lyxrc.zoom;
+ int zoom = lyxrc.currentZoom;
if (cmd.argument().empty()) {
if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
zoom += 20;
@@ -3984,17 +4025,7 @@ void GuiView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
} else
zoom += convert<int>(cmd.argument());
- if (zoom < static_cast<int>(zoom_min_))
- zoom = zoom_min_;
- lyxrc.zoom = zoom;
-
- dr.setMessage(bformat(_("Zoom level is now %1$d%"),
lyxrc.zoom));
-
- // The global QPixmapCache is used in GuiPainter to
cache text
- // painting so we must reset it.
- QPixmapCache::clear();
- guiApp->fontLoader().update();
- lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+ lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM,
convert<docstring>(zoom)));
break;
}
diff --git a/src/frontends/qt4/GuiWorkArea.cpp
b/src/frontends/qt4/GuiWorkArea.cpp
index 31df06b..2273c85 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -214,7 +214,7 @@ public:
void recomputeWidth() {
cursor_width_ = lyxrc.cursor_width
? lyxrc.cursor_width
- : 1 + int((lyxrc.zoom + 50) / 200.0);
+ : 1 + int((lyxrc.currentZoom + 50) / 200.0);
}
QRect const & rect() { return rect_; }
diff --git a/src/tests/check_Length.cpp b/src/tests/check_Length.cpp
index 8311e45..55b9999 100644
--- a/src/tests/check_Length.cpp
+++ b/src/tests/check_Length.cpp
@@ -14,7 +14,7 @@ using namespace std;
void test_inPixels()
{
// want to see non-zero SP
- lyxrc.zoom = 100000;
+ lyxrc.currentZoom = 100000;
lyxrc.dpi = 72;
for (int i = Length::BP; i <= Length::UNIT_NONE; ++i) {
Length const l(2342, static_cast<Length::UNIT>(i));
--
2.9.0.windows.1