]> git.lyx.org Git - lyx.git/commitdiff
Add possibility for command inset to inherit enclosing font
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 23 Jun 2016 17:45:10 +0000 (19:45 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 28 Mar 2017 11:57:34 +0000 (13:57 +0200)
The RenderButton object now has this property. It is set depending on
the value of inheritFont() method that is currently only set for
InsetRef, InsetBibtex and InsetCitation.

Fixes bug #10258

src/insets/InsetBibtex.h
src/insets/InsetCitation.h
src/insets/InsetCommand.cpp
src/insets/InsetCommand.h
src/insets/InsetExternal.cpp
src/insets/InsetInclude.cpp
src/insets/InsetRef.h
src/insets/RenderButton.cpp
src/insets/RenderButton.h
src/mathed/CommandInset.cpp

index 038065ffc0dc8b9a6ddf71d67fd47c08c15820c2..4f6f68cef2d96fd89eaf41a772356cf0ef6ea53c 100644 (file)
@@ -48,6 +48,8 @@ public:
        ///
        bool hasSettings() const { return true; }
        ///
+       bool inheritFont() const { return true; }
+       ///
        InsetCode lyxCode() const { return BIBTEX_CODE; }
        ///
        DisplayType display() const { return AlignCenter; }
index 992a85ee2198978927472592a595daf32a4d6f4a..18a9305a899459e4fa8aaa811432dbe250415e24 100644 (file)
@@ -43,6 +43,8 @@ public:
        ///
        bool hasSettings() const { return true; }
        ///
+       bool inheritFont() const { return true; }
+       ///
        docstring toolTip(BufferView const & bv, int x, int y) const;
        ///
        void doDispatch(Cursor & cur, FuncRequest & cmd);
index f4f169232b2a8cfb50f55547348f843543b28c57..fe10466e238b43b36f1c3796e10d997ea9a2c6e7 100644 (file)
@@ -96,7 +96,8 @@ InsetCommand::~InsetCommand()
 
 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       button_.update(screenLabel(), editable() || clickable(*mi.base.bv, 0, 0));
+       button_.update(screenLabel(), editable() || clickable(*mi.base.bv, 0, 0),
+                      inheritFont());
        button_.metrics(mi, dim);
 }
 
index 0514e09ffe987d38e19fb07608486db6e3460ebc..78e6d7fc5d6f6c9aba604018db08e681d9ce5220 100644 (file)
@@ -125,6 +125,8 @@ private:
        RenderButton & button() const { return button_; }
        /// This should provide the text for the button
        virtual docstring screenLabel() const = 0;
+       /// This should return true when font is inherited from text
+       virtual bool inheritFont() const { return false; }
 
        /// \name Static public methods obligated for InsetCommand derived classes
        //@{
index a88769b8ee3c4a587ae259b59251acc23b2c9087..8efdd3e97e3972c693123789f8141dc4ba3bb99e 100644 (file)
@@ -623,7 +623,7 @@ void InsetExternal::setParams(InsetExternalParams const & p)
                        renderer_.reset(new RenderButton);
                        button_ptr = renderer_->asButton();
                }
-               button_ptr->update(screenLabel(params_, buffer()), true);
+               button_ptr->update(screenLabel(params_, buffer()), true, false);
                return;
        }
 
index 9b5c3f0961f119f2ed6ff50e38d4cb9dd4d40feb..b2eca715054a7f1f82ab01740796e1f90ee42b13 100644 (file)
@@ -1019,7 +1019,7 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
        } else {
                if (!set_label_) {
                        set_label_ = true;
-                       button_.update(screenLabel(), true);
+                       button_.update(screenLabel(), true, false);
                }
                button_.metrics(mi, dim);
        }
@@ -1201,7 +1201,7 @@ void InsetInclude::updateCommand()
 
 void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype)
 {
-       button_.update(screenLabel(), true);
+       button_.update(screenLabel(), true, false);
 
        Buffer const * const childbuffer = getChildBuffer();
        if (childbuffer) {
index 80b767814ce81e96476f2a64ee919e9dacacd4c4..1af1790bf917c13ffcbb8f057aa819c0d6ff4f06 100644 (file)
@@ -45,10 +45,12 @@ public:
        docstring toolTip(BufferView const &, int, int) const
                { return tooltip_; }
        ///
-  docstring getTOCString() const;
+       docstring getTOCString() const;
        ///
        bool hasSettings() const { return true; }
        ///
+       bool inheritFont() const { return true; }
+       ///
        InsetCode lyxCode() const { return REF_CODE; }
        ///
        DisplayType display() const { return Inline; }
index ee1b1f44cd04326aafa2ae8d631873cb9520622b..69d28482b9de531e0478ef6122514f3bf5bfa555 100644 (file)
@@ -32,16 +32,18 @@ RenderBase * RenderButton::clone(Inset const *) const
 }
 
 
-void RenderButton::update(docstring const & text, bool editable)
+void RenderButton::update(docstring const & text, bool editable,
+                          bool inherit_font)
 {
        text_ = text;
        editable_ = editable;
+       inherit_font_ = inherit_font;
 }
 
 
-void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
+void RenderButton::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       FontInfo font = sane_font;
+       FontInfo font = inherit_font_ ? mi.base.font : sane_font;
        font.decSize();
        frontend::FontMetrics const & fm =
                theFontMetrics(font);
@@ -58,7 +60,7 @@ void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
 void RenderButton::draw(PainterInfo & pi, int x, int y) const
 {
        // Draw it as a box with the LaTeX text
-       FontInfo font = sane_font;
+       FontInfo font = inherit_font_ ? pi.base.font : sane_font;
        font.setColor(Color_command);
        font.decSize();
 
index 5e6ad35a087374886b51b1a3a67e735bab66dc67..480effd16ace2ae931325c8a7bcc79ba202952da 100644 (file)
@@ -33,7 +33,7 @@ public:
        virtual void draw(PainterInfo & pi, int x, int y) const;
 
        /// Provide the text for the button
-       void update(docstring const &, bool editable);
+       void update(docstring const &, bool editable, bool inherit_font);
 
        /// The "sensitive area" box, i.e., the button area
        Box box() const { return button_box_; }
@@ -47,6 +47,7 @@ private:
        /// The stored data.
        docstring text_;
        bool editable_;
+       bool inherit_font_;
        Box button_box_;
 };
 
index 0c9e585e1a7a976893db08d832889aba627b0c8b..344c570323a32aef7156509539c2574617d242b0 100644 (file)
@@ -40,7 +40,7 @@ void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        if (!set_label_) {
                set_label_ = true;
-               button_.update(screenLabel(), true);
+               button_.update(screenLabel(), true, false);
        }
        button_.metrics(mi, dim);
 }