2 Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
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.
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.
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.
26 #include "RenderPath.h"
27 #include "AffineTransform.h"
28 #include "GraphicsContext.h"
29 #include "SVGResourceClipper.h"
30 #include "SVGResourceMarker.h"
31 #include "KRenderingDeviceQt.h"
32 #include "SVGPaintServerSolid.h"
33 #include "SVGPaintServerLinearGradient.h"
34 #include "SVGPaintServerRadialGradient.h"
35 #include "SVGPaintServerPattern.h"
39 KRenderingDeviceContextQt::KRenderingDeviceContextQt(QPainter* painter)
43 Q_ASSERT(m_painter != 0);
46 KRenderingDeviceContextQt::~KRenderingDeviceContextQt()
50 AffineTransform KRenderingDeviceContextQt::concatCTM(const AffineTransform& worldMatrix)
52 AffineTransform ret = ctm();
53 m_painter->setMatrix(worldMatrix, true);
57 AffineTransform KRenderingDeviceContextQt::ctm() const
59 return AffineTransform(m_painter->matrix());
62 IntRect KRenderingDeviceContextQt::mapFromVisual(const IntRect& rect)
67 IntRect KRenderingDeviceContextQt::mapToVisual(const IntRect& rect)
72 void KRenderingDeviceContextQt::clearPath()
74 m_path = QPainterPath();
77 void KRenderingDeviceContextQt::addPath(const Path& path)
79 m_path.addPath(*(path.platformPath()));
82 GraphicsContext* KRenderingDeviceContextQt::createGraphicsContext()
84 return new GraphicsContext(m_painter);
87 QPainter& KRenderingDeviceContextQt::painter()
92 QRectF KRenderingDeviceContextQt::pathBBox() const
94 return m_path.boundingRect();
97 void KRenderingDeviceContextQt::setFillRule(WindRule rule)
99 m_path.setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
102 void KRenderingDeviceContextQt::fillPath()
104 m_painter->fillPath(m_path, m_painter->brush());
107 void KRenderingDeviceContextQt::strokePath()
109 m_painter->strokePath(m_path, m_painter->pen());
112 // KRenderingDeviceQt
113 KRenderingDeviceQt::KRenderingDeviceQt() : KRenderingDevice()
117 KRenderingDeviceQt::~KRenderingDeviceQt()
121 KRenderingDeviceContext* KRenderingDeviceQt::popContext()
123 // Any special things needed?
124 return KRenderingDevice::popContext();
127 void KRenderingDeviceQt::pushContext(KRenderingDeviceContext* context)
129 // Any special things needed?
130 KRenderingDevice::pushContext(context);
133 // context management.
134 KRenderingDeviceContextQt* KRenderingDeviceQt::qtContext() const
136 return static_cast<KRenderingDeviceContextQt*>(currentContext());
139 KRenderingDeviceContext* KRenderingDeviceQt::contextForImage(SVGResourceImage* image) const
141 qDebug("KRenderingDeviceQt::contextForImage() TODO!");
146 PassRefPtr<SVGResource> KRenderingDeviceQt::createResource(const SVGResourceType& type) const
150 case ClipperResourceType:
151 return new SVGResourceClipper();
152 case MarkerResourceType:
153 return new SVGResourceMarker(); // Use default implementation...
154 case ImageResourceType:
155 // return new SVGResourceImageQt();
156 case FilterResourceType:
157 // return new KCanvasFilterQt();
158 case MaskerResourceType:
159 // return new KCanvasMaskerQt();
165 PassRefPtr<SVGPaintServer> KRenderingDeviceQt::createPaintServer(const SVGPaintServerType& type) const
169 case SolidPaintServer:
170 return new SVGPaintServerSolid();
171 case PatternPaintServer:
172 return new SVGPaintServerPattern();
173 case LinearGradientPaintServer:
174 return new SVGPaintServerLinearGradient();
175 case RadialGradientPaintServer:
176 return new SVGPaintServerRadialGradient();
182 SVGFilterEffect* KRenderingDeviceQt::createFilterEffect(const SVGFilterEffectType& type) const
184 qDebug("KRenderingDeviceQt::createFilterEffect() TODO!");
188 KRenderingDevice* renderingDevice()
190 static KRenderingDevice *sharedRenderingDevice = new KRenderingDeviceQt();
191 return sharedRenderingDevice;