]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPainter.h
Make the different Painter::text void methods
[lyx.git] / src / frontends / qt4 / GuiPainter.h
1 // -*- C++ -*-
2 /**
3  * \file GuiPainter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef GUIPAINTER_H
14 #define GUIPAINTER_H
15
16 #include "Color.h"
17
18 #include "frontends/Painter.h"
19
20 #include <QPainter>
21 #include <QPainterPath>
22 #include <stack>
23
24 class QString;
25
26 namespace lyx {
27
28 class FontInfo;
29
30 namespace frontend {
31
32 /**
33  * GuiPainter - a painter implementation for Qt
34  */
35 class GuiPainter : public QPainter, public Painter {
36 public:
37         GuiPainter(QPaintDevice *, double pixel_ratio);
38         virtual ~GuiPainter();
39
40         /// draw a line from point to point
41         virtual void line(
42                 int x1, int y1,
43                 int x2, int y2,
44                 Color,
45                 line_style ls = line_solid,
46                 int lw = thin_line);
47
48         /**
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
53          */
54         virtual void lines(
55                 int const * xp,
56                 int const * yp,
57                 int np,
58                 Color,
59                 fill_style fs = fill_none,
60                 line_style ls = line_solid,
61                 int lw = thin_line);
62
63         /**
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
72          */
73         virtual void path(int const * xp, int const * yp,
74                 int const * c1x, int const * c1y,
75                 int const * c2x, int const * c2y,
76                 int np, Color,
77                 fill_style = fill_none, line_style = line_solid,
78                 int line_width = thin_line);
79
80         /// draw a rectangle
81         virtual void rectangle(
82                 int x, int y,
83                 int w, int h,
84                 Color,
85                 line_style = line_solid,
86                 int lw = thin_line);
87
88         /// draw a filled rectangle
89         virtual void fillRectangle(
90                 int x, int y,
91                 int w, int h,
92                 Color);
93
94         /// draw an arc
95         virtual void arc(
96                 int x, int y,
97                 unsigned int w, unsigned int h,
98                 int a1, int a2,
99                 Color);
100
101         /// draw a pixel
102         virtual void point(int x, int y, Color);
103
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);
107
108         /** draw a string at position x, y (y is the baseline). The
109          * text direction is given by \c rtl.
110          */
111         virtual void text(int x, int y, docstring const & str, FontInfo const & f,
112                       bool rtl = false, double wordspacing = 0.0);
113
114         /** draw a string at position x, y (y is the baseline). The
115          * text direction is enforced by the \c Font.
116          */
117         virtual void text(int x, int y, docstring const & str, Font const & f,
118                       double wordspacing = 0.0);
119
120         /** draw a string at position x, y (y is the baseline), but
121          * make sure that the part between \c from and \c to is in
122          * \c other color. The text direction is enforced by the \c Font.
123          */
124         virtual void text(int x, int y, docstring const & str, Font const & f,
125                           Color other, size_type from, size_type to,
126                       double const wordspacing);
127
128         /// draw a char at position x, y (y is the baseline)
129         virtual void text(int x, int y, char_type c, FontInfo const & f);
130
131         ///
132         virtual void textDecoration(FontInfo const & f, int x, int y, int width);
133
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, bool mouseHover);
137
138         /// start monochrome painting mode, i.e. map every color into [min,max]
139         virtual void enterMonochromeMode(Color const & min, 
140                 Color const & max);
141         /// leave monochrome painting mode
142         virtual void leaveMonochromeMode();
143         
144         /**
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.
149          */
150         virtual void rectText(int x, int baseline, docstring const & str,
151                 FontInfo const & font, Color back, Color frame);
152
153         /// draw a filled rectangle with the shape of a 3D button
154         virtual void button(int x, int y, int w, int h, bool mouseHover);
155
156         /// draw a character of a preedit string for cjk support.
157         virtual int preeditText(int x, int y,
158                 char_type c, FontInfo const & f, preedit_style style);
159
160         void wavyHorizontalLine(int x, int y, int width, ColorCode col);
161
162 private:
163         /// check the font, and if set, draw an underline
164         void underline(FontInfo const & f,
165                        int x, int y, int width, line_style ls = line_solid);
166
167         /// check the font, and if set, draw an dashed underline
168         void dashedUnderline(FontInfo const & f,
169                 int x, int y, int width);
170
171         /// check the font, and if set, draw an strike-through line
172         void strikeoutLine(FontInfo const & f,
173                 int x, int y, int width);
174
175         /// check the font, and if set, draw double underline
176         void doubleUnderline(FontInfo const & f,
177                 int x, int y, int width);
178
179         /// draw a bevelled button border
180         void buttonFrame(int x, int y, int w, int h);
181
182         /// set pen parameters
183         void setQPainterPen(QColor const & col,
184                 line_style ls = line_solid, int lw = thin_line);
185
186         // Helper for text() method
187         void do_drawText(int x, int y, QString str, bool rtl, FontInfo const & f, QFont ff);
188
189         QColor current_color_;
190         Painter::line_style current_ls_;
191         int current_lw_;
192         ///
193         bool const use_pixmap_cache_;
194         ///
195         std::stack<QColor> monochrome_min_;
196         ///
197         std::stack<QColor> monochrome_max_;
198         /// convert into Qt color, possibly applying the monochrome mode
199         QColor computeColor(Color col);
200         /// possibly apply monochrome mode
201         QColor filterColor(QColor const & col);
202         ///
203         QString generateStringSignature(QString const & str, FontInfo const & f,
204                                         double wordspacing);
205 };
206
207 } // namespace frontend
208 } // namespace lyx
209
210 #endif // GUIPAINTER_H