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

KHTML

SVGPaintServerGradientQt.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
00003 
00004     This file is part of the KDE project
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     aint with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "config.h"
00023 #include "wtf/Platform.h"
00024 
00025 #if ENABLE(SVG)
00026 #include "SVGPaintServerGradient.h"
00027 
00028 /*#include "GraphicsContext.h"*/
00029 #include "RenderObject.h"
00030 #include "RenderStyle.h"
00031 #include "SVGGradientElement.h"
00032 
00033 #include <QPainter>
00034 #include <QPainterPath>
00035 #include <QColor>
00036 #include <QGradient>
00037 
00038 namespace WebCore {
00039 
00040 // Helper function used by linear & radial gradient
00041 void SVGPaintServerGradient::fillColorArray(QGradient& gradient, const Vector<SVGGradientStop>& stops,
00042                                             float opacity) const
00043 {
00044     kDebug() << stops.size() << endl;
00045     for (unsigned i = 0; i < stops.size(); ++i) {
00046         float offset = stops[i].first;
00047         QColor color = stops[i].second;
00048         kDebug() << "offset" << offset << "color" << color << endl;
00049 
00050         QColor c(color.red(), color.green(), color.blue());
00051         c.setAlpha(int(color.alpha() * opacity));
00052 
00053         gradient.setColorAt(offset, c);
00054     }
00055 }
00056 
00057 bool SVGPaintServerGradient::setup(QPainter* painter, QPainterPath* painterPath, const RenderObject* object,
00058                                    SVGPaintTargetType type, bool isPaintingText) const
00059 {
00060     kDebug() << "!!!!!!!" << endl;
00061     m_ownerElement->buildGradient();
00062 
00063     /*QPainter* painter(context ? context->platformContext() : 0);
00064     Q_ASSERT(painter);*/
00065 
00066     /*QPainterPath* path(context ? context->currentPath() : 0);
00067     Q_ASSERT(path);*/
00068 
00069     RenderStyle* renderStyle = object->style();
00070 
00071     QGradient gradient = setupGradient(painter, painterPath, object);
00072 
00073     painter->setPen(Qt::NoPen);
00074     painter->setBrush(Qt::NoBrush);
00075 
00076     if (spreadMethod() == SPREADMETHOD_REPEAT)
00077         gradient.setSpread(QGradient::RepeatSpread);
00078     else if (spreadMethod() == SPREADMETHOD_REFLECT)
00079         gradient.setSpread(QGradient::ReflectSpread);
00080     else
00081         gradient.setSpread(QGradient::PadSpread);    
00082     double opacity = 1.0;
00083 
00084     kDebug() << "type: " << type << (type & ApplyToFillTargetType) << endl;
00085     if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) {
00086         fillColorArray(gradient, gradientStops(), opacity);
00087 
00088         QBrush brush(gradient);
00089         brush.setMatrix(gradientTransform());
00090 
00091         painter->setBrush(brush);
00092         /* FIXME khtml context->setFillRule(renderStyle->svgStyle()->fillRule());*/
00093     }
00094 
00095     if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) {
00096         fillColorArray(gradient, gradientStops(), opacity);
00097 
00098         QPen pen;
00099         QBrush brush(gradient);
00100         brush.setMatrix(gradientTransform());
00101 
00102         setPenProperties(object, renderStyle, pen);
00103         pen.setBrush(brush);
00104 
00105         painter->setPen(pen);
00106     }
00107 
00108     return true;
00109 }
00110 
00111 } // namespace WebCore
00112 
00113 #endif
00114 
00115 // vim:ts=4

KHTML

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal