]> git.lyx.org Git - lyx.git/blob - src/insets/render_button.C
This commit is a big rework of the FontLoader/FontMetrics interaction. Only Qt4 for...
[lyx.git] / src / insets / render_button.C
1 /**
2  * \file render_button.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "render_button.h"
14
15 #include "LColor.h"
16 #include "metricsinfo.h"
17
18 #include "frontends/Application.h"
19 #include "frontends/FontLoader.h"
20 #include "frontends/FontMetrics.h"
21 #include "frontends/Painter.h"
22
23 using lyx::docstring;
24
25 using std::string;
26 using std::auto_ptr;
27
28
29 RenderButton::RenderButton()
30         : editable_(false)
31 {}
32
33
34 auto_ptr<RenderBase> RenderButton::clone(InsetBase const *) const
35 {
36         return auto_ptr<RenderBase>(new RenderButton(*this));
37 }
38
39
40 void RenderButton::update(string const & text, bool editable)
41 {
42         text_ = text;
43         editable_ = editable;
44 }
45
46
47 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
48 {
49         LyXFont font(LyXFont::ALL_SANE);
50         font.decSize();
51         lyx::frontend::FontMetrics const & fm =
52                 theApp->fontLoader().metrics(font);
53         
54         docstring dtext(text_.begin(), text_.end());
55         
56         if (editable_)
57                 fm.buttonText(dtext, dim.wid, dim.asc, dim.des);
58         else
59                 fm.rectText(dtext, dim.wid, dim.asc, dim.des);
60
61         dim.wid += 4;
62 }
63
64
65 void RenderButton::draw(PainterInfo & pi, int x, int y) const
66 {
67         // Draw it as a box with the LaTeX text
68         LyXFont font(LyXFont::ALL_SANE);
69         font.setColor(LColor::command);
70         font.decSize();
71
72         docstring dtext(text_.begin(), text_.end());
73         
74         if (editable_) {
75                 pi.pain.buttonText(x + 2, y, dtext, font);
76         } else {
77                 pi.pain.rectText(x + 2, y, dtext, font,
78                                  LColor::commandbg, LColor::commandframe);
79         }
80 }