From ab3464b0f6e8c87ab81547310f0b04af3a594454 Mon Sep 17 00:00:00 2001 From: donovaly Date: Mon, 22 Feb 2021 02:17:05 +0100 Subject: [PATCH] [TD] fix balloon dragging Fixes bug that dragging while pressing CTRL did not work anymore, see https://forum.freecadweb.org/viewtopic.php?f=35&t=55863 --- src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index 1811104877..a100894875 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -487,16 +487,16 @@ void QGIViewBalloon::balloonLabelDragged(bool ctrl) } } + // store if origin is also moving to be able to later calc new origin and update feature + if (ctrl) + m_originDragged = true; + DrawView* balloonParent = getSourceView(); if (balloonParent) // redraw the balloon at the new position // note that we don't store the new position to the X/Y properties // since the dragging is not yet finished - drawBalloon(true); - - // store if origin is also moving to be able to later calc new origin and update feature - if (ctrl) - m_originDragged = true; + drawBalloon(true); } void QGIViewBalloon::balloonLabelDragFinished() @@ -623,7 +623,7 @@ void QGIViewBalloon::drawBalloon(bool dragged) if (!refObj) { return; } - if(!refObj->hasGeometry()) { //nothing to draw yet (restoring) + if(!refObj->hasGeometry()) { // nothing to draw yet (restoring) balloonLabel->hide(); hide(); return; @@ -638,21 +638,31 @@ void QGIViewBalloon::drawBalloon(bool dragged) double textWidth = balloonLabel->getDimText()->boundingRect().width(); double textHeight = balloonLabel->getDimText()->boundingRect().height(); - float x, y; + float x, y, arrowTipX, arrowTipY; // when not dragging take the X/Y properties otherwise the current label position if (!dragged) { x = Rez::guiX(balloon->X.getValue() * refObj->getScale()); y = Rez::guiX(balloon->Y.getValue() * refObj->getScale()); + arrowTipX = Rez::guiX(balloon->OriginX.getValue() * refObj->getScale()); + arrowTipY = -Rez::guiX(balloon->OriginY.getValue() * refObj->getScale()); } else { x = balloonLabel->X(); y = -balloonLabel->Y(); + if (m_originDragged) { + double scale = Rez::guiX(refObj->getScale()); + Base::Vector3d pos(x / scale, y / scale, 0.0); + Base::Vector3d newOrg = pos - m_saveOffset; + arrowTipX = newOrg.x * scale; + arrowTipY = -newOrg.y * scale; + } + else { + arrowTipX = Rez::guiX(balloon->OriginX.getValue() * refObj->getScale()); + arrowTipY = -Rez::guiX(balloon->OriginY.getValue() * refObj->getScale()); + } } Base::Vector3d lblCenter(x, -y, 0.0); - float arrowTipX = Rez::guiX(balloon->OriginX.getValue() * refObj->getScale()); - float arrowTipY = - Rez::guiX(balloon->OriginY.getValue() * refObj->getScale()); - if (balloon->isLocked()) { balloonLabel->setFlag(QGraphicsItem::ItemIsMovable, false); } else