Warning, file /office/calligra/libs/flake/KoFilterEffect.h 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 Cyrille Berger <cberger@cberger.net> 0003 * Copyright (c) 2009 Jan Hambrecht <jaham@gmx.net> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2.1 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef _KO_FILTER_EFFECT_H_ 0022 #define _KO_FILTER_EFFECT_H_ 0023 0024 class QImage; 0025 class QString; 0026 class QRectF; 0027 class KoXmlWriter; 0028 class KoFilterEffectRenderContext; 0029 class KoFilterEffectLoadingContext; 0030 class KoXmlElement; 0031 0032 #include "flake_export.h" 0033 #include <QList> 0034 0035 /** 0036 * This is the base for filter effect (blur, invert...) that can be applied on a shape. 0037 * All sizes and coordinates of the filter effect are stored in object bounding box 0038 * coordinates, where (0,0) refers to the top-left corner of a shapes bounding rect 0039 * and (1,1) refers to the bottom-right corner. 0040 * When loading, a transformation matrix is given to convert from user space coordinates. 0041 * Another transformation matrix is given via the render context to convert back to 0042 * user space coordinates when applying the effect. 0043 * Using object bounding box coordinates internally makes it easy to share effects 0044 * between shapes or even between users via the filter effect resources. 0045 */ 0046 class FLAKE_EXPORT KoFilterEffect 0047 { 0048 public: 0049 KoFilterEffect(const QString &id, const QString &name); 0050 virtual ~KoFilterEffect(); 0051 0052 /// Returns the user visible name of the filter 0053 QString name() const; 0054 0055 /// Returns the unique id of the filter 0056 QString id() const; 0057 0058 /// Sets the region the filter is applied to in bounding box units 0059 void setFilterRect(const QRectF &filterRect); 0060 0061 /// Returns the region this filter is applied to in bounding box units 0062 QRectF filterRect() const; 0063 0064 /// Returns the region this filter is applied to for the given bounding rect 0065 QRectF filterRectForBoundingRect(const QRectF &boundingRect) const; 0066 0067 /** 0068 * Sets the name of the output image 0069 * 0070 * The name is used so that other effects can reference 0071 * the output of this effect as one of their input images. 0072 * 0073 * @param output the output image name 0074 */ 0075 void setOutput(const QString &output); 0076 0077 /// Returns the name of the output image 0078 QString output() const; 0079 0080 /** 0081 * Returns list of named input images of this filter effect. 0082 * 0083 * These names identify the input images for this filter effect. 0084 * These can be one of the keywords SourceGraphic, SourceAlpha, 0085 * BackgroundImage, BackgroundAlpha, FillPaint or StrokePaint, 0086 * as well as a named output of another filter effect in the stack. 0087 * An empty input list of the first effect in the stack default to 0088 * SourceGraphic, whereas on subsequent effects it defaults to the 0089 * result of the previous filter effect. 0090 */ 0091 QList<QString> inputs() const; 0092 0093 /// Adds a new input at the end of the input list 0094 void addInput(const QString &input); 0095 0096 /// Inserts an input at the giben position in the input list 0097 void insertInput(int index, const QString &input); 0098 0099 /// Sets an existing input to a new value 0100 void setInput(int index, const QString &input); 0101 0102 /// Removes an input from the given position in the input list 0103 void removeInput(int index); 0104 0105 /** 0106 * Return the required number of input images. 0107 * The default required number of input images is 1. 0108 * Derived classes should call setRequiredInputCount to set 0109 * a different number. 0110 */ 0111 int requiredInputCount() const; 0112 0113 /** 0114 * Returns the maximal number of input images. 0115 * The default maximal number of input images is 1. 0116 * Derived classes should call setMaximalInputCount to set 0117 * a different number. 0118 */ 0119 int maximalInputCount() const; 0120 0121 /** 0122 * Apply the effect on an image. 0123 * @param image the image the filter should be applied to 0124 * @param context the render context providing additional data 0125 */ 0126 virtual QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const; 0127 0128 /** 0129 * Apply the effect on a list of images. 0130 * @param images the images the filter should be applied to 0131 * @param context the render context providing additional data 0132 */ 0133 virtual QImage processImages(const QVector<QImage> &images, const KoFilterEffectRenderContext &context) const; 0134 0135 /** 0136 * Loads data from given xml element. 0137 * @param element the xml element to load data from 0138 * @param context the loading context providing additional data 0139 * @return true if loading was successful, else false 0140 */ 0141 virtual bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context); 0142 0143 /** 0144 * Writes custom data to given xml element. 0145 * @param writer the xml writer to write data to 0146 */ 0147 virtual void save(KoXmlWriter &writer); 0148 0149 protected: 0150 /// Sets the required number of input images 0151 void setRequiredInputCount(int count); 0152 0153 /// Sets the maximal number of input images 0154 void setMaximalInputCount(int count); 0155 0156 /** 0157 * Saves common filter attributes 0158 * 0159 * Saves result, subregion and input attributes. The input attrinbute 0160 * is only saved if required, maximal and actual input count equals 1. 0161 * All other filters have to write inputs on their own. 0162 */ 0163 void saveCommonAttributes(KoXmlWriter &writer); 0164 0165 private: 0166 class Private; 0167 Private* const d; 0168 }; 0169 0170 #endif // _KO_FILTER_EFFECT_H_