a1d208b15052379e6e2ffbed22212b608aa4a42f
[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 "AffineTransform.h"
28 #include "GraphicsContext.h"
29 #include "SVGResourceClipper.h"
30 #include "SVGResourceMarker.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 Path& path)
77 {
78     m_path.addPath(*(path.platformPath()));
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(WindRule 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(SVGResourceImage* image) const
139 {
140     qDebug("KRenderingDeviceQt::contextForImage() TODO!");
141     return 0;
142 }
143
144 // Resource creation
145 PassRefPtr<SVGResource> KRenderingDeviceQt::createResource(const SVGResourceType& type) const
146 {
147     switch (type)
148     {
149         case RS_CLIPPER:
150             return new SVGResourceClipper();
151         case RS_MARKER:
152             return new SVGResourceMarker(); // Use default implementation...
153         case RS_IMAGE:
154             // return new SVGResourceImageQt();
155         case RS_FILTER:
156             // return new KCanvasFilterQt();
157         case RS_MASKER:
158             // return new KCanvasMaskerQt();
159         default:
160             return 0;
161     }
162 }
163
164 PassRefPtr<KRenderingPaintServer> KRenderingDeviceQt::createPaintServer(const KCPaintServerType& type) const
165 {
166     switch (type)
167     {
168         case PS_SOLID:
169             return new KRenderingPaintServerSolidQt();
170         case PS_PATTERN:
171             return new KRenderingPaintServerPatternQt();
172         case PS_LINEAR_GRADIENT:
173             return new KRenderingPaintServerLinearGradientQt();
174         case PS_RADIAL_GRADIENT:
175             return new KRenderingPaintServerRadialGradientQt();
176         default:
177             return 0;
178     }
179 }
180
181 KCanvasFilterEffect* KRenderingDeviceQt::createFilterEffect(const KCFilterEffectType& type) const
182 {
183     qDebug("KRenderingDeviceQt::createFilterEffect() TODO!");
184     return 0;
185 }
186
187 KRenderingDevice* renderingDevice()
188 {
189     static KRenderingDevice *sharedRenderingDevice = new KRenderingDeviceQt();
190     return sharedRenderingDevice;
191 }
192
193 }
194
195 // vim:ts=4:noet