chalk

kis_layer.h
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
4 *
5 * this program is free software; you can redistribute it and/or modify
6 * it under the terms of the gnu general public license as published by
7 * the free software foundation; either version 2 of the license, or
8 * (at your option) any later version.
9 *
10 * this program is distributed in the hope that it will be useful,
11 * but without any warranty; without even the implied warranty of
12 * merchantability or fitness for a particular purpose. see the
13 * gnu general public license for more details.
14 *
15 * you should have received a copy of the gnu general public license
16 * along with this program; if not, write to the free software
17 * foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
18 */
19#ifndef KIS_LAYER_H_
20#define KIS_LAYER_H_
21
22#include <tqobject.h>
23#include "kis_types.h"
24#include "kis_layer_visitor.h"
25#include "kis_composite_op.h"
26#include <koffice_export.h>
27
28class KNamedCommand;
29class TQPainter;
30class KisUndoAdapter;
31class KisGroupLayer;
32
41class KRITACORE_EXPORT KisLayer : public TQObject, public TDEShared
42{
43 TQ_OBJECT
44
45
46public:
47 KisLayer(KisImage *img, const TQString &name, TQ_UINT8 opacity);
48 KisLayer(const KisLayer& rhs);
49 virtual ~KisLayer();
50
51
55 virtual void setClean(const TQRect & rect);
56
60 virtual bool dirty();
61
65 virtual bool dirty(const TQRect & rc);
66
67
68 virtual TQRect dirtyRect() const;
69
70
75 virtual void setDirty(bool propagate = true);
76
82 virtual void setDirty(const TQRect & rect, bool propagate = true);
83
85 virtual KisLayerSP clone() const = 0;
86
88 int id() const { return m_id; }
89
90 /* Returns the index of the layer in its parent's list of child layers. Indices
91 * increase from 0, which is the topmost layer in the list, to the bottommost.
92 */
93 virtual int index() const;
94
96 virtual void setIndex(int index);
97
101 virtual KisGroupLayerSP parent() const;
102
108 virtual KisLayerSP prevSibling() const;
109
115 virtual KisLayerSP nextSibling() const;
116
121 KisLayerSP siblingAbove() const { return prevSibling(); }
122
127 KisLayerSP siblingBelow() const { return nextSibling(); }
128
130 virtual uint childCount() const { return 0; }
131
133 virtual KisLayerSP firstChild() const { return 0; }
134
136 virtual KisLayerSP lastChild() const { return 0; }
137
139 virtual KisLayerSP findLayer(const TQString& name) const;
140
142 virtual KisLayerSP findLayer(int id) const;
143
144 enum { Visible = 1, Hidden = 2, Locked = 4, Unlocked = 8 };
145
147 virtual int numLayers(int type = 0) const;
148
149public:
151 virtual void activate() {};
152
154 virtual void deactivate() {};
155
156public:
157 virtual TQ_INT32 x() const = 0;
158 virtual void setX(TQ_INT32) = 0;
159
160 virtual TQ_INT32 y() const = 0;
161 virtual void setY(TQ_INT32) = 0;
162
163 virtual KNamedCommand *moveCommand(TQPoint oldPosition, TQPoint newPosition);
164
166 virtual TQRect extent() const = 0;
168 virtual TQRect exactBounds() const = 0;
169
170 virtual const bool visible() const;
171 virtual void setVisible(bool v);
172 KNamedCommand *setVisibleCommand(bool visiblel);
173
174 TQ_UINT8 opacity() const;
175 void setOpacity(TQ_UINT8 val);
176 KNamedCommand *setOpacityCommand(TQ_UINT8 val);
177 KNamedCommand *setOpacityCommand(TQ_UINT8 prevOpacity, TQ_UINT8 newOpacity);
178
179 bool locked() const;
180 void setLocked(bool l);
181 KNamedCommand *setLockedCommand(bool locked);
182
183 void notifyPropertyChanged();
184
185 bool temporary() const;
186 void setTemporary(bool t);
187
188 virtual TQString name() const;
189 virtual void setName(const TQString& name);
190
191 KisCompositeOp compositeOp() { return m_compositeOp; }
192 void setCompositeOp(const KisCompositeOp& compositeOp);
193 KNamedCommand *setCompositeOpCommand(const KisCompositeOp& compositeOp);
194
195 KisImage *image() const { return m_image; }
196 virtual void setImage(KisImage *image) { m_image = image; }
197
198 KisUndoAdapter *undoAdapter() const;
199
201 virtual void paintSelection(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
202 virtual void paintSelection(TQImage &img, const TQRect& scaledImageRect, const TQSize& scaledImageSize, const TQSize& imageSize);
203
205 virtual void paintMaskInactiveLayers(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
206
209 virtual TQImage createThumbnail(TQ_INT32 w, TQ_INT32 h);
210
212 virtual bool accept(KisLayerVisitor &) = 0;
213
214private:
215 friend class KisGroupLayer;
216
217 bool matchesFlags(int flags) const;
218
219 int m_id;
220 int m_index;
221 TQ_UINT8 m_opacity;
222 bool m_locked;
223 bool m_visible;
224 bool m_temporary;
225
226 // XXX: keep a list of dirty rects instead of always aggegrating them
227 TQRect m_dirtyRect;
228 TQString m_name;
229 KisGroupLayerSP m_parent;
230 KisImage *m_image;
231
232 // Operation used to composite this layer with the layers _under_ this layer
233 KisCompositeOp m_compositeOp;
234};
235
236// For classes that support indirect painting
237class KRITACORE_EXPORT KisLayerSupportsIndirectPainting {
238 // To simulate the indirect painting
239 KisPaintDeviceSP m_temporaryTarget;
240 KisCompositeOp m_compositeOp;
241 TQ_UINT8 m_compositeOpacity;
242public:
243 // Indirect painting
244 void setTemporaryTarget(KisPaintDeviceSP t);
245 void setTemporaryCompositeOp(const KisCompositeOp& c);
246 void setTemporaryOpacity(TQ_UINT8 o);
247 KisPaintDeviceSP temporaryTarget();
248 KisCompositeOp temporaryCompositeOp() const;
249 TQ_UINT8 temporaryOpacity() const;
250
251 // Or I could make KisLayer a virtual base of KisLayerSupportsIndirectPainting and so, but
252 // I'm sure virtual diamond inheritance isn't as appreciated as this
253 virtual KisLayer* layer() = 0;
254};
255
256#endif // KIS_LAYER_H_
257
A KisLayer that bundles child layers into a single layer.
Abstract class that represents the concept of a Layer in Chalk.
Definition kis_layer.h:42
virtual KisLayerSP nextSibling() const
Returns the next sibling of this layer in the parent's list.
KisLayerSP siblingBelow() const
Returns the sibling below this layer in its parent's list.
Definition kis_layer.h:127
KisLayerSP siblingAbove() const
Returns the sibling above this layer in its parent's list.
Definition kis_layer.h:121
virtual void setClean(const TQRect &rect)
Set the specified rect to clean.
int id() const
Returns the ID of the layer, which is guaranteed to be unique among all KisLayers.
Definition kis_layer.h:88
virtual bool dirty()
If the layer has been changed and not been composited yet, this returns true.
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
Definition kis_layer.h:133
virtual void activate()
Called when the layer is made active.
Definition kis_layer.h:151
virtual KisLayerSP clone() const =0
Return a copy of this layer.
virtual bool accept(KisLayerVisitor &)=0
Accept the KisLayerVisitor (for the Visitor design pattern), should call the correct function on the ...
virtual KisLayerSP lastChild() const
Returns the last child layer of this layer (if it supports that).
Definition kis_layer.h:136
virtual TQRect extent() const =0
Returns an approximation of where the bounds on actual data are in this layer.
virtual TQRect exactBounds() const =0
Returns the exact bounds of where the actual data resides in this layer.
virtual uint childCount() const
Returns how many direct child layers this layer has (not recursive).
Definition kis_layer.h:130
virtual void setDirty(bool propagate=true)
Set the entire layer extent dirty; this percolates up to parent layers all the way to the root layer.
virtual void deactivate()
Called when another layer is made active.
Definition kis_layer.h:154
virtual KisLayerSP prevSibling() const
Returns the previous sibling of this layer in the parent's list.