Allow for some argument visual customization

This commit is contained in:
Juergen Spitzmueller 2012-11-26 09:10:14 +01:00
parent b4c9e902ad
commit e0f392e075
7 changed files with 87 additions and 7 deletions

View 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;

View 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;

View 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

View 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

View 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();

View 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,

View 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;