From 009756e6288ee9f3dca0b68642106c36cb0b1b70 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Wed, 4 Dec 2024 14:18:21 +0100
Subject: [PATCH] update cursors

---
 GUI/View/Overlay/LineOverlays.cpp    |  2 --
 GUI/View/Overlay/PolygonOverlay.cpp  |  1 -
 GUI/View/Scene/MaskGraphicsScene.cpp | 31 +++++++++++++++++++++-------
 GUI/View/Scene/MaskGraphicsScene.h   |  1 +
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/GUI/View/Overlay/LineOverlays.cpp b/GUI/View/Overlay/LineOverlays.cpp
index 37815b02a16..675f4b4e2c0 100644
--- a/GUI/View/Overlay/LineOverlays.cpp
+++ b/GUI/View/Overlay/LineOverlays.cpp
@@ -67,7 +67,6 @@ OverlayItem* LineOverlay::parameterizedItem() const
 HorizontalLineOverlay::HorizontalLineOverlay(LineItem* item, ColorMap* plot)
     : LineOverlay(item, plot)
 {
-    setCursor(Qt::SizeVerCursor);
 }
 
 QRectF HorizontalLineOverlay::rectangle() const
@@ -115,7 +114,6 @@ QVariant HorizontalLineOverlay::itemChange(QGraphicsItem::GraphicsItemChange cha
 VerticalLineOverlay::VerticalLineOverlay(LineItem* item, ColorMap* plot)
     : LineOverlay(item, plot)
 {
-    setCursor(Qt::SizeHorCursor);
 }
 
 QRectF VerticalLineOverlay::rectangle() const
diff --git a/GUI/View/Overlay/PolygonOverlay.cpp b/GUI/View/Overlay/PolygonOverlay.cpp
index 0e97afd01fd..ad9c08ebee6 100644
--- a/GUI/View/Overlay/PolygonOverlay.cpp
+++ b/GUI/View/Overlay/PolygonOverlay.cpp
@@ -90,7 +90,6 @@ bool PolygonOverlay::closePolygonIfNecessary()
             childItem->setFlag(QGraphicsItem::ItemIsMovable);
             childItem->setFlag(QGraphicsItem::ItemSendsGeometryChanges);
             childItem->setAcceptHoverEvents(false);
-            childItem->setCursor(Qt::SizeAllCursor);
         }
         m_item->setIsClosed(true);
         update();
diff --git a/GUI/View/Scene/MaskGraphicsScene.cpp b/GUI/View/Scene/MaskGraphicsScene.cpp
index 2e75c59aeab..aea0c5968d0 100644
--- a/GUI/View/Scene/MaskGraphicsScene.cpp
+++ b/GUI/View/Scene/MaskGraphicsScene.cpp
@@ -178,13 +178,8 @@ void MaskGraphicsScene::onActivityChanged(Canvas2DMode::Flag mode)
         cancelCurrentDrawing();
 
     m_mode = mode;
-    const bool zooming = m_mode == Canvas2DMode::PAN_ZOOM;
-    m_proxy->setZooming(zooming);
-    for (auto const& [item, overlay] : m_mask2overlay) {
-        overlay->setAcceptedMouseButtons(zooming ? Qt::NoButton : Qt::LeftButton);
-        overlay->setCursor(zooming ? Qt::ArrowCursor : Qt::SizeAllCursor);
-    }
-    m_plot->setCursor(zooming ? Qt::PointingHandCursor : Qt::ArrowCursor);
+    m_proxy->setZooming(m_mode == Canvas2DMode::PAN_ZOOM);
+    updateCursors();
 }
 
 //  ************************************************************************************************
@@ -312,6 +307,26 @@ void MaskGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
         emit itemContextMenuRequest(event->screenPos());
 }
 
+void MaskGraphicsScene::updateCursors()
+{
+    const bool zooming = m_mode == Canvas2DMode::PAN_ZOOM;
+    const auto zoom_cursor = Qt::ClosedHandCursor;
+    for (auto const& [item, overlay] : m_mask2overlay) {
+        overlay->setAcceptedMouseButtons(zooming ? Qt::NoButton : Qt::LeftButton);
+
+        if (dynamic_cast<HorizontalLineOverlay*>(overlay))
+            overlay->setCursor(zooming ? zoom_cursor : Qt::SizeVerCursor);
+        else if (dynamic_cast<VerticalLineOverlay*>(overlay))
+            overlay->setCursor(zooming ? zoom_cursor : Qt::SizeHorCursor);
+        else if (dynamic_cast<VertexOverlay*>(overlay))
+            overlay->setCursor(zooming ? zoom_cursor : Qt::CrossCursor);
+        else
+            // rectangle, ellipse, polygon
+            overlay->setCursor(zooming ? zoom_cursor : Qt::PointingHandCursor);
+    }
+    m_viewport->setCursor(zooming ? zoom_cursor : Qt::ArrowCursor);
+}
+
 //  ************************************************************************************************
 //  private modifying functions
 //  ************************************************************************************************
@@ -350,6 +365,8 @@ void MaskGraphicsScene::updateOverlays()
         IOverlay* overlay = registerOverlay(t);
         ASSERT(overlay);
     }
+
+    updateCursors();
 }
 
 //! Creates a view for given item.
diff --git a/GUI/View/Scene/MaskGraphicsScene.h b/GUI/View/Scene/MaskGraphicsScene.h
index be8669055df..34898fa1808 100644
--- a/GUI/View/Scene/MaskGraphicsScene.h
+++ b/GUI/View/Scene/MaskGraphicsScene.h
@@ -63,6 +63,7 @@ private:
     void drawForeground(QPainter* painter, const QRectF& rect) override;
     void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
 
+    void updateCursors();
     void associateItems(Data2DItem* data_item);
     void clearOverlays();
     void updateOverlays();
-- 
GitLab