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>
33 * GuiPainter - a painter implementation for Qt
35 class GuiPainter : public QPainter, public Painter {
37 GuiPainter(QPaintDevice *, double pixel_ratio, bool devel_mode);
38 virtual ~GuiPainter();
40 /// This painter paints
41 virtual bool isNull() const { return false; }
43 /// draw a line from point to point
48 line_style ls = line_solid,
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
62 fill_style fs = fill_none,
63 line_style ls = line_solid,
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
76 virtual void path(int const * xp, int const * yp,
77 int const * c1x, int const * c1y,
78 int const * c2x, int const * c2y,
80 fill_style = fill_none, line_style = line_solid,
81 int line_width = thin_line);
84 virtual void rectangle(
88 line_style = line_solid,
91 /// draw a filled rectangle
92 virtual void fillRectangle(
100 unsigned int w, unsigned int h,
105 virtual void point(int x, int y, Color);
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);
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);
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);
117 /** draw a string at position x, y (y is the baseline). The
118 * text direction is enforced by the \c Font.
120 virtual void text(int x, int y, docstring const & str, Font const & f,
121 double wordspacing, double textwidth);
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.
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);
132 virtual void textDecoration(FontInfo const & f, int x, int y, int width);
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);
138 /// start monochrome painting mode, i.e. map every color a shade of \c blend.
139 virtual void enterMonochromeMode(Color const & blend);
140 /// leave monochrome painting mode
141 virtual void leaveMonochromeMode();
144 * Draw a string and enclose it inside a rectangle. If
145 * back color is specified, the background is cleared with
146 * the given color. If frame is specified, a thin frame is drawn
147 * around the text with the given color.
149 virtual void rectText(int x, int baseline, docstring const & str,
150 FontInfo const & font, Color back, Color frame);
152 /// draw a character of a preedit string for cjk support.
153 virtual int preeditText(int x, int y,
154 char_type c, FontInfo const & f, preedit_style style);
156 void wavyHorizontalLine(int x, int y, int width, ColorCode col);
159 /// check the font, and if set, draw an underline
160 void underline(FontInfo const & f,
161 int x, int y, int width, line_style ls = line_solid);
163 /// check the font, and if set, draw an dashed underline
164 void dashedUnderline(FontInfo const & f,
165 int x, int y, int width);
167 /// check the font, and if set, draw an strike-through line
168 void strikeoutLine(FontInfo const & f,
169 int x, int y, int width);
171 /// check the font, and if set, draw cross-through lines
172 void crossoutLines(FontInfo const & f,
173 int x, int y, int width);
175 /// check the font, and if set, draw double underline
176 void doubleUnderline(FontInfo const & f,
177 int x, int y, int width);
179 /// set pen parameters
180 void setQPainterPen(QColor const & col,
181 line_style ls = line_solid, int lw = thin_line);
183 // Direction for painting text
184 enum Direction { LtR, RtL, Auto };
186 // Real text() method
187 void text(int x, int y, docstring const & s,
188 FontInfo const & f, Direction const dir,
189 double const wordspacing, double tw);
191 QColor current_color_;
192 Painter::line_style current_ls_;
195 std::stack<QColor> monochrome_blend_;
196 /// convert into Qt color, possibly applying the monochrome mode
197 QColor computeColor(Color col);
198 /// possibly apply monochrome mode
199 QColor filterColor(QColor const & col);
202 } // namespace frontend
205 #endif // GUIPAINTER_H