]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPainter.h
5538d14fe4faa84c43f63593f989905de32aeddb
[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 Qt
33  */
34 class GuiPainter : public QPainter, public Painter {
35 public:
36         GuiPainter(QPaintDevice *, double pixel_ratio);
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                 int 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                 fill_style fs = fill_none,
59                 line_style ls = line_solid,
60                 int lw = thin_line);
61
62         /// draw a rectangle
63         virtual void rectangle(
64                 int x, int y,
65                 int w, int h,
66                 Color,
67                 line_style = line_solid,
68                 int lw = thin_line);
69
70         /// draw a filled rectangle
71         virtual void fillRectangle(
72                 int x, int y,
73                 int w, int h,
74                 Color);
75
76         /// draw an arc
77         virtual void arc(
78                 int x, int y,
79                 unsigned int w, unsigned int h,
80                 int a1, int a2,
81                 Color);
82
83         /// draw a pixel
84         virtual void point(int x, int y, Color);
85
86         /// draw an image from the image cache
87         virtual void image(int x, int y, int w, int h,
88                 lyx::graphics::Image const & image);
89
90         /** draw a string at position x, y (y is the baseline). The
91          * text direction is given by \c rtl.
92          * \return the width of the drawn text.
93          */
94         virtual int text(int x, int y, docstring const & str, FontInfo const & f,
95                      bool rtl = false, double wordspacing = 0.0);
96
97         /** draw a string at position x, y (y is the baseline). The
98          * text direction is enforced by the \c Font.
99          * \return the width of the drawn text.
100          */
101         virtual int text(int x, int y, docstring const & str, Font const & f,
102                      double wordspacing = 0.0);
103
104         /** draw a string at position x, y (y is the baseline), but
105          * make sure that the part between \c from and \c to is in
106          * \c other color. The text direction is enforced by the \c Font.
107          * \return the width of the drawn text.
108          */
109         virtual int text(int x, int y, docstring const & str, Font const & f,
110                      Color other, size_type from, size_type to,
111                      double const wordspacing);
112
113         /// draw a char at position x, y (y is the baseline)
114         virtual int text(int x, int y, char_type c, FontInfo const & f);
115
116         ///
117         virtual void textDecoration(FontInfo const & f, int x, int y, int width);
118
119         /// draw a string and enclose it inside a button frame
120         virtual void buttonText(int x, int baseline, docstring const & s,
121                 FontInfo const & font, bool mouseHover);
122
123         /// start monochrome painting mode, i.e. map every color into [min,max]
124         virtual void enterMonochromeMode(Color const & min, 
125                 Color const & max);
126         /// leave monochrome painting mode
127         virtual void leaveMonochromeMode();
128         
129         /**
130          * Draw a string and enclose it inside a rectangle. If
131          * back color is specified, the background is cleared with
132          * the given color. If frame is specified, a thin frame is drawn
133          * around the text with the given color.
134          */
135         virtual void rectText(int x, int baseline, docstring const & str,
136                 FontInfo const & font, Color back, Color frame);
137
138         /// draw a filled rectangle with the shape of a 3D button
139         virtual void button(int x, int y, int w, int h, bool mouseHover);
140
141         /// draw a character of a preedit string for cjk support.
142         virtual int preeditText(int x, int y,
143                 char_type c, FontInfo const & f, preedit_style style);
144
145         void wavyHorizontalLine(int x, int y, int width, ColorCode col);
146
147 private:
148         /// check the font, and if set, draw an underline
149         void underline(FontInfo const & f,
150                 int x, int y, int width);
151
152         /// check the font, and if set, draw an dashed underline
153         void dashedUnderline(FontInfo const & f,
154                 int x, int y, int width);
155
156         /// check the font, and if set, draw an strike-through line
157         void strikeoutLine(FontInfo const & f,
158                 int x, int y, int width);
159
160         /// check the font, and if set, draw double underline
161         void doubleUnderline(FontInfo const & f,
162                 int x, int y, int width);
163
164         /// draw a bevelled button border
165         void buttonFrame(int x, int y, int w, int h);
166
167         /// set pen parameters
168         void setQPainterPen(QColor const & col,
169                 line_style ls = line_solid, int lw = thin_line);
170
171         QColor current_color_;
172         Painter::line_style current_ls_;
173         int current_lw_;
174         ///
175         bool const use_pixmap_cache_;
176         ///
177         std::stack<QColor> monochrome_min_;
178         ///
179         std::stack<QColor> monochrome_max_;
180         /// convert into Qt color, possibly applying the monochrome mode
181         QColor computeColor(Color col);
182         /// possibly apply monochrome mode
183         QColor filterColor(QColor const & col);
184         ///
185         QString generateStringSignature(QString const & str, FontInfo const & f);       
186 };
187
188 } // namespace frontend
189 } // namespace lyx
190
191 #endif // GUIPAINTER_H