]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiPainter.h
#10571 improved handling of WM's signal when switching from or to full-screen window
[features.git] / src / frontends / qt / 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, bool devel_mode);
38         virtual ~GuiPainter();
39
40         /// This painter paints
41         virtual bool isNull() const { return false; }
42
43         /// draw a line from point to point
44         virtual void line(
45                 int x1, int y1,
46                 int x2, int y2,
47                 Color,
48                 line_style ls = line_solid,
49                 int lw = thin_line);
50
51         /**
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
56          */
57         virtual void lines(
58                 int const * xp,
59                 int const * yp,
60                 int np,
61                 Color,
62                 fill_style fs = fill_none,
63                 line_style ls = line_solid,
64                 int lw = thin_line);
65
66         /**
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
75          */
76         virtual void path(int const * xp, int const * yp,
77                 int const * c1x, int const * c1y,
78                 int const * c2x, int const * c2y,
79                 int np, Color,
80                 fill_style = fill_none, line_style = line_solid,
81                 int line_width = thin_line);
82
83         /// draw a rectangle
84         virtual void rectangle(
85                 int x, int y,
86                 int w, int h,
87                 Color,
88                 line_style = line_solid,
89                 int lw = thin_line);
90
91         /// draw a filled rectangle
92         virtual void fillRectangle(
93                 int x, int y,
94                 int w, int h,
95                 Color);
96
97         /// draw an arc
98         virtual void arc(
99                 int x, int y,
100                 unsigned int w, unsigned int h,
101                 int a1, int a2,
102                 Color);
103
104         /// draw a pixel
105         virtual void point(int x, int y, Color);
106
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);
110
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);
113
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);
116
117         /** draw a string at position x, y (y is the baseline). The
118          * text direction is enforced by the \c Font.
119          */
120         virtual void text(int x, int y, docstring const & str, Font const & f,
121                       double wordspacing, double textwidth);
122
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.
126          */
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);
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, Color back, Color frame, int offset);
137
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();
142
143         /**
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.
148          */
149         virtual void rectText(int x, int baseline, docstring const & str,
150                 FontInfo const & font, Color back, Color frame);
151
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);
155
156         void wavyHorizontalLine(int x, int y, int width, ColorCode col);
157
158 private:
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);
162
163         /// check the font, and if set, draw an dashed underline
164         void dashedUnderline(FontInfo const & f,
165                 int x, int y, int width);
166
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);
170
171         /// check the font, and if set, draw cross-through lines
172         void crossoutLines(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         /// set pen parameters
180         void setQPainterPen(QColor const & col,
181                 line_style ls = line_solid, int lw = thin_line);
182
183         // Direction for painting text
184         enum Direction { LtR, RtL, Auto };
185
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);
190
191         QColor current_color_;
192         Painter::line_style current_ls_;
193         int current_lw_;
194         ///
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);
200 };
201
202 } // namespace frontend
203 } // namespace lyx
204
205 #endif // GUIPAINTER_H