On Thu, Dec 04, 2003 at 06:25:24PM +0100, Michael Schmitt spake thusly:
 
> Jean-Marc Lasgouttes wrote:
> 
> > Martin> Talking about looks, see the attached.
> 
> Looks good, Martin!
> 
> > --------------------
> > |some contents here|
> > ----name------------
> > 
> > This would reduce the height of the inset...
> 
> 
> > You can even do
> >   some contents here
> >   \---name---------/
> > and avoid the frame altogether.
> 
> Ha! That was exactly _my_ idea (about 15 seconds ago) :-)
> 
> I think the red frame should be removed, if possible, since (a) it 
> occupies some space and (b) looks too eye-catching.
> 
> However, we might need the red box for insets that span more than one 
> row. Martin, can we check whether an inset is a one-liner or not and 
> output it differently in both possible cases? That would be (nearly) 
> perfect!
> 
> Michael

That isn't quite so easy... feel free to try ;-)

I tightened up the thing a little bit. The patch is attached.  

I think this is such a clear improvement on what we had, that this
should go in as it stands, despite small quirks (which I am not even
sure have to do with the patch). I think we have at least the right
visual model now.

- Martin

Index: insetcharstyle.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.C,v
retrieving revision 1.7
diff -u -p -r1.7 insetcharstyle.C
--- insetcharstyle.C    1 Dec 2003 16:01:50 -0000       1.7
+++ insetcharstyle.C    4 Dec 2003 21:31:08 -0000
@@ -25,6 +25,8 @@
 #include "metricsinfo.h"
 #include "paragraph.h"
 
+#include "frontends/font_metrics.h"
+#include "frontends/Painter.h"
 #include "support/std_sstream.h"
 
 
@@ -38,13 +40,13 @@ using std::ostringstream;
 void InsetCharStyle::init()
 {
        setInsetName("CharStyle");
-       setButtonLabel();
+       setStatus(Inlined);
 }
 
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
                                CharStyles::iterator cs)
-       : InsetCollapsable(bp)
+       : InsetCollapsable(bp), has_label_(true)
 {
        params_.type = cs->name;
        params_.latextype = cs->latextype;
@@ -57,7 +59,7 @@ InsetCharStyle::InsetCharStyle(BufferPar
 
 
 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
-       : InsetCollapsable(in), params_(in.params_)
+       : InsetCollapsable(in), params_(in.params_), has_label_(true)
 {
        init();
 }
@@ -85,24 +87,41 @@ void InsetCharStyle::write(Buffer const 
 void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
 {
        InsetCollapsable::read(buf, lex);
-       setButtonLabel();
+       setStatus(Inlined);
 }
 
 
-void InsetCharStyle::setButtonLabel()
+void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont font(params_.labelfont);
-       font.realize(LyXFont(LyXFont::ALL_SANE));
-       string const s = "Style: " + params_.type;
-       setLabel(isOpen() ? s : getNewLabel(s) );
-       setLabelFont(font);
+       InsetCollapsable::metrics(mi, dim);
+       dim_ = dim;
+       if (has_label_)
+               dim_.des += ascent();
 }
 
 
-void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCollapsable::metrics(mi, dim);
-       dim_ = dim;
+       xo_ = x;
+       yo_ = y;
+
+       status_ = Inlined;
+       InsetCollapsable::draw(pi, x, y);
+       if (has_label_) {
+               if (!owner())
+                       x += scroll();
+       LyXFont font;
+       font.setColor(LColor::blue);
+       font.realize(LyXFont(LyXFont::ALL_SANE));
+       font.decSize();
+       font.decSize();
+       int w = 0;
+       int a = 0;
+       int d = 0;
+       font_metrics::rectText(params_.type, font, w, a, d);
+       pi.pain.rectText(x + 0.5 * (dim_.wid - w), y + inset.descent() + a,
+               params_.type, font, LColor::none, LColor::none);
+       }
 }
 
 
@@ -116,9 +135,17 @@ DispatchResult
 InsetCharStyle::priv_dispatch(FuncRequest const & cmd,
                        idx_type & idx, pos_type & pos)
 {
-       DispatchResult dr = InsetCollapsable::priv_dispatch(cmd, idx, pos);
-       setButtonLabel();
-       return dr;
+       setStatus(Inlined);
+       switch (cmd.action) {
+               case LFUN_MOUSE_PRESS:
+                       if (cmd.button() == mouse_button::button3) {
+                               has_label_ = !has_label_;
+                               return DispatchResult(true);
+                       }
+               default:
+                       inset.dispatch(cmd);
+                       return DispatchResult(true, true);
+       }
 }
 
 

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to