Commit 7a9350d7 authored by Tusooa Zhu's avatar Tusooa Zhu 🅱

Port transforming, boolean op and splitting to new strokes

parent 1bfd3493
......@@ -1196,35 +1196,34 @@ void DefaultTool::selectionTransform(int transformAction)
QList<QTransform> oldTransforms;
QList<QTransform> newTransforms;
const QRectF outlineRect = KoShape::absoluteOutlineRect(editableShapes);
const QPointF centerPoint = outlineRect.center();
const QTransform centerTrans = QTransform::fromTranslate(centerPoint.x(), centerPoint.y());
const QTransform centerTransInv = QTransform::fromTranslate(-centerPoint.x(), -centerPoint.y());
// we also add selection to the list of transformed shapes, so that its outline is updated correctly
QList<KoShape*> transformedShapes = editableShapes;
transformedShapes << selection;
Q_FOREACH (KoShape *shape, transformedShapes) {
oldTransforms.append(shape->transformation());
QTransform t;
if (!shouldReset) {
const QTransform world = shape->absoluteTransformation(0);
t = world * centerTransInv * applyTransform * centerTrans * world.inverted() * shape->transformation();
} else {
const QPointF center = shape->outlineRect().center();
const QPointF offset = shape->transformation().map(center) - center;
t = QTransform::fromTranslate(offset.x(), offset.y());
canvas()->strokeHelper()->run(actionName,
[selection, editableShapes, shouldReset, applyTransform]() {
const QRectF outlineRect = KoShape::absoluteOutlineRect(editableShapes);
const QPointF centerPoint = outlineRect.center();
const QTransform centerTrans = QTransform::fromTranslate(centerPoint.x(), centerPoint.y());
const QTransform centerTransInv = QTransform::fromTranslate(-centerPoint.x(), -centerPoint.y());
// we also add selection to the list of transformed shapes, so that its outline is updated correctly
QList<KoShape*> transformedShapes = editableShapes;
transformedShapes << selection;
Q_FOREACH (KoShape* shape, transformedShapes) {
QTransform t;
if (!shouldReset) {
const QTransform world = shape->absoluteTransformation(0);
t = world * centerTransInv * applyTransform * centerTrans * world.inverted() * shape->transformation();
} else {
const QPointF center = shape->outlineRect().center();
const QPointF offset = shape->transformation().map(center) - center;
t = QTransform::fromTranslate(offset.x(), offset.y());
}
const QRectF oldDirtyRect = shape->boundingRect();
shape->setTransformation(t);
shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
}
newTransforms.append(t);
}
KoShapeTransformCommand *cmd = new KoShapeTransformCommand(transformedShapes, oldTransforms, newTransforms);
cmd->setText(actionName);
canvas()->addCommand(cmd);
return true;
});
}
void DefaultTool::selectionBooleanOp(int booleanOp)
......@@ -1286,28 +1285,31 @@ void DefaultTool::selectionBooleanOp(int booleanOp)
newShape = KoPathShape::createShapeFromPainterPath(dstOutline);
}
KUndo2Command *cmd = new KUndo2Command(actionName);
new KoKeepShapesSelectedCommand(editableShapes, {}, canvas()->selectedShapesProxy(), false, cmd);
QList<KoShape*> newSelectedShapes;
canvas()->strokeHelper()->run(actionName,
[selection, editableShapes, newShape, referenceShape, this]() {
selection->deselectAll();
if (newShape) {
newShape->setBackground(referenceShape->background());
newShape->setStroke(referenceShape->stroke());
newShape->setZIndex(referenceShape->zIndex());
QList<KoShape*> newSelectedShapes;
KoShapeContainer *parent = referenceShape->parent();
canvas()->shapeController()->addShapeDirect(newShape, parent, cmd);
if (newShape) {
newShape->setBackground(referenceShape->background());
newShape->setStroke(referenceShape->stroke());
newShape->setZIndex(referenceShape->zIndex());
newSelectedShapes << newShape;
}
KoShapeContainer* parent = referenceShape->parent();
canvas()->shapeController()->addShapeDirect(newShape, parent);
canvas()->shapeController()->removeShapes(editableShapes, cmd);
newSelectedShapes << newShape;
}
new KoKeepShapesSelectedCommand({}, newSelectedShapes, canvas()->selectedShapesProxy(), true, cmd);
canvas()->shapeController()->removeShapes(editableShapes);
canvas()->addCommand(cmd);
selection->deselectAll();
Q_FOREACH (KoShape *shape, newSelectedShapes) {
selection->select(shape);
}
return true;
});
}
void DefaultTool::selectionSplitShapes()
......@@ -1320,29 +1322,35 @@ void DefaultTool::selectionSplitShapes()
return;
}
KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Split Shapes"));
canvas()->strokeHelper()->run(kundo2_i18n("Split Shapes"),
[selection, editableShapes, this]() {
QList<KoShape*> newShapes;
new KoKeepShapesSelectedCommand(editableShapes, {}, canvas()->selectedShapesProxy(), false, cmd);
QList<KoShape*> newShapes;
Q_FOREACH (KoShape* shape, editableShapes) {
KoPathShape* pathShape = dynamic_cast<KoPathShape*>(shape);
if (!pathShape) return false;
}
Q_FOREACH (KoShape *shape, editableShapes) {
KoPathShape *pathShape = dynamic_cast<KoPathShape*>(shape);
if (!pathShape) return;
Q_FOREACH (KoShape *shape, editableShapes) {
KoPathShape* pathShape = dynamic_cast<KoPathShape*>(shape);
QList<KoPathShape*> splitShapes;
if (pathShape->separate(splitShapes)) {
QList<KoShape*> normalShapes = implicitCastList<KoShape*>(splitShapes);
QList<KoPathShape*> splitShapes;
if (pathShape->separate(splitShapes)) {
QList<KoShape*> normalShapes = implicitCastList<KoShape*>(splitShapes);
KoShapeContainer *parent = shape->parent();
canvas()->shapeController()->addShapesDirect(normalShapes, parent, cmd);
canvas()->shapeController()->removeShape(shape, cmd);
newShapes << normalShapes;
KoShapeContainer* parent = shape->parent();
canvas()->shapeController()->addShapesDirect(normalShapes, parent);
canvas()->shapeController()->removeShape(shape);
newShapes << normalShapes;
}
}
selection->deselectAll();
Q_FOREACH (KoShape *shape, newShapes) {
selection->select(shape);
}
}
new KoKeepShapesSelectedCommand({}, newShapes, canvas()->selectedShapesProxy(), true, cmd);
canvas()->addCommand(cmd);
return true;
});
}
void DefaultTool::selectionAlign(int _align)
......
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