]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPainter.h
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiPainter.h
1 // -*- C++ -*-
2 /**
3  * \file GuiPainter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef GUIPAINTER_H
14 #define GUIPAINTER_H
15
16 #include "Color.h"
17
18 #include "frontends/Painter.h"
19
20 #include <QPainter>
21 #include <stack>
22
23 class QString;
24
25 namespace lyx {
26
27 class FontInfo;
28
29 namespace frontend {
30
31 /**
32  * GuiPainter - a painter implementation for Qt4
33  */
34 class GuiPainter : public QPainter, public Painter {
35 public:
36         GuiPainter(QPaintDevice *);
37         virtual ~GuiPainter();
38
39         /// draw a line from point to point
40         virtual void line(
41                 int x1, int y1,
42                 int x2, int y2,
43                 Color,
44                 line_style = line_solid,
45                 line_width = line_thin);
46
47         /**
48          * lines -  draw a set of lines
49          * @param xp array of points' x co-ords
50          * @param yp array of points' y co-ords
51          * @param np size of the points array
52          */
53         virtual void lines(
54                 int const * xp,
55                 int const * yp,
56                 int np,
57                 Color,
58                 line_style = line_solid,
59                 line_width = line_thin);
60
61         /// draw a rectangle
62         virtual void rectangle(
63                 int x, int y,
64                 int w, int h,
65                 Color,
66                 line_style = line_solid,
67                 line_width = line_thin);
68
69         /// draw a filled rectangle
70         virtual void fillRectangle(
71                 int x, int y,
72                 int w, int h,
73                 Color);
74
75         /// draw an arc
76         virtual void arc(
77                 int x, int y,
78                 unsigned int w, unsigned int h,
79                 int a1, int a2,
80                 Color);
81
82         /// draw a pixel
83         virtual void point(int x, int y, Color);
84
85         /// draw an image from the image cache
86         virtual void image(int x, int y, int w, int h,
87                 lyx::graphics::Image const & image);
88
89         /// draw a string at position x, y (y is the baseline)
90         virtual int text(int x, int y,
91                 docstring const & str, FontInfo const & f);
92
93         /// draw a char at position x, y (y is the baseline)
94         virtual int text(int x, int y, char_type c, FontInfo const & f);
95
96         /// draw a string and enclose it inside a button frame
97         virtual void buttonText(int x, int baseline, docstring const & s,
98                 FontInfo const & font, bool mouseHover);
99
100         /// start monochrome painting mode, i.e. map every color into [min,max]
101         virtual void enterMonochromeMode(Color const & min, 
102                 Color const & max);
103         /// leave monochrome painting mode
104         virtual void leaveMonochromeMode();
105         
106         /**
107          * Draw a string and enclose it inside a rectangle. If
108          * back color is specified, the background is cleared with
109          * the given color. If frame is specified, a thin frame is drawn
110          * around the text with the given color.
111          */
112         virtual void rectText(int x, int baseline, docstring const & str,
113                 FontInfo const & font, Color back, Color frame);
114
115         /// draw a filled rectangle with the shape of a 3D button
116         virtual void button(int x, int y, int w, int h, bool mouseHover);
117
118         /// draw a character of a preedit string for cjk support.
119         virtual int preeditText(int x, int y,
120                 char_type c, FontInfo const & f, preedit_style style);
121
122         void wavyHorizontalLine(int x, int y, int width, ColorCode col);
123
124 private:
125         /// check the font, and if set, draw an underline
126         void underline(FontInfo const & f,
127                 int x, int y, int width);
128
129         /// check the font, and if set, draw an dashed underline
130         void dashedUnderline(FontInfo const & f,
131                 int x, int y, int width);
132
133         /// check the font, and if set, draw an strike-through line
134         void strikeoutLine(FontInfo const & f,
135                 int x, int y, int width);
136
137         /// check the font, and if set, draw double underline
138         void doubleUnderline(FontInfo const & f,
139                 int x, int y, int width);
140
141         /// draw a bevelled button border
142         void buttonFrame(int x, int y, int w, int h);
143
144         /// draw small caps text
145         /**
146         \return width of the drawn text.
147         */
148         int smallCapsText(int x, int y,
149                 QString const & str, FontInfo const & f);
150
151         /// set pen parameters
152         void setQPainterPen(QColor const & col,
153                 line_style ls = line_solid, line_width lw = line_thin);
154
155         QColor current_color_;
156         Painter::line_style current_ls_;
157         Painter::line_width current_lw_;
158         ///
159         bool const use_pixmap_cache_;
160         ///
161         std::stack<QColor> monochrome_min_;
162         ///
163         std::stack<QColor> monochrome_max_;
164         /// convert into Qt color, possibly applying the monochrome mode
165         QColor computeColor(Color col);
166         /// possibly apply monochrome mode
167         QColor filterColor(QColor const & col);
168         ///
169         QString generateStringSignature(QString const & str, FontInfo const & f);       
170 };
171
172 } // namespace frontend
173 } // namespace lyx
174
175 #endif // GUIPAINTER_H