]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Tool for adding Lines works now.
[architektonas] / src / drawingview.cpp
index 957aaf87a56d27b70fb622fccfb45ad07b990d3d..015431c88e3fece1f53954e22d489a460bd5e1bf 100644 (file)
@@ -334,6 +334,13 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
                painter.DrawCrosshair(oldPoint);
                toolAction->Draw(&painter);
        }
+#else
+       if (Global::tool)
+       {
+               painter.SetPen(QPen(QColor(200, 100, 0, 255), 1.0, Qt::DashLine));
+               painter.DrawCrosshair(oldPoint);
+               ToolDraw(&painter);
+       }
 #endif
 
 #if 1
@@ -595,6 +602,73 @@ void DrawingView::resizeEvent(QResizeEvent * /*event*/)
 }
 
 
+void DrawingView::ToolMouseDown(Point p)
+{
+       if (Global::tool == TTLine)
+       {
+               if (Global::toolState == TSNone)
+               {
+                       toolPoint[0] = p;
+//                     toolState = TSPoint1;
+//                     toolObject = (Object *)(new Line(p, Vector(0, 0)));
+               }
+               else //if (Global::toolState == TSPoint1)
+               {
+                       toolPoint[1] = p;
+               }
+       }
+}
+
+
+void DrawingView::ToolMouseMove(Point p)
+{
+       if (Global::tool == TTLine)
+       {
+               if (Global::toolState == TSNone)
+                       toolPoint[0] = p;
+               else
+                       toolPoint[1] = p;
+       }
+}
+
+
+void DrawingView::ToolMouseUp(Point p)
+{
+       if (Global::tool == TTLine)
+       {
+               if (Global::toolState == TSNone)
+               {
+                       Global::toolState = TSPoint2;
+                       // Prevent spurious line from drawing...
+                       toolPoint[1] = toolPoint[0];
+               }
+               else
+               {
+                       Line * l = new Line(toolPoint[0], toolPoint[1]);
+                       document.objects.push_back(l);
+                       toolPoint[0] = toolPoint[1];
+               }
+       }
+}
+
+
+void DrawingView::ToolDraw(Painter * painter)
+{
+       if (Global::tool == TTLine)
+       {
+               if (Global::toolState == TSNone)
+               {
+                       painter->DrawHandle(toolPoint[0]);
+               }
+               else
+               {
+                       painter->DrawLine(toolPoint[0], toolPoint[1]);
+                       painter->DrawHandle(toolPoint[1]);
+               }
+       }
+}
+
+
 void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -626,6 +700,15 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
 #else
                if (Global::tool)
                {
+                       if (Global::snapToGrid)
+                               point = SnapPointToGrid(point);
+
+                       // Snap to object point if valid...
+                       
+
+                       ToolMouseDown(point);
+                       //Also, may want to figure out if hovering over a snap point on an object,
+                       //snap to grid if not.
                        return;
                }
 #endif
@@ -682,7 +765,8 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
 #if 1
        // Grid processing... (only snap here is left button is down)
-       if ((event->buttons() & Qt::LeftButton) && Global::snapToGrid)
+       // Umm, WHY??
+       if (/*(event->buttons() & Qt::LeftButton) &&*/ Global::snapToGrid)
        {
                point = SnapPointToGrid(point);
        }
@@ -885,7 +969,9 @@ selected object last and thus fucks up the algorithm. Need to fix this...
 
                toolAction->MouseMoved(point);
        }
+#else
 #endif
+
        bool needUpdate = false;
 
        // Don't do this kind of checking unless we're not doing a selection rectangle!
@@ -967,6 +1053,13 @@ selected object last and thus fucks up the algorithm. Need to fix this...
        }
 //printf("MouseMove: numHovered = %i\n", numHovered);
 
+       // Tool handling...
+       if (Global::tool)
+       {
+               // Need to do snapping, etc. as well
+               ToolMouseMove(point);
+       }
+
        // This is used to draw the tool crosshair...
        oldPoint = point;
 
@@ -994,6 +1087,13 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
 #if 0
                if (toolAction)
                        toolAction->MouseReleased();
+#else
+               if (Global::tool)
+               {
+                       Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
+                       ToolMouseUp(point);
+                       return;
+               }
 #endif
 
                if (Global::selectionInProgress)