On Thu, Aug 16, 2007 at 10:54:40AM +0200, Jean-Marc Lasgouttes wrote: > Martin Vermeer <[EMAIL PROTECTED]> writes: > > > On Thu, Aug 16, 2007 at 09:23:40AM +0200, Jean-Marc Lasgouttes wrote: > >> Martin Vermeer <[EMAIL PROTECTED]> writes: > >> > >> > Hmmm, elsewhere in the code I see such constructs as > >> > CS_LATEXNAME and TC_SOMETHING... we're not the first time > >> > running into this problem. > >> > >> Very good point :) > > > > So what shall I do? Apply the same kludge (D_Inlined, > > G_Collapsed etc)? > > It may be an occasion to pick more telling names. For example, the > decoration should describe what is shown on screen, so that it could > be: > > + enum Decoration { > + FrameOnly, > + ButtonFrame, > + LabelBelow > + }; > > Maybe some sensible and descriptive names could be found for Geometry > too.
This was a great idea... result attached. I will commit this presently if I hear no objections. - Martin
Index: insets/InsetCharStyle.h =================================================================== --- insets/InsetCharStyle.h (revision 19567) +++ insets/InsetCharStyle.h (working copy) @@ -78,6 +78,9 @@ /// bool forceDefaultParagraphs(idx_type) const { return true; } /// + virtual Decoration decoration() const { return Conglomerate; } + + /// int latex(Buffer const &, odocstream &, OutputParams const &) const; /// Index: insets/Inset.h =================================================================== --- insets/Inset.h (revision 19567) +++ insets/Inset.h (working copy) @@ -486,7 +486,6 @@ /// enum CollapseStatus { Collapsed, - Inlined, Open }; /// Index: insets/InsetCharStyle.cpp =================================================================== --- insets/InsetCharStyle.cpp (revision 19567) +++ insets/InsetCharStyle.cpp (working copy) @@ -51,7 +51,6 @@ void InsetCharStyle::init() { - setInlined(); setDrawFrame(false); } @@ -134,7 +133,6 @@ { params_.read(lex); InsetCollapsable::read(buf, lex); - setInlined(); } @@ -236,7 +234,6 @@ void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd) { - setInlined(); switch (cmd.action) { case LFUN_MOUSE_RELEASE: Index: insets/InsetCollapsable.cpp =================================================================== --- insets/InsetCollapsable.cpp (revision 19567) +++ insets/InsetCollapsable.cpp (working copy) @@ -45,10 +45,32 @@ 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; + } +} + + InsetCollapsable::InsetCollapsable (BufferParams const & bp, CollapseStatus status) : InsetText(bp), label(from_ascii("Label")), status_(status), @@ -95,9 +117,6 @@ case Collapsed: os << "collapsed"; break; - case Inlined: - os << "inlined"; - break; } os << "\n"; text_.write(buf, os); @@ -114,10 +133,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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::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; + 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; } - if (status() != Collapsed) - InsetText::drawSelection(pi, x, y); } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ // 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 @@ } // The mouse click is within the opened inset. - if (status() == Open) + if (geometry() == TopButton + || geometry() == LeftButton) InsetText::doDispatch(cur, cmd); break; Index: insets/InsetCollapsable.h =================================================================== --- insets/InsetCollapsable.h (revision 19567) +++ insets/InsetCollapsable.h (working copy) @@ -42,7 +42,7 @@ /// 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,12 +77,52 @@ /// 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; } /// bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; @@ -103,8 +143,6 @@ /// Inset * editXY(Cursor & cur, int x, int y); /// - void setInlined() { status_ = Inlined; } - /// docstring floatName(std::string const & type, BufferParams const &) const; protected: ndex: frontends/qt4/ui/ERTUi.ui =================================================================== --- frontends/qt4/ui/ERTUi.ui (revision 19567) +++ frontends/qt4/ui/ERTUi.ui (working copy) @@ -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> Index: frontends/qt4/QERT.cpp =================================================================== --- frontends/qt4/QERT.cpp (revision 19567) +++ frontends/qt4/QERT.cpp (working copy) @@ -36,7 +36,6 @@ 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::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 @@ switch (controller().status()) { case InsetERT::Open: rb = dialog_->openRB; break; - case InsetERT::Inlined: rb = dialog_->inlineRB; break; case InsetERT::Collapsed: rb = dialog_->collapsedRB; break; }