Commit 044ce0f8 authored by Halla Rempt's avatar Halla Rempt
Browse files

Don't crash when d&d'ing a shape layer

The content of the shape layer isn't visible yet, though.

CCBUG:297393
parent 2c1593ad
......@@ -190,7 +190,7 @@ void KisLayer::disableAlphaChannel(bool disable)
{
if(m_d->channelFlags.isEmpty())
m_d->channelFlags = colorSpace()->channelFlags(true, true);
if(disable)
m_d->channelFlags &= colorSpace()->channelFlags(true, false);
else
......@@ -232,6 +232,7 @@ KisImageWSP KisLayer::image() const
void KisLayer::setImage(KisImageWSP image)
{
qDebug() << ">>>>>>>>>>>> " << kisimage;
m_d->image = image;
for (uint i = 0; i < childCount(); ++i) {
// Only layers know about the image
......
......@@ -165,7 +165,7 @@ public:
/**
* Set the image this layer belongs to.
*/
void setImage(KisImageWSP image);
virtual void setImage(KisImageWSP image);
/**
* Clones should be informed about updates of the original
......
......@@ -87,7 +87,9 @@
class ShapeLayerContainerModel : public SimpleShapeContainerModel
{
public:
ShapeLayerContainerModel(KisShapeLayer *parent) : q(parent) {}
ShapeLayerContainerModel(KisShapeLayer *parent)
: q(parent)
{}
void add(KoShape *child) {
SimpleShapeContainerModel::add(child);
......@@ -107,7 +109,13 @@ private:
struct KisShapeLayer::Private
{
public:
Private() : x(0), y(0) {}
Private()
: converter(0)
, canvas(0)
, controller(0)
, x(0)
, y(0)
{}
KoViewConverter * converter;
KisPaintDeviceSP paintDevice;
......@@ -158,7 +166,7 @@ KisShapeLayer::~KisShapeLayer()
* Small hack alert: we set the image to null to disable
* updates those will be emitted on shape deletion
*/
setImage(0);
KisLayer::setImage(0);
foreach(KoShape *shape, shapes()) {
shape->setParent(0);
......@@ -179,6 +187,8 @@ void KisShapeLayer::initShapeLayer(KoShapeBasedDocumentBase* controller)
m_d->canvas->setProjection(m_d->paintDevice);
m_d->controller = controller;
m_d->canvas->shapeManager()->selection()->disconnect(this);
connect(m_d->canvas->shapeManager()->selection(), SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
connect(m_d->canvas->shapeManager()->selection(), SIGNAL(currentLayerChanged(const KoShapeLayer*)), this, SIGNAL(currentLayerChanged(const KoShapeLayer*)));
......@@ -190,6 +200,14 @@ bool KisShapeLayer::allowAsChild(KisNodeSP node) const
return node->inherits("KisMask");
}
void KisShapeLayer::setImage(KisImageWSP _image)
{
KisLayer::setImage(_image);
delete m_d->converter;
m_d->converter = new KisImageViewConverter(image());
m_d->paintDevice = new KisPaintDevice(image()->colorSpace());
}
QIcon KisShapeLayer::icon() const
{
return KIcon("bookmark-new");
......
......@@ -66,6 +66,8 @@ public:
}
bool allowAsChild(KisNodeSP) const;
virtual void setImage(KisImageWSP image);
public:
// KoShape overrides
......
......@@ -432,7 +432,8 @@ void KisView2::dragEnterEvent(QDragEnterEvent *event)
void KisView2::dropEvent(QDropEvent *event)
{
KisImageWSP kisimage = image();
KisImageSP kisimage = image();
QPointF pos = kisimage->documentToIntPixel(m_d->viewConverter->viewToDocument(event->pos() + m_d->canvas->documentOffset() - m_d->canvas->documentOrigin()));
if (event->mimeData()->hasFormat("application/x-krita-node") || event->mimeData()->hasImage())
......@@ -450,9 +451,9 @@ void KisView2::dropEvent(QDropEvent *event)
node = tempImage->rootLayer()->firstChild();
tempImage->removeNode(node);
// layers store a lisk to the image, so update it
// layers store a link to the image, so update it
KisLayer *layer = dynamic_cast<KisLayer*>(node.data());
if(layer) {
if (layer) {
layer->setImage(kisimage);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment