diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 9c5652a761..705b58cf6e 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -123,6 +123,7 @@ Format 4 \bind "F11" "ui-toggle fullscreen" +\bind "M-0" "buffer-zoom" \bind "M-equal" "buffer-zoom-in" \bind "M-plus" "buffer-zoom-in" \bind "M-minus" "buffer-zoom-out" diff --git a/src/Buffer.cpp b/src/Buffer.cpp index b1ed2f582f..436b0a8ba3 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -729,7 +729,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 a6e4ba69c1..9561cbc6d2 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -463,13 +463,15 @@ enum FuncCode LFUN_SERVER_GET_STATISTICS, // brokenclock 20141010 LFUN_BUFFER_VIEW_CACHE, // skostysh 20150401 LFUN_BUFFER_MOVE_NEXT, // skostysh 20150408 - // 340 + // 360 LFUN_BUFFER_MOVE_PREVIOUS, // skostysh 20150408 LFUN_TABULAR_FEATURE, // gm, 20151210 LFUN_BRANCH_INVERT, // rgheck, 20160712 LFUN_LYX_ACTIVATE, // skostysh, 20160804 LFUN_ICON_SIZE, // daniel, 20160712 + // 365 LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR,// gm, 20170302 + LFUN_BUFFER_ZOOM, // daniel, 20161028 LFUN_LASTACTION // end of the table }; diff --git a/src/Length.cpp b/src/Length.cpp index bc8fb7ea55..42188d8929 100644 --- a/src/Length.cpp +++ b/src/Length.cpp @@ -202,7 +202,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 e9f45f58e2..d3c1895694 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -888,6 +888,16 @@ void LyXAction::init() { LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR, "buffer-external-modification-clear", ReadOnly, Buffer }, +/*! +* \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 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. diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 94e78376f5..ae3569096e 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -244,6 +244,7 @@ void LyXRC::setDefaults() dpi = 75; // Because a screen is typically wider than a piece of paper: zoom = 150; + currentZoom = zoom; allow_geometry_session = true; // Default LaTeX font size: font_sizes[FONT_SIZE_TINY] = "5.0"; diff --git a/src/LyXRC.h b/src/LyXRC.h index dccb3007f6..c7207048c2 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -293,7 +293,9 @@ public: /// Scrolling speed of the mouse wheel double mouse_wheel_speed; /// Zoom factor for screen fonts - unsigned int zoom; + int zoom; + /// Current zoom factor for screen fonts + 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 b2f9974504..b61011d63d 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -41,19 +41,19 @@ MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w) textwidth(w), macro_nesting(0), 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 d61a2782dc..41d62505ec 100644 --- a/src/frontends/qt4/GuiFontLoader.cpp +++ b/src/frontends/qt4/GuiFontLoader.cpp @@ -363,7 +363,7 @@ QFont makeQFont(FontInfo const & f) LYXERR(Debug::FONT, "XFLD: " << font.rawName()); - font.setPointSizeF(f.realSize() * lyxrc.zoom / 100.0); + font.setPointSizeF(f.realSize() * 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 db99d6a361..f01b94c919 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -713,6 +713,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) @@ -742,6 +743,8 @@ void GuiView::saveUISettings() const bool GuiView::restoreLayout() { QSettings settings; + lyxrc.currentZoom = settings.value("zoom", lyxrc.zoom).toInt(); + lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM, convert(lyxrc.currentZoom))); settings.beginGroup("views"); settings.beginGroup(QString::number(id_)); QString const icon_key = "icon_size"; @@ -1999,7 +2002,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) bool const neg_zoom = convert(cmd.argument()) < 0 || (cmd.action() == LFUN_BUFFER_ZOOM_OUT && cmd.argument().empty()); - if (lyxrc.zoom <= zoom_min_ && neg_zoom) { + if (lyxrc.currentZoom <= zoom_min_ && neg_zoom) { docstring const msg = bformat(_("Zoom level cannot be less than %1$d%."), zoom_min_); flag.message(msg); @@ -2008,6 +2011,21 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) enable = doc_buffer; break; } + + case LFUN_BUFFER_ZOOM: { + bool const less_than_min_zoom = + !cmd.argument().empty() && convert(cmd.argument()) < zoom_min_; + if (lyxrc.currentZoom <= zoom_min_ && less_than_min_zoom) { + 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_MOVE_NEXT: case LFUN_BUFFER_MOVE_PREVIOUS: // we do not cycle when moving @@ -3969,22 +3987,32 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; case LFUN_BUFFER_ZOOM_IN: - case LFUN_BUFFER_ZOOM_OUT: { + case LFUN_BUFFER_ZOOM_OUT: + case LFUN_BUFFER_ZOOM: { // 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) + if (cmd.action() == LFUN_BUFFER_ZOOM) + zoom = lyxrc.zoom; + else if (cmd.action() == LFUN_BUFFER_ZOOM_IN) zoom += 20; else zoom -= 20; - } else - zoom += convert(cmd.argument()); + } else { + if (cmd.action() == LFUN_BUFFER_ZOOM) + zoom = convert(cmd.argument()); + else if (cmd.action() == LFUN_BUFFER_ZOOM_IN) + zoom += convert(cmd.argument()); + else + zoom -= convert(cmd.argument()); + } if (zoom < static_cast(zoom_min_)) zoom = zoom_min_; - lyxrc.zoom = zoom; - dr.setMessage(bformat(_("Zoom level is now %1$d%"), lyxrc.zoom)); + 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. diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index a864f4b52a..4b0429c29b 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -461,7 +461,7 @@ private: QLabel * version_control_; /// Minimum zoom percentage - static unsigned int const zoom_min_ = 10; + static int const zoom_min_ = 10; }; diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 4753b2b483..d41b5b074c 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -213,7 +213,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/frontends/qt4/ui/PrefScreenFontsUi.ui b/src/frontends/qt4/ui/PrefScreenFontsUi.ui index 83705c2724..2eaa453360 100644 --- a/src/frontends/qt4/ui/PrefScreenFontsUi.ui +++ b/src/frontends/qt4/ui/PrefScreenFontsUi.ui @@ -1,7 +1,8 @@ - + + PrefScreenFontsUi - - + + 0 0 @@ -9,53 +10,78 @@ 454 - + - - + + 9 - + + 9 + + + 9 + + + 9 + + 6 - - - - 0 - - + + + 6 + + 0 + + + 0 + + + 0 + + + 0 + - - + + 0 - + + 0 + + + 0 + + + 0 + + 6 - - - + + + 20 - + false - - - - - 3 - 5 + + + + 0 0 - + 60 0 @@ -63,27 +89,25 @@ - - - + + + Sans Seri&f: - + screenSansCO - - - - - 3 - 5 + + + + 0 0 - + 60 0 @@ -91,54 +115,52 @@ - - - + + + 20 - + false - - - + + + T&ypewriter: - + screenTypewriterCO - - - + + + R&oman: - + screenRomanCO - - - - - 3 - 5 + + + + 0 0 - - - + + + 20 - + false @@ -147,35 +169,53 @@ - - - - 0 - - + + + 6 + + 0 + + + 0 + + + 0 + + + 0 + - - + + 0 - + + 0 + + + 0 + + + 0 + + 6 - - - - &Zoom %: + + + + Default &zoom %: - + screenZoomSB - - - + + + 999 @@ -184,13 +224,13 @@ - + Qt::Horizontal - + QSizePolicy::Expanding - + 20 20 @@ -200,144 +240,153 @@ - - - + + + Font Sizes - - + + 9 - + + 9 + + + 9 + + + 9 + + 6 - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + &Large: - + screenLargeED - - - + + + &Larger: - + screenLargerED - - - + + + &Largest: - + screenLargestED - - + + - - - + + + &Huge: - + screenHugeED - - - + + + &Hugest: - + screenHugerED - - - + + + S&mallest: - + screenSmallestED - - - + + + S&maller: - + screenSmallerED - - - + + + S&mall: - + screenSmallED - - - + + + &Normal: - + screenNormalED - - - + + + &Tiny: - + screenTinyED @@ -345,12 +394,12 @@ - + - + Qt::Horizontal - + 40 20 @@ -358,22 +407,22 @@ - - - + + + Checking this improves performance, but might decrease the on-screen quality of fonts - + &Use pixmap cache to speed up font rendering - + - + Qt::Vertical - + 20 6 @@ -407,7 +456,7 @@ screenHugerED - qt_i18n.h + qt_i18n.h diff --git a/src/tests/check_Length.cpp b/src/tests/check_Length.cpp index 37286e5b2d..3ee9f95697 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(i));