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,
103 void point(int x, int y, Color) override;
105 /// draw an image from the image cache
106 void image(int x, int y, int w, int h,
107 lyx::graphics::Image const & image, bool const darkmode = false) override;
109 /// draw a string at position x, y (y is the baseline).
110 void text(int x, int y, docstring const & str, FontInfo const & f) override;
112 /// draw a char at position x, y (y is the baseline)
113 void text(int x, int y, char_type c, FontInfo const & f) override;
115 /** draw a string at position x, y (y is the baseline). The
116 * text direction is enforced by the \c Font.
118 void text(int x, int y, docstring const & str, Font const & f,
119 double wordspacing, double textwidth) override;
121 /** draw a string at position x, y (y is the baseline), but
122 * make sure that the part between \c from and \c to is in
123 * \c other color. The text direction is enforced by the \c Font.
125 void text(int x, int y, docstring const & str, Font const & f,
126 Color other, size_type from, size_type to,
127 double wordspacing, double textwidth) override;
130 void textDecoration(FontInfo const & f, int x, int y, int width) override;
132 /// draw a string and enclose it inside a button frame
133 void buttonText(int x, int baseline, docstring const & s,
134 FontInfo const & font, Color back, Color frame, int offset) override;
136 /// start monochrome painting mode, i.e. map every color a shade of \c blend.
137 void enterMonochromeMode(Color const & blend) override;
138 /// leave monochrome painting mode
139 void leaveMonochromeMode() override;
142 * Draw a string and enclose it inside a rectangle. If
143 * back color is specified, the background is cleared with
144 * the given color. If frame is specified, a thin frame is drawn
145 * around the text with the given color.
147 void rectText(int x, int baseline, docstring const & str,
148 FontInfo const & font, Color back, Color frame) override;
150 /// draw a character of a preedit string for cjk support.
151 int preeditText(int x, int y,
152 char_type c, FontInfo const & f, preedit_style style) override;
154 void wavyHorizontalLine(int x, int y, int width, ColorCode col) override;
157 /// check the font, and if set, draw an underline
158 void underline(FontInfo const & f,
159 int x, int y, int width, line_style ls = line_solid);
161 /// check the font, and if set, draw an dashed underline
162 void dashedUnderline(FontInfo const & f,
163 int x, int y, int width);
165 /// check the font, and if set, draw an strike-through line
166 void strikeoutLine(FontInfo const & f,
167 int x, int y, int width);
169 /// check the font, and if set, draw cross-through lines
170 void crossoutLines(FontInfo const & f,
171 int x, int y, int width);
173 /// check the font, and if set, draw double underline
174 void doubleUnderline(FontInfo const & f,
175 int x, int y, int width);
177 /// set pen parameters
178 void setQPainterPen(QColor const & col,
179 line_style ls = line_solid, int lw = thin_line);
181 // Direction for painting text
182 enum Direction { LtR, RtL, Auto };
184 // Real text() method
185 void text(int x, int y, docstring const & s,
186 FontInfo const & f, Direction const dir,
187 double const wordspacing, double tw);
189 QColor current_color_;
190 Painter::line_style current_ls_;
193 std::stack<QColor> monochrome_blend_;
194 /// convert into Qt color, possibly applying the monochrome mode
195 QColor computeColor(Color col);
196 /// possibly apply monochrome mode
197 QColor filterColor(QColor const & col);
200 } // namespace frontend
203 #endif // GUIPAINTER_H