1 /* 2 * Copyright (c) 2008 Boudewijn Rempt <boud@valdyas.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 #ifndef KIS_GENERATOR_LAYER_H_ 19 #define KIS_GENERATOR_LAYER_H_ 20 21 #include "kis_selection_based_layer.h" 22 #include <kritaimage_export.h> 23 #include <KisDelayedUpdateNodeInterface.h> 24 25 #include <QScopedPointer> 26 27 class KisFilterConfiguration; 28 29 /** 30 * A generator layer is a special kind of layer that can be prefilled 31 * with some pixel pattern generated by a KisGenerator plugin. 32 * A KisGenerator is similar to a filter, but doesn't take 33 * input pixel data and creates new pixel data. 34 * 35 * It is not possible to destructively paint on a generator layer. 36 * 37 * XXX: what about threadedness? 38 */ 39 class KRITAIMAGE_EXPORT KisGeneratorLayer 40 : public KisSelectionBasedLayer, 41 public KisDelayedUpdateNodeInterface 42 { 43 Q_OBJECT 44 45 public: 46 /** 47 * Create a new Generator layer with the given configuration 48 * and selection. Note that the selection will be _copied_ 49 * (using COW, though). 50 */ 51 KisGeneratorLayer(KisImageWSP image, const QString &name, KisFilterConfigurationSP kfc, KisSelectionSP selection); 52 KisGeneratorLayer(const KisGeneratorLayer& rhs); 53 ~KisGeneratorLayer() override; 54 clone()55 KisNodeSP clone() const override { 56 return KisNodeSP(new KisGeneratorLayer(*this)); 57 } 58 59 void setFilter(KisFilterConfigurationSP filterConfig) override; 60 /** 61 * Changes the filter configuration without triggering an update. 62 */ 63 void setFilterWithoutUpdate(KisFilterConfigurationSP filterConfig); 64 65 bool accept(KisNodeVisitor &) override; 66 void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override; 67 68 QIcon icon() const override; 69 KisBaseNode::PropertyList sectionModelProperties() const override; 70 71 /** 72 * re-run the generator. This happens over the bounds 73 * of the associated selection. 74 */ 75 void update(); 76 /** 77 * re-runs the generator with the specified configuration. 78 * Used for previewing the layer inside the stroke. 79 */ 80 void previewWithStroke(const KisStrokeId stroke); 81 82 using KisSelectionBasedLayer::setDirty; 83 void setDirty(const QVector<QRect> &rects) override; 84 /** 85 * Updates the selected tiles without triggering the update job. 86 */ 87 void setDirtyWithoutUpdate(const QVector<QRect> &rects); 88 void setX(qint32 x) override; 89 void setY(qint32 y) override; 90 91 void resetCache() override; 92 93 void forceUpdateTimedNode() override; 94 bool hasPendingTimedUpdates() const override; 95 96 private Q_SLOTS: 97 void slotDelayedStaticUpdate(); 98 99 private: 100 /** 101 * Injects render jobs into the given stroke. 102 */ 103 void requestUpdateJobsWithStroke(const KisStrokeId stroke, const KisFilterConfigurationSP configuration); 104 /** 105 * Resets the projection cache without triggering the update job. 106 */ 107 void resetCacheWithoutUpdate(); 108 109 public: 110 // KisIndirectPaintingSupport layer()111 KisLayer* layer() { 112 return this; 113 } 114 115 private: 116 struct Private; 117 const QScopedPointer<Private> m_d; 118 }; 119 120 #endif 121 122