mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Slight improvement to caption inset
* insetcaption.C (InsetCaption::setLabel): added (InsetCaption::metrics): modified (InsetCaption::draw): modified * insetcaption.h (descendable): added (setCount): added git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13946 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9614a1d698
commit
32a51961ae
@ -89,9 +89,40 @@ void InsetCaption::cursorPos
|
||||
}
|
||||
|
||||
|
||||
void InsetCaption::setLabel(LCursor & cur) const
|
||||
{
|
||||
// Set caption label _only_ if the cursor is in _this_ float:
|
||||
if (cur.top().text() == &text_) {
|
||||
string s;
|
||||
size_t i = cur.depth();
|
||||
while (i > 0) {
|
||||
--i;
|
||||
InsetBase * const in = &cur[i].inset();
|
||||
if (in->lyxCode() == InsetBase::FLOAT_CODE
|
||||
|| in->lyxCode() == InsetBase::WRAP_CODE) {
|
||||
s = in->getInsetName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Floating const & fl = textclass_.floats().getType(s);
|
||||
s = fl.name();
|
||||
string num;
|
||||
if (s.empty())
|
||||
s = "Senseless";
|
||||
else
|
||||
num = convert<string>(counter_);
|
||||
|
||||
// Generate the label
|
||||
label = bformat("%1$s %2$s:", _(s), num);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
||||
LCursor cur = mi.base.bv->cursor();
|
||||
setLabel(cur);
|
||||
labelwidth_ = font_metrics::width(label, mi.base.font);
|
||||
dim.wid = labelwidth_;
|
||||
Dimension textdim;
|
||||
@ -118,30 +149,7 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const
|
||||
// See if we can find the name of the float this caption
|
||||
// belongs to.
|
||||
LCursor cur = pi.base.bv->cursor();
|
||||
// Set caption label _only_ if the cursor is in _this_ float:
|
||||
if (cur.top().text() == &text_) {
|
||||
string s;
|
||||
size_t i = cur.depth();
|
||||
while (i > 0) {
|
||||
--i;
|
||||
InsetBase * const in = &cur[i].inset();
|
||||
if (in->lyxCode() == InsetBase::FLOAT_CODE
|
||||
|| in->lyxCode() == InsetBase::WRAP_CODE) {
|
||||
s = in->getInsetName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Floating const & fl = textclass_.floats().getType(s);
|
||||
s = fl.name();
|
||||
string num;
|
||||
if (s.empty())
|
||||
s = "Senseless";
|
||||
else
|
||||
num = convert<string>(textclass_.counters().value(fl.type()));
|
||||
|
||||
// Generate the label
|
||||
label = bformat("%1$s %2$s:", _(s), num);
|
||||
}
|
||||
setLabel(cur);
|
||||
|
||||
labelwidth_ = font_metrics::width(label, pi.base.font);
|
||||
pi.pain.text(x, y, label, pi.base.font);
|
||||
|
@ -38,6 +38,8 @@ public:
|
||||
virtual void cursorPos
|
||||
(CursorSlice const & sl, bool boundary, int & x, int & y) const;
|
||||
///
|
||||
bool descendable() const { return true; }
|
||||
///
|
||||
virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
///
|
||||
virtual void draw(PainterInfo & pi, int x, int y) const;
|
||||
@ -54,7 +56,11 @@ public:
|
||||
///
|
||||
int docbook(Buffer const & buf, std::ostream & os,
|
||||
OutputParams const & runparams) const;
|
||||
///
|
||||
void setCount(int c) { counter_ = c; }
|
||||
private:
|
||||
///
|
||||
void setLabel(LCursor & cur) const;
|
||||
///
|
||||
virtual std::auto_ptr<InsetBase> doClone() const;
|
||||
///
|
||||
@ -62,6 +68,8 @@ private:
|
||||
///
|
||||
mutable int labelwidth_;
|
||||
///
|
||||
mutable int counter_;
|
||||
///
|
||||
LyXTextClass const & textclass_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user