bool removeKeyframes(KisImageSP image, const FrameItemList &frames) { bool result = false; QScopedPointer<KUndo2Command> cmd( new KUndo2Command(kundo2_i18np("Remove Keyframe", "Remove Keyframes", frames.size()))); // lisp-lovers present ;) foreach (const FrameItem &item, frames) { const int time = item.time; KisNodeSP node = item.node; KisKeyframeChannel *content = node->getKeyframeChannel(KisKeyframeChannel::Content.id()); if (!content) continue; KisKeyframeSP keyframe = content->keyframeAt(time); if (!keyframe) continue; content->deleteKeyframe(keyframe, cmd.data()); result = true; } if (result) { image->postExecutionUndoAdapter()->addCommand(toQShared(cmd.take())); } return result; }
QImage utils::StrokeTester::doStroke(bool cancelled, bool indirectPainting, bool externalLayer, bool testUpdates, bool needQImage) { KisImageSP image = utils::createImage(0, m_imageSize); KoCanvasResourceManager *manager = utils::createResourceManager(image, 0, m_presetFilename); KisNodeSP currentNode; for (int i = 0; i < m_numIterations; i++) { modifyResourceManager(manager, image, i); KisPainter *painter = new KisPainter(); KisResourcesSnapshotSP resources = new KisResourcesSnapshot(image, image->rootLayer()->firstChild(), image->postExecutionUndoAdapter(), manager); if(externalLayer) { KisNodeSP externalNode = new KisPaintLayer(0, "extlyr", OPACITY_OPAQUE_U8, image->colorSpace()); resources->setCurrentNode(externalNode); Q_ASSERT(resources->currentNode() == externalNode); } initImage(image, resources->currentNode(), i); KisStrokeStrategy *stroke = createStroke(indirectPainting, resources, painter, image); m_strokeId = image->startStroke(stroke); addPaintingJobs(image, resources, painter, i); if(!cancelled) { image->endStroke(m_strokeId); } else { image->cancelStroke(m_strokeId); } image->waitForDone(); currentNode = resources->currentNode(); } QImage resultImage; if(needQImage) { KisPaintDeviceSP device = testUpdates ? image->projection() : currentNode->paintDevice(); resultImage = device->convertToQImage(0, 0, 0, image->width(), image->height()); } image = 0; delete manager; return resultImage; }
bool moveKeyframes(KisImageSP image, const FrameItemList &srcFrames, const FrameItemList &dstFrames, bool copy) { if (srcFrames.size() != dstFrames.size()) return false; bool result = false; QScopedPointer<KUndo2Command> cmd( new KUndo2Command(!copy ? kundo2_i18np("Move Keyframe", "Move Keyframes", srcFrames.size()) : kundo2_i18np("Copy Keyframe", "Copy Keyframes", srcFrames.size()))); // lisp-lovers present ;) for (int i = 0; i < srcFrames.size(); i++) { const int srcTime = srcFrames[i].time; KisNodeSP srcNode = srcFrames[i].node; const int dstTime = dstFrames[i].time; KisNodeSP dstNode = dstFrames[i].node; if (srcNode != dstNode) continue; KisKeyframeChannel *content = srcNode->getKeyframeChannel(KisKeyframeChannel::Content.id()); if (!content) continue; KisKeyframeSP dstKeyframe = content->keyframeAt(dstTime); if (dstKeyframe) { content->deleteKeyframe(dstKeyframe, cmd.data()); } KisKeyframeSP srcKeyframe = content->keyframeAt(srcTime); if (srcKeyframe) { if (copy) { content->copyKeyframe(srcKeyframe, dstTime, cmd.data()); } else { content->moveKeyframe(srcKeyframe, dstTime, cmd.data()); } } result = true; } if (result) { image->postExecutionUndoAdapter()->addCommand(toQShared(cmd.take())); } return result; }
void KisStrokeStrategyUndoCommandBasedTest::testCancelledStroke() { QString result; KUndo2CommandSP initCommand(new TestingUndoCommand(kundo2_noi18n("init"), result)); KUndo2CommandSP dabCommand(new TestingUndoCommand(kundo2_noi18n("dab"), result)); KUndo2CommandSP finishCommand(new TestingUndoCommand(kundo2_noi18n("finish"), result)); const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(0, 300, 300, cs, "test", true); KisStrokeStrategy *strategy = new KisStrokeStrategyUndoCommandBased(kundo2_noi18n("test"), false, image->postExecutionUndoAdapter(), initCommand, finishCommand); KisStrokeId id = image->startStroke(strategy); image->addJob(id, new KisStrokeStrategyUndoCommandBased::Data(dabCommand)); QTest::qSleep(500); image->cancelStroke(id); image->waitForDone(); SCOMPARE(result.trimmed(), "init_redo dab_redo dab_undo init_undo"); }
bool moveKeyframes(KisImageSP image, const FrameItemList &srcFrames, const FrameItemList &dstFrames, bool copy, KUndo2Command *parentCommand) { if (srcFrames.size() != dstFrames.size()) return false; bool result = false; QScopedPointer<KUndo2Command> cmd( new KUndo2Command(!copy ? kundo2_i18np("Move Keyframe", "Move %1 Keyframes", srcFrames.size()) : kundo2_i18np("Copy Keyframe", "Copy %1 Keyframes", srcFrames.size()), parentCommand)); for (int i = 0; i < srcFrames.size(); i++) { const int srcTime = srcFrames[i].time; KisNodeSP srcNode = srcFrames[i].node; KisKeyframeChannel *srcChannel = srcNode->getKeyframeChannel(srcFrames[i].channel); const int dstTime = dstFrames[i].time; KisNodeSP dstNode = dstFrames[i].node; KisKeyframeChannel *dstChannel = dstNode->getKeyframeChannel(dstFrames[i].channel, true); if (srcNode == dstNode) { if (!srcChannel) continue; KisKeyframeSP srcKeyframe = srcChannel->keyframeAt(srcTime); if (srcKeyframe) { if (copy) { srcChannel->copyKeyframe(srcKeyframe, dstTime, cmd.data()); } else { srcChannel->moveKeyframe(srcKeyframe, dstTime, cmd.data()); } } } else { if (!srcChannel|| !dstChannel) continue; KisKeyframeSP srcKeyframe = srcChannel->keyframeAt(srcTime); if (!srcKeyframe) continue; dstChannel->copyExternalKeyframe(srcChannel, srcTime, dstTime, cmd.data()); if (!copy) { srcChannel->deleteKeyframe(srcKeyframe, cmd.data()); } } result = true; } if (parentCommand) { cmd.take(); } else if (result) { image->postExecutionUndoAdapter()->addCommand(toQShared(cmd.take())); } return result; }