4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
18 #include "frontends/Painter.h"
21 #include <QPainterPath>
31 * GuiPainter - a painter implementation for Qt
33 class GuiPainter : public QPainter, public Painter {
35 GuiPainter(QPaintDevice *, double pixel_ratio, bool devel_mode);
36 virtual ~GuiPainter();
38 /// This painter paints
39 bool isNull() const override { return false; }
41 /// draw a line from point to point
46 line_style ls = line_solid,
47 int lw = thin_line) override;
50 * lines - draw a set of lines
51 * @param xp array of points' x co-ords
52 * @param yp array of points' y co-ords
53 * @param np size of the points array
60 fill_style fs = fill_none,
61 line_style ls = line_solid,
62 int lw = thin_line) override;
65 * path - draw a path with bezier curves
66 * @param xp array of points' x co-ords
67 * @param yp array of points' y co-ords
68 * @param c1x array of first control points' x co-ords
69 * @param c1y array of first control points' y co-ords
70 * @param c2x array of second control points' x co-ords
71 * @param c2y array of second control points' y co-ords
72 * @param np size of the points array
74 void path(int const * xp, int const * yp,
75 int const * c1x, int const * c1y,
76 int const * c2x, int const * c2y,
78 fill_style = fill_none, line_style = line_solid,
79 int line_width = thin_line) override;
86 line_style = line_solid,
87 int lw = thin_line) override;
89 /// draw a filled rectangle
98 unsigned int w, unsigned int h,
105 double rx, double ry,
107 fill_style fs = fill_none,
108 line_style ls = line_solid,
109 int lw = thin_line) override;
112 void point(int x, int y, Color) override;
114 /// draw an image from the image cache
115 void image(int x, int y, int w, int h,
116 lyx::graphics::Image const & image, bool const darkmode = false) override;
118 /// draw a string at position x, y (y is the baseline).
119 void text(int x, int y, docstring const & str, FontInfo const & f) override;
121 /// draw a char at position x, y (y is the baseline)
122 void text(int x, int y, char_type c, FontInfo const & f) override;
124 /** draw a string at position x, y (y is the baseline). The
125 * text direction is enforced by the \c Font.
127 void text(int x, int y, docstring const & str, Font const & f,
128 double wordspacing, double textwidth) override;
130 /** draw a string at position x, y (y is the baseline), but
131 * make sure that the part between \c from and \c to is in
132 * \c other color. The text direction is enforced by the \c Font.
134 void text(int x, int y, docstring const & str, Font const & f,
135 Color other, size_type from, size_type to,
136 double wordspacing, double textwidth) override;
139 void textDecoration(FontInfo const & f, int x, int y, int width) override;
141 /// draw a string and enclose it inside a button frame
142 void buttonText(int x, int baseline, docstring const & s,
143 FontInfo const & font, Color back, Color frame, int offset) override;
145 /// start monochrome painting mode, i.e. map every color a shade of \c blend.
146 void enterMonochromeMode(Color const & blend) override;
147 /// leave monochrome painting mode
148 void leaveMonochromeMode() override;
151 * Draw a string and enclose it inside a rectangle. If
152 * back color is specified, the background is cleared with
153 * the given color. If frame is specified, a thin frame is drawn
154 * around the text with the given color.
156 void rectText(int x, int baseline, docstring const & str,
157 FontInfo const & font, Color back, Color frame) override;
159 /// draw a character of a preedit string for cjk support.
160 int preeditText(int x, int y,
161 char_type c, FontInfo const & f, preedit_style style) override;
163 void wavyHorizontalLine(FontInfo const & f, int x, int y, int width, ColorCode col) override;
166 /// check the font, and if set, draw an underline
167 void underline(FontInfo const & f,
168 int x, int y, int width, line_style ls = line_solid);
170 /// check the font, and if set, draw an dashed underline
171 void dashedUnderline(FontInfo const & f,
172 int x, int y, int width);
174 /// check the font, and if set, draw an strike-through line
175 void strikeoutLine(FontInfo const & f,
176 int x, int y, int width);
178 /// check the font, and if set, draw cross-through lines
179 void crossoutLines(FontInfo const & f,
180 int x, int y, int width);
182 /// check the font, and if set, draw double underline
183 void doubleUnderline(FontInfo const & f,
184 int x, int y, int width);
186 /// set pen parameters
187 void setQPainterPen(QColor const & col,
188 line_style ls = line_solid, int lw = thin_line,
189 Qt::PenJoinStyle js = Qt::BevelJoin);
191 // Direction for painting text
192 enum Direction { LtR, RtL, Auto };
194 // Real text() method
195 void text(int x, int y, docstring const & s,
196 FontInfo const & f, Direction const dir,
197 double const wordspacing, double tw);
199 QColor current_color_;
200 Painter::line_style current_ls_;
203 std::stack<QColor> monochrome_blend_;
204 /// convert into Qt color, possibly applying the monochrome mode
205 QColor computeColor(Color col);
206 /// possibly apply monochrome mode
207 QColor filterColor(QColor const & col);
210 } // namespace frontend
213 #endif // GUIPAINTER_H