Warning, file /office/calligra/libs/flake/KoFilterEffectLoadingContext.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) 2010 Jan Hambrecht <jaham@gmx.net> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoFilterEffectLoadingContext.h" 0021 0022 #include <QString> 0023 #include <QRectF> 0024 #include <QFileInfo> 0025 #include <QDir> 0026 0027 class Q_DECL_HIDDEN KoFilterEffectLoadingContext::Private 0028 { 0029 public: 0030 Private() 0031 : convertFilterUnits(false), convertFilterPrimitiveUnits(false) 0032 {} 0033 QString basePath; 0034 QRectF shapeBound; 0035 bool convertFilterUnits; 0036 bool convertFilterPrimitiveUnits; 0037 }; 0038 0039 KoFilterEffectLoadingContext::KoFilterEffectLoadingContext(const QString &basePath) 0040 : d(new Private()) 0041 { 0042 d->basePath = basePath; 0043 } 0044 0045 KoFilterEffectLoadingContext::~KoFilterEffectLoadingContext() 0046 { 0047 delete d; 0048 } 0049 0050 void KoFilterEffectLoadingContext::setShapeBoundingBox(const QRectF &shapeBound) 0051 { 0052 d->shapeBound = shapeBound; 0053 } 0054 0055 void KoFilterEffectLoadingContext::enableFilterUnitsConversion(bool enable) 0056 { 0057 d->convertFilterUnits = enable; 0058 } 0059 0060 void KoFilterEffectLoadingContext::enableFilterPrimitiveUnitsConversion(bool enable) 0061 { 0062 d->convertFilterPrimitiveUnits = enable; 0063 } 0064 0065 QPointF KoFilterEffectLoadingContext::convertFilterUnits(const QPointF &value) const 0066 { 0067 if (!d->convertFilterUnits) 0068 return value; 0069 0070 return QPointF(convertFilterUnitsX(value.x()), convertFilterUnitsY(value.y())); 0071 } 0072 0073 qreal KoFilterEffectLoadingContext::convertFilterUnitsX(qreal value) const 0074 { 0075 if (!d->convertFilterUnits) 0076 return value; 0077 0078 return value / d->shapeBound.width(); 0079 } 0080 0081 qreal KoFilterEffectLoadingContext::convertFilterUnitsY(qreal value) const 0082 { 0083 if (!d->convertFilterUnits) 0084 return value; 0085 0086 return value / d->shapeBound.height(); 0087 } 0088 0089 QPointF KoFilterEffectLoadingContext::convertFilterPrimitiveUnits(const QPointF &value) const 0090 { 0091 if (!d->convertFilterPrimitiveUnits) 0092 return value; 0093 0094 return QPointF(convertFilterPrimitiveUnitsX(value.x()), convertFilterPrimitiveUnitsY(value.y())); 0095 } 0096 0097 qreal KoFilterEffectLoadingContext::convertFilterPrimitiveUnitsX(qreal value) const 0098 { 0099 if (!d->convertFilterPrimitiveUnits) 0100 return value; 0101 0102 return value / d->shapeBound.width(); 0103 } 0104 0105 qreal KoFilterEffectLoadingContext::convertFilterPrimitiveUnitsY(qreal value) const 0106 { 0107 if (!d->convertFilterPrimitiveUnits) 0108 return value; 0109 0110 return value / d->shapeBound.height(); 0111 } 0112 0113 QString KoFilterEffectLoadingContext::pathFromHref(const QString &href) const 0114 { 0115 QFileInfo info(href); 0116 if (! info.isRelative()) 0117 return href; 0118 0119 QFileInfo pathInfo(QFileInfo(d->basePath).filePath()); 0120 0121 QString relFile = href; 0122 while (relFile.startsWith(QLatin1String("../"))) { 0123 relFile.remove(0, 3); 0124 pathInfo.setFile(pathInfo.dir(), QString()); 0125 } 0126 0127 QString absFile = pathInfo.absolutePath() + '/' + relFile; 0128 0129 return absFile; 0130 }