From e0f392e075e8e99732f4e2966700158185b5fb95 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 26 Nov 2012 09:10:14 +0100 Subject: [PATCH] Allow for some argument visual customization --- src/Layout.cpp | 9 +++++++ src/Layout.h | 3 +++ src/insets/InsetArgument.cpp | 43 ++++++++++++++++++++++++++++++++- src/insets/InsetArgument.h | 12 +++++++++ src/insets/InsetCollapsable.cpp | 14 ++++++----- src/insets/InsetCollapsable.h | 4 +++ src/insets/InsetLayout.cpp | 9 +++++++ 7 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/Layout.cpp b/src/Layout.cpp index a5d3550ffb..7fcf882e81 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -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; diff --git a/src/Layout.h b/src/Layout.h index 45bdf460bf..b0c3ac5bad 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -95,6 +95,9 @@ public: docstring rdelim; docstring tooltip; std::string requires; + std::string decoration; + FontInfo font; + FontInfo labelfont; }; /// typedef std::map LaTeXArgMap; diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index 256afcfe29..b113878f06 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -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 diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 274623ab3e..bff6056934 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -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 diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 6c880cd514..d038cfc281 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -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(); diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index d7d050e3fe..1c990f93c8 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -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, diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 8081766021..3b5589d8b8 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -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; -- 2.39.2