Warning, file /office/calligra/libs/flake/KoFlake.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2009 Jos van den Oever <jos@vandenoever.info> 0003 * Copyright (C) 2009 Thomas Zander <zander@kde.org> 0004 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net> 0005 * Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org> 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Library General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Library General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Library General Public License 0018 * along with this library; see the file COPYING.LIB. If not, write to 0019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include "KoFlake.h" 0024 #include "KoShape.h" 0025 0026 #include <QGradient> 0027 #include <math.h> 0028 0029 QGradient *KoFlake::cloneGradient(const QGradient *gradient) 0030 { 0031 if (! gradient) 0032 return 0; 0033 0034 QGradient *clone = 0; 0035 0036 switch (gradient->type()) { 0037 case QGradient::LinearGradient: 0038 { 0039 const QLinearGradient *lg = static_cast<const QLinearGradient*>(gradient); 0040 clone = new QLinearGradient(lg->start(), lg->finalStop()); 0041 break; 0042 } 0043 case QGradient::RadialGradient: 0044 { 0045 const QRadialGradient *rg = static_cast<const QRadialGradient*>(gradient); 0046 clone = new QRadialGradient(rg->center(), rg->radius(), rg->focalPoint()); 0047 break; 0048 } 0049 case QGradient::ConicalGradient: 0050 { 0051 const QConicalGradient *cg = static_cast<const QConicalGradient*>(gradient); 0052 clone = new QConicalGradient(cg->center(), cg->angle()); 0053 break; 0054 } 0055 default: 0056 return 0; 0057 } 0058 0059 clone->setCoordinateMode(gradient->coordinateMode()); 0060 clone->setSpread(gradient->spread()); 0061 clone->setStops(gradient->stops()); 0062 0063 return clone; 0064 } 0065 0066 QPointF KoFlake::toRelative(const QPointF &absolute, const QSizeF &size) 0067 { 0068 return QPointF(size.width() == 0 ? 0: absolute.x() / size.width(), 0069 size.height() == 0 ? 0: absolute.y() / size.height()); 0070 } 0071 0072 QPointF KoFlake::toAbsolute(const QPointF &relative, const QSizeF &size) 0073 { 0074 return QPointF(relative.x() * size.width(), relative.y() * size.height()); 0075 }