chengxr 1 year ago
parent
commit
1ead72865f
2 changed files with 24 additions and 29 deletions
  1. 22 29
      QFD/CCanvas/CMindView.cpp
  2. 2 0
      QFD/CCanvas/CMindView.h

+ 22 - 29
QFD/CCanvas/CMindView.cpp

@@ -194,11 +194,7 @@ void CMindView::mousePressEvent(QMouseEvent *event)
     m_isMovingItem =
             item != nullptr && (item->flags() & QGraphicsObject::ItemIsMovable) == QGraphicsObject::ItemIsMovable;
 
-    if (m_isMovingItem) {
-        setCursor(Qt::ClosedHandCursor);
-    } else {
-        setCursor(Qt::ArrowCursor);
-    }
+    updateCursor(event->pos());
 
     QGraphicsView::mousePressEvent(event);
 }
@@ -206,34 +202,13 @@ void CMindView::mousePressEvent(QMouseEvent *event)
 void CMindView::mouseMoveEvent(QMouseEvent *event)
 {
     QGraphicsView::mouseMoveEvent(event);
-    QGraphicsItem *item = itemAt(event->pos());
-
-    if (m_isMovingItem) {
-        setCursor(Qt::ClosedHandCursor);
-    } else {
-        bool movable =
-                item != nullptr && (item->flags() & QGraphicsObject::ItemIsMovable) == QGraphicsObject::ItemIsMovable;
-
-        if (movable) {
-            setCursor(Qt::OpenHandCursor);
-        } else {
-            setCursor(Qt::ArrowCursor);
-        }
-    }
+    updateCursor(event->pos());
 }
 
 void CMindView::mouseReleaseEvent(QMouseEvent *event)
 {
-    m_isMovingItem      = false;
-    QGraphicsItem *item = itemAt(event->pos());
-    bool movable =
-            item != nullptr && (item->flags() & QGraphicsObject::ItemIsMovable) == QGraphicsObject::ItemIsMovable;
-
-    if (movable) {
-        setCursor(Qt::OpenHandCursor);
-    } else {
-        setCursor(Qt::ArrowCursor);
-    }
+    m_isMovingItem = false;
+    updateCursor(event->pos());
     QGraphicsView::mouseReleaseEvent(event);
 }
 
@@ -271,6 +246,24 @@ void CMindView::testData()
     }
 }
 
+void CMindView::updateCursor(QPoint pos)
+{
+    QGraphicsItem *item = itemAt(pos);
+
+    if (m_isMovingItem) {
+        setCursor(Qt::ClosedHandCursor);
+    } else {
+        bool movable =
+                item != nullptr && (item->flags() & QGraphicsObject::ItemIsMovable) == QGraphicsObject::ItemIsMovable;
+
+        if (movable) {
+            setCursor(Qt::OpenHandCursor);
+        } else {
+            setCursor(Qt::ArrowCursor);
+        }
+    }
+}
+
 void CMindView::slotEditNode(CNodeData n)
 {
     emit sigEditNode(n);

+ 2 - 0
QFD/CCanvas/CMindView.h

@@ -48,6 +48,8 @@ public:
 
     void testData();
 
+    void updateCursor(QPoint pos);
+
 public slots:
 
     void slotEditNode(CNodeData n);