• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
  • graphics
  • qt
SVGPaintServerGradientQt.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
3 
4  This file is part of the KDE project
5 
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.
10 
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.
15 
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., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "config.h"
23 #include "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGPaintServerGradient.h"
27 
28 /*#include "GraphicsContext.h"*/
29 #include "RenderObject.h"
30 #include "RenderStyle.h"
31 #include "SVGGradientElement.h"
32 
33 #include <QPainter>
34 #include <QPainterPath>
35 #include <QColor>
36 #include <QGradient>
37 
38 namespace WebCore {
39 
40 // Helper function used by linear & radial gradient
41 void SVGPaintServerGradient::fillColorArray(QGradient& gradient, const Vector<SVGGradientStop>& stops,
42  float opacity) const
43 {
44  kDebug() << stops.size() << endl;
45  for (unsigned i = 0; i < stops.size(); ++i) {
46  float offset = stops[i].first;
47  QColor color = stops[i].second;
48  kDebug() << "offset" << offset << "color" << color << endl;
49 
50  QColor c(color.red(), color.green(), color.blue());
51  c.setAlpha(int(color.alpha() * opacity));
52 
53  gradient.setColorAt(offset, c);
54  }
55 }
56 
57 bool SVGPaintServerGradient::setup(QPainter* painter, QPainterPath* painterPath, const RenderObject* object,
58  SVGPaintTargetType type, bool isPaintingText) const
59 {
60  Q_UNUSED(isPaintingText);
61  kDebug() << "!!!!!!!" << endl;
62  m_ownerElement->buildGradient();
63 
64  /*QPainter* painter(context ? context->platformContext() : 0);
65  Q_ASSERT(painter);*/
66 
67  /*QPainterPath* path(context ? context->currentPath() : 0);
68  Q_ASSERT(path);*/
69 
70  RenderStyle* renderStyle = object->style();
71 
72  QGradient gradient = setupGradient(painter, painterPath, object);
73 
74  painter->setPen(Qt::NoPen);
75  painter->setBrush(Qt::NoBrush);
76 
77  if (spreadMethod() == SPREADMETHOD_REPEAT)
78  gradient.setSpread(QGradient::RepeatSpread);
79  else if (spreadMethod() == SPREADMETHOD_REFLECT)
80  gradient.setSpread(QGradient::ReflectSpread);
81  else
82  gradient.setSpread(QGradient::PadSpread);
83  double opacity = 1.0;
84 
85  kDebug() << "type: " << type << (type & ApplyToFillTargetType) << endl;
86  if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) {
87  fillColorArray(gradient, gradientStops(), opacity);
88 
89  QBrush brush(gradient);
90  brush.setMatrix(gradientTransform());
91 
92  painter->setBrush(brush);
93  /* FIXME khtml context->setFillRule(renderStyle->svgStyle()->fillRule());*/
94  }
95 
96  if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) {
97  fillColorArray(gradient, gradientStops(), opacity);
98 
99  QPen pen;
100  QBrush brush(gradient);
101  brush.setMatrix(gradientTransform());
102 
103  setPenProperties(object, renderStyle, pen);
104  pen.setBrush(brush);
105 
106  painter->setPen(pen);
107  }
108 
109  return true;
110 }
111 
112 } // namespace WebCore
113 
114 #endif
115 
116 // vim:ts=4
QColor
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
RenderStyle.h
SVGGradientElement.h
SVGPaintServerGradient.h
RenderObject.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal