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 "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"
38 KRenderingDeviceContextQt::KRenderingDeviceContextQt(QPainter* painter)
42 Q_ASSERT(m_painter != 0);
45 KRenderingDeviceContextQt::~KRenderingDeviceContextQt()
49 AffineTransform KRenderingDeviceContextQt::concatCTM(const AffineTransform& worldMatrix)
51 AffineTransform ret = ctm();
52 m_painter->setMatrix(worldMatrix, true);
56 AffineTransform KRenderingDeviceContextQt::ctm() const
58 return AffineTransform(m_painter->matrix());
61 IntRect KRenderingDeviceContextQt::mapFromVisual(const IntRect& rect)
66 IntRect KRenderingDeviceContextQt::mapToVisual(const IntRect& rect)
71 void KRenderingDeviceContextQt::clearPath()
73 m_path = QPainterPath();
76 void KRenderingDeviceContextQt::addPath(const KCanvasPath* path)
78 m_path.addPath(static_cast<const KCanvasPathQt*>(path)->qtPath());
81 GraphicsContext* KRenderingDeviceContextQt::createGraphicsContext()
83 return new GraphicsContext(m_painter);
86 QPainter& KRenderingDeviceContextQt::painter()
91 QRectF KRenderingDeviceContextQt::pathBBox() const
93 return m_path.boundingRect();
96 void KRenderingDeviceContextQt::setFillRule(KCWindRule rule)
98 m_path.setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
101 void KRenderingDeviceContextQt::fillPath()
103 m_painter->fillPath(m_path, m_painter->brush());
106 void KRenderingDeviceContextQt::strokePath()
108 m_painter->strokePath(m_path, m_painter->pen());
111 // KRenderingDeviceQt
112 KRenderingDeviceQt::KRenderingDeviceQt() : KRenderingDevice()
116 KRenderingDeviceQt::~KRenderingDeviceQt()
120 KRenderingDeviceContext* KRenderingDeviceQt::popContext()
122 // Any special things needed?
123 return KRenderingDevice::popContext();
126 void KRenderingDeviceQt::pushContext(KRenderingDeviceContext* context)
128 // Any special things needed?
129 KRenderingDevice::pushContext(context);
132 // context management.
133 KRenderingDeviceContextQt* KRenderingDeviceQt::qtContext() const
135 return static_cast<KRenderingDeviceContextQt*>(currentContext());
138 KRenderingDeviceContext* KRenderingDeviceQt::contextForImage(KCanvasImage* image) const
140 qDebug("KRenderingDeviceQt::contextForImage() TODO!");
144 DeprecatedString KRenderingDeviceQt::stringForPath(const KCanvasPath* path)
146 qDebug("KRenderingDeviceQt::stringForPath() TODO!");
151 KCanvasResource* KRenderingDeviceQt::createResource(const KCResourceType& type) const
156 return new KCanvasClipperQt();
158 return new KCanvasMarker(); // Use default implementation...
160 // return new KCanvasImageQt();
162 // return new KCanvasFilterQt();
164 // return new KCanvasMaskerQt();
170 KRenderingPaintServer* KRenderingDeviceQt::createPaintServer(const KCPaintServerType& type) const
175 return new KRenderingPaintServerSolidQt();
177 return new KRenderingPaintServerPatternQt();
178 case PS_LINEAR_GRADIENT:
179 return new KRenderingPaintServerLinearGradientQt();
180 case PS_RADIAL_GRADIENT:
181 return new KRenderingPaintServerRadialGradientQt();
187 KCanvasFilterEffect* KRenderingDeviceQt::createFilterEffect(const KCFilterEffectType& type) const
189 qDebug("KRenderingDeviceQt::createFilterEffect() TODO!");
193 KCanvasPath* KRenderingDeviceQt::createPath() const
195 return new KCanvasPathQt();
199 RenderPath* KRenderingDeviceQt::createItem(RenderArena* arena, RenderStyle* style, SVGStyledElement* node, KCanvasPath* path) const
201 RenderPath* item = new (arena) RenderPathQt(style, node);
206 KRenderingDevice* renderingDevice()
208 static KRenderingDevice *sharedRenderingDevice = new KRenderingDeviceQt();
209 return sharedRenderingDevice;