krita
kis_adjustment_layer.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <kdebug.h>
00021 #include <qimage.h>
00022
00023 #include "kis_debug_areas.h"
00024 #include "kis_group_layer.h"
00025 #include "kis_image.h"
00026 #include "kis_layer.h"
00027 #include "kis_adjustment_layer.h"
00028 #include "kis_painter.h"
00029 #include "kis_undo_adapter.h"
00030 #include "kis_selection.h"
00031 #include "kis_fill_painter.h"
00032
00033 KisAdjustmentLayer::KisAdjustmentLayer(KisImageSP img, const QString &name, KisFilterConfiguration * kfc, KisSelectionSP selection)
00034 : KisLayer (img, name, OPACITY_OPAQUE)
00035 {
00036 m_filterConfig = kfc;
00037 setSelection( selection );
00038 m_cachedPaintDev = new KisPaintDevice( img->colorSpace(), name.latin1());
00039 Q_ASSERT(m_cachedPaintDev);
00040 }
00041
00042 KisAdjustmentLayer::KisAdjustmentLayer(const KisAdjustmentLayer& rhs)
00043 : KisLayer(rhs)
00044 {
00045 m_filterConfig = new KisFilterConfiguration(*rhs.m_filterConfig);
00046 if (rhs.m_selection) {
00047 m_selection = new KisSelection( *rhs.m_selection.data() );
00048 m_selection->setParentLayer(this);
00049 }
00050 m_cachedPaintDev = new KisPaintDevice( *rhs.m_cachedPaintDev.data() );
00051 }
00052
00053
00054 KisAdjustmentLayer::~KisAdjustmentLayer()
00055 {
00056 delete m_filterConfig;
00057 }
00058
00059
00060 KisLayerSP KisAdjustmentLayer::clone() const
00061 {
00062 return new KisAdjustmentLayer(*this);
00063 }
00064
00065
00066 void KisAdjustmentLayer::resetCache()
00067 {
00068 m_cachedPaintDev = new KisPaintDevice(image()->colorSpace(), name().latin1());
00069 }
00070
00071 KisFilterConfiguration * KisAdjustmentLayer::filter()
00072 {
00073 Q_ASSERT(m_filterConfig);
00074 return m_filterConfig;
00075 }
00076
00077
00078 void KisAdjustmentLayer::setFilter(KisFilterConfiguration * filterConfig)
00079 {
00080 Q_ASSERT(filterConfig);
00081 m_filterConfig = filterConfig;
00082 }
00083
00084
00085 KisSelectionSP KisAdjustmentLayer::selection()
00086 {
00087 return m_selection;
00088 }
00089
00090 void KisAdjustmentLayer::setSelection(KisSelectionSP selection)
00091 {
00092 m_selection = new KisSelection();
00093 KisFillPainter gc(m_selection.data());
00094 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
00095
00096 if (selection) {
00097 gc.bitBlt(0, 0, COMPOSITE_COPY, selection.data(),
00098 0, 0, image()->bounds().width(), image()->bounds().height());
00099 } else {
00100 gc.fillRect(image()->bounds(), KisColor(Qt::white, cs), MAX_SELECTED);
00101 }
00102
00103 gc.end();
00104
00105 m_selection->setParentLayer(this);
00106 }
00107
00108
00109 Q_INT32 KisAdjustmentLayer::x() const
00110 {
00111 if (m_selection)
00112 return m_selection->getX();
00113 else
00114 return 0;
00115 }
00116
00117 void KisAdjustmentLayer::setX(Q_INT32 x)
00118 {
00119 if (m_selection) {
00120 m_selection->setX(x);
00121 resetCache();
00122 }
00123
00124 }
00125
00126 Q_INT32 KisAdjustmentLayer::y() const
00127 {
00128 if (m_selection)
00129 return m_selection->getY();
00130 else
00131 return 0;
00132 }
00133
00134 void KisAdjustmentLayer::setY(Q_INT32 y)
00135 {
00136 if (m_selection) {
00137 m_selection->setY(y);
00138 resetCache();
00139 }
00140 }
00141
00142 QRect KisAdjustmentLayer::extent() const
00143 {
00144 if (m_selection)
00145 return m_selection->extent();
00146 else if (image())
00147 return image()->bounds();
00148 else
00149 return QRect();
00150 }
00151
00152 QRect KisAdjustmentLayer::exactBounds() const
00153 {
00154 if (m_selection)
00155 return m_selection->exactBounds();
00156 else if (image())
00157 return image()->bounds();
00158 else
00159 return QRect();
00160 }
00161
00162 bool KisAdjustmentLayer::accept(KisLayerVisitor & v)
00163 {
00164 return v.visit( this );
00165 }
00166
00167 #include "kis_adjustment_layer.moc"
|