Warning, file /office/calligra/libs/flake/KoFilterEffectStack.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-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 "KoFilterEffectStack.h"
0021 #include "KoFilterEffect.h"
0022 #include "KoXmlWriter.h"
0023 
0024 #include <QRectF>
0025 #include <QAtomicInt>
0026 #include <QSet>
0027 #include <QDebug>
0028 
0029 class Q_DECL_HIDDEN KoFilterEffectStack::Private
0030 {
0031 public:
0032     Private()
0033     : clipRect(-0.1, -0.1, 1.2, 1.2) // initialize as per svg spec
0034     {
0035     }
0036 
0037     ~Private()
0038     {
0039         qDeleteAll(filterEffects);
0040     }
0041 
0042     QList<KoFilterEffect*> filterEffects;
0043     QRectF clipRect;
0044     QAtomicInt refCount;
0045 };
0046 
0047 KoFilterEffectStack::KoFilterEffectStack()
0048 : d(new Private())
0049 {
0050 }
0051 
0052 KoFilterEffectStack::~KoFilterEffectStack()
0053 {
0054     delete d;
0055 }
0056 
0057 QList<KoFilterEffect*> KoFilterEffectStack::filterEffects() const
0058 {
0059     return d->filterEffects;
0060 }
0061 
0062 bool KoFilterEffectStack::isEmpty() const
0063 {
0064     return d->filterEffects.isEmpty();
0065 }
0066 
0067 void KoFilterEffectStack::insertFilterEffect(int index, KoFilterEffect * filter)
0068 {
0069     if (filter)
0070         d->filterEffects.insert(index, filter);
0071 }
0072 
0073 void KoFilterEffectStack::appendFilterEffect(KoFilterEffect *filter)
0074 {
0075     if (filter)
0076         d->filterEffects.append(filter);
0077 }
0078 
0079 void KoFilterEffectStack::removeFilterEffect(int index)
0080 {
0081     KoFilterEffect * filter = takeFilterEffect(index);
0082     delete filter;
0083 }
0084 
0085 KoFilterEffect* KoFilterEffectStack::takeFilterEffect(int index)
0086 {
0087     if (index >= d->filterEffects.size())
0088         return 0;
0089     return d->filterEffects.takeAt(index);
0090 }
0091 
0092 void KoFilterEffectStack::setClipRect(const QRectF &clipRect)
0093 {
0094     d->clipRect = clipRect;
0095 }
0096 
0097 QRectF KoFilterEffectStack::clipRect() const
0098 {
0099     return d->clipRect;
0100 }
0101 
0102 QRectF KoFilterEffectStack::clipRectForBoundingRect(const QRectF &boundingRect) const
0103 {
0104     qreal x = boundingRect.x() + d->clipRect.x() * boundingRect.width();
0105     qreal y = boundingRect.y() + d->clipRect.y() * boundingRect.height();
0106     qreal w = d->clipRect.width() * boundingRect.width();
0107     qreal h = d->clipRect.height() * boundingRect.height();
0108     return QRectF(x, y, w, h);
0109 }
0110 
0111 bool KoFilterEffectStack::ref()
0112 {
0113     return d->refCount.ref();
0114 }
0115 
0116 bool KoFilterEffectStack::deref()
0117 {
0118     return d->refCount.deref();
0119 }
0120 
0121 int KoFilterEffectStack::useCount() const
0122 {
0123     return d->refCount;
0124 }
0125 
0126 void KoFilterEffectStack::save(KoXmlWriter &writer, const QString &filterId)
0127 {
0128     writer.startElement("filter");
0129     writer.addAttribute("id", filterId);
0130     writer.addAttribute("filterUnits", "objectBoundingBox");
0131     writer.addAttribute("primitiveUnits", "objectBoundingBox");
0132     writer.addAttribute("x", d->clipRect.x());
0133     writer.addAttribute("y", d->clipRect.y());
0134     writer.addAttribute("width", d->clipRect.width());
0135     writer.addAttribute("height", d->clipRect.height());
0136 
0137     foreach(KoFilterEffect *effect, d->filterEffects) {
0138         effect->save(writer);
0139     }
0140 
0141     writer.endElement();
0142 }
0143 
0144 QSet<QString> KoFilterEffectStack::requiredStandarsInputs() const
0145 {
0146     static QSet<QString> stdInputs = QSet<QString>()
0147         << "SourceGraphic"
0148         << "SourceAlpha"
0149         << "BackgroundImage"
0150         << "BackgroundAlpha"
0151         << "FillPaint"
0152         << "StrokePaint";
0153 
0154     QSet<QString> requiredInputs;
0155     if (isEmpty())
0156         return requiredInputs;
0157 
0158     if (d->filterEffects.first()->inputs().contains(""))
0159         requiredInputs.insert("SourceGraphic");
0160 
0161     foreach(KoFilterEffect *effect, d->filterEffects) {
0162         foreach(const QString &input, effect->inputs()) {
0163             if (stdInputs.contains(input))
0164                 requiredInputs.insert(input);
0165         }
0166     }
0167 
0168     return requiredInputs;
0169 }