summaryrefslogtreecommitdiffstats
path: root/krita/ui/kis_canvas_painter.h
blob: 5559057d6d64ee72ceeed8c07caa78fbcd4d6768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
 *  Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef KIS_CANVAS_PAINTER_H_
#define KIS_CANVAS_PAINTER_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <qpainter.h>

#include "kis_global.h"

class KisCanvas;
class KisCanvasWidget;

class KisCanvasWidgetPainter {
public:
    KisCanvasWidgetPainter();
    virtual ~KisCanvasWidgetPainter();

    virtual bool begin(KisCanvasWidget *canvasWidget, bool unclipped = false) = 0;
    virtual bool end();

    virtual void save();
    virtual void restore();

    virtual QFontMetrics fontMetrics() const;
    virtual QFontInfo fontInfo() const;

    virtual const QFont& font() const;
    virtual void setFont(const QFont&);
    virtual const QPen& pen() const;
    virtual void setPen(const QPen&);
    virtual void setPen(Qt::PenStyle);
    virtual void setPen(const QColor&);
    virtual const QBrush&brush() const;
    virtual void setBrush(const QBrush&);
    virtual void setBrush(Qt::BrushStyle);
    virtual void setBrush(const QColor&);
    virtual QPoint pos() const;

    virtual const QColor&backgroundColor() const;
    virtual void setBackgroundColor(const QColor&);
    virtual Qt::BGMode backgroundMode() const;
    virtual void setBackgroundMode(Qt::BGMode);
    virtual Qt::RasterOp rasterOp()	const;
    virtual void setRasterOp(Qt::RasterOp);
    virtual const QPoint&brushOrigin() const;
    virtual void setBrushOrigin(int x, int y);
    virtual void setBrushOrigin(const QPoint&);

    virtual bool hasViewXForm() const;
    virtual bool hasWorldXForm() const;

    virtual void setViewXForm(bool);
    virtual QRect window() const;
    virtual void setWindow(const QRect&);
    virtual void setWindow(int x, int y, int w, int h);
    virtual QRect viewport() const;
    virtual void setViewport(const QRect&);
    virtual void setViewport(int x, int y, int w, int h);

    virtual void setWorldXForm(bool);
    virtual const QWMatrix&worldMatrix() const;
    virtual void setWorldMatrix(const QWMatrix&, bool combine=FALSE);

    virtual void saveWorldMatrix();
    virtual void restoreWorldMatrix();

    virtual void scale(double sx, double sy);
    virtual void shear(double sh, double sv);
    virtual void rotate(double a);

    virtual void translate(double dx, double dy);
    virtual void resetXForm();
    virtual double translationX() const;
    virtual double translationY() const;

    virtual QPoint xForm(const QPoint&) const;
    virtual QRect xForm(const QRect&)	const;
    virtual QPointArray xForm(const QPointArray&) const;
    virtual QPointArray xForm(const QPointArray&, int index, int npoints) const;
    virtual QPoint xFormDev(const QPoint&) const;
    virtual QRect xFormDev(const QRect&)  const;
    virtual QPointArray xFormDev(const QPointArray&) const;
    virtual QPointArray xFormDev(const QPointArray&, int index, int npoints) const;

    virtual void setClipping(bool);
    virtual bool hasClipping() const;
    virtual QRegion clipRegion(QPainter::CoordinateMode = QPainter::CoordDevice) const;
    virtual void setClipRect(const QRect&, QPainter::CoordinateMode = QPainter::CoordDevice);
    virtual void setClipRect(int x, int y, int w, int h, QPainter::CoordinateMode = QPainter::CoordDevice);
    virtual void setClipRegion(const QRegion&, QPainter::CoordinateMode = QPainter::CoordDevice);

