]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiPainter.h
Keep dialog connected to cross-ref inset after Apply.
[lyx.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 namespace lyx {
25
26 class FontInfo;
27
28 namespace frontend {
29
30 /**
31  * GuiPainter - a painter implementation for Qt
32  */
33 class GuiPainter : public QPainter, public Painter {
34 public:
35         GuiPainter(QPaintDevice *, double pixel_ratio, bool devel_mode);
36         virtual ~GuiPainter();
37
38         /// This painter paints
39         bool isNull() const override { return false; }
40
41         /// draw a line from point to point
42         void line(
43                 int x1, int y1,
44                 int x2, int y2,
45                 Color,
46                 line_style ls = line_solid,
47                 int lw = thin_line) override;
48
49         /**
50          * lines -  draw a set of lines
51          * @param xp array of points' x co-ords
52          * @param yp array of points' y co-ords
53          * @param np size of the points array
54          */
55         void lines(
56                 int const * xp,
57                 int const * yp,
58                 int np,
59                 Color,
60                 fill_style fs = fill_none,
61                 line_style ls = line_solid,
62                 int lw = thin_line) override;
63
64         /**
65          * path -  draw a path with bezier curves
66          * @param xp array of points' x co-ords
67          * @param yp array of points' y co-ords
68          * @param c1x array of first control points' x co-ords
69          * @param c1y array of first control points' y co-ords
70          * @param c2x array of second control points' x co-ords
71          * @param c2y array of second control points' y co-ords
72          * @param np size of the points array
73          */
74         void path(int const * xp, int const * yp,
75                 int const * c1x, int const * c1y,
76                 int const * c2x, int const * c2y,
77                 int np, Color,
78                 fill_style = fill_none, line_style = line_solid,
79                 int line_width = thin_line) override;
80
81         /// draw a rectangle
82         void rectangle(
83                 int x, int y,
84                 int w, int h,
85                 Color,
86                 line_style = line_solid,
87                 int lw = thin_line) override;
88
89         /// draw a filled rectangle
90         void fillRectangle(
91                 int x, int y,
92                 int w, int h,
93                 Color) override;
94
95         /// draw an arc
96         void arc(
97                 int x, int y,
98                 unsigned int w, unsigned int h,
99                 int a1, int a2,
100                 Color) override;
101
102         /// draw a pixel
103         void point(int x, int y, Color) override;
104
105         /// draw an image from the image cache
106         void image(int x, int y, int w, int h,
107                 lyx::graphics::Image const & image, bool const darkmode = false) override;
108
109         /// draw a string at position x, y (y is the baseline).
110         void text(int x, int y, docstring const & str, FontInfo const & f) override;
111
112         /// draw a char at position x, y (y is the baseline)
113         void text(int x, int y, char_type c, FontInfo const & f) override;
114
115         /** draw a string at position x, y (y is the baseline). The
116          * text direction is enforced by the \c Font.
117          */
118         void text(int x, int y, docstring const & str, Font const & f,
119                       double wordspacing, double textwidth) override;
120
121         /** draw a string at position x, y (y is the baseline), but
122          * make sure that the part between \c from and \c to is in
123          * \c other color. The text direction is enforced by the \c Font.
124          */
125         void text(int x, int y, docstring const & str, Font const & f,
126                           Color other, size_type from, size_type to,
127                       double wordspacing, double textwidth) override;
128
129         ///
130         void textDecoration(FontInfo const & f, int x, int y, int width) override;
131
132         /// draw a string and enclose it inside a button frame
133         void buttonText(int x, int baseline, docstring const & s,
134                 FontInfo const & font, Color back, Color frame, int offset) override;
135
136         /// start monochrome painting mode, i.e. map every color a shade of \c blend.
137         void enterMonochromeMode(Color const & blend) override;
138         /// leave monochrome painting mode
139         void leaveMonochromeMode() override;
140
141         /**
142          * Draw a string and enclose it inside a rectangle. If
143          * back color is specified, the background is cleared with
144          * the given color. If frame is specified, a thin frame is drawn
145          * around the text with the given color.
146          */
147         void rectText(int x, int baseline, docstring const & str,
148                 FontInfo const & font, Color back, Color frame) override;
149
150         /// draw a character of a preedit string for cjk support.
151         int preeditText(int x, int y,
152                 char_type c, FontInfo const & f, preedit_style style) override;
153
154         void wavyHorizontalLine(int x, int y, int width, ColorCode col) override;
155
156 private:
157         /// check the font, and if set, draw an underline
158         void underline(FontInfo const & f,
159                        int x, int y, int width, line_style ls = line_solid);
160
161         /// check the font, and if set, draw an dashed underline
162         void dashedUnderline(FontInfo const & f,
163                 int x, int y, int width);
164
165         /// check the font, and if set, draw an strike-through line
166         void strikeoutLine(FontInfo const & f,
167                 int x, int y, int width);
168
169         /// check the font, and if set, draw cross-through lines
170         void crossoutLines(FontInfo const & f,
171                 int x, int y, int width);
172
173         /// check the font, and if set, draw double underline
174         void doubleUnderline(FontInfo const & f,
175                 int x, int y, int width);
176
177         /// set pen parameters
178         void setQPainterPen(QColor const & col,
179                 line_style ls = line_solid, int lw = thin_line);
180
181         // Direction for painting text
182         enum Direction { LtR, RtL, Auto };
183
184         // Real text() method
185         void text(int x, int y, docstring const & s,
186               FontInfo const & f, Direction const dir,
187               double const wordspacing, double tw);
188
189         QColor current_color_;
190         Painter::line_style current_ls_;
191         int current_lw_;
192         ///
193         std::stack<QColor> monochrome_blend_;
194         /// convert into Qt color, possibly applying the monochrome mode
195         QColor computeColor(Color col);
196         /// possibly apply monochrome mode
197         QColor filterColor(QColor const & col);
198 };
199
200 } // namespace frontend
201 } // namespace lyx
202
203 #endif // GUIPAINTER_H