[calligra/calligra/2.7] krita/ui: Fixed positioning of the image/layer Drag&Dropped to the Krita Canvas
Dmitry Kazakov
dimula73 at gmail.com
Wed May 8 18:08:31 UTC 2013
Git commit 8fb27085803e844cbfac7663b2d0e4cb5fc86a80 by Dmitry Kazakov.
Committed on 05/05/2013 at 10:47.
Pushed by dkazakov into branch 'calligra/2.7'.
Fixed positioning of the image/layer Drag&Dropped to the Krita Canvas
Now the Drag&Drop of the image or a layer to the canvas works
in the following way:
1) [no modifiers pressed]
* Dropping Krita Layer (from Layer Box):
Positions to the original offset in the original image. If it doesn't
fit into new image, it drops to the center of the new image.
*Dropping an *image* (not URL) from Chromium or other application:
Drops to the center of the image.
2) [Shift modifier is pressed]
Both types of pastes are recentered near the center of the new image.
3) URL's are always dropped as usual to the top-left corner of the image.
BUG:319332
CCMAIL:kimageshop at kde.org
M +30 -11 krita/ui/kis_view2.cpp
http://commits.kde.org/calligra/8fb27085803e844cbfac7663b2d0e4cb5fc86a80
diff --git a/krita/ui/kis_view2.cpp b/krita/ui/kis_view2.cpp
index 7b21a60..d01991f 100644
--- a/krita/ui/kis_view2.cpp
+++ b/krita/ui/kis_view2.cpp
@@ -451,11 +451,27 @@ void KisView2::dragEnterEvent(QDragEnterEvent *event)
void KisView2::dropEvent(QDropEvent *event)
{
KisImageSP kisimage = image();
+ Q_ASSERT(kisimage);
- QPointF pos = canvasBase()->coordinatesConverter()->widgetToImage(event->pos());
+ QPoint cursorPos = canvasBase()->coordinatesConverter()->widgetToImage(event->pos()).toPoint();
+ QRect imageBounds = kisimage->bounds();
+ QPoint pasteCenter;
+ bool forceRecenter;
- if (event->mimeData()->hasFormat("application/x-krita-node") || event->mimeData()->hasImage())
+ if (event->keyboardModifiers() & Qt::ShiftModifier &&
+ imageBounds.contains(cursorPos)) {
+
+ pasteCenter = cursorPos;
+ forceRecenter = true;
+ } else {
+ pasteCenter = imageBounds.center();
+ forceRecenter = false;
+ }
+
+ if (event->mimeData()->hasFormat("application/x-krita-node") ||
+ event->mimeData()->hasImage())
{
+ bool alwaysRecenter = false;
KisNodeSP node;
if (event->mimeData()->hasFormat("application/x-krita-node")) {
@@ -487,22 +503,26 @@ void KisView2::dropEvent(QDropEvent *event)
}
node = shapeLayer2;
}
-
}
else if (event->mimeData()->hasImage()) {
QImage qimage = qvariant_cast<QImage>(event->mimeData()->imageData());
- if (kisimage) {
- KisPaintDeviceSP device = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
- device->convertFromQImage(qimage, 0);
- node = new KisPaintLayer(kisimage.data(), kisimage->nextLayerName(), OPACITY_OPAQUE_U8, device);
- }
+ KisPaintDeviceSP device = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
+ device->convertFromQImage(qimage, 0);
+ node = new KisPaintLayer(kisimage.data(), kisimage->nextLayerName(), OPACITY_OPAQUE_U8, device);
+
+ alwaysRecenter = true;
}
if (node) {
+ QRect bounds = node->projection()->exactBounds();
+ if (alwaysRecenter || forceRecenter ||
+ !imageBounds.contains(bounds)) {
- node->setX(pos.x() - node->projection()->exactBounds().width());
- node->setY(pos.y() - node->projection()->exactBounds().height());
+ QPoint pt = pasteCenter - bounds.center();
+ node->setX(pt.x());
+ node->setY(pt.y());
+ }
KisNodeCommandsAdapter adapter(this);
if (!m_d->nodeManager->activeLayer()) {
@@ -564,7 +584,6 @@ void KisView2::dropEvent(QDropEvent *event)
m_d->doc->documentPart()->save();
}
- bool result = false;
if (shell() != 0) {
/**
* NOTE: this is effectively deferred self-destruction
More information about the kimageshop
mailing list