    virtual void drawPoint(int x, int y);
    virtual void drawPoint(const QPoint&);
    virtual void drawPoints(const QPointArray& a, int index=0, int npoints=-1);
    virtual void moveTo(int x, int y);
    virtual void moveTo(const QPoint&);
    virtual void lineTo(int x, int y);
    virtual void lineTo(const QPoint&);
    virtual void drawLine(int x1, int y1, int x2, int y2);
    virtual void drawLine(const QPoint&, const QPoint&);
    virtual void drawRect(int x, int y, int w, int h);
    virtual void drawRect(const QRect&);
    virtual void drawWinFocusRect(int x, int y, int w, int h);
    virtual void drawWinFocusRect(int x, int y, int w, int h, const QColor&bgColor);
    virtual void drawWinFocusRect(const QRect&);
    virtual void drawWinFocusRect(const QRect&, const QColor&bgColor);
    virtual void drawRoundRect(int x, int y, int w, int h, int = 25, int = 25);
    virtual void drawRoundRect(const QRect&, int = 25, int = 25);
    virtual void drawEllipse(int x, int y, int w, int h);
    virtual void drawEllipse(const QRect&);
    virtual void drawArc(int x, int y, int w, int h, int a, int alen);
    virtual void drawArc(const QRect&, int a, int alen);
    virtual void drawPie(int x, int y, int w, int h, int a, int alen);
    virtual void drawPie(const QRect&, int a, int alen);
    virtual void drawChord(int x, int y, int w, int h, int a, int alen);
    virtual void drawChord(const QRect&, int a, int alen);
    virtual void drawLineSegments(const QPointArray&, int index=0, int nlines=-1);
    virtual void drawPolyline(const QPointArray&, int index=0, int npoints=-1);
    virtual void drawPolygon(const QPointArray&, bool winding=FALSE, int index=0, int npoints=-1);
    virtual void drawConvexPolygon(const QPointArray&, int index=0, int npoints=-1);
    virtual void drawCubicBezier(const QPointArray&, int index=0);
    virtual void drawPixmap(int x, int y, const QPixmap&, int sx=0, int sy=0, int sw=-1, int sh=-1);
    virtual void drawPixmap(const QPoint&, const QPixmap&, const QRect&sr);
    virtual void drawPixmap(const QPoint&, const QPixmap&);
    virtual void drawPixmap(const QRect&, const QPixmap&);
    virtual void drawImage(int x, int y, const QImage&, int sx = 0, int sy = 0, int sw = -1, int sh = -1, int conversionFlags = 0);
    virtual void drawImage(const QPoint&, const QImage&, const QRect&sr, int conversionFlags = 0);
    virtual void drawImage(const QPoint&, const QImage&, int conversion_flags = 0);
    virtual void drawImage(const QRect&, const QImage&);
    virtual void drawTiledPixmap(int x, int y, int w, int h, const QPixmap&, int sx=0, int sy=0);
    virtual void drawTiledPixmap(const QRect&, const QPixmap&, const QPoint&);
    virtual void drawTiledPixmap(const QRect&, const QPixmap&);
    //virtual void drawPicture(const QPicture&);
    //virtual void drawPicture(int x, int y, const QPicture&);
    //virtual void drawPicture(const QPoint&, const QPicture&);

    virtual void fillRect(int x, int y, int w, int h, const QBrush&);
    virtual void fillRect(const QRect&, const QBrush&);
    virtual void eraseRect(int x, int y, int w, int h);
    virtual void eraseRect(const QRect&);

    virtual void drawText(int x, int y, const QString&, int len = -1, QPainter::TextDirection dir = QPainter::Auto);
    virtual void drawText(const QPoint&, const QString&, int len = -1, QPainter::TextDirection dir = QPainter::Auto);

    virtual void drawText(int x, int y, const QString&, int pos, int len, QPainter::TextDirection dir = QPainter::Auto);
    virtual void drawText(const QPoint&p, const QString&, int pos, int len, QPainter::TextDirection dir = QPainter::Auto);

    virtual void drawText(int x, int y, int w, int h, int flags, const QString&, int len = -1, QRect *br=0, QTextParag **intern=0);
    virtual void drawText(const QRect&, int flags, const QString&, int len = -1, QRect *br=0, QTextParag **intern=0);

    virtual void drawTextItem(int x, int y, const QTextItem&ti, int textflags = 0);
    virtual void drawTextItem(const QPoint& p, const QTextItem&ti, int textflags = 0);

    virtual QRect boundingRect(int x, int y, int w, int h, int flags, const QString&, int len = -1, QTextParag **intern=0);
    virtual QRect boundingRect(const QRect&, int flags, const QString&, int len = -1, QTextParag **intern=0);

    virtual int	tabStops() const;
    virtual void setTabStops(int);
    virtual int	*tabArray() const;
    virtual void setTabArray(int *);

protected:
    QFont m_defaultFont;
    QPen m_defaultPen;
    QBrush m_defaultBrush;
    QColor m_defaultColor;
    QPoint m_defaultBrushOrigin;
    QWMatrix m_defaultWorldMatrix;
};

class KisCanvasPainter {
public:
    KisCanvasPainter();
    KisCanvasPainter(KisCanvas *canvas);
    KisCanvasPainter(const QPaintDevice *paintDevice);

    ~KisCanvasPainter();

    bool begin(KisCanvas *canvas, bool unclipped = false);
    bool begin(const QPaintDevice *paintDevice, bool unclipped = false);

    bool end();

    void save();
    void restore();

    QFontMetrics fontMetrics() const;
    QFontInfo fontInfo() const;

    const QFont& font() const;
    void setFont(const QFont&);
    const QPen& pen() const;
    void setPen(const QPen&);
    void setPen(Qt::PenStyle);
    void setPen(const QColor&);
    const QBrush&brush() const;
    void setBrush(const QBrush&);
    void setBrush(Qt::BrushStyle);
    void setBrush(const QColor&);
    QPoint pos() const;

    const QColor&backgroundColor() const;
    void setBackgroundColor(const QColor&);
    Qt::BGMode backgroundMode() const;
    void setBackgroundMode(Qt::BGMode);
    Qt::RasterOp rasterOp()	const;
    void setRasterOp(Qt::RasterOp);
    const QPoint&brushOrigin() const;
    void setBrushOrigin(int x, int y);
    void setBrushOrigin(const QPoint&);

    bool hasViewXForm() const;
    bool hasWorldXForm() const;

    void setViewXForm(bool);
    QRect window() const;
    void setWindow(const QRect&);
    void setWindow(int x, int y, int w, int h);
    QRect viewport() const;
    void setViewport(const QRect&);
    void setViewport(int x, int y, int w, int h);

    void setWorldXForm(bool);
    const QWMatrix&worldMatrix() const;
    void setWorldMatrix(const QWMatrix&, bool combine=FALSE);

    void saveWorldMatrix();
    void restoreWorldMatrix();

    void scale(double sx, double sy);
    void shear(double sh, double sv);
    void rotate(double a);

    void translate(double dx, double dy);
    void resetXForm();
    double translationX() const;
    double translationY() const;

    QPoint xForm(const QPoint&) const;
    QRect xForm(const QRect&)	const;
    QPointArray xForm(const QPointArray&) const;
    QPointArray xForm(const QPointArray&, int index, int npoints) const;
    QPoint xFormDev(const QPoint&) const;
    QRect xFormDev(const QRect&)  const;
    QPointArray xFormDev(const QPointArray&) const;
    QPointArray xFormDev(const QPointArray&, int index, int npoints) const;

    void setClipping(bool);
    bool hasClipping() const;
    QRegion clipRegion(QPainter::CoordinateMode = QPainter::CoordDevice) const;
    void setClipRect(const QRect&, QPainter::CoordinateMode = QPainter::CoordDevice);
    void setClipRect(int x, int y, int w, int h, QPainter::CoordinateMode = QPainter::CoordDevice);
    void setClipRegion(const QRegion&, QPainter::CoordinateMode = QPainter::CoordDevice);

    void drawPoint(int x, int y);
    void drawPoint(const QPoint&);
    void drawPoints(const QPointArray& a, int index=0, int npoints=-1);
    void moveTo(int x, int y);
    void moveTo(const QPoint&);
    void lineTo(int x, int y);
    void lineTo(const QPoint&);
    void drawLine(int x1, int y1, int x2, int y2);
    void drawLine(const QPoint&, const QPoint&);
    void drawRect(int x, int y, int w, int h);
    void drawRect(const QRect&);
    void drawWinFocusRect(int x, int y, int w, int h);
    void drawWinFocusRect(int x, int y, int w, int h, const QColor&bgColor);
    void drawWinFocusRect(const QRect&);
    void drawWinFocusRect(const QRect&, const QColor&bgColor);
    void drawRoundRect(int x, int y, int w, int h, int = 25, int = 25);
    void drawRoundRect(const QRect&, int = 25, int = 25);
    void drawEllipse(int x, int y, int w, int h);
    void drawEllipse(const QRect&);
    void drawArc(int x, int y, int w, int h, int a, int alen);
    void drawArc(const QRect&, int a, int alen);
    void drawPie(int x, int y, int w, int h, int a, int alen);
    void drawPie(const QRect&, int a, int alen);
    void drawChord(int x, int y, int w, int h, int a, int alen);
    void drawChord(const QRect&, int a, int alen);
    void drawLineSegments(const QPointArray&, int index=0, int nlines=-1);
    void drawPolyline(const QPointArray&, int index=0, int npoints=-1);
    void drawPolygon(const QPointArray&, bool winding=FALSE, int index=0, int npoints=-1);
    void drawConvexPolygon(const QPointArray&, int index=0, int npoints=-1);
    void drawCubicBezier(const QPointArray&, int index=0);
    void drawPixmap(int x, int y, const QPixmap&, int sx=0, int sy=0, int sw=-1, int sh=-1);
    void drawPixmap(const QPoint&, const QPixmap&, const QRect&sr);
    void drawPixmap(const QPoint&, const QPixmap&);
    void drawPixmap(const QRect&, const QPixmap&);
    void drawImage(int x, int y, const QImage&, int sx = 0, int sy = 0, int sw = -1, int sh = -1, int conversionFlags = 0);
    void drawImage(const QPoint&, const QImage&, const QRect&sr, int conversionFlags = 0);
    void drawImage(const QPoint&, const QImage&, int conversion_flags = 0);
    void drawImage(const QRect&, const QImage&);
    void drawTiledPixmap(int x, int y, int w, int h, const QPixmap&, int sx=0, int sy=0);
    void drawTiledPixmap(const QRect&, const QPixmap&, const QPoint&);
    void drawTiledPixmap(const QRect&, const QPixmap&);
    //void drawPicture(const QPicture&);
    //void drawPicture(int x, int y, const QPicture&);
    //void drawPicture(const QPoint&, const QPicture&);

    void fillRect(int x, int y, int w, int h, const QBrush&);
    void fillRect(const QRect&, const QBrush&);
    void eraseRect(int x, int y, int w, int h);
    void eraseRect(const QRect&);

    void drawText(int x, int y, const QString&, int len = -1, QPainter::TextDirection dir = QPainter::Auto);
    void drawText(const QPoint&, const QString&, int len = -1, QPainter::TextDirection dir = QPainter::Auto);

    void drawText(int x, int y, const QString&, int pos, int len, QPainter::TextDirection dir = QPainter::Auto);
    void drawText(const QPoint&p, const QString&, int pos, int len, QPainter::TextDirection dir = QPainter::Auto);

    void drawText(int x, int y, int w, int h, int flags, const QString&, int len = -1, QRect *br=0, QTextParag **intern=0);
    void drawText(const QRect&, int flags, const QString&, int len = -1, QRect *br=0, QTextParag **intern=0);

    void drawTextItem(int x, int y, const QTextItem&ti, int textflags = 0);
    void drawTextItem(const QPoint& p, const QTextItem&ti, int textflags = 0);

    QRect boundingRect(int x, int y, int w, int h, int flags, const QString&, int len = -1, QTextParag **intern=0);
    QRect boundingRect(const QRect&, int flags, const QString&, int len = -1, QTextParag **intern=0);

    int	tabStops() const;
    void setTabStops(int);
    int	*tabArray() const;
    void setTabArray(int *);

protected:
    KisCanvasWidgetPainter *m_canvasWidgetPainter;
    QFont m_defaultFont;
    QPen m_defaultPen;
    QBrush m_defaultBrush;
    QColor m_defaultColor;
    QPoint m_defaultBrushOrigin;
    QWMatrix m_defaultWorldMatrix;
};

#endif // KIS_CANVAS_PAINTER_H_