23#include "kis_debug_areas.h"
24#include "kis_group_layer.h"
27#include "kis_painter.h"
28#include "kis_undo_adapter.h"
32 class KisLayerCommand :
public KNamedCommand {
33 typedef KNamedCommand super;
36 KisLayerCommand(
const TQString& name, KisLayerSP layer);
37 virtual ~KisLayerCommand() {}
39 virtual void execute() = 0;
40 virtual void unexecute() = 0;
43 void setUndo(
bool undo);
48 KisLayerCommand::KisLayerCommand(
const TQString& name, KisLayerSP layer) :
49 super(name), m_layer(layer)
53 void KisLayerCommand::setUndo(
bool undo)
55 if (m_layer->undoAdapter()) {
56 m_layer->undoAdapter()->setUndo(undo);
60 class KisLayerLockedCommand :
public KisLayerCommand {
61 typedef KisLayerCommand super;
64 KisLayerLockedCommand(KisLayerSP layer,
bool newLocked);
66 virtual void execute();
67 virtual void unexecute();
73 KisLayerLockedCommand::KisLayerLockedCommand(KisLayerSP layer,
bool newLocked) :
74 super(i18n(
"Lock Layer"), layer)
76 m_newLocked = newLocked;
79 void KisLayerLockedCommand::execute()
82 m_layer->setLocked(m_newLocked);
86 void KisLayerLockedCommand::unexecute()
89 m_layer->setLocked(!m_newLocked);
93 class KisLayerOpacityCommand :
public KisLayerCommand {
94 typedef KisLayerCommand super;
97 KisLayerOpacityCommand(KisLayerSP layer, TQ_UINT8 oldOpacity, TQ_UINT8 newOpacity);
99 virtual void execute();
100 virtual void unexecute();
103 TQ_UINT8 m_oldOpacity;
104 TQ_UINT8 m_newOpacity;
107 KisLayerOpacityCommand::KisLayerOpacityCommand(KisLayerSP layer, TQ_UINT8 oldOpacity, TQ_UINT8 newOpacity) :
108 super(i18n(
"Layer Opacity"), layer)
110 m_oldOpacity = oldOpacity;
111 m_newOpacity = newOpacity;
114 void KisLayerOpacityCommand::execute()
117 m_layer->setOpacity(m_newOpacity);
121 void KisLayerOpacityCommand::unexecute()
124 m_layer->setOpacity(m_oldOpacity);
128 class KisLayerVisibilityCommand :
public KisLayerCommand {
129 typedef KisLayerCommand super;
132 KisLayerVisibilityCommand(KisLayerSP layer,
bool newVisibility);
134 virtual void execute();
135 virtual void unexecute();
138 bool m_newVisibility;
141 KisLayerVisibilityCommand::KisLayerVisibilityCommand(KisLayerSP layer,
bool newVisibility) :
142 super(i18n(
"Layer Visibility"), layer)
144 m_newVisibility = newVisibility;
147 void KisLayerVisibilityCommand::execute()
150 m_layer->setVisible(m_newVisibility);
154 void KisLayerVisibilityCommand::unexecute()
157 m_layer->setVisible(!m_newVisibility);
161 class KisLayerCompositeOpCommand :
public KisLayerCommand {
162 typedef KisLayerCommand super;
165 KisLayerCompositeOpCommand(KisLayerSP layer,
const KisCompositeOp& oldCompositeOp,
const KisCompositeOp& newCompositeOp);
167 virtual void execute();
168 virtual void unexecute();
171 KisCompositeOp m_oldCompositeOp;
172 KisCompositeOp m_newCompositeOp;
175 KisLayerCompositeOpCommand::KisLayerCompositeOpCommand(KisLayerSP layer,
const KisCompositeOp& oldCompositeOp,
176 const KisCompositeOp& newCompositeOp) :
177 super(i18n(
"Layer Composite Mode"), layer)
179 m_oldCompositeOp = oldCompositeOp;
180 m_newCompositeOp = newCompositeOp;
183 void KisLayerCompositeOpCommand::execute()
186 m_layer->setCompositeOp(m_newCompositeOp);
190 void KisLayerCompositeOpCommand::unexecute()
193 m_layer->setCompositeOp(m_oldCompositeOp);
197 class KisLayerOffsetCommand :
public KNamedCommand {
198 typedef KNamedCommand super;
201 KisLayerOffsetCommand(KisLayerSP layer,
const TQPoint& oldpos,
const TQPoint& newpos);
202 virtual ~KisLayerOffsetCommand();
204 virtual void execute();
205 virtual void unexecute();
208 void moveTo(
const TQPoint& pos);
217 KisLayerOffsetCommand::KisLayerOffsetCommand(KisLayerSP layer,
const TQPoint& oldpos,
const TQPoint& newpos) :
218 super(i18n(
"Move Layer"))
224 TQRect currentBounds = m_layer->exactBounds();
225 TQRect oldBounds = currentBounds;
226 oldBounds.moveBy(oldpos.x() - newpos.x(), oldpos.y() - newpos.y());
228 m_updateRect = currentBounds | oldBounds;
231 KisLayerOffsetCommand::~KisLayerOffsetCommand()
235 void KisLayerOffsetCommand::execute()
240 void KisLayerOffsetCommand::unexecute()
245 void KisLayerOffsetCommand::moveTo(
const TQPoint& pos)
247 if (m_layer->undoAdapter()) {
248 m_layer->undoAdapter()->setUndo(
false);
251 m_layer->setX(pos.x());
252 m_layer->setY(pos.y());
254 m_layer->setDirty(m_updateRect);
256 if (m_layer->undoAdapter()) {
257 m_layer->undoAdapter()->setUndo(
true);
269KisLayer::KisLayer(KisImage *img,
const TQString &name, TQ_UINT8 opacity) :
270 TQObject(0, name.latin1()),
281 m_compositeOp(COMPOSITE_OVER)
285KisLayer::KisLayer(
const KisLayer& rhs) :
292 m_opacity = rhs.m_opacity;
293 m_locked = rhs.m_locked;
294 m_visible = rhs.m_visible;
295 m_temporary = rhs.m_temporary;
296 m_dirtyRect = rhs.m_dirtyRect;
298 m_image = rhs.m_image;
300 m_compositeOp = rhs.m_compositeOp;
310 if (m_dirtyRect.isValid() && rect.isValid()) {
315 m_dirtyRect = TQRect();
322 return m_dirtyRect.isValid();
328 if (!m_dirtyRect.isValid() || !rc.isValid())
return false;
330 return rc.intersects(m_dirtyRect);
333TQRect KisLayer::dirtyRect()
const
342 if (rc.isValid()) m_dirtyRect = rc;
345 if (propagate && m_parent && rc.isValid()) m_parent->setDirty(m_dirtyRect);
347 if (m_image && rc.isValid()) {
348 m_image->notifyLayerUpdated(
this, rc);
359 if (propagate && m_parent && m_dirtyRect.isValid())
360 m_parent->setDirty(m_dirtyRect);
362 if (m_image && rc.isValid()) {
363 m_image->notifyLayerUpdated(
this, rc);
376 return parent()->at(index() - 1);
383 return parent()->at(index() + 1);
386int KisLayer::index()
const
395 parent()->setIndex(
this, i);
402 for (KisLayerSP layer =
firstChild(); layer; layer = layer->nextSibling())
403 if (KisLayerSP found = layer->findLayer(n))
412 for (KisLayerSP layer =
firstChild(); layer; layer = layer->nextSibling())
413 if (KisLayerSP found = layer->findLayer(i))
421 if (matchesFlags(flags)) num++;
422 for (KisLayerSP layer =
firstChild(); layer; layer = layer->nextSibling())
427bool KisLayer::matchesFlags(
int flags)
const
429 if ((flags & Visible) && !visible())
431 if ((flags & Hidden) && visible())
433 if ((flags & Locked) && !locked())
435 if ((flags & Unlocked) && locked())
440TQ_UINT8 KisLayer::opacity()
const
445void KisLayer::setOpacity(TQ_UINT8 val)
447 if (m_opacity != val)
451 notifyPropertyChanged();
455KNamedCommand *KisLayer::setOpacityCommand(TQ_UINT8 newOpacity)
457 return new KisLayerOpacityCommand(
this, opacity(), newOpacity);
460KNamedCommand *KisLayer::setOpacityCommand(TQ_UINT8 prevOpacity, TQ_UINT8 newOpacity)
462 return new KisLayerOpacityCommand(
this, prevOpacity, newOpacity);
465const bool KisLayer::visible()
const
470void KisLayer::setVisible(
bool v)
472 if (m_visible != v) {
475 notifyPropertyChanged();
478 if (undoAdapter() && undoAdapter()->undo()) {
479 undoAdapter()->addCommand(setVisibleCommand(v));
484KNamedCommand *KisLayer::setVisibleCommand(
bool newVisibility)
486 return new KisLayerVisibilityCommand(
this, newVisibility);
489bool KisLayer::locked()
const
494void KisLayer::setLocked(
bool l)
498 notifyPropertyChanged();
500 if (undoAdapter() && undoAdapter()->undo()) {
501 undoAdapter()->addCommand(setLockedCommand(l));
506bool KisLayer::temporary()
const
511void KisLayer::setTemporary(
bool t)
516KNamedCommand *KisLayer::setLockedCommand(
bool newLocked)
518 return new KisLayerLockedCommand(
this, newLocked);
521TQString KisLayer::name()
const
526void KisLayer::setName(
const TQString& name)
528 if (!name.isEmpty() && m_name != name)
531 notifyPropertyChanged();
535void KisLayer::setCompositeOp(
const KisCompositeOp& compositeOp)
537 if (m_compositeOp != compositeOp)
539 m_compositeOp = compositeOp;
540 notifyPropertyChanged();
546KNamedCommand *KisLayer::setCompositeOpCommand(
const KisCompositeOp& newCompositeOp)
548 return new KisLayerCompositeOpCommand(
this, compositeOp(), newCompositeOp);
551KNamedCommand *KisLayer::moveCommand(TQPoint oldPosition, TQPoint newPosition)
553 return new KisLayerOffsetCommand(
this, oldPosition, newPosition);
556KisUndoAdapter *KisLayer::undoAdapter()
const
559 return m_image->undoAdapter();
581void KisLayer::notifyPropertyChanged()
583 if(image() && !signalsBlocked())
584 image()->notifyPropertyChanged(
this);
587void KisLayerSupportsIndirectPainting::setTemporaryTarget(KisPaintDeviceSP t) {
588 m_temporaryTarget = t;
591void KisLayerSupportsIndirectPainting::setTemporaryCompositeOp(
const KisCompositeOp& c) {
595void KisLayerSupportsIndirectPainting::setTemporaryOpacity(TQ_UINT8 o) {
596 m_compositeOpacity = o;
599KisPaintDeviceSP KisLayerSupportsIndirectPainting::temporaryTarget() {
600 return m_temporaryTarget;
603KisCompositeOp KisLayerSupportsIndirectPainting::temporaryCompositeOp()
const {
604 return m_compositeOp;
607TQ_UINT8 KisLayerSupportsIndirectPainting::temporaryOpacity()
const {
608 return m_compositeOpacity;
611#include "kis_layer.moc"
Abstract class that represents the concept of a Layer in Chalk.
virtual KisLayerSP nextSibling() const
Returns the next sibling of this layer in the parent's list.
virtual void setClean(const TQRect &rect)
Set the specified rect to clean.
virtual TQImage createThumbnail(TQ_INT32 w, TQ_INT32 h)
Returns a thumbnail in requested size.
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).
virtual void paintSelection(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
paints a mask where the selection on this layer resides
virtual void paintMaskInactiveLayers(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
paints where no data is on this layer. Useful when it is a transparent layer stacked on top of anothe...
virtual TQRect extent() const =0
Returns an approximation of where the bounds on actual data are in this layer.
virtual KisLayerSP findLayer(const TQString &name) const
Recursively searches this layer and any child layers for a layer with the specified name.
virtual KisGroupLayerSP parent() const
Returns the parent layer of a layer.
virtual int numLayers(int type=0) const
Returns the total number of layers in this layer, its child layers, and their child layers recursivel...
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 setIndex(int index)
Moves this layer to the specified index within its parent's list of child layers.
virtual KisLayerSP prevSibling() const
Returns the previous sibling of this layer in the parent's list.