]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPainter.h
Use <cstdint> instead of <boost/cstdint.hpp>
[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 <QPainterPath>
22 #include <stack>
23
24 class QString;
25
26 namespace lyx {
27
28 class FontInfo;
29
30 namespace frontend {
31
32 /**
33  * GuiPainter - a painter implementation for Qt
34  */
35 class GuiPainter : public QPainter, public Painter {
36 public:
37         GuiPainter(QPaintDevice *, double pixel_ratio);
38         virtual ~GuiPainter();
39
40         /// This painter paints
41         virtual bool isNull() const { return false; }
42
43         /// draw a line from point to point
44         virtual void line(
45                 int x1, int y1,
46                 int x2, int y2,
47                 Color,
48                 line_style ls = line_solid,
49                 int lw = thin_line);
50
51         /**
52          * lines -  draw a set of lines
53          * @param xp array of points' x co-ords
54          * @param yp array of points' y co-ords
55          * @param np size of the points array
56          */
57         virtual void lines(
58                 int const * xp,
59                 int const * yp,
60                 int np,
61                 Color,
62                 fill_style fs = fill_none,
63                 line_style ls = line_solid,
64                 int lw = thin_line);
65
66         /**
67          * path -  draw a path with bezier curves
68          * @param xp array of points' x co-ords
69          * @param yp array of points' y co-ords
70          * @param c1x array of first control points' x co-ords
71          * @param c1y array of first control points' y co-ords
72          * @param c2x array of second control points' x co-ords
73          * @param c2y array of second control points' y co-ords
74          * @param np size of the points array
75          */
76         virtual void path(int const * xp, int const * yp,
77                 int const * c1x, int const * c1y,
78                 int const * c2x, int const * c2y,
79                 int np, Color,
80                 fill_style = fill_none, line_style = line_solid,
81                 int line_width = thin_line);
82
83         /// draw a rectangle
84         virtual void rectangle(
85                 int x, int y,
86                 int w, int h,
87                 Color,
88                 line_style = line_solid,
89                 int lw = thin_line);
90
91         /// draw a filled rectangle
92         virtual void fillRectangle(
93                 int x, int y,
94                 int w, int h,
95                 Color);
96
97         /// draw an arc
98         virtual void arc(
99                 int x, int y,
100                 unsigned int w, unsigned int h,
101                 int a1, int a2,
102                 Color);
103
104         /// draw a pixel
105         virtual void point(int x, int y, Color);
106
107         /// draw an image from the image cache
108         virtual void image(int x, int y, int w, int h,
109                 lyx::graphics::Image const & image);
110
111         /// draw a string at position x, y (y is the baseline).
112         virtual void text(int x, int y, docstring const & str, FontInfo const & f);
113
114         /// draw a char at position x, y (y is the baseline)
115         virtual void text(int x, int y, char_type c, FontInfo const & f);
116
117         /** draw a string at position x, y (y is the baseline). The
118          * text direction is enforced by the \c Font.
119          */
120         virtual void text(int x, int y, docstring const & str, Font const & f,
121                       double wordspacing, double textwidth);
122
123         /** draw a string at position x, y (y is the baseline), but
124          * make sure that the part between \c from and \c to is in
125          * \c other color. The text direction is enforced by the \c Font.
126          */
127         virtual void text(int x, int y, docstring const & str, Font const & f,
128                           Color other, size_type from, size_type to,
129                       double wordspacing, double textwidth);
130
131         ///
132         virtual void textDecoration(FontInfo const & f, int x, int y, int width);
133
134         /// draw a string and enclose it inside a button frame
135         virtual void buttonText(int x, int baseline, docstring const & s,
136                 FontInfo const & font, Color back, Color frame, int offset);
137
138         /// start monochrome painting mode, i.e. map every color into [min,max]
139         virtual void enterMonochromeMode(Color const & min,
140                 Color const & max);
141         /// leave monochrome painting mode
142         virtual void leaveMonochromeMode();
143
144         /**
145          * Draw a string and enclose it inside a rectangle. If
146          * back color is specified, the background is cleared with
147          * the given color. If frame is specified, a thin frame is drawn
148          * around the text with the given color.
149          */
150         virtual void rectText(int x, int baseline, docstring const & str,
151                 FontInfo const & font, Color back, Color frame);
152
153         /// draw a character of a preedit string for cjk support.
154         virtual int preeditText(int x, int y,
155                 char_type c, FontInfo const & f, preedit_style style);
156
157         void wavyHorizontalLine(int x, int y, int width, ColorCode col);
158
159 private:
160         /// check the font, and if set, draw an underline
161         void underline(FontInfo const & f,
162                        int x, int y, int width, line_style ls = line_solid);
163
164         /// check the font, and if set, draw an dashed underline
165         void dashedUnderline(FontInfo const & f,
166                 int x, int y, int width);
167
168         /// check the font, and if set, draw an strike-through line
169         void strikeoutLine(FontInfo const & f,
170                 int x, int y, int width);
171
172         /// check the font, and if set, draw cross-through lines
173         void crossoutLines(FontInfo const & f,
174                 int x, int y, int width);
175
176         /// check the font, and if set, draw double underline
177         void doubleUnderline(FontInfo const & f,
178                 int x, int y, int width);
179
180         /// set pen parameters
181         void setQPainterPen(QColor const & col,
182                 line_style ls = line_solid, int lw = thin_line);
183
184         // Direction for painting text
185         enum Direction { LtR, RtL, Auto };
186
187         // Real text() method
188         void text(int x, int y, docstring const & s,
189               FontInfo const & f, Direction const dir,
190               double const wordspacing, double tw);
191
192         QColor current_color_;
193         Painter::line_style current_ls_;
194         int current_lw_;
195         ///
196         std::stack<QColor> monochrome_min_;
197         ///
198         std::stack<QColor> monochrome_max_;
199         /// convert into Qt color, possibly applying the monochrome mode
200         QColor computeColor(Color col);
201         /// possibly apply monochrome mode
202         QColor filterColor(QColor const & col);
203 };
204
205 } // namespace frontend
206 } // namespace lyx
207
208 #endif // GUIPAINTER_H