From: Jean-Marc Lasgouttes Date: Wed, 15 Jan 2020 14:54:47 +0000 (+0100) Subject: Make graĥics and external insets tighter X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=31a3dbd570b37ea3c268fe26e5c01ff4474f67e8;p=features.git Make graĥics and external insets tighter Now RenderGraphics adds offsets that depends on its parent inset. These offsets are set to 0 for InsetGraphics and InsetExternal. A nice consequence is that icons shown by Info inset stick out less on screen. As an unrelated change, the "private:" specifier of these two insets is moved to a more reasonable place. --- diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h index 20ccfededf..eefce3a10d 100644 --- a/src/insets/InsetExternal.h +++ b/src/insets/InsetExternal.h @@ -120,13 +120,20 @@ public: /// void addToToc(DocIterator const & di, bool output_active, UpdateType utype, TocBackend & backend) const; -private: - /// - InsetExternal(InsetExternal const &); /// InsetCode lyxCode() const { return EXTERNAL_CODE; } /// bool hasSettings() const { return true; } + + /// + int topOffset(BufferView const *) const { return 0; } + /// + int bottomOffset(BufferView const *) const { return 0; } + /// + int leftOffset(BufferView const *) const { return 0; } + /// + int rightOffset(BufferView const *) const { return 0; } + /// void metrics(MetricsInfo &, Dimension &) const; /// @@ -159,6 +166,11 @@ private: * and the preview should be regenerated. */ void fileChanged() const; + +private: + /// + InsetExternal(InsetExternal const &); + /// Is this inset using (instant or graphics) preview? bool isPreviewed() const; /// Do we have the right renderer (button, graphic or monitored preview)? diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index 22d70b233b..be4a31773a 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -61,13 +61,8 @@ public: /// InsetGraphics const * asInsetGraphics() const { return this; } -private: - /// - InsetGraphics(InsetGraphics const &); - /// bool isLabeled() const { return true; } - void metrics(MetricsInfo &, Dimension &) const; /// bool hasSettings() const { return true; } /// @@ -96,6 +91,18 @@ private: docstring layoutName() const { return from_ascii("Graphics"); } /// Get the inset parameters, used by the GUIndependent dialog. InsetGraphicsParams const & params() const; + + /// + int topOffset(BufferView const *) const { return 0; } + /// + int bottomOffset(BufferView const *) const { return 0; } + /// + int leftOffset(BufferView const *) const { return 0; } + /// + int rightOffset(BufferView const *) const { return 0; } + + /// + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -136,6 +143,10 @@ private: /// OutputParams::CtObject CtObject(OutputParams const &) const { return OutputParams::CT_OBJECT; } +private: + /// + InsetGraphics(InsetGraphics const &); + /// InsetGraphicsParams params_; /// holds the entity name that defines the graphics location (SGML). diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp index fe2d9b9eb4..280a657ceb 100644 --- a/src/insets/RenderGraphic.cpp +++ b/src/insets/RenderGraphic.cpp @@ -36,14 +36,14 @@ namespace lyx { RenderGraphic::RenderGraphic(Inset const * inset) - : loader_(inset->buffer().fileName()) + : inset_(inset), loader_(inset->buffer().fileName()) { loader_.connect(bind(&Inset::updateFrontend, inset)); } RenderGraphic::RenderGraphic(RenderGraphic const & other, Inset const * inset) - : RenderBase(other), loader_(other.loader_), params_(other.params_) + : RenderBase(other), inset_(inset), loader_(other.loader_), params_(other.params_) { loader_.connect(bind(&Inset::updateFrontend, inset)); } @@ -147,7 +147,8 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const bool const image_ready = displayGraphic(params_) && readyToDisplay(loader_); if (image_ready) { - dim.wid = loader_.image()->width() + 2 * Inset::textOffset(mi.base.bv); + dim.wid = loader_.image()->width() + inset_->leftOffset(mi.base.bv) + + inset_->rightOffset(mi.base.bv); dim.asc = loader_.image()->height(); dim_ = dim; return; @@ -190,9 +191,9 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const { // This will draw the graphics. If the graphics has not been // loaded yet, we draw just a rectangle. - int const x1 = x + Inset::textOffset(pi.base.bv); + int const x1 = x + inset_->leftOffset(pi.base.bv); int const y1 = y - dim_.asc; - int const w = dim_.wid - 2 * Inset::textOffset(pi.base.bv); + int const w = dim_.wid - inset_->leftOffset(pi.base.bv) - inset_->rightOffset(pi.base.bv); int const h = dim_.height(); if (displayGraphic(params_) && readyToDisplay(loader_)) diff --git a/src/insets/RenderGraphic.h b/src/insets/RenderGraphic.h index da09c4cc0f..37f3aaaa93 100644 --- a/src/insets/RenderGraphic.h +++ b/src/insets/RenderGraphic.h @@ -45,6 +45,9 @@ private: /// Not implemented. RenderGraphic & operator=(RenderGraphic const &); + /// Reference to owner + Inset const * inset_; + /// The stored data. graphics::Loader loader_; graphics::Params params_;