]> git.lyx.org Git - lyx.git/commitdiff
Allow for some argument visual customization
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 26 Nov 2012 08:10:14 +0000 (09:10 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 26 Nov 2012 08:10:14 +0000 (09:10 +0100)
src/Layout.cpp
src/Layout.h
src/insets/InsetArgument.cpp
src/insets/InsetArgument.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetLayout.cpp

index a5d3550ffb493b8ce5dadf2510f307610a890877..7fcf882e818e8f908fe485eebab876168430b05e 100644 (file)
@@ -877,6 +877,8 @@ void Layout::readArgument(Lexer & lex)
        arg.mandatory = false;
        bool error = false;
        bool finished = false;
+       arg.font = inherit_font;
+       arg.labelfont = inherit_font;
        unsigned int nr;
        lex >> nr;
        while (!finished && lex.isOK() && !error) {
@@ -905,6 +907,13 @@ void Layout::readArgument(Lexer & lex)
                } else if (tok == "requires") {
                        lex.next();
                        arg.requires = lex.getString();
+               } else if (tok == "decoration") {
+                       lex.next();
+                       arg.decoration = lex.getString();
+               } else if (tok == "font") {
+                       arg.font = lyxRead(lex, arg.font);
+               } else if (tok == "labelfont") {
+                       arg.labelfont = lyxRead(lex, arg.labelfont);
                } else {
                        lex.printError("Unknown tag");
                        error = true;
index 45bdf460bf7a0eb3245325a80bc17bda96d15df0..b0c3ac5bad36eab221f67dc81bbaa0a504bff0cd 100644 (file)
@@ -95,6 +95,9 @@ public:
                docstring rdelim;
                docstring tooltip;
                std::string requires;
+               std::string decoration;
+               FontInfo font;
+               FontInfo labelfont;
        };
        ///
        typedef std::map<unsigned int, latexarg> LaTeXArgMap;
index 256afcfe29e130c8a971f33bb8e7d3a17248063f..b113878f062e9c60eee7c65702ac86daa6fedc5b 100644 (file)
@@ -34,7 +34,8 @@ namespace lyx {
 
 
 InsetArgument::InsetArgument(Buffer * buf, string const & name)
-    : InsetCollapsable(buf), name_(name), labelstring_(docstring())
+    : InsetCollapsable(buf), name_(name), labelstring_(docstring()),
+      font_(inherit_font), labelfont_(inherit_font), decoration_(string())
 {}
 
 
@@ -102,6 +103,9 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
                support::rsplit(label, striplabel, '|');
                labelstring_ = striplabel.empty() ? label: striplabel;
                tooltip_ = translateIfPossible((*lait).second.tooltip);
+               font_ = (*lait).second.font;
+               labelfont_ = (*lait).second.labelfont;
+               decoration_ = (*lait).second.decoration;
        } else {
                labelstring_ = _("Unknown Argument");
                tooltip_ = _("Argument not known in this Layout. Will be supressed in the output.");
@@ -202,6 +206,43 @@ string InsetArgument::contextMenuName() const
        return "context-argument";
 }
 
+FontInfo InsetArgument::getFont() const
+{
+       if (font_ != inherit_font)
+               return font_;
+       return getLayout().font();
+}
+
+FontInfo InsetArgument::getLabelfont() const
+{
+       if (labelfont_ != inherit_font)
+               return labelfont_;
+       return getLayout().labelfont();
+}
+
+namespace {
+
+InsetLayout::InsetDecoration translateDecoration(std::string const & str) 
+{
+       if (support::compare_ascii_no_case(str, "classic") == 0)
+               return InsetLayout::CLASSIC;
+       if (support::compare_ascii_no_case(str, "minimalistic") == 0)
+               return InsetLayout::MINIMALISTIC;
+       if (support::compare_ascii_no_case(str, "conglomerate") == 0)
+               return InsetLayout::CONGLOMERATE;
+       return InsetLayout::DEFAULT;
+}
+
+}// namespace anon
+
+InsetLayout::InsetDecoration InsetArgument::decoration() const
+{
+       InsetLayout::InsetDecoration dec = getLayout().decoration();
+       if (!decoration_.empty())
+               dec = translateDecoration(decoration_);
+       return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
+}
+
 void InsetArgument::latexArgument(otexstream & os,
                OutputParams const & runparams_in, docstring const & ldelim,
                docstring const & rdelim) const
index 274623ab3edb2460ff310f099e6c2bcd4c2a5945..bff6056934e8ad2d1e23c217539ae0043cb4f5eb 100644 (file)
@@ -66,6 +66,12 @@ public:
        /// \name Public functions inherited from InsetCollapsable class
        //@{
        ///
+       InsetLayout::InsetDecoration decoration() const;
+       ///
+       FontInfo getFont() const;
+       ///
+       FontInfo getLabelfont() const;
+       ///
        void setButtonLabel();
        //@}
 
@@ -78,6 +84,12 @@ private:
        docstring labelstring_;
        ///
        docstring tooltip_;
+       ///
+       FontInfo font_;
+       ///
+       FontInfo labelfont_;
+       ///
+       std::string decoration_;
 
 protected:
        /// \name Protected functions inherited from Inset class
index 6c880cd514c53c4eeff51d38c114d34a2640516b..d038cfc2813a8a277a2bd713555576c681646885 100644 (file)
@@ -173,7 +173,9 @@ void InsetCollapsable::read(Lexer & lex)
 Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
 {
        Dimension dim;
-       theFontMetrics(getLayout().labelfont()).buttonText(
+       FontInfo labelfont(getLabelfont());
+       labelfont.realize(sane_font);
+       theFontMetrics(labelfont).buttonText(
                buttonLabel(bv), dim.wid, dim.asc, dim.des);
        return dim;
 }
@@ -184,7 +186,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
        auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
 
        FontInfo tmpfont = mi.base.font;
-       mi.base.font = getLayout().font();
+       mi.base.font = getFont();
        mi.base.font.realize(tmpfont);
 
        BufferView const & bv = *mi.base.bv;
@@ -201,7 +203,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
        case SubLabel: {
                InsetText::metrics(mi, dim);
                // consider width of the inset label
-               FontInfo font(getLayout().labelfont());
+               FontInfo font(getLabelfont());
                font.realize(sane_font);
                font.decSize();
                font.decSize();
@@ -253,7 +255,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
        auto_open_[&bv] = bv.cursor().isInside(this);
 
        FontInfo tmpfont = pi.base.font;
-       pi.base.font = getLayout().font();
+       pi.base.font = getFont();
        pi.base.font.realize(tmpfont);
 
        // Draw button first -- top, left or only
@@ -267,7 +269,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                button_dim.y1 = y - dimc.asc;
                button_dim.y2 = y + dimc.des;
 
-               FontInfo labelfont = getLayout().labelfont();
+               FontInfo labelfont = getLabelfont();
                labelfont.setColor(labelColor());
                pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
                        mouse_hover_[&bv]);
@@ -334,7 +336,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 
                // the label below the text. Can be toggled.
                if (geometry(bv) == SubLabel) {
-                       FontInfo font(getLayout().labelfont());
+                       FontInfo font(getLabelfont());
                        font.realize(sane_font);
                        font.decSize();
                        font.decSize();
index d7d050e3fea9a44aba29ea8d1b5b28026714f58d..1c990f93c88c4c2103ac5695f97a4a0a102d59fc 100644 (file)
@@ -111,6 +111,10 @@ public:
 
        /// Default looks
        virtual InsetLayout::InsetDecoration decoration() const;
+       /// Inset font
+       virtual FontInfo getFont() const { return getLayout().font(); }
+       /// Label font
+       virtual FontInfo getLabelfont() const { return getLayout().labelfont(); }
        ///
        enum Geometry {
                TopButton,
index 808176602178638c071ab501fea5799b7fc8349f..3b5589d8b84c6cb614207d5b3a4d341b68ef0ad0 100644 (file)
@@ -496,6 +496,8 @@ void InsetLayout::readArgument(Lexer & lex)
        arg.mandatory = false;
        bool error = false;
        bool finished = false;
+       arg.font = inherit_font;
+       arg.labelfont = inherit_font;
        unsigned int nr;
        lex >> nr;
        while (!finished && lex.isOK() && !error) {
@@ -524,6 +526,13 @@ void InsetLayout::readArgument(Lexer & lex)
                } else if (tok == "requires") {
                        lex.next();
                        arg.requires = lex.getString();
+               } else if (tok == "decoration") {
+                       lex.next();
+                       arg.decoration = lex.getString();
+               } else if (tok == "font") {
+                       arg.font = lyxRead(lex, arg.font);
+               } else if (tok == "labelfont") {
+                       arg.labelfont = lyxRead(lex, arg.labelfont);
                } else {
                        lex.printError("Unknown tag");
                        error = true;