From 18182665a9432190d4fa3ade5c44fdafae0d30a1 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Fri, 10 Nov 2023 21:36:34 +0100
Subject: [PATCH] comm, const

---
 GUI/View/Mask/MaskGraphicsScene.cpp | 31 ++++++++++++++++-------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/GUI/View/Mask/MaskGraphicsScene.cpp b/GUI/View/Mask/MaskGraphicsScene.cpp
index 906e0704cf2..17227988f95 100644
--- a/GUI/View/Mask/MaskGraphicsScene.cpp
+++ b/GUI/View/Mask/MaskGraphicsScene.cpp
@@ -618,21 +618,24 @@ void MaskGraphicsScene::makeViewAtMousePosSelected(QGraphicsSceneMouseEvent* eve
         graphicsItem->setSelected(true);
 }
 
-//! Processes RectangleItem and EllipseItem drawing
-//! If the mouse move distance with left button down is larger than certain threshold,
-//! new item will be created. Further, this function will update size and position
-//! of current rectangle if mouse keep moving.
+//! Processes RectangleItem and EllipseItem drawing.
+//! If mouse has moved sufficiently far with left button down, new item is created.
+//! On further calls, update size and position of current rectangle.
 
 void MaskGraphicsScene::processRectangleOrEllipseItem(QGraphicsSceneMouseEvent* event)
 {
     if (!m_drawing_in_progress)
         m_drawing_in_progress = true;
 
-    QPointF click_pos = event->buttonDownScenePos(Qt::LeftButton);
-    QPointF mouse_pos = event->scenePos();
-    QLineF line(mouse_pos, click_pos);
+    const QPointF click_pos = event->buttonDownScenePos(Qt::LeftButton);
+    const QPointF mouse_pos = event->scenePos();
+    const QLineF line(mouse_pos, click_pos);
+
+    //... Create new item?
 
-    if (!m_currentItem && line.length() > min_distance_to_create_rect) {
+    if (!m_currentItem) {
+	if (line.length() < min_distance_to_create_rect)
+	    return; // selected area is too small => don't create object yet
 
         MaskItem* newMaskItem;
         if (m_activity == MaskEditorFlags::RECTANGLE_MODE)
@@ -651,14 +654,14 @@ void MaskGraphicsScene::processRectangleOrEllipseItem(QGraphicsSceneMouseEvent*
             dynamic_cast<MaskItem*>(m_currentItem)->setMaskValue(m_mask_value);
 
         m_maskContainerItem->updateMaskNames();
+    }
 
-    } else if (!m_currentItem)
-        return;
+    //... Update item geometry
 
-    qreal xmin = m_adaptor->fromSceneX(std::min(click_pos.x(), mouse_pos.x()));
-    qreal xmax = m_adaptor->fromSceneX(std::max(click_pos.x(), mouse_pos.x()));
-    qreal ymin = m_adaptor->fromSceneY(std::min(click_pos.y(), mouse_pos.y()));
-    qreal ymax = m_adaptor->fromSceneY(std::max(click_pos.y(), mouse_pos.y()));
+    const qreal xmin = m_adaptor->fromSceneX(std::min(click_pos.x(), mouse_pos.x()));
+    const qreal xmax = m_adaptor->fromSceneX(std::max(click_pos.x(), mouse_pos.x()));
+    const qreal ymin = m_adaptor->fromSceneY(std::min(click_pos.y(), mouse_pos.y()));
+    const qreal ymax = m_adaptor->fromSceneY(std::max(click_pos.y(), mouse_pos.y()));
 
     if (auto* rectItem = dynamic_cast<RectangleItem*>(m_currentItem)) {
         // RectangleItem or RegionOfInterestItem
-- 
GitLab