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

KHTML

SVGPaintServerRadialGradientQt.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 "SVGPaintServerRadialGradient.h"
00027 
00028 /*#include "GraphicsContext.h"*/
00029 #include "RenderPath.h"
00030 
00031 #include <math.h>
00032 #include <QPainter>
00033 #include <QPainterPath>
00034 #include <QRadialGradient>
00035 
00036 namespace WebCore {
00037 
00038 QGradient SVGPaintServerRadialGradient::setupGradient(QPainter* painter, QPainterPath* painterPath, const RenderObject* object) const
00039 {
00040     Q_UNUSED(object);
00041     //QPainter* painter(context ? context->platformContext() : 0);
00042     //Q_ASSERT(painter);
00043 
00044     //QPainterPath* path(context ? context->currentPath() : 0);
00045     //Q_ASSERT(path);
00046     QPainterPath* path(painterPath);
00047 
00048     //RenderStyle* renderStyle = object->style();
00049 
00050     QMatrix mat = painter->matrix();
00051 
00052     double cx, fx, cy, fy, r;
00053     if (boundingBoxMode()) {
00054         QRectF bbox = path->boundingRect(); 
00055         cx = double(bbox.left()) + (double(gradientCenter().x() / 100.0) * double(bbox.width()));
00056         cy = double(bbox.top()) + (double(gradientCenter().y() / 100.0) * double(bbox.height()));
00057         fx = double(bbox.left()) + (double(gradientFocal().x() / 100.0) * double(bbox.width())) - cx;
00058         fy = double(bbox.top()) + (double(gradientFocal().y() / 100.0) * double(bbox.height())) - cy;
00059         r = double(gradientRadius() / 100.0) * (sqrt(pow(bbox.width(), 2) + pow(bbox.height(), 2)));
00060 
00061         float width = bbox.width();
00062         float height = bbox.height();
00063 
00064         int diff = int(width - height); // allow slight tolerance
00065         if (!(diff > -2 && diff < 2)) {
00066             // make elliptical or circular depending on bbox aspect ratio
00067             float ratioX = (width / height);
00068             float ratioY = (height / width);
00069             mat.scale((width > height) ? 1 : ratioX, (width > height) ? ratioY : 1);
00070         }
00071     } else {
00072         cx = gradientCenter().x();
00073         cy = gradientCenter().y();
00074 
00075         fx = gradientFocal().x();
00076         fy = gradientFocal().y();
00077 
00078         fx -= cx;
00079         fy -= cy;
00080 
00081         r = gradientRadius();
00082     }
00083 
00084     if (sqrt(fx * fx + fy * fy) > r) {
00085         // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and r, set (fx, fy)
00086         // to the point of intersection of the line through (fx, fy) and the circle.
00087         double angle = atan2(fy, fx);
00088         fx = int(cos(angle) * r) - 1;
00089         fy = int(sin(angle) * r) - 1;
00090     }
00091 
00092     kDebug() << "cx:" << cx << "cy:" << cy << "radius:" << gradientRadius() << "fx:" << fx + cx << "fy:" << fy + cy << endl;
00093     QRadialGradient gradient(QPointF(cx, cy), gradientRadius(), QPointF(fx + cx, fy + cy));
00094 
00095     return gradient;
00096 }
00097 
00098 } // namespace WebCore
00099 
00100 #endif
00101 
00102 // vim:ts=4:noet

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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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