Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
nyalldawson committed Nov 29, 2019
1 parent 6ef3746 commit d8be3f5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/app/layout/qgslayoutimagedrophandler.cpp
Expand Up @@ -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 );

Expand All @@ -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();
Expand Down

0 comments on commit d8be3f5

Please sign in to comment.