Reviewed by ap.
[WebKit-https.git] / WebCore / kcanvas / device / qt / KRenderingDeviceQt.cpp
1 /*
2     Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
4
5     This file is part of the KDE project
6
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; see the file COPYING.LIB. If not, write to
19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20     Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24
25 #include "IntRect.h"
26 #include "RenderPathQt.h"
27 #include "KCanvasPathQt.h"
28 #include "AffineTransform.h"
29 #include "GraphicsContext.h"
30 #include "KCanvasClipperQt.h"
31 #include "KRenderingDeviceQt.h"
32 #include "KRenderingPaintServerSolidQt.h"
33 #include "KRenderingPaintServerGradientQt.h"
34 #include "KRenderingPaintServerPatternQt.h"
35
36 namespace WebCore {
37
38 KRenderingDeviceContextQt::KRenderingDeviceContextQt(QPainter* painter)
39     : m_painter(painter)
40     , m_path()
41 {
42     Q_ASSERT(m_painter != 0);
43 }
44
45 KRenderingDeviceContextQt::~KRenderingDeviceContextQt()
46 {
47 }
48
49 AffineTransform KRenderingDeviceContextQt::concatCTM(const AffineTransform& worldMatrix)
50 {
51     AffineTransform ret = ctm();
52     m_painter->setMatrix(worldMatrix, true);
53     return ret;
54 }
55
56 AffineTransform KRenderingDeviceContextQt::ctm() const
57 {
58     return AffineTransform(m_painter->matrix());
59 }
60
61 IntRect KRenderingDeviceContextQt::mapFromVisual(const IntRect& rect)
62 {
63     return IntRect();
64 }
65
66 IntRect KRenderingDeviceContextQt::mapToVisual(const IntRect& rect)
67 {
68     return IntRect();
69 }
70
71 void KRenderingDeviceContextQt::clearPath()
72 {
73     m_path = QPainterPath();
74 }
75
76 void KRenderingDeviceContextQt::addPath(const KCanvasPath* path)
77 {
78     m_path.addPath(static_cast<const KCanvasPathQt*>(path)->qtPath());
79 }
80
81 GraphicsContext* KRenderingDeviceContextQt::createGraphicsContext()
82 {
83     return new GraphicsContext(m_painter);
84 }
85
86 QPainter& KRenderingDeviceContextQt::painter()
87 {
88     return *m_painter;
89 }
90
91 QRectF KRenderingDeviceContextQt::pathBBox() const
92 {
93     return m_path.boundingRect();
94 }
95
96 void KRenderingDeviceContextQt::setFillRule(KCWindRule rule)
97 {
98     m_path.setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
99 }
100
101 void KRenderingDeviceContextQt::fillPath()
102 {
103     m_painter->fillPath(m_path, m_painter->brush());
104 }
105
106 void KRenderingDeviceContextQt::strokePath()
107 {
108     m_painter->strokePath(m_path, m_painter->pen());
109 }
110
111 // KRenderingDeviceQt
112 KRenderingDeviceQt::KRenderingDeviceQt() : KRenderingDevice()
113 {
114 }
115
116 KRenderingDeviceQt::~KRenderingDeviceQt()
117 {
118 }
119
120 KRenderingDeviceContext* KRenderingDeviceQt::popContext()
121 {
122     // Any special things needed?
123     return KRenderingDevice::popContext();
124 }
125
126 void KRenderingDeviceQt::pushContext(KRenderingDeviceContext* context)
127 {
128     // Any special things needed?
129     KRenderingDevice::pushContext(context);
130 }
131
132 // context management.
133 KRenderingDeviceContextQt* KRenderingDeviceQt::qtContext() const
134 {
135     return static_cast<KRenderingDeviceContextQt*>(currentContext());
136 }
137
138 KRenderingDeviceContext* KRenderingDeviceQt::contextForImage(KCanvasImage* image) const
139 {
140     qDebug("KRenderingDeviceQt::contextForImage() TODO!");
141     return 0;
142 }
143
144 DeprecatedString KRenderingDeviceQt::stringForPath(const KCanvasPath* path)
145 {
146     qDebug("KRenderingDeviceQt::stringForPath() TODO!");
147     return 0;
148 }
149
150 // Resource creation
151 KCanvasResource* KRenderingDeviceQt::createResource(const KCResourceType& type) const
152 {
153     switch (type)
154     {
155         case RS_CLIPPER:
156             return new KCanvasClipperQt();
157         case RS_MARKER:
158             return new KCanvasMarker(); // Use default implementation...
159         case RS_IMAGE:
160             // return new KCanvasImageQt();
161         case RS_FILTER:
162             // return new KCanvasFilterQt();
163         case RS_MASKER:
164             // return new KCanvasMaskerQt();
165         default:
166             return 0;
167     }
168 }
169
170 KRenderingPaintServer* KRenderingDeviceQt::createPaintServer(const KCPaintServerType& type) const
171 {
172     switch (type)
173     {
174         case PS_SOLID:
175             return new KRenderingPaintServerSolidQt();
176         case PS_PATTERN:
177             return new KRenderingPaintServerPatternQt();
178         case PS_LINEAR_GRADIENT:
179             return new KRenderingPaintServerLinearGradientQt();
180         case PS_RADIAL_GRADIENT:
181             return new KRenderingPaintServerRadialGradientQt();
182         default:
183             return 0;
184     }
185 }
186
187 KCanvasFilterEffect* KRenderingDeviceQt::createFilterEffect(const KCFilterEffectType& type) const
188 {
189     qDebug("KRenderingDeviceQt::createFilterEffect() TODO!");
190     return 0;
191 }
192
193 KCanvasPath* KRenderingDeviceQt::createPath() const
194 {
195     return new KCanvasPathQt();
196 }
197
198 // item creation
199 RenderPath* KRenderingDeviceQt::createItem(RenderArena* arena, RenderStyle* style, SVGStyledElement* node, KCanvasPath* path) const
200 {
201     RenderPath* item = new (arena) RenderPathQt(style, node);
202     item->setPath(path);
203     return item;
204 }
205
206 KRenderingDevice* renderingDevice()
207 {
208     static KRenderingDevice *sharedRenderingDevice = new KRenderingDeviceQt();
209     return sharedRenderingDevice;
210 }
211
212 }
213
214 // vim:ts=4:noet