2 Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
4 This file is part of the KDE project
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 aint with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
25 #include "SVGPaintServerLinearGradient.h"
27 #include "KRenderingDeviceQt.h"
28 #include "RenderPath.h"
30 #include <QLinearGradient>
34 bool SVGPaintServerLinearGradient::setup(KRenderingDeviceContext* context, const RenderObject* object, SVGPaintTargetType type) const
36 KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
37 Q_ASSERT(qtContext != 0);
40 listener()->resourceNotification();
42 RenderStyle* renderStyle = object->style();
44 double x1, x2, y1, y2;
45 if (boundingBoxMode()) {
46 QRectF bbox = qtContext->pathBBox();
47 x1 = double(bbox.left()) + (double(gradientStart().x() / 100.0) * double(bbox.width()));
48 y1 = double(bbox.top()) + (double(gradientStart().y() / 100.0) * double(bbox.height()));
49 x2 = double(bbox.left()) + (double(gradientEnd().x() / 100.0) * double(bbox.width()));
50 y2 = double(bbox.top()) + (double(gradientEnd().y() / 100.0) * double(bbox.height()));
52 x1 = gradientStart().x();
53 y1 = gradientStart().y();
54 x2 = gradientEnd().x();
55 y2 = gradientEnd().y();
58 qtContext->painter().setPen(Qt::NoPen);
59 qtContext->painter().setBrush(Qt::NoBrush);
61 QLinearGradient gradient(QPointF(x1, y1), QPointF(x2, y2));
62 if (spreadMethod() == SPREADMETHOD_REPEAT)
63 gradient.setSpread(QGradient::RepeatSpread);
64 else if (spreadMethod() == SPREADMETHOD_REFLECT)
65 gradient.setSpread(QGradient::ReflectSpread);
67 gradient.setSpread(QGradient::PadSpread);
71 // TODO: Gradient transform + opacity fixes!
73 if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) {
74 fillColorArray(gradient, gradientStops(), opacity);
76 QBrush brush(gradient);
78 qtContext->painter().setBrush(brush);
79 qtContext->setFillRule(renderStyle->svgStyle()->fillRule());
82 if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) {
83 fillColorArray(gradient, gradientStops(), opacity);
86 QBrush brush(gradient);
88 setPenProperties(object, renderStyle, pen);
91 qtContext->painter().setPen(pen);
97 } // namespace WebCore