Exemplo n.º 1
0
void KisTransactionTest::testUndoWithUnswitchedFrames()
{
    KisSurrogateUndoAdapter undoAdapter;
    const QRect imageRect(0,0,100,100);


    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisPaintDeviceSP dev = new KisPaintDevice(cs);

    TestUtil::TestingTimedDefaultBounds *bounds = new TestUtil::TestingTimedDefaultBounds();
    dev->setDefaultBounds(bounds);

    KisRasterKeyframeChannel *channel = dev->createKeyframeChannel(KisKeyframeChannel::Content);
    QVERIFY(channel);

    KisPaintDeviceFramesInterface *i = dev->framesInterface();
    QVERIFY(i);

    QCOMPARE(i->frames().size(), 1);


    dev->fill(QRect(10,10,20,20), KoColor(Qt::white, cs));

    KIS_DUMP_DEVICE_2(dev, imageRect, "00_f0_w20", "dd");
    QCOMPARE(dev->exactBounds(), QRect(10,10,20,20));


    // add keyframe at position 10
    channel->addKeyframe(10);

    // add keyframe at position 11
    channel->addKeyframe(11);

    // add keyframe at position 12
    channel->addKeyframe(12);

    KIS_DUMP_DEVICE_2(dev, imageRect, "01_f0_b20", "dd");
    QCOMPARE(dev->exactBounds(), QRect(10,10,20,20));

    {
        KisTransaction transaction(kundo2_noi18n("first_stroke"), dev, 0);

        dev->clear();
        dev->fill(QRect(40,40,21,21), KoColor(Qt::red, cs));

        transaction.commit(&undoAdapter);

        KIS_DUMP_DEVICE_2(dev, imageRect, "02_f0_b21_stroke", "dd");
        QCOMPARE(dev->exactBounds(), QRect(40,40,21,21));
    }

    // switch to frame 10
    bounds->testingSetTime(10);

    KIS_DUMP_DEVICE_2(dev, imageRect, "03_f10_b0_switched", "dd");
    QVERIFY(dev->exactBounds().isEmpty());

    {
        KisTransaction transaction(kundo2_noi18n("second_stroke"), dev, 0);

        dev->fill(QRect(60,60,22,22), KoColor(Qt::green, cs));

        transaction.commit(&undoAdapter);

        KIS_DUMP_DEVICE_2(dev, imageRect, "04_f10_b22_stroke", "dd");
        QCOMPARE(dev->exactBounds(), QRect(60,60,22,22));
    }

    undoAdapter.undo();

    KIS_DUMP_DEVICE_2(dev, imageRect, "05_f10_b0_undone", "dd");
    QVERIFY(dev->exactBounds().isEmpty());

    bounds->testingSetTime(0);
    KIS_DUMP_DEVICE_2(dev, imageRect, "06_f0_b21_undone", "dd");
    QCOMPARE(dev->exactBounds(), QRect(40,40,21,21));

    bounds->testingSetTime(10);
    QVERIFY(dev->exactBounds().isEmpty());

    undoAdapter.undo();

    KIS_DUMP_DEVICE_2(dev, imageRect, "07_f10_b0_undone_x2", "dd");
    QVERIFY(dev->exactBounds().isEmpty());

    bounds->testingSetTime(0);
    KIS_DUMP_DEVICE_2(dev, imageRect, "08_f0_b20_undone_x2", "dd");
    QCOMPARE(dev->exactBounds(), QRect(10,10,20,20));

    {
        KisTransaction transaction(kundo2_noi18n("third_move"), dev, 0);

        dev->moveTo(17,17);

        transaction.commit(&undoAdapter);

        KIS_DUMP_DEVICE_2(dev, imageRect, "09_f0_o27_move", "dd");
        QCOMPARE(dev->exactBounds(), QRect(27,27,20,20));
    }

    bounds->testingSetTime(10);
    QVERIFY(dev->exactBounds().isEmpty());

    undoAdapter.undo();

    KIS_DUMP_DEVICE_2(dev, imageRect, "10_f10_b0_undone_x3", "dd");
    QVERIFY(dev->exactBounds().isEmpty());

    bounds->testingSetTime(0);
    KIS_DUMP_DEVICE_2(dev, imageRect, "11_f0_b20_undone_x3", "dd");
    QCOMPARE(dev->exactBounds(), QRect(10,10,20,20));
}
Exemplo n.º 2
0
void KisTransformMaskTest::testWeirdFullUpdates()
{
    //TestUtil::ExternalImageChecker chk("mask_with_offset", "transform_mask_updates");

    QRect imageRect(0,0,512,512);
    QRect fillRect(10, 10, 236, 236);
    TestUtil::MaskParent p(imageRect);

    p.layer->paintDevice()->fill(fillRect, KoColor(Qt::red, p.layer->colorSpace()));

    KisPaintLayerSP player1 = new KisPaintLayer(p.image, "pl1", OPACITY_OPAQUE_U8, p.image->colorSpace());
    player1->paintDevice()->fill(fillRect, KoColor(Qt::red, p.layer->colorSpace()));
    p.image->addNode(player1, p.image->root());

    KisTransformMaskSP mask1 = new KisTransformMask();
    mask1->setName("mask1");
    QTransform transform1 =
        QTransform::fromTranslate(256, 0);
    mask1->setTransformParams(KisTransformMaskParamsInterfaceSP(
                                  new KisDumbTransformMaskParams(transform1)));

    p.image->addNode(mask1, player1);


    KisPaintLayerSP player2 = new KisPaintLayer(p.image, "pl2", OPACITY_OPAQUE_U8, p.image->colorSpace());
    player2->paintDevice()->fill(fillRect, KoColor(Qt::red, p.layer->colorSpace()));
    p.image->addNode(player2, p.image->root());

    KisTransformMaskSP mask2 = new KisTransformMask();
    mask2->setName("mask2");
    QTransform transform2 =
        QTransform::fromTranslate(0, 256);
    mask2->setTransformParams(KisTransformMaskParamsInterfaceSP(
                                  new KisDumbTransformMaskParams(transform2)));

    p.image->addNode(mask2, player2);


    KisPaintLayerSP player3 = new KisPaintLayer(p.image, "pl3", OPACITY_OPAQUE_U8, p.image->colorSpace());
    player3->paintDevice()->fill(fillRect, KoColor(Qt::red, p.layer->colorSpace()));
    p.image->addNode(player3, p.image->root());

    KisTransformMaskSP mask3 = new KisTransformMask();
    mask3->setName("mask3");
    QTransform transform3 =
        QTransform::fromTranslate(256, 256);
    mask3->setTransformParams(KisTransformMaskParamsInterfaceSP(
                                  new KisDumbTransformMaskParams(transform3)));

    p.image->addNode(mask3, player3);



    //p.image->initialRefreshGraph();

    p.image->refreshGraphAsync(0, QRect(0,0,256,256), QRect());
    p.image->waitForDone();

    QVERIFY(player1->projection()->extent().isEmpty());
    QVERIFY(player1->projection()->exactBounds().isEmpty());

    QVERIFY(player2->projection()->extent().isEmpty());
    QVERIFY(player2->projection()->exactBounds().isEmpty());

    QVERIFY(player3->projection()->extent().isEmpty());
    QVERIFY(player3->projection()->exactBounds().isEmpty());

    QCOMPARE(p.image->projection()->exactBounds(), QRect(QRect(10,10,236,236)));



    p.image->refreshGraphAsync(0, QRect(0,256,256,256), QRect());
    p.image->waitForDone();

    QVERIFY(player1->projection()->extent().isEmpty());
    QVERIFY(player1->projection()->exactBounds().isEmpty());

    QVERIFY(!player2->projection()->extent().isEmpty());
    QVERIFY(!player2->projection()->exactBounds().isEmpty());

    QVERIFY(player3->projection()->extent().isEmpty());
    QVERIFY(player3->projection()->exactBounds().isEmpty());

    QCOMPARE(p.image->projection()->exactBounds(), QRect(QRect(10,10,236,492)));


    p.image->refreshGraphAsync(0, QRect(256,0,256,256), QRect());
    p.image->waitForDone();

    QVERIFY(!player1->projection()->extent().isEmpty());
    QVERIFY(!player1->projection()->exactBounds().isEmpty());

    QVERIFY(!player2->projection()->extent().isEmpty());
    QVERIFY(!player2->projection()->exactBounds().isEmpty());

    QVERIFY(player3->projection()->extent().isEmpty());
    QVERIFY(player3->projection()->exactBounds().isEmpty());

    QCOMPARE(p.image->projection()->exactBounds(), QRect(QRect(10,10,492,492)));
    QVERIFY((p.image->projection()->region() & QRect(256,256,256,256)).isEmpty());



    p.image->refreshGraphAsync(0, QRect(256,256,256,256), QRect());
    p.image->waitForDone();

    QVERIFY(!player1->projection()->extent().isEmpty());
    QVERIFY(!player1->projection()->exactBounds().isEmpty());

    QVERIFY(!player2->projection()->extent().isEmpty());
    QVERIFY(!player2->projection()->exactBounds().isEmpty());

    QVERIFY(!player3->projection()->extent().isEmpty());
    QVERIFY(!player3->projection()->exactBounds().isEmpty());

    QCOMPARE(p.image->projection()->exactBounds(), QRect(QRect(10,10,492,492)));
    QVERIFY(!(p.image->projection()->region() & QRect(256,256,256,256)).isEmpty());

    p.image->waitForDone();

    KIS_DUMP_DEVICE_2(p.image->projection(), imageRect, "image_proj", "dd");

}