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