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.
30 #include <QPainterPath>
32 #include "RenderStyle.h"
33 #include "KRenderingDeviceQt.h"
34 #include "KCanvasRenderingStyle.h"
35 #include "KRenderingFillPainter.h"
36 #include "KRenderingStrokePainter.h"
37 #include "KRenderingPaintServerPatternQt.h"
38 #include "KCanvasImage.h"
42 // KRenderingPaintServerPatternQt
43 KRenderingPaintServerPatternQt::KRenderingPaintServerPatternQt()
44 : KRenderingPaintServerPattern()
45 , KRenderingPaintServerQt()
49 KRenderingPaintServerPatternQt::~KRenderingPaintServerPatternQt()
53 void KRenderingPaintServerPatternQt::renderPath(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
55 RenderStyle* renderStyle = path->style();
56 KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
58 if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle))
59 qtContext->fillPath();
61 if ((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle))
62 qtContext->strokePath();
65 bool KRenderingPaintServerPatternQt::setup(KRenderingDeviceContext* context, const RenderObject* object, KCPaintTargetType type) const
68 KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
69 Q_ASSERT(qtContext != 0);
71 QPainterPath* _path = static_cast<QPainterPath*>(qtContext->path());
75 listener()->resourceNotification();
78 RenderStyle* renderStyle = object->style();
80 qtContext->painter().setPen(Qt::NoPen);
81 qtContext->painter().setBrush(Qt::NoBrush);
82 QImage* patternimage = new QImage(tile()->bits(), tile()->width(), tile()->height(), QImage::Format_ARGB32_Premultiplied);
83 patternimage->setAlphaBuffer(true);
84 if (type & APPLY_TO_FILL) {
86 //c.setAlphaF(style->fillPainter()->opacity() * style->opacity() * opacity());
87 KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object);
88 QBrush brush(QPixmap::fromImage(*patternimage));
89 _path->setFillRule(fillPainter.fillRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
90 qtContext->painter().setBrush(brush);
92 if (type & APPLY_TO_STROKE) {
94 //c.setAlphaF(style->strokePainter()->opacity() * style->opacity() * opacity());
95 KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object);
98 QBrush brush(QPixmap::fromImage(*patternimage));
100 setPenProperties(strokePainter, pen);
102 qtContext->painter().setPen(pen);
105 qtContext->painter().drawPath(*_path);
113 void KRenderingPaintServerPatternQt::teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const
117 void KRenderingPaintServerPatternQt::draw(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
119 if (!setup(context, path, type))
122 renderPath(context, path, type);
123 teardown(context, path, type);