]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPainter.h
06a81128983fef5d509b5188f50723a992a9bf8c
[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(
82                 int x, int y,
83                 ColorCode);
84
85         /// draw an image from the image cache
86         virtual void image(int x, int y,
87                 int w, int h,
88                 lyx::graphics::Image const & image);
89
90         /// draw a string at position x, y (y is the baseline)
91         virtual int text(int x, int y,
92                 docstring const & str, FontInfo const & f);
93
94         /// draw a char at position x, y (y is the baseline)
95         virtual int text(int x, int y, char_type c, FontInfo const & f);
96
97         /// start monochrome painting mode, i.e. map every color into [min,max]
98         virtual void enterMonochromeMode(ColorCode const & min, 
99                 ColorCode const & max);
100         /// leave monochrome painting mode
101         virtual void leaveMonochromeMode();
102         
103 private:
104         /// draw small caps text
105         /**
106         \return width of the drawn text.
107         */
108         int smallCapsText(int x, int y,
109                 QString const & str, FontInfo const & f);
110
111         /// set pen parameters
112         void setQPainterPen(QColor const & col,
113                 line_style ls = line_solid,
114                 line_width lw = line_thin);
115
116         QColor current_color_;
117         Painter::line_style current_ls_;
118         Painter::line_width current_lw_;
119         ///
120         bool const use_pixmap_cache_;
121         ///
122         std::stack<QColor> monochrome_min_;
123         ///
124         std::stack<QColor> monochrome_max_;
125         /// convert into Qt color, possibly applying the monochrome mode
126         QColor computeColor(ColorCode col);
127         /// possibly apply monochrome mode
128         QColor filterColor(QColor const & col);
129         ///
130         QString generateStringSignature(QString const & str, FontInfo const & f);       
131 };
132
133 } // namespace frontend
134 } // namespace lyx
135
136 #endif // GUIPAINTER_H