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