Preferences shows current zoom instead of preference's default zoom (#10455)

- Adds a currentZoom variable which holds the current zoom level.

- The zoom stored in preferences is used as default zoom level (default binding:
  M+0).

- The currentZoom is saved and restored via QSettings.

- Adds LFUN buffer-zoom for (re)setting zoom.
This commit is contained in:
Daniel Ramöller 2016-10-29 10:28:34 +02:00 committed by Guillaume MM
parent 9bf8ac4432
commit 4183a9f4dc
14 changed files with 270 additions and 177 deletions

View File

@ -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"

View File

@ -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;
}

View File

@ -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
};

View File

@ -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]

View File

@ -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 [<ZOOM>]
* \li Params: <ZOOM>: 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.

View File

@ -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";

View File

@ -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.

View File

@ -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;
}
}

View File

@ -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());

View File

@ -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<docstring>(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<int>(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<int>(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
} else {
if (cmd.action() == LFUN_BUFFER_ZOOM)
zoom = convert<int>(cmd.argument());
else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
zoom += convert<int>(cmd.argument());
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));
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.

View File

@ -461,7 +461,7 @@ private:
QLabel * version_control_;
/// Minimum zoom percentage
static unsigned int const zoom_min_ = 10;
static int const zoom_min_ = 10;
};

View File

@ -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_; }

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PrefScreenFontsUi</class>
<widget class="QWidget" name="PrefScreenFontsUi">
@ -13,7 +14,16 @@
<string/>
</property>
<layout class="QGridLayout">
<property name="margin" >
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
@ -21,15 +31,33 @@
</property>
<item row="0" column="0">
<layout class="QHBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout">
<property name="margin" >
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
@ -46,11 +74,9 @@
</widget>
</item>
<item row="1" column="2">
<widget class="GuiFontExample" native="1" name="screenSansFE" >
<widget class="GuiFontExample" name="screenSansFE" native="true">
<property name="sizePolicy">
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>5</vsizetype>
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -74,11 +100,9 @@
</widget>
</item>
<item row="0" column="2">
<widget class="GuiFontExample" native="1" name="screenRomanFE" >
<widget class="GuiFontExample" name="screenRomanFE" native="true">
<property name="sizePolicy">
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>5</vsizetype>
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -122,11 +146,9 @@
</widget>
</item>
<item row="2" column="2">
<widget class="GuiFontExample" native="1" name="screenTypewriterFE" >
<widget class="GuiFontExample" name="screenTypewriterFE" native="true">
<property name="sizePolicy">
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>5</vsizetype>
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -149,15 +171,33 @@
</item>
<item row="1" column="0">
<layout class="QHBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout">
<property name="margin" >
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
@ -166,7 +206,7 @@
<item row="0" column="0">
<widget class="QLabel" name="screenZoomLA">
<property name="text">
<string>&amp;Zoom %:</string>
<string>Default &amp;zoom %:</string>
</property>
<property name="buddy">
<cstring>screenZoomSB</cstring>
@ -190,7 +230,7 @@
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
@ -206,7 +246,16 @@
<string>Font Sizes</string>
</property>
<layout class="QGridLayout">
<property name="margin" >
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
@ -350,7 +399,7 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@ -373,7 +422,7 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>6</height>

View File

@ -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));