krita

kis_layer.h

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *  Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
00004  *
00005  *  this program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the gnu general public license as published by
00007  *  the free software foundation; either version 2 of the license, or
00008  *  (at your option) any later version.
00009  *
00010  *  this program is distributed in the hope that it will be useful,
00011  *  but without any warranty; without even the implied warranty of
00012  *  merchantability or fitness for a particular purpose.  see the
00013  *  gnu general public license for more details.
00014  *
00015  *  you should have received a copy of the gnu general public license
00016  *  along with this program; if not, write to the free software
00017  *  foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
00018  */
00019 #ifndef KIS_LAYER_H_
00020 #define KIS_LAYER_H_
00021 
00022 #include <qobject.h>
00023 #include "kis_types.h"
00024 #include "kis_layer_visitor.h"
00025 #include "kis_composite_op.h"
00026 #include <koffice_export.h>
00027 
00028 class KNamedCommand;
00029 class QPainter;
00030 class KisUndoAdapter;
00031 class KisGroupLayer;
00032 
00041 class KRITACORE_EXPORT KisLayer : public QObject, public KShared
00042 {
00043     Q_OBJECT
00044 
00045 public:
00046     KisLayer(KisImage *img, const QString &name, Q_UINT8 opacity);
00047     KisLayer(const KisLayer& rhs);
00048     virtual ~KisLayer();
00049 
00050     
00054     virtual void setClean(const QRect & rect);
00055     
00059     virtual bool dirty();
00060 
00064     virtual bool dirty(const QRect & rc);
00065 
00066 
00067     virtual QRect dirtyRect() const;
00068     
00069     
00074     virtual void setDirty(bool propagate = true);
00075 
00081     virtual void setDirty(const QRect & rect, bool propagate = true);
00082     
00084     virtual KisLayerSP clone() const = 0;
00085 
00087     int id() const { return m_id; }
00088 
00089     /* Returns the index of the layer in its parent's list of child layers. Indices
00090      * increase from 0, which is the topmost layer in the list, to the bottommost.
00091      */
00092     virtual int index() const;
00093 
00095     virtual void setIndex(int index);
00096 
00100     virtual KisGroupLayerSP parent() const;
00101 
00107     virtual KisLayerSP prevSibling() const;
00108 
00114     virtual KisLayerSP nextSibling() const;
00115 
00120     KisLayerSP siblingAbove() const { return prevSibling(); }
00121 
00126     KisLayerSP siblingBelow() const { return nextSibling(); }
00127 
00129     virtual uint childCount() const { return 0; }
00130 
00132     virtual KisLayerSP firstChild() const { return 0; }
00133 
00135     virtual KisLayerSP lastChild() const { return 0; }
00136 
00138     virtual KisLayerSP findLayer(const QString& name) const;
00139 
00141     virtual KisLayerSP findLayer(int id) const;
00142 
00143     enum { Visible = 1, Hidden = 2, Locked = 4, Unlocked = 8 };
00144 
00146     virtual int numLayers(int type = 0) const;
00147 
00148 public:
00150     virtual void activate() {};
00151 
00153     virtual void deactivate() {};
00154 
00155 public:
00156     virtual Q_INT32 x() const = 0;
00157     virtual void setX(Q_INT32) = 0;
00158 
00159     virtual Q_INT32 y() const = 0;
00160     virtual void setY(Q_INT32) = 0;
00161 
00162     virtual KNamedCommand *moveCommand(QPoint oldPosition, QPoint newPosition);
00163 
00165     virtual QRect extent() const = 0;
00167     virtual QRect exactBounds() const = 0;
00168 
00169     virtual const bool visible() const;
00170     virtual void setVisible(bool v);
00171     KNamedCommand *setVisibleCommand(bool visiblel);
00172 
00173     Q_UINT8 opacity() const;
00174     void setOpacity(Q_UINT8 val);
00175     KNamedCommand *setOpacityCommand(Q_UINT8 val);
00176     KNamedCommand *setOpacityCommand(Q_UINT8 prevOpacity, Q_UINT8 newOpacity);
00177 
00178     bool locked() const;
00179     void setLocked(bool l);
00180     KNamedCommand *setLockedCommand(bool locked);
00181 
00182     void notifyPropertyChanged();
00183 
00184     bool temporary() const;
00185     void setTemporary(bool t);
00186 
00187     virtual QString name() const;
00188     virtual void setName(const QString& name);
00189 
00190     KisCompositeOp compositeOp() { return m_compositeOp; }
00191     void setCompositeOp(const KisCompositeOp& compositeOp);
00192     KNamedCommand *setCompositeOpCommand(const KisCompositeOp& compositeOp);
00193 
00194     KisImage *image() const { return m_image; }
00195     virtual void setImage(KisImage *image) { m_image = image; }
00196 
00197     KisUndoAdapter *undoAdapter() const;
00198 
00200     virtual void paintSelection(QImage &img, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00201     virtual void paintSelection(QImage &img, const QRect& scaledImageRect, const QSize& scaledImageSize, const QSize& imageSize);
00202 
00204     virtual void paintMaskInactiveLayers(QImage &img, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00205 
00208     virtual QImage createThumbnail(Q_INT32 w, Q_INT32 h);
00209 
00211     virtual bool accept(KisLayerVisitor &) = 0;
00212 
00213 
00214 private:
00215     friend class KisGroupLayer;
00216 
00217     bool matchesFlags(int flags) const;
00218 
00219     int m_id;
00220     int m_index;
00221     Q_UINT8 m_opacity;
00222     bool m_locked;
00223     bool m_visible;
00224     bool m_temporary;
00225 
00226     // XXX: keep a list of dirty rects instead of always aggegrating them
00227     QRect m_dirtyRect;
00228     QString m_name;
00229     KisGroupLayerSP m_parent;
00230     KisImage *m_image;
00231 
00232     // Operation used to composite this layer with the layers _under_ this layer
00233     KisCompositeOp m_compositeOp;
00234 };
00235 
00236 #endif // KIS_LAYER_H_
00237 
KDE Home | KDE Accessibility Home | Description of Access Keys