]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QLPainter.h
- LyX is dead slow, so the least we can do is use anti-alised text
[lyx.git] / src / frontends / qt4 / QLPainter.h
1 // -*- C++ -*-
2 /**
3  * \file QLPainter.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 QLPAINTER_H
14 #define QLPAINTER_H
15
16 #include "Painter.h"
17
18 #include <boost/scoped_ptr.hpp>
19
20 class QPaintDevice;
21 class QPainter;
22 class QString;
23 class QPixmap;
24 class QImage;
25
26 namespace lyx {
27
28 class LyXFont;
29
30 namespace frontend {
31
32 class GuiWorkArea;
33
34 /**
35  * QLPainter - a painter implementation for Qt4
36  */
37 class QLPainter : public Painter {
38 public:
39         QLPainter(GuiWorkArea *);
40
41         ~QLPainter();
42
43         /// begin painting
44         virtual void start();
45
46         /// end painting
47         virtual void end();
48
49         /// return the width of the work area in pixels
50         virtual int paperWidth() const;
51         /// return the height of the work area in pixels
52         virtual int paperHeight() const;
53
54         /// draw a line from point to point
55         virtual void line(
56                 int x1, int y1,
57                 int x2, int y2,
58                 LColor_color,
59                 line_style = line_solid,
60                 line_width = line_thin);
61
62         /**
63          * lines -  draw a set of lines
64          * @param xp array of points' x co-ords
65          * @param yp array of points' y co-ords
66          * @param np size of the points array
67          */
68         virtual void lines(
69                 int const * xp,
70                 int const * yp,
71                 int np,
72                 LColor_color,
73                 line_style = line_solid,
74                 line_width = line_thin);
75
76         /// draw a rectangle
77         virtual void rectangle(
78                 int x, int y,
79                 int w, int h,
80                 LColor_color,
81                 line_style = line_solid,
82                 line_width = line_thin);
83
84         /// draw a filled rectangle
85         virtual void fillRectangle(
86                 int x, int y,
87                 int w, int h,
88                 LColor_color);
89
90         /// draw an arc
91         virtual void arc(
92                 int x, int y,
93                 unsigned int w, unsigned int h,
94                 int a1, int a2,
95                 LColor_color);
96
97         /// draw a pixel
98         virtual void point(
99                 int x, int y,
100                 LColor_color);
101
102         /// draw an image from the image cache
103         virtual void image(int x, int y,
104                 int w, int h,
105                 lyx::graphics::Image const & image);
106
107         /// draw a string at position x, y (y is the baseline)
108         virtual int text(int x, int y,
109                 lyx::docstring const & str, LyXFont const & f);
110
111         /** Draw a string at position x, y (y is the baseline)
112          *  This is just for fast drawing
113          */
114         virtual int text(int x, int y,
115                 lyx::char_type const * str, size_t l,
116                 LyXFont const & f);
117
118         /// draw a char at position x, y (y is the baseline)
119         virtual int text(int x, int y,
120                 lyx::char_type c, LyXFont const & f);
121
122         /// draw a pixmap from the image cache
123         virtual void drawPixmap(int x, int y, QPixmap const & pixmap);
124
125         /// draw a pixmap from the image cache
126         virtual void drawImage(int x, int y, QImage const & image);
127
128 private:
129         /// draw small caps text
130         /**
131         \return width of the drawn text.
132         */
133         int smallCapsText(int x, int y,
134                 QString const & str, LyXFont const & f);
135
136         /// set pen parameters
137         void setQPainterPen(LColor_color col,
138                 line_style ls = line_solid,
139                 line_width lw = line_thin);
140
141         /// our qt painter
142         boost::scoped_ptr<QPainter> qp_;
143
144         /// the working area
145         GuiWorkArea * qwa_;
146
147         LColor::color current_color_;
148         Painter::line_style current_ls_;
149         Painter::line_width current_lw_;
150 };
151
152 } // namespace frontend
153 } // namespace lyx
154
155 #endif // QLPAINTER_H