Commit e41db7b6 authored by Ivan Yossi's avatar Ivan Yossi 👌 Committed by Dmitry Kazakov
Browse files

Fix paste outside of image boundaries

If paste data does not intersect canvas, the image is pasted
at the center of the canvas.

BUG:459111
parent 684d4b9f
Pipeline #256974 failed with stage
in 75 minutes
......@@ -219,23 +219,31 @@ void KisPasteActionFactory::run(bool pasteAtCursorPosition, KisViewManager *view
// If no shapes, check for layers
if (KisClipboard::instance()->hasLayers()) {
const QPointF offsetTopLeft = [&]() -> QPointF {
KisPaintDeviceSP clip =
KisClipboard::instance()->clipFromKritaLayers(
fittingBounds,
image->colorSpace());
KIS_ASSERT(clip);
QPointF imagePos;
if (pasteAtCursorPosition) {
KisPaintDeviceSP clip =
KisClipboard::instance()->clipFromKritaLayers(
fittingBounds,
image->colorSpace());
KIS_ASSERT(clip);
const QPointF imagePos =
imagePos =
view->canvasBase()->coordinatesConverter()->documentToImage(
docPos);
const QPointF offset =
(imagePos - QRectF(clip->exactBounds()).center()).toPoint();
return offset;
} else if (!clip->exactBounds().contains(image->bounds()) &&
!clip->exactBounds().intersects(image->bounds())) {
// BUG:459111
pasteAtCursorPosition = true;
imagePos = QPointF(image->bounds().center());
} else {
return {};
}
const QPointF offset =
(imagePos - QRectF(clip->exactBounds()).center()).toPoint();
return offset;
}();
view->nodeManager()->pasteLayersFromClipboard(pasteAtCursorPosition,
offsetTopLeft);
return;
......@@ -302,9 +310,16 @@ void KisPasteIntoActionFactory::run(KisViewManager *viewManager)
KisImageSP image = viewManager->image();
if (!image) return;
KisPaintDeviceSP clip =
KisClipboard::instance()->clipFromKritaLayers(image->bounds(),
image->colorSpace());
const KisPaintDevice *clipdev = KisClipboard::instance()->clipFromKritaLayers(image->bounds(),
image->colorSpace()).data();
KisPaintDeviceSP clip = new KisPaintDevice(*clipdev);
if (clip) {
QRect clipBounds = clip->exactBounds();
QPoint diff = image->bounds().center() - clipBounds.center();
clip->setX(diff.x());
clip->setY(diff.y());
}
if (!clip)
clip =
......
Supports Markdown
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