343c49d6127feb4e7c5b089650c81824c3627e63
[WebKit-https.git] / WebCore / kcanvas / device / qt / KRenderingPaintServerSolidQt.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 <QPen>
26 #include <QBrush>
27 #include <QPainter>
28
29 #include "RenderStyle.h"
30 #include "KRenderingDeviceQt.h"
31 #include "KCanvasRenderingStyle.h"
32 #include "KRenderingFillPainter.h"
33 #include "KRenderingStrokePainter.h"
34 #include "KRenderingPaintServerSolidQt.h"
35
36 namespace WebCore {
37
38 KRenderingPaintServerSolidQt::KRenderingPaintServerSolidQt()
39     : KRenderingPaintServerSolid()
40     , KRenderingPaintServerQt()
41 {
42 }
43
44 KRenderingPaintServerSolidQt::~KRenderingPaintServerSolidQt()
45 {
46 }
47
48 // 'Solid' interface
49 void KRenderingPaintServerSolidQt::draw(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
50 {
51     if (!setup(context, path, type))
52         return;
53
54     renderPath(context, path, type);
55     teardown(context, path, type);
56 }
57
58 bool KRenderingPaintServerSolidQt::setup(KRenderingDeviceContext* context, const RenderObject* object, KCPaintTargetType type) const
59 {
60     KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
61
62     RenderStyle* renderStyle = object->style();
63     // TODO? qtContext->painter().setOpacity(renderStyle->opacity());
64
65     QColor c = color();
66
67     if ((type & APPLY_TO_FILL) && renderStyle->svgStyle()->hasFill()) {
68         KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object);
69         c.setAlphaF(fillPainter.opacity());
70
71         QBrush brush(c);
72         qtContext->painter().setBrush(brush);
73         qtContext->setFillRule(fillPainter.fillRule());
74
75         /* if(isPaintingText()) ... */
76     }
77
78     if((type & APPLY_TO_STROKE) && renderStyle->svgStyle()->hasStroke()) {
79         KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object);
80         c.setAlphaF(strokePainter.opacity());
81
82         QPen pen(c);
83         setPenProperties(strokePainter, pen);
84         qtContext->painter().setPen(pen);
85
86         /* if(isPaintingText()) ... */
87     }
88
89     return true;
90 }
91
92 void KRenderingPaintServerSolidQt::teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const
93 {
94 }
95
96 void KRenderingPaintServerSolidQt::renderPath(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
97 {
98     RenderStyle* renderStyle = path->style();
99     KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
100
101     if ((type & APPLY_TO_FILL) && renderStyle->svgStyle()->hasFill())
102         qtContext->fillPath();
103
104     if ((type & APPLY_TO_STROKE) && renderStyle->svgStyle()->hasStroke())
105         qtContext->strokePath();
106 }
107
108 }
109
110 // vim:ts=4:noet