From d8be3f5a43b098bceaea064a0eb976c538a8d810 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 29 Nov 2019 09:05:50 +1000 Subject: [PATCH] [layouts] When dropping a picture to a layout, place the center of the picture item at the cursor drop location instead of the top left We want the drop location to be the center of the placed item, because drag thumbnails are usually centered on the mouse cursor --- src/app/layout/qgslayoutimagedrophandler.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/layout/qgslayoutimagedrophandler.cpp b/src/app/layout/qgslayoutimagedrophandler.cpp index b575f6f689c..cc20aca855b 100644 --- a/src/app/layout/qgslayoutimagedrophandler.cpp +++ b/src/app/layout/qgslayoutimagedrophandler.cpp @@ -50,7 +50,6 @@ bool QgsLayoutImageDropHandler::handleFileDrop( QgsLayoutDesignerInterface *ifac std::unique_ptr< QgsLayoutItemPicture > item = qgis::make_unique< QgsLayoutItemPicture >( iface->layout() ); QgsLayoutPoint layoutPoint = iface->layout()->convertFromLayoutUnits( point, iface->layout()->units() ); - item->attemptMove( layoutPoint ); item->setPicturePath( file ); @@ -59,6 +58,13 @@ bool QgsLayoutImageDropHandler::handleFileDrop( QgsLayoutDesignerInterface *ifac // and then move back to standard freeform image sizing item->setResizeMode( QgsLayoutItemPicture::Zoom ); + // we want the drop location to be the center of the placed item, because drag thumbnails are usually centered on the mouse cursor + item->setReferencePoint( QgsLayoutItem::Middle ); + item->attemptMove( layoutPoint ); + + // reset to standard top-left reference point location + item->setReferencePoint( QgsLayoutItem::UpperLeft ); + // and auto select new item for convenience QList< QgsLayoutItem * > newSelection; newSelection << item.get();