]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
This commit is a big rework of the FontLoader/FontMetrics interaction. Only Qt4 for...
[lyx.git] / src / frontends / Painter.C
1 /**
2  * \file Painter.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "frontends/Painter.h"
15
16 #include "frontends/Application.h"
17 #include "frontends/FontLoader.h"
18 #include "frontends/FontMetrics.h"
19
20 #include "LColor.h"
21 #include "lyxfont.h"
22
23 using lyx::docstring;
24
25 using std::max;
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 void Painter::button(int x, int y, int w, int h)
32 {
33         fillRectangle(x, y, w, h, LColor::buttonbg);
34         buttonFrame(x, y, w, h);
35 }
36
37
38 void Painter::buttonFrame(int x, int y, int w, int h)
39 {
40         //  Width of a side of the button
41         int const d = 2;
42
43         fillRectangle(x, y, w, d, LColor::top);
44         fillRectangle(x, y + h - d, w, d, LColor::bottom);
45
46         for (int i = 0 ; i < d ; ++i) {
47                 line(x + i, y + i,
48                      x + i, y + h - 1 - i, LColor::left);
49                 line(x + w - 1 - i, y + i + 1,
50                      x + w - 1 - i, y + h - 1 - i, LColor::right);
51         }
52 }
53
54
55 void Painter::rectText(int x, int y,
56         docstring const & str,
57         LyXFont const & font,
58         LColor_color back,
59         LColor_color frame)
60 {
61         int width;
62         int ascent;
63         int descent;
64
65         FontMetrics const & fm = theApp->fontLoader().metrics(font);
66         fm.rectText(str, width, ascent, descent);
67
68         if (back != LColor::none)
69                 fillRectangle(x + 1, y - ascent + 1, width - 1,
70                               ascent + descent - 1, back);
71
72         if (frame != LColor::none)
73                 rectangle(x, y - ascent, width, ascent + descent, frame);
74
75         text(x + 3, y, str, font);
76 }
77
78
79 void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & font)
80 {
81         int width;
82         int ascent;
83         int descent;
84
85         FontMetrics const & fm = theApp->fontLoader().metrics(font);
86         fm.buttonText(str, width, ascent, descent);
87
88         button(x, y - ascent, width, descent + ascent);
89         text(x + 4, y, str, font);
90 }
91
92
93 void Painter::underline(LyXFont const & f, int x, int y, int width)
94 {
95         FontMetrics const & fm = theApp->fontLoader().metrics(f);
96
97         int const below = max(fm.maxDescent() / 2, 2);
98         int const height = max((fm.maxDescent() / 4) - 1, 1);
99
100         if (height < 2)
101                 line(x, y + below, x + width, y + below, f.color());
102         else
103                 fillRectangle(x, y + below, width, below + height, f.color());
104 }
105
106 } // namespace frontend
107 } // namespace lyx