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);
38 virtual ~GuiPainter();
40 /// draw a line from point to point
45 line_style ls = line_solid,
49 * lines - draw a set of lines
50 * @param xp array of points' x co-ords
51 * @param yp array of points' y co-ords
52 * @param np size of the points array
59 fill_style fs = fill_none,
60 line_style ls = line_solid,
64 * path - draw a path with bezier curves
65 * @param xp array of points' x co-ords
66 * @param yp array of points' y co-ords
67 * @param c1x array of first control points' x co-ords
68 * @param c1y array of first control points' y co-ords
69 * @param c2x array of second control points' x co-ords
70 * @param c2y array of second control points' y co-ords
71 * @param np size of the points array
73 virtual void path(int const * xp, int const * yp,
74 int const * c1x, int const * c1y,
75 int const * c2x, int const * c2y,
77 fill_style = fill_none, line_style = line_solid,
78 int line_width = thin_line);
81 virtual void rectangle(
85 line_style = line_solid,
88 /// draw a filled rectangle
89 virtual void fillRectangle(
97 unsigned int w, unsigned int h,
102 virtual void point(int x, int y, Color);
104 /// draw an image from the image cache
105 virtual void image(int x, int y, int w, int h,
106 lyx::graphics::Image const & image);
108 /** draw a string at position x, y (y is the baseline). The
109 * text direction is given by \c rtl.
110 * \return the width of the drawn text.
112 virtual int text(int x, int y, docstring const & str, FontInfo const & f,
113 bool rtl = false, double wordspacing = 0.0);
115 /** draw a string at position x, y (y is the baseline). The
116 * text direction is enforced by the \c Font.
117 * \return the width of the drawn text.
119 virtual int text(int x, int y, docstring const & str, Font const & f,
120 double wordspacing = 0.0);
122 /** draw a string at position x, y (y is the baseline), but
123 * make sure that the part between \c from and \c to is in
124 * \c other color. The text direction is enforced by the \c Font.
125 * \return the width of the drawn text.
127 virtual int text(int x, int y, docstring const & str, Font const & f,
128 Color other, size_type from, size_type to,
129 double const wordspacing);
131 /// draw a char at position x, y (y is the baseline)
132 virtual int text(int x, int y, char_type c, FontInfo const & f);
135 virtual void textDecoration(FontInfo const & f, int x, int y, int width);
137 /// draw a string and enclose it inside a button frame
138 virtual void buttonText(int x, int baseline, docstring const & s,
139 FontInfo const & font, bool mouseHover);
141 /// start monochrome painting mode, i.e. map every color into [min,max]
142 virtual void enterMonochromeMode(Color const & min,
144 /// leave monochrome painting mode
145 virtual void leaveMonochromeMode();
148 * Draw a string and enclose it inside a rectangle. If
149 * back color is specified, the background is cleared with
150 * the given color. If frame is specified, a thin frame is drawn
151 * around the text with the given color.
153 virtual void rectText(int x, int baseline, docstring const & str,
154 FontInfo const & font, Color back, Color frame);
156 /// draw a filled rectangle with the shape of a 3D button
157 virtual void button(int x, int y, int w, int h, bool mouseHover);
159 /// draw a character of a preedit string for cjk support.
160 virtual int preeditText(int x, int y,
161 char_type c, FontInfo const & f, preedit_style style);
163 void wavyHorizontalLine(int x, int y, int width, ColorCode col);
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 double underline
179 void doubleUnderline(FontInfo const & f,
180 int x, int y, int width);
182 /// draw a bevelled button border
183 void buttonFrame(int x, int y, int w, int h);
185 /// set pen parameters
186 void setQPainterPen(QColor const & col,
187 line_style ls = line_solid, int lw = thin_line);
189 // Helper for text() method
190 void do_drawText(int x, int y, QString str, bool rtl, FontInfo const & f, QFont ff);
192 QColor current_color_;
193 Painter::line_style current_ls_;
196 bool const use_pixmap_cache_;
198 std::stack<QColor> monochrome_min_;
200 std::stack<QColor> monochrome_max_;
201 /// convert into Qt color, possibly applying the monochrome mode
202 QColor computeColor(Color col);
203 /// possibly apply monochrome mode
204 QColor filterColor(QColor const & col);
206 QString generateStringSignature(QString const & str, FontInfo const & f,
210 } // namespace frontend
213 #endif // GUIPAINTER_H