[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-kimageshop
Subject: [calligra/krita-psd-plugin-siddharth] krita/ui: Fixed positioning of the image/layer Drag&Dropped to
From: Siddharth Sharma <siddharth.kde () gmail ! com>
Date: 2013-05-17 7:15:21
Message-ID: 20130517071521.2AA89A610C () git ! kde ! org
[Download RAW message or body]
Git commit 954480d6388c0e364d7992e21c1775e4611b1c63 by Siddharth Sharma, on behalf of \
Dmitry Kazakov. Committed on 05/05/2013 at 10:47.
Pushed by siddharthsharma into branch 'krita-psd-plugin-siddharth'.
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@kde.org
M +30 -11 krita/ui/kis_view2.cpp
http://commits.kde.org/calligra/954480d6388c0e364d7992e21c1775e4611b1c63
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
_______________________________________________
Krita mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic