19#include "tqpaintdevice.h"
26#include "KoDocument.h"
27#include "KoDocumentChild.h"
33#include "kis_colorspace_factory_registry.h"
34#include "kis_part_layer.h"
35#include "kis_group_layer.h"
36#include "kis_factory.h"
37#include "kis_paint_device.h"
38#include <kis_meta_registry.h>
40KisChildDoc::KisChildDoc ( KisDoc * kisDoc,
const TQRect & rect, KoDocument * childDoc )
41 : KoDocumentChild( kisDoc, childDoc, rect )
48KisChildDoc::KisChildDoc ( KisDoc * kisDoc )
49 : KoDocumentChild( kisDoc)
54KisChildDoc::~KisChildDoc ()
62KisPartLayerImpl::KisPartLayerImpl(KisImageSP img,
KisChildDoc * doc)
63 : super(img, i18n(
"Embedded Document"), OPACITY_OPAQUE), m_doc(doc)
66 KisMetaRegistry::instance()->csRegistry()->getColorSpace(
KisID(
"RGBA",
""),
""), name().latin1() );
70KisPartLayerImpl::~KisPartLayerImpl()
75 return new KisPartLayerImpl(image(),
childDoc());
79void KisPartLayerImpl::childActivated(KoDocumentChild* child)
82 if (!m_activated && child == m_doc) {
86 TQPtrList<KoView> views = child->parentDocument()->views();
87 Q_ASSERT(views.count());
89 connect(views.at(0), TQ_SIGNAL(activated(
bool)),
90 this, TQ_SLOT(childDeactivated(
bool)));
95void KisPartLayerImpl::childDeactivated(
bool activated)
99 if (m_activated && !activated ) {
100 TQPtrList<KoView> views = m_doc->parentDocument()->views();
101 Q_ASSERT(views.count());
102 views.at(0)->disconnect(TQ_SIGNAL(activated(
bool)));
108void KisPartLayerImpl::setX(TQ_INT32 x) {
109 TQRect rect = m_doc->geometry();
113 rect.moveBy(x - this->x(), 0);
114 m_doc->setGeometry(rect);
117void KisPartLayerImpl::setY(TQ_INT32 y) {
118 TQRect rect = m_doc->geometry();
122 rect.moveBy(0, y - this->y());
123 m_doc->setGeometry(rect);
127 uchar *j = img.bits();
128 TQRect rect = m_doc->geometry();
130 for (
int y2 = y; y2 < h + y; ++y2) {
131 for (
int x2 = x; x2 < w + x; ++x2) {
132 if (!rect.contains(x2, y2)) {
133 TQ_UINT8 g = (*(j + 0) + *(j + 1 ) + *(j + 2 )) / 9;
144KisPaintDeviceSP KisPartLayerImpl::prepareProjection(KisPaintDeviceSP projection,
const TQRect& r)
146 if (!m_doc || !m_doc->document() || m_activated)
return 0;
151 if (intersection.isEmpty())
157 TQRect embedRect(intersection);
162 TQPixmap pm1(projection->convertToTQImage(0 ,
163 intersection.x(), intersection.y(),
164 intersection.width(), intersection.height()));
166 copyBlt(&pm2, embedRect.x(), embedRect.y(), &pm1,
167 0, 0, embedRect.width(), embedRect.height());
168 TQPainter painter(&pm2);
169 painter.setClipRect(embedRect);
176 m_doc->document()->paintEverything(painter, paintRect,
true);
178 copyBlt(&pm1, 0, 0, &pm2,
179 embedRect.x(), embedRect.y(), embedRect.width(), embedRect.height());
180 TQImage qimg = pm1.convertToImage();
184 m_cache->convertFromTQImage(qimg,
"", intersection.left(), intersection.top());
192 TQPainter painter(&pm);
194 painter.fillRect(0, 0, w, h, TQt::white);
196 painter.scale(w / bounds.width(), h / bounds.height());
197 m_doc->document()->paintEverything(painter, bounds);
198 TQImage qimg = pm.convertToImage();
203bool KisPartLayerImpl::saveToXML(TQDomDocument doc, TQDomElement elem)
205 TQDomElement embeddedElement = doc.createElement(
"layer");
206 embeddedElement.setAttribute(
"name", name());
209 embeddedElement.setAttribute(
"x", 0);
210 embeddedElement.setAttribute(
"y", 0);
212 embeddedElement.setAttribute(
"opacity", opacity());
213 embeddedElement.setAttribute(
"compositeop", compositeOp().
id().
id());
214 embeddedElement.setAttribute(
"visible", visible());
215 embeddedElement.setAttribute(
"locked", locked());
216 embeddedElement.setAttribute(
"layertype",
"partlayer");
217 elem.appendChild(embeddedElement);
219 TQDomElement objectElem =
childDoc()->save(doc);
220 embeddedElement.appendChild(objectElem);
225KisConnectPartLayerVisitor::KisConnectPartLayerVisitor(KisImageSP img, KisView* view,
bool mode)
226 : m_img(img), m_view(view), m_connect(mode)
230bool KisConnectPartLayerVisitor::visit(
KisGroupLayer *layer) {
234 child->accept(*
this);
235 child = child->prevSibling();
241bool KisConnectPartLayerVisitor::visit(
KisPartLayer *layer) {
243 TQObject::connect(m_view, TQ_SIGNAL(childActivated(KoDocumentChild*)),
244 layer, TQ_SLOT(childActivated(KoDocumentChild*)));
246 TQObject::disconnect(m_view, TQ_SIGNAL(childActivated(KoDocumentChild*)), layer, 0 );
260#include "kis_part_layer.moc"
Class that contains a KisFilter and optionally a KisSelection.
The child document is responsible for saving and loading the embedded layers.
A KisLayer that bundles child layers into a single layer.
virtual KisLayerSP lastChild() const
Returns the last child layer of this layer (if it supports that).
Chalk has a large number of extensible resources.
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.
A paint device contains the actual pixel data and offers methods to read and write pixels.
This layer is of a type that can be painted on.
virtual TQRect extent() const
Returns an approximation of where the bounds on actual data are in this layer.
virtual TQImage createThumbnail(TQ_INT32 w, TQ_INT32 h)
Returns a thumbnail in requested size.
virtual KisChildDoc * childDoc() const
Returns the childDoc so that we can access the doc from other places, if need be (KisDoc).
virtual TQRect exactBounds() const
Returns the exact bounds of where the actual data resides in this layer.
virtual KisLayerSP clone() const
Return a copy of this layer.
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
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.