]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPainter.h
Fix a bunch of minor issues discovered by the cppcheck script.
[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 <stack>
22
23 class QString;
24
25 namespace lyx {
26
27 class FontInfo;
28
29 namespace frontend {
30
31 /**
32  * GuiPainter - a painter implementation for Qt4
33  */
34 class GuiPainter : public QPainter, public Painter {
35 public:
36         GuiPainter(QPaintDevice *);
37         virtual ~GuiPainter();
38
39         /// draw a line from point to point
40         virtual void line(
41                 int x1, int y1,
42                 int x2, int y2,
43                 Color,
44                 line_style ls = line_solid,
45                 float lw = thin_line);
46
47         /**
48          * lines -  draw a set of lines
49          * @param xp array of points' x co-ords
50          * @param yp array of points' y co-ords
51          * @param np size of the points array
52          */
53         virtual void lines(
54                 int const * xp,
55                 int const * yp,
56                 int np,
57                 Color,
58                 line_style ls = line_solid,
59                 float lw = thin_line);
60
61         /// draw a rectangle
62         virtual void rectangle(
63                 int x, int y,
64                 int w, int h,
65                 Color,
66                 line_style = line_solid,
67                 float lw = thin_line);
68
69         /// draw a filled rectangle
70         virtual void fillRectangle(
71                 int x, int y,
72                 int w, int h,
73                 Color);
74
75         /// draw an arc
76         virtual void arc(
77                 int x, int y,
78                 unsigned int w, unsigned int h,
79                 int a1, int a2,
80                 Color);
81
82         /// draw a pixel
83         virtual void point(int x, int y, Color);
84
85         /// draw an image from the image cache
86         virtual void image(int x, int y, int w, int h,
87                 lyx::graphics::Image const & image);
88
89         /// draw a string at position x, y (y is the baseline)
90         virtual int text(int x, int y,
91                 docstring const & str, FontInfo const & f);
92
93         /// draw a char at position x, y (y is the baseline)
94         virtual int text(int x, int y, char_type c, FontInfo const & f);
95
96         ///
97         virtual void textDecoration(FontInfo const & f, int x, int y, int width);
98
99         /// draw a string and enclose it inside a button frame
100         virtual void buttonText(int x, int baseline, docstring const & s,
101                 FontInfo const & font, bool mouseHover);
102
103         /// start monochrome painting mode, i.e. map every color into [min,max]
104         virtual void enterMonochromeMode(Color const & min, 
105                 Color const & max);
106         /// leave monochrome painting mode
107         virtual void leaveMonochromeMode();
108         
109         /**
110          * Draw a string and enclose it inside a rectangle. If
111          * back color is specified, the background is cleared with
112          * the given color. If frame is specified, a thin frame is drawn
113          * around the text with the given color.
114          */
115         virtual void rectText(int x, int baseline, docstring const & str,
116                 FontInfo const & font, Color back, Color frame);
117
118         /// draw a filled rectangle with the shape of a 3D button
119         virtual void button(int x, int y, int w, int h, bool mouseHover);
120
121         /// draw a character of a preedit string for cjk support.
122         virtual int preeditText(int x, int y,
123                 char_type c, FontInfo const & f, preedit_style style);
124
125         void wavyHorizontalLine(int x, int y, int width, ColorCode col);
126
127 private:
128         /// check the font, and if set, draw an underline
129         void underline(FontInfo const & f,
130                 int x, int y, int width);
131
132         /// check the font, and if set, draw an dashed underline
133         void dashedUnderline(FontInfo const & f,
134                 int x, int y, int width);
135
136         /// check the font, and if set, draw an strike-through line
137         void strikeoutLine(FontInfo const & f,
138                 int x, int y, int width);
139
140         /// check the font, and if set, draw double underline
141         void doubleUnderline(FontInfo const & f,
142                 int x, int y, int width);
143
144         /// draw a bevelled button border
145         void buttonFrame(int x, int y, int w, int h);
146
147         /// draw small caps text
148         /**
149         \return width of the drawn text.
150         */
151         int smallCapsText(int x, int y,
152                 QString const & str, FontInfo const & f);
153
154         /// set pen parameters
155         void setQPainterPen(QColor const & col,
156                 line_style ls = line_solid, float lw = thin_line);
157
158         QColor current_color_;
159         Painter::line_style current_ls_;
160         float current_lw_;
161         ///
162         bool const use_pixmap_cache_;
163         ///
164         std::stack<QColor> monochrome_min_;
165         ///
166         std::stack<QColor> monochrome_max_;
167         /// convert into Qt color, possibly applying the monochrome mode
168         QColor computeColor(Color col);
169         /// possibly apply monochrome mode
170         QColor filterColor(QColor const & col);
171         ///
172         QString generateStringSignature(QString const & str, FontInfo const & f);       
173 };
174
175 } // namespace frontend
176 } // namespace lyx
177
178 #endif // GUIPAINTER_H