mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
Cleanup 2: moving more stuff charstyle -> collapsable
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19648 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3e13089402
commit
2b927e1575
@ -134,18 +134,9 @@ bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
getDrawFont(mi.base.font);
|
getDrawFont(mi.base.font);
|
||||||
mi.base.font.reduce(Font(Font::ALL_SANE));
|
mi.base.font.reduce(Font(Font::ALL_SANE));
|
||||||
mi.base.font.realize(tmpfont);
|
mi.base.font.realize(tmpfont);
|
||||||
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
bool changed = InsetCollapsable::metrics(mi, dim);
|
||||||
InsetText::metrics(mi, dim);
|
|
||||||
mi.base.font = tmpfont;
|
mi.base.font = tmpfont;
|
||||||
if (status() == Open) {
|
if (status() == Open) {
|
||||||
// consider width of the inset label
|
|
||||||
Font font(layout_.labelfont);
|
|
||||||
font.realize(Font(Font::ALL_SANE));
|
|
||||||
font.decSize();
|
|
||||||
font.decSize();
|
|
||||||
int w = 0;
|
|
||||||
int a = 0;
|
|
||||||
int d = 0;
|
|
||||||
// FIXME UNICODE
|
// FIXME UNICODE
|
||||||
docstring s(from_utf8(params_.name));
|
docstring s(from_utf8(params_.name));
|
||||||
if (undefined())
|
if (undefined())
|
||||||
@ -153,21 +144,8 @@ bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
// Chop off prefix:
|
// Chop off prefix:
|
||||||
if (s.find(':') != string::npos)
|
if (s.find(':') != string::npos)
|
||||||
s = s.substr(s.find(':'));
|
s = s.substr(s.find(':'));
|
||||||
theFontMetrics(font).rectText(s, w, a, d);
|
layout_.labelstring = s;
|
||||||
dim.wid = max(dim.wid, w);
|
|
||||||
}
|
}
|
||||||
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
||||||
dim.des += TEXT_TO_INSET_OFFSET;
|
|
||||||
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
|
||||||
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
|
|
||||||
if (status() == Open)
|
|
||||||
dim.des += ascent();
|
|
||||||
else {
|
|
||||||
dim.des -= 3;
|
|
||||||
dim.asc -= 3;
|
|
||||||
}
|
|
||||||
bool const changed = dim_ != dim;
|
|
||||||
dim_ = dim;
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,27 +161,8 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
|
|||||||
InsetCollapsable::draw(pi, x, y);
|
InsetCollapsable::draw(pi, x, y);
|
||||||
pi.base.font = tmpfont;
|
pi.base.font = tmpfont;
|
||||||
|
|
||||||
int desc = InsetText::descent();
|
|
||||||
if (status() == Open)
|
|
||||||
desc -= ascent();
|
|
||||||
else
|
|
||||||
desc -= 3;
|
|
||||||
|
|
||||||
pi.pain.line(x, y + desc - 4, x, y + desc, layout_.labelfont.color());
|
|
||||||
pi.pain.line(x, y + desc, x + dim_.wid - 3, y + desc,
|
|
||||||
layout_.labelfont.color());
|
|
||||||
pi.pain.line(x + dim_.wid - 3, y + desc, x + dim_.wid - 3, y + desc - 4,
|
|
||||||
layout_.labelfont.color());
|
|
||||||
|
|
||||||
// the name of the charstyle. Can be toggled.
|
// the name of the charstyle. Can be toggled.
|
||||||
if (status() == Open) {
|
if (status() == Open) {
|
||||||
Font font(layout_.labelfont);
|
|
||||||
font.realize(Font(Font::ALL_SANE));
|
|
||||||
font.decSize();
|
|
||||||
font.decSize();
|
|
||||||
int w = 0;
|
|
||||||
int a = 0;
|
|
||||||
int d = 0;
|
|
||||||
// FIXME UNICODE
|
// FIXME UNICODE
|
||||||
docstring s(from_utf8(params_.name));
|
docstring s(from_utf8(params_.name));
|
||||||
if (undefined())
|
if (undefined())
|
||||||
@ -211,22 +170,7 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
|
|||||||
// Chop off prefix:
|
// Chop off prefix:
|
||||||
if (s.find(':') != string::npos)
|
if (s.find(':') != string::npos)
|
||||||
s = s.substr(s.find(':'));
|
s = s.substr(s.find(':'));
|
||||||
theFontMetrics(font).rectText(s, w, a, d);
|
layout_.labelstring = s;
|
||||||
pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
|
|
||||||
s, font, Color::none, Color::none);
|
|
||||||
}
|
|
||||||
|
|
||||||
// a visual cue when the cursor is inside the inset
|
|
||||||
Cursor & cur = pi.base.bv->cursor();
|
|
||||||
if (cur.isInside(this)) {
|
|
||||||
y -= ascent();
|
|
||||||
y += 3;
|
|
||||||
pi.pain.line(x, y + 4, x, y, layout_.labelfont.color());
|
|
||||||
pi.pain.line(x + 4, y, x, y, layout_.labelfont.color());
|
|
||||||
pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
|
|
||||||
layout_.labelfont.color());
|
|
||||||
pi.pain.line(x + dim_.wid - 7, y, x + dim_.wid - 3, y,
|
|
||||||
layout_.labelfont.color());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +187,7 @@ void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
|
|
||||||
case LFUN_MOUSE_RELEASE:
|
case LFUN_MOUSE_RELEASE:
|
||||||
if (cmd.button() == mouse_button::button3)
|
if (cmd.button() == mouse_button::button3)
|
||||||
if (status() == Open)
|
if (internalStatus() == Open)
|
||||||
setStatus(cur, Collapsed);
|
setStatus(cur, Collapsed);
|
||||||
else
|
else
|
||||||
setStatus(cur, Open);
|
setStatus(cur, Open);
|
||||||
@ -257,7 +201,7 @@ void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
else if (cmd.argument() == "close")
|
else if (cmd.argument() == "close")
|
||||||
setStatus(cur, Collapsed);
|
setStatus(cur, Collapsed);
|
||||||
else if (cmd.argument() == "toggle" || cmd.argument().empty())
|
else if (cmd.argument() == "toggle" || cmd.argument().empty())
|
||||||
if (status() == Open)
|
if (internalStatus() == Open)
|
||||||
setStatus(cur, Collapsed);
|
setStatus(cur, Collapsed);
|
||||||
else
|
else
|
||||||
setStatus(cur, Open);
|
setStatus(cur, Open);
|
||||||
|
@ -178,8 +178,29 @@ bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
|
|
||||||
switch (decoration()) {
|
switch (decoration()) {
|
||||||
case Minimalistic:
|
case Minimalistic:
|
||||||
|
InsetText::metrics(mi, dim);
|
||||||
|
break;
|
||||||
case Conglomerate:
|
case Conglomerate:
|
||||||
InsetText::metrics(mi, dim);
|
InsetText::metrics(mi, dim);
|
||||||
|
if (status() == Open) {
|
||||||
|
// consider width of the inset label
|
||||||
|
Font font(layout_.labelfont);
|
||||||
|
font.realize(Font(Font::ALL_SANE));
|
||||||
|
font.decSize();
|
||||||
|
font.decSize();
|
||||||
|
int w = 0;
|
||||||
|
int a = 0;
|
||||||
|
int d = 0;
|
||||||
|
docstring s = layout_.labelstring;
|
||||||
|
theFontMetrics(font).rectText(s, w, a, d);
|
||||||
|
dim.wid = max(dim.wid, w);
|
||||||
|
}
|
||||||
|
if (status() == Open)
|
||||||
|
dim.des += ascent();
|
||||||
|
else {
|
||||||
|
dim.des -= 3;
|
||||||
|
dim.asc -= 3;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Classic:
|
case Classic:
|
||||||
dim = dimensionCollapsed();
|
dim = dimensionCollapsed();
|
||||||
@ -259,13 +280,64 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
|||||||
break;
|
break;
|
||||||
case SubLabel:
|
case SubLabel:
|
||||||
case Corners:
|
case Corners:
|
||||||
// FIXME add handling of SubLabel, Corners
|
|
||||||
// still in CharStyle
|
|
||||||
textx = xx;
|
textx = xx;
|
||||||
texty = y + textdim_.asc;
|
texty = y + textdim_.asc;
|
||||||
const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
|
const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
|
||||||
InsetText::draw(pi, textx, texty);
|
InsetText::draw(pi, textx, texty);
|
||||||
const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
|
const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
|
||||||
|
|
||||||
|
int desc = InsetText::descent();
|
||||||
|
if (status() == Open)
|
||||||
|
desc -= ascent();
|
||||||
|
else
|
||||||
|
desc -= 3;
|
||||||
|
|
||||||
|
pi.pain.line(x, y + desc - 4, x, y + desc,
|
||||||
|
layout_.labelfont.color());
|
||||||
|
if (internalStatus() == Open)
|
||||||
|
pi.pain.line(x, y + desc,
|
||||||
|
x + dim_.wid - 3, y + desc,
|
||||||
|
layout_.labelfont.color());
|
||||||
|
else {
|
||||||
|
// Make status_ value visible:
|
||||||
|
pi.pain.line(x, y + desc,
|
||||||
|
x + 4, y + desc,
|
||||||
|
layout_.labelfont.color());
|
||||||
|
pi.pain.line(x + dim_.wid - 7, y + desc,
|
||||||
|
x + dim_.wid -3, y + desc,
|
||||||
|
layout_.labelfont.color());
|
||||||
|
}
|
||||||
|
pi.pain.line(x + dim_.wid - 3, y + desc, x + dim_.wid - 3, y + desc - 4,
|
||||||
|
layout_.labelfont.color());
|
||||||
|
|
||||||
|
// the label of the charstyle. Can be toggled.
|
||||||
|
if (status() == Open) {
|
||||||
|
Font font(layout_.labelfont);
|
||||||
|
font.realize(Font(Font::ALL_SANE));
|
||||||
|
font.decSize();
|
||||||
|
font.decSize();
|
||||||
|
int w = 0;
|
||||||
|
int a = 0;
|
||||||
|
int d = 0;
|
||||||
|
// FIXME UNICODE
|
||||||
|
docstring s = layout_.labelstring;
|
||||||
|
theFontMetrics(font).rectText(s, w, a, d);
|
||||||
|
pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
|
||||||
|
s, font, Color::none, Color::none);
|
||||||
|
}
|
||||||
|
|
||||||
|
// a visual cue when the cursor is inside the inset
|
||||||
|
Cursor & cur = pi.base.bv->cursor();
|
||||||
|
if (cur.isInside(this)) {
|
||||||
|
y -= ascent();
|
||||||
|
y += 3;
|
||||||
|
pi.pain.line(x, y + 4, x, y, layout_.labelfont.color());
|
||||||
|
pi.pain.line(x + 4, y, x, y, layout_.labelfont.color());
|
||||||
|
pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
|
||||||
|
layout_.labelfont.color());
|
||||||
|
pi.pain.line(x + dim_.wid - 7, y, x + dim_.wid - 3, y,
|
||||||
|
layout_.labelfont.color());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
setPosCache(pi, x, y);
|
setPosCache(pi, x, y);
|
||||||
|
@ -154,6 +154,8 @@ protected:
|
|||||||
mutable int topbaseline;
|
mutable int topbaseline;
|
||||||
///
|
///
|
||||||
mutable InsetLayout layout_;
|
mutable InsetLayout layout_;
|
||||||
|
///
|
||||||
|
CollapseStatus internalStatus() const { return status_; }
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
mutable CollapseStatus status_;
|
mutable CollapseStatus status_;
|
||||||
|
Loading…
Reference in New Issue
Block a user