Commits

Ian Chen committed 9092591

More updates to cursor

  • Participants
  • Parent commits b5b086e
  • Branches ian-building

Comments (0)

Files changed (1)

gazebo/gui/model_editor/EditorView.cc

     this->gridLines = new GridLines (this->scene()->sceneRect().width(),
     this->scene()->sceneRect().height());
     this->scene()->addItem(this->gridLines);
-//    qDebug() << this->scene()->sceneRect().width() <<
-//    this->scene()->sceneRect().height();
   }
 
 }
       WallItem *wallItem = dynamic_cast<WallItem*>(this->currentMouseItem);
       if (this->drawInProgress && wallItem)
       {
-        if (wallItem)
+        // snap walls to 0/90/180 degrees
+        LineSegmentItem *segment = wallItem->GetSegment(
+            wallItem->GetSegmentCount()-1);
+        QPointF p1 = segment->mapToScene(segment->line().p1());
+        QPointF p2 = this->mapToScene(_event->pos());
+        QLineF line(p1, p2);
+        double angle = line.angle();
+        double range = 10;
+        if ((angle < range) || (angle > (360 - range)) ||
+            ((angle > (180 - range)) && (angle < (180 + range))))
         {
-          // snap walls to 0/90/180 degrees
-          LineSegmentItem *segment = wallItem->GetSegment(
-              wallItem->GetSegmentCount()-1);
-          QPointF p1 = segment->mapToScene(segment->line().p1());
-          QPointF p2 = this->mapToScene(_event->pos());
-          QLineF line(p1, p2);
-          double angle = line.angle();
-          double range = 10;
-          if ((angle < range) || (angle > (360 - range)) ||
-              ((angle > (180 - range)) && (angle < (180 + range))))
-          {
-            wallItem->SetVertexPosition(wallItem->GetVertexCount()-1,
-                QPointF(p2.x(), p1.y()));
-          }
-          else if (((angle > (90 - range)) && (angle < (90 + range))) ||
-              ((angle > (270 - range)) && (angle < (270 + range))))
-          {
-            wallItem->SetVertexPosition(wallItem->GetVertexCount()-1,
-                QPointF(p1.x(), p2.y()));
-          }
-          else
-          {
-            wallItem->SetVertexPosition(wallItem->GetVertexCount()-1, p2);
-          }
+          wallItem->SetVertexPosition(wallItem->GetVertexCount()-1,
+              QPointF(p2.x(), p1.y()));
+        }
+        else if (((angle > (90 - range)) && (angle < (90 + range))) ||
+            ((angle > (270 - range)) && (angle < (270 + range))))
+        {
+          wallItem->SetVertexPosition(wallItem->GetVertexCount()-1,
+              QPointF(p1.x(), p2.y()));
+        }
+        else
+        {
+          wallItem->SetVertexPosition(wallItem->GetVertexCount()-1, p2);
         }
       }
+      QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
       break;
     }
     case WINDOW:
       break;
   }
 
-
   // auto attach windows and doors to walls
   QGraphicsItem *grabber = this->scene()->mouseGrabberItem();
   if (!grabber)
     this->drawMode = NONE;
     this->drawInProgress = false;
     this->currentMouseItem = NULL;
+    this->releaseKeyboard();
     QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
   }
   else if (_event->key() == Qt::Key_Escape)
   {
     this->CancelDrawMode();
+    this->releaseKeyboard();
   }
 }
 
     this->currentMouseItem = NULL;
     this->drawMode = NONE;
     this->drawInProgress = false;
+    this->releaseKeyboard();
     QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
   }
   else
 
   if (this->drawMode == WALL)
     QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
+
+  this->grabKeyboard();
 }
 
 /////////////////////////////////////////////////
 /////////////////////////////////////////////////
 void EditorView::CancelDrawMode()
 {
-  if (this->drawMode != NONE && this->currentMouseItem)
+  if (this->drawMode != NONE)
   {
-    EditorItem *item = dynamic_cast<EditorItem *>(this->currentMouseItem);
-    this->itemToModelMap.erase(item);
-    if (drawMode == WALL)
-    {
-      WallItem* wallItem = dynamic_cast<WallItem*>(this->currentMouseItem);
-      wallItem->PopEndPoint();
-      wallList.push_back(wallItem);
-      //this->buildingMaker->RemoveWall(this->lastWallSegmentName);
-      this->lastWallSegmentName = "";
+    if (this->currentMouseItem)
+      {
+      EditorItem *item = dynamic_cast<EditorItem *>(this->currentMouseItem);
+      this->itemToModelMap.erase(item);
+      if (drawMode == WALL)
+      {
+        WallItem* wallItem = dynamic_cast<WallItem*>(this->currentMouseItem);
+        wallItem->PopEndPoint();
+        wallList.push_back(wallItem);
+        //this->buildingMaker->RemoveWall(this->lastWallSegmentName);
+        this->lastWallSegmentName = "";
+      }
+      else
+      {
+        delete this->currentMouseItem;
+      }
     }
-    else
-    {
-      delete this->currentMouseItem;
-    }
-
     this->drawMode = NONE;
     this->drawInProgress = false;
     this->currentMouseItem = NULL;