mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-19 22:40:26 +00:00
Streamlining CollapseStatus stuff
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19610 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5a82011b90
commit
f0ece382e4
@ -36,7 +36,6 @@ QERTDialog::QERTDialog(QERT * form)
|
||||
setupUi(this);
|
||||
connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
|
||||
connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
|
||||
connect(inlineRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
||||
connect(collapsedRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
||||
connect(openRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
||||
}
|
||||
@ -82,11 +81,9 @@ void QERT::build_dialog()
|
||||
void QERT::apply()
|
||||
{
|
||||
if (dialog_->openRB->isChecked())
|
||||
controller().setStatus(InsetERT::Open);
|
||||
else if (dialog_->inlineRB->isChecked())
|
||||
controller().setStatus(InsetERT::Inlined);
|
||||
controller().setStatus(Inset::Open);
|
||||
else
|
||||
controller().setStatus(InsetERT::Collapsed);
|
||||
controller().setStatus(Inset::Collapsed);
|
||||
}
|
||||
|
||||
|
||||
@ -96,7 +93,6 @@ void QERT::update_contents()
|
||||
|
||||
switch (controller().status()) {
|
||||
case InsetERT::Open: rb = dialog_->openRB; break;
|
||||
case InsetERT::Inlined: rb = dialog_->inlineRB; break;
|
||||
case InsetERT::Collapsed: rb = dialog_->collapsedRB; break;
|
||||
}
|
||||
|
||||
|
@ -37,17 +37,7 @@
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="inlineRB" >
|
||||
<property name="toolTip" >
|
||||
<string>Show ERT inline</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Inline</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="collapsedRB" >
|
||||
<property name="toolTip" >
|
||||
<string>Show ERT button only</string>
|
||||
|
@ -486,7 +486,6 @@ public:
|
||||
///
|
||||
enum CollapseStatus {
|
||||
Collapsed,
|
||||
Inlined,
|
||||
Open
|
||||
};
|
||||
///
|
||||
|
@ -51,7 +51,6 @@ using std::ostringstream;
|
||||
|
||||
void InsetCharStyle::init()
|
||||
{
|
||||
setInlined();
|
||||
setDrawFrame(false);
|
||||
}
|
||||
|
||||
@ -134,7 +133,6 @@ void InsetCharStyle::read(Buffer const & buf, Lexer & lex)
|
||||
{
|
||||
params_.read(lex);
|
||||
InsetCollapsable::read(buf, lex);
|
||||
setInlined();
|
||||
}
|
||||
|
||||
|
||||
@ -236,7 +234,6 @@ void InsetCharStyle::getDrawFont(Font & font) const
|
||||
|
||||
void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
setInlined();
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_MOUSE_RELEASE:
|
||||
|
@ -77,6 +77,9 @@ public:
|
||||
void getDrawFont(Font &) const;
|
||||
///
|
||||
bool forceDefaultParagraphs(idx_type) const { return true; }
|
||||
///
|
||||
virtual Decoration decoration() const { return Conglomerate; }
|
||||
|
||||
///
|
||||
int latex(Buffer const &, odocstream &,
|
||||
OutputParams const &) const;
|
||||
|
@ -45,7 +45,29 @@ using std::ostream;
|
||||
|
||||
InsetCollapsable::CollapseStatus InsetCollapsable::status() const
|
||||
{
|
||||
return (autoOpen_ && status_ != Inlined) ? Open : status_;
|
||||
return autoOpen_ ? Open : status_;
|
||||
}
|
||||
|
||||
|
||||
InsetCollapsable::Geometry InsetCollapsable::geometry() const
|
||||
{
|
||||
switch (decoration()) {
|
||||
case Classic:
|
||||
if (status_ == Open || autoOpen_) {
|
||||
if (openinlined_)
|
||||
return LeftButton;
|
||||
else
|
||||
return TopButton;
|
||||
} else
|
||||
return ButtonOnly;
|
||||
break;
|
||||
case Minimalistic:
|
||||
return NoButton;
|
||||
break;
|
||||
case Conglomerate:
|
||||
return ( status_ == Open ? SubLabel : Corners );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -95,9 +117,6 @@ void InsetCollapsable::write(Buffer const & buf, ostream & os) const
|
||||
case Collapsed:
|
||||
os << "collapsed";
|
||||
break;
|
||||
case Inlined:
|
||||
os << "inlined";
|
||||
break;
|
||||
}
|
||||
os << "\n";
|
||||
text_.write(buf, os);
|
||||
@ -114,10 +133,7 @@ void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
|
||||
lex.next();
|
||||
string const tmp_token = lex.getString();
|
||||
|
||||
if (tmp_token == "inlined") {
|
||||
status_ = Inlined;
|
||||
token_found = true;
|
||||
} else if (tmp_token == "collapsed") {
|
||||
if (tmp_token == "collapsed") {
|
||||
status_ = Collapsed;
|
||||
token_found = true;
|
||||
} else if (tmp_token == "open") {
|
||||
@ -159,11 +175,15 @@ bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
autoOpen_ = mi.base.bv->cursor().isInside(this);
|
||||
mi.base.textwidth -= (int) (1.5 * TEXT_TO_INSET_OFFSET);
|
||||
|
||||
if (status() == Inlined) {
|
||||
switch (decoration()) {
|
||||
case Minimalistic:
|
||||
case Conglomerate:
|
||||
InsetText::metrics(mi, dim);
|
||||
} else {
|
||||
break;
|
||||
case Classic:
|
||||
dim = dimensionCollapsed();
|
||||
if (status() == Open) {
|
||||
if (geometry() == TopButton
|
||||
|| geometry() == LeftButton) {
|
||||
InsetText::metrics(mi, textdim_);
|
||||
// This expression should not contain mi.base.texwidth
|
||||
openinlined_ = !hasFixedWidth()
|
||||
@ -182,6 +202,7 @@ bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
dim.wid = max(dim.wid, mi.base.textwidth);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
dim.asc += TEXT_TO_INSET_OFFSET;
|
||||
dim.des += TEXT_TO_INSET_OFFSET;
|
||||
@ -203,7 +224,8 @@ bool InsetCollapsable::setMouseHover(bool mouse_hover)
|
||||
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
const int xx = x + TEXT_TO_INSET_OFFSET;
|
||||
if (status() == Inlined) {
|
||||
|
||||
if (decoration() == Minimalistic) {
|
||||
InsetText::draw(pi, xx, y);
|
||||
} else {
|
||||
Dimension dimc = dimensionCollapsed();
|
||||
@ -215,16 +237,30 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
||||
|
||||
pi.pain.buttonText(xx, top + dimc.asc, label, layout_.labelfont, mouse_hover_);
|
||||
|
||||
if (status() == Open) {
|
||||
int textx, texty;
|
||||
if (openinlined_) {
|
||||
textx = xx + dimc.width();
|
||||
texty = top + textdim_.asc;
|
||||
} else {
|
||||
textx = xx;
|
||||
texty = top + dimc.height() + textdim_.asc;
|
||||
}
|
||||
int textx, texty;
|
||||
switch (geometry()) {
|
||||
case LeftButton:
|
||||
textx = xx + dimc.width();
|
||||
texty = top + textdim_.asc;
|
||||
InsetText::draw(pi, textx, texty);
|
||||
break;
|
||||
case TopButton:
|
||||
textx = xx;
|
||||
texty = top + dimc.height() + textdim_.asc;
|
||||
InsetText::draw(pi, textx, texty);
|
||||
break;
|
||||
case ButtonOnly:
|
||||
break;
|
||||
case NoButton:
|
||||
textx = xx;
|
||||
texty = top + textdim_.asc;
|
||||
InsetText::draw(pi, textx, texty);
|
||||
break;
|
||||
case SubLabel:
|
||||
case Corners:
|
||||
// FIXME add handling of SubLabel, Corners
|
||||
// still in CharStyle
|
||||
break;
|
||||
}
|
||||
}
|
||||
setPosCache(pi, x, y);
|
||||
@ -234,30 +270,49 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
||||
void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
x += TEXT_TO_INSET_OFFSET;
|
||||
if (status() == Open) {
|
||||
if (openinlined_)
|
||||
x += dimensionCollapsed().wid;
|
||||
else
|
||||
y += dimensionCollapsed().des + textdim_.asc;
|
||||
}
|
||||
if (status() != Collapsed)
|
||||
switch (geometry()) {
|
||||
case LeftButton:
|
||||
x += dimensionCollapsed().wid;
|
||||
InsetText::drawSelection(pi, x, y);
|
||||
break;
|
||||
case TopButton:
|
||||
y += dimensionCollapsed().des + textdim_.asc;
|
||||
InsetText::drawSelection(pi, x, y);
|
||||
break;
|
||||
case ButtonOnly:
|
||||
break;
|
||||
case NoButton:
|
||||
case SubLabel:
|
||||
case Corners:
|
||||
InsetText::drawSelection(pi, x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetCollapsable::cursorPos(BufferView const & bv,
|
||||
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
||||
{
|
||||
BOOST_ASSERT(status() != Collapsed);
|
||||
BOOST_ASSERT(geometry() != ButtonOnly);
|
||||
|
||||
InsetText::cursorPos(bv, sl, boundary, x, y);
|
||||
|
||||
if (status() == Open) {
|
||||
if (openinlined_)
|
||||
x += dimensionCollapsed().wid;
|
||||
else
|
||||
y += dimensionCollapsed().height() - ascent()
|
||||
+ TEXT_TO_INSET_OFFSET + textdim_.asc;
|
||||
switch (geometry()) {
|
||||
case LeftButton:
|
||||
x += dimensionCollapsed().wid;
|
||||
break;
|
||||
case TopButton:
|
||||
y += dimensionCollapsed().height() - ascent()
|
||||
+ TEXT_TO_INSET_OFFSET + textdim_.asc;
|
||||
break;
|
||||
case NoButton:
|
||||
case SubLabel:
|
||||
case Corners:
|
||||
// Do nothing
|
||||
break;
|
||||
case ButtonOnly:
|
||||
// Cannot get here
|
||||
break;
|
||||
}
|
||||
x += TEXT_TO_INSET_OFFSET;
|
||||
}
|
||||
@ -265,13 +320,13 @@ void InsetCollapsable::cursorPos(BufferView const & bv,
|
||||
|
||||
Inset::EDITABLE InsetCollapsable::editable() const
|
||||
{
|
||||
return status() != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
|
||||
return geometry() != ButtonOnly? HIGHLY_EDITABLE : IS_EDITABLE;
|
||||
}
|
||||
|
||||
|
||||
bool InsetCollapsable::descendable() const
|
||||
{
|
||||
return status() != Collapsed;
|
||||
return geometry() != ButtonOnly;
|
||||
}
|
||||
|
||||
|
||||
@ -313,7 +368,9 @@ void InsetCollapsable::edit(Cursor & cur, bool left)
|
||||
Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
|
||||
{
|
||||
//lyxerr << "InsetCollapsable: edit xy" << endl;
|
||||
if (status() == Collapsed || (button_dim.contains(x, y) && status() != Inlined))
|
||||
if (geometry() == ButtonOnly
|
||||
|| (button_dim.contains(x, y)
|
||||
&& decoration() != Minimalistic))
|
||||
return this;
|
||||
cur.push(*this);
|
||||
return InsetText::editXY(cur, x, y);
|
||||
@ -327,7 +384,9 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
|
||||
switch (cmd.action) {
|
||||
case LFUN_MOUSE_PRESS:
|
||||
if (cmd.button() == mouse_button::button1 && hitButton(cmd) && status() != Inlined) {
|
||||
if (cmd.button() == mouse_button::button1
|
||||
&& hitButton(cmd)
|
||||
&& decoration() != Minimalistic) {
|
||||
// reset selection if necessary (see bug 3060)
|
||||
if (cur.selection())
|
||||
cur.bv().cursor().clearSelection();
|
||||
@ -336,9 +395,10 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
cur.dispatched();
|
||||
break;
|
||||
}
|
||||
if (status() == Inlined)
|
||||
if (decoration() == Minimalistic)
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
else if (status() == Open && !hitButton(cmd))
|
||||
else if (geometry() != ButtonOnly
|
||||
&& !hitButton(cmd))
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
else
|
||||
cur.undispatched();
|
||||
@ -347,9 +407,10 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
case LFUN_MOUSE_MOTION:
|
||||
case LFUN_MOUSE_DOUBLE:
|
||||
case LFUN_MOUSE_TRIPLE:
|
||||
if (status_ == Inlined)
|
||||
if (decoration() == Minimalistic)
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
else if (status() && !hitButton(cmd))
|
||||
else if (geometry() != ButtonOnly
|
||||
&& !hitButton(cmd))
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
else
|
||||
cur.undispatched();
|
||||
@ -362,7 +423,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
break;
|
||||
}
|
||||
|
||||
if (status() == Inlined) {
|
||||
if (decoration() == Minimalistic) {
|
||||
// The mouse click has to be within the inset!
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
break;
|
||||
@ -377,7 +438,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
// toggle the inset visual state.
|
||||
cur.dispatched();
|
||||
cur.updateFlags(Update::Force | Update::FitCursor);
|
||||
if (status() == Collapsed) {
|
||||
if (geometry() == ButtonOnly) {
|
||||
setStatus(cur, Open);
|
||||
edit(cur, true);
|
||||
}
|
||||
@ -389,7 +450,8 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
}
|
||||
|
||||
// The mouse click is within the opened inset.
|
||||
if (status() == Open)
|
||||
if (geometry() == TopButton
|
||||
|| geometry() == LeftButton)
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
break;
|
||||
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
///
|
||||
static int const TEXT_TO_BOTTOM_OFFSET = 2;
|
||||
///
|
||||
InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
|
||||
InsetCollapsable(BufferParams const &, CollapseStatus status = Inset::Open);
|
||||
///
|
||||
InsetCollapsable(InsetCollapsable const & rhs);
|
||||
///
|
||||
@ -77,11 +77,51 @@ public:
|
||||
///
|
||||
void setLabelFont(Font const & f);
|
||||
///
|
||||
bool isOpen() const { return status_ == Open || status_ == Inlined; }
|
||||
bool isOpen() const { return geometry() != ButtonOnly; }
|
||||
///
|
||||
bool inlined() const { return status_ == Inlined; }
|
||||
bool inlined() const { return decoration() == Minimalistic|| decoration() == Conglomerate; }
|
||||
///
|
||||
CollapseStatus status() const;
|
||||
/** Of the old CollapseStatus we only keep the values
|
||||
* Open and Collapsed.
|
||||
* We define a list of possible inset decoration
|
||||
* styles, and a list of possible (concrete, visual)
|
||||
* inset geometries. Relationships between them
|
||||
* (geometries in body of table):
|
||||
*
|
||||
* \ CollapseStatus:
|
||||
* Decoration: \ Open Collapsed
|
||||
* -------------+-------------------------------
|
||||
* Classic | *) TopButton, <--x) ButtonOnly
|
||||
* | LeftButton
|
||||
* Minimalistic | NoButton NoButton
|
||||
* Conglomerate | SubLabel Corners
|
||||
* ---------------------------------------------
|
||||
* *) toggled by openinlined_
|
||||
* x) toggled by autoOpen_
|
||||
*/
|
||||
|
||||
///
|
||||
enum Decoration {
|
||||
Classic,
|
||||
Minimalistic,
|
||||
Conglomerate
|
||||
};
|
||||
/// Default looks
|
||||
virtual Decoration decoration() const { return Classic; }
|
||||
///
|
||||
enum Geometry {
|
||||
TopButton,
|
||||
ButtonOnly,
|
||||
NoButton,
|
||||
LeftButton,
|
||||
SubLabel,
|
||||
Corners
|
||||
};
|
||||
/// Returns the geometry based on CollapseStatus
|
||||
/// (status_), autoOpen_ and openinlined_, and of
|
||||
/// course decoration().
|
||||
Geometry geometry() const;
|
||||
///
|
||||
bool allowSpellCheck() const { return true; }
|
||||
///
|
||||
@ -103,8 +143,6 @@ protected:
|
||||
///
|
||||
Inset * editXY(Cursor & cur, int x, int y);
|
||||
///
|
||||
void setInlined() { status_ = Inlined; }
|
||||
///
|
||||
docstring floatName(std::string const & type, BufferParams const &) const;
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user