]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPainter.h
3af51750fd9719919e2108d5bf88a6d820252035
[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 ls = line_solid,
45                 float lw = thin_line);
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 ls = line_solid,
59                 float lw = thin_line);
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                 float lw = thin_line);
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). The
90          * text direction is given by \c rtl.
91          * \return the width of the drawn text.
92          */
93         virtual int text(int x, int y, docstring const & str, FontInfo const & f, bool rtl = false);
94
95         /** draw a string at position x, y (y is the baseline). The
96          * text direction is enforced by the \c Font.
97          * \return the width of the drawn text.
98          */
99         virtual int text(int x, int y, docstring const & str, Font const & f);
100
101         /** draw a string at position x, y (y is the baseline), but
102          * make sure that the part between \c from and \c to is in
103          * \c other color. The text direction is enforced by the \c Font.
104          * \return the width of the drawn text.
105          */
106         virtual int text(int x, int y, docstring const & str, Font const & f,
107                          Color other, size_type from, size_type to);
108
109         /// draw a char at position x, y (y is the baseline)
110         virtual int text(int x, int y, char_type c, FontInfo const & f);
111
112         ///
113         virtual void textDecoration(FontInfo const & f, int x, int y, int width);
114
115         /// draw a string and enclose it inside a button frame
116         virtual void buttonText(int x, int baseline, docstring const & s,
117                 FontInfo const & font, bool mouseHover);
118
119         /// start monochrome painting mode, i.e. map every color into [min,max]
120         virtual void enterMonochromeMode(Color const & min, 
121                 Color const & max);
122         /// leave monochrome painting mode
123         virtual void leaveMonochromeMode();
124         
125         /**
126          * Draw a string and enclose it inside a rectangle. If
127          * back color is specified, the background is cleared with
128          * the given color. If frame is specified, a thin frame is drawn
129          * around the text with the given color.
130          */
131         virtual void rectText(int x, int baseline, docstring const & str,
132                 FontInfo const & font, Color back, Color frame);
133
134         /// draw a filled rectangle with the shape of a 3D button
135         virtual void button(int x, int y, int w, int h, bool mouseHover);
136
137         /// draw a character of a preedit string for cjk support.
138         virtual int preeditText(int x, int y,
139                 char_type c, FontInfo const & f, preedit_style style);
140
141         void wavyHorizontalLine(int x, int y, int width, ColorCode col);
142
143 private:
144         /// check the font, and if set, draw an underline
145         void underline(FontInfo const & f,
146                 int x, int y, int width);
147
148         /// check the font, and if set, draw an dashed underline
149         void dashedUnderline(FontInfo const & f,
150                 int x, int y, int width);
151
152         /// check the font, and if set, draw an strike-through line
153         void strikeoutLine(FontInfo const & f,
154                 int x, int y, int width);
155
156         /// check the font, and if set, draw double underline
157         void doubleUnderline(FontInfo const & f,
158                 int x, int y, int width);
159
160         /// draw a bevelled button border
161         void buttonFrame(int x, int y, int w, int h);
162
163         /// set pen parameters
164         void setQPainterPen(QColor const & col,
165                 line_style ls = line_solid, float lw = thin_line);
166
167         QColor current_color_;
168         Painter::line_style current_ls_;
169         float current_lw_;
170         ///
171         bool const use_pixmap_cache_;
172         ///
173         std::stack<QColor> monochrome_min_;
174         ///
175         std::stack<QColor> monochrome_max_;
176         /// convert into Qt color, possibly applying the monochrome mode
177         QColor computeColor(Color col);
178         /// possibly apply monochrome mode
179         QColor filterColor(QColor const & col);
180         ///
181         QString generateStringSignature(QString const & str, FontInfo const & f);       
182 };
183
184 } // namespace frontend
185 } // namespace lyx
186
187 #endif // GUIPAINTER_H