krita

kis_paint_layer.h

00001 /*
00002  *  Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
00003  *
00004  *  this program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the gnu general public license as published by
00006  *  the free software foundation; either version 2 of the license, or
00007  *  (at your option) any later version.
00008  *
00009  *  this program is distributed in the hope that it will be useful,
00010  *  but without any warranty; without even the implied warranty of
00011  *  merchantability or fitness for a particular purpose.  see the
00012  *  gnu general public license for more details.
00013  *
00014  *  you should have received a copy of the gnu general public license
00015  *  along with this program; if not, write to the free software
00016  *  foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
00017  */
00018 #ifndef KIS_PAINT_LAYER_H_
00019 #define KIS_PAINT_LAYER_H_
00020 
00021 #include "kis_types.h"
00022 #include "kis_layer.h"
00023 #include "kis_paint_device.h"
00024 #include "kis_colorspace.h"
00028 class KisPaintLayer : public KisLayer, public KisLayerSupportsIndirectPainting {
00029     typedef KisLayer super;
00030 
00031     Q_OBJECT
00032 
00033 public:
00034     KisPaintLayer(KisImage *img, const QString& name, Q_UINT8 opacity, KisPaintDeviceSP dev);
00035     KisPaintLayer(KisImage *img, const QString& name, Q_UINT8 opacity);
00036     KisPaintLayer(KisImage *img, const QString& name, Q_UINT8 opacity, KisColorSpace * colorSpace);
00037     KisPaintLayer(const KisPaintLayer& rhs);
00038     virtual ~KisPaintLayer();
00039 
00040     virtual KisLayerSP clone() const;
00041 public:
00042 
00043     // Called when the layer is made active
00044     virtual void activate() {}
00045 
00046     // Called when another layer is made active
00047     virtual void deactivate() {}
00048 
00049     virtual Q_INT32 x() const;
00050     virtual void setX(Q_INT32 x);
00051 
00052     virtual Q_INT32 y() const;
00053     virtual void setY(Q_INT32 y);
00054 
00055     virtual QRect extent() const;
00056     virtual QRect exactBounds() const;
00057 
00058     virtual void paintSelection(QImage &img, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00059     virtual void paintSelection(QImage &img, const QRect& scaledImageRect, const QSize& scaledImageSize, const QSize& imageSize);
00060 
00061     virtual void paintMaskInactiveLayers(QImage &img, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00062 
00063     virtual QImage createThumbnail(Q_INT32 w, Q_INT32 h);
00064 
00065     virtual bool accept(KisLayerVisitor &v)
00066         {
00067 //            kdDebug(41001) << "\tPAINT\t" << name()
00068 //                    << " dirty: " << dirty() << "\n";
00069             return v.visit(this);
00070         }
00071 
00072 
00073     inline KisPaintDeviceSP paintDevice() const { return m_paintdev; }
00074 
00076     inline KisPaintDeviceSP paintDeviceOrMask() const {
00077         if (hasMask() && editMask())
00078             return m_mask;
00079         return m_paintdev;
00080     }
00081 
00082     // Mask Layer
00083 
00085     bool hasMask() const { return m_mask != 0; }
00086     // XXX TODO: Make these undo-able!
00088     KisPaintDeviceSP createMask();
00090     void createMaskFromPaintDevice(KisPaintDeviceSP from);
00095     void createMaskFromSelection(KisSelectionSP from);
00097     void removeMask();
00099     void applyMask();
00101     KisPaintDeviceSP getMask();
00103     KisSelectionSP getMaskAsSelection();
00104 
00106     KNamedCommand* createMaskCommand();
00108     KNamedCommand* maskFromSelectionCommand();
00110     KNamedCommand* maskToSelectionCommand();
00112     KNamedCommand* removeMaskCommand();
00114     KNamedCommand* applyMaskCommand();
00115 
00117     bool renderMask() const { return m_renderMask; }
00119     void setRenderMask(bool b);
00120 
00126     bool editMask() const { return m_editMask; }
00128     void setEditMask(bool b);
00129 
00131     virtual void setDirty(bool propagate = true);
00133     virtual void setDirty(const QRect & rect, bool propagate = true);
00134 
00135     // KisLayerSupportsIndirectPainting
00136     virtual KisLayer* layer() { return this; }
00137 signals:
00139     void sigMaskInfoChanged();
00140 
00141 private:
00142     void convertMaskToSelection(const QRect& r);
00143     void genericMaskCreationHelper();
00144     KisPaintDeviceSP m_paintdev;
00145     // Layer mask related:
00146     // XXX It would be nice to merge the next 2 devices...
00147     KisPaintDeviceSP m_mask; // The mask that we can edit and display easily
00148     KisSelectionSP m_maskAsSelection; // The mask as selection, to apply and render easily
00149     bool m_renderMask;
00150     bool m_editMask;
00151 };
00152 
00153 typedef KSharedPtr<KisPaintLayer> KisPaintLayerSP;
00154 
00155 #endif // KIS_PAINT_LAYER_H_
00156 
KDE Home | KDE Accessibility Home | Description of Access Keys