From 06e40ada85c13ea22c4ea484f338fdf7cefef57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ram=C3=83=3F=C3=82=C2=B6ller?= <d....@web.de> Date: Mon, 17 Oct 2016 01:21:01 +0200 Subject: [PATCH] Some inset offset fine tuning: - Make outer inset offset independent of inner. - Reduced the outer offset.
--- src/frontends/qt4/GuiFontMetrics.cpp | 4 ++-- src/frontends/qt4/GuiPainter.cpp | 6 +++--- src/insets/Inset.h | 6 +++++- src/insets/InsetText.cpp | 13 ++++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp index eade8cc..43cf0d1 100644 --- a/src/frontends/qt4/GuiFontMetrics.cpp +++ b/src/frontends/qt4/GuiFontMetrics.cpp @@ -254,7 +254,7 @@ void GuiFontMetrics::rectText(docstring const & str, { static int const d = Inset::TEXT_TO_INSET_OFFSET / 2; - w = width(str) + Inset::TEXT_TO_INSET_OFFSET; + w = Inset::TEXT_TO_INSET_OFFSET_INSIDE + width(str) + Inset::TEXT_TO_INSET_OFFSET_INSIDE; ascent = metrics_.ascent() + d; descent = metrics_.descent() + d; } @@ -265,7 +265,7 @@ void GuiFontMetrics::buttonText(docstring const & str, int & w, int & ascent, int & descent) const { rectText(str, w, ascent, descent); - w += Inset::TEXT_TO_INSET_OFFSET; + w += 2 * Inset::TEXT_TO_INSET_OFFSET_OUTSIDE; } diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp index e613f3f..1774939 100644 --- a/src/frontends/qt4/GuiPainter.cpp +++ b/src/frontends/qt4/GuiPainter.cpp @@ -593,10 +593,10 @@ void GuiPainter::buttonText(int x, int y, docstring const & str, FontMetrics const & fm = theFontMetrics(font); fm.buttonText(str, width, ascent, descent); - static int const d = Inset::TEXT_TO_INSET_OFFSET / 2; + static int const d = Inset::TEXT_TO_INSET_OFFSET_OUTSIDE; - button(x + d, y - ascent, width - Inset::TEXT_TO_INSET_OFFSET, descent + ascent, mouseHover); - text(x + Inset::TEXT_TO_INSET_OFFSET, y, str, font); + button(x + d, y - ascent, width - 2 * d, descent + ascent, mouseHover); + text(x + Inset::TEXT_TO_INSET_OFFSET_INSIDE + Inset::TEXT_TO_INSET_OFFSET_OUTSIDE, y, str, font); } diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 48ad7be..34ba4e9 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -574,7 +574,11 @@ public: /// virtual ColorCode labelColor() const; // - enum { TEXT_TO_INSET_OFFSET = 4 }; + enum { + TEXT_TO_INSET_OFFSET = 4, + TEXT_TO_INSET_OFFSET_INSIDE = 2, + TEXT_TO_INSET_OFFSET_OUTSIDE = 1 + }; protected: /// Constructors diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index df4f6e2..e3a18f1 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -208,7 +208,8 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET; dim.asc += TEXT_TO_INSET_OFFSET; dim.des += TEXT_TO_INSET_OFFSET; - dim.wid += 2 * TEXT_TO_INSET_OFFSET; + // cursor position after inset + dim.wid += 2 * (TEXT_TO_INSET_OFFSET_INSIDE + TEXT_TO_INSET_OFFSET_OUTSIDE + 1); } @@ -216,10 +217,10 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const { TextMetrics & tm = pi.base.bv->textMetrics(&text_); - int const w = tm.width() + TEXT_TO_INSET_OFFSET; + int const w = tm.width() + 2 * TEXT_TO_INSET_OFFSET_INSIDE + 1; int const yframe = y - TEXT_TO_INSET_OFFSET - tm.ascent(); int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET; - int const xframe = x + TEXT_TO_INSET_OFFSET / 2; + int const xframe = x + TEXT_TO_INSET_OFFSET_OUTSIDE; bool change_drawn = false; if (drawFrame_ || pi.full_repaint) { if (pi.full_repaint) @@ -251,7 +252,8 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const pi.backgroundColor(this, false)); // The change tracking cue must not be inherited Changer dummy2 = make_change(pi.change_, Change()); - tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y); + // text position within inset + tm.draw(pi, x + TEXT_TO_INSET_OFFSET_INSIDE + TEXT_TO_INSET_OFFSET_OUTSIDE + 1, y); } if (canPaintChange(*pi.base.bv) && (!change_drawn || pi.change_.deleted())) // Do not draw the change tracking cue if already done by RowPainter and @@ -680,7 +682,8 @@ void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in, void InsetText::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const { - x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET; + // cursor position within inset + x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET_INSIDE + TEXT_TO_INSET_OFFSET_OUTSIDE + 1; y = bv.textMetrics(&text_).cursorY(sl, boundary); } -- 2.9.0.windows.1
test inset offset.lyx
Description: application/lyx