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 into [min,max]
139 virtual void enterMonochromeMode(Color const & min,
141 /// leave monochrome painting mode
142 virtual void leaveMonochromeMode();
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.
150 virtual void rectText(int x, int baseline, docstring const & str,
151 FontInfo const & font, Color back, Color frame);
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);
157 void wavyHorizontalLine(int x, int y, int width, ColorCode col);
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);
164 /// check the font, and if set, draw an dashed underline
165 void dashedUnderline(FontInfo const & f,
166 int x, int y, int width);
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);
172 /// check the font, and if set, draw cross-through lines
173 void crossoutLines(FontInfo const & f,
174 int x, int y, int width);
176 /// check the font, and if set, draw double underline
177 void doubleUnderline(FontInfo const & f,
178 int x, int y, int width);
180 /// set pen parameters
181 void setQPainterPen(QColor const & col,
182 line_style ls = line_solid, int lw = thin_line);
184 // Direction for painting text
185 enum Direction { LtR, RtL, Auto };
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);
192 QColor current_color_;
193 Painter::line_style current_ls_;
196 std::stack<QColor> monochrome_min_;
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);
205 } // namespace frontend
208 #endif // GUIPAINTER_H