]> Shamusworld >> Repos - architektonas/commitdiff
Tool for adding Lines works now.
authorShamus Hammons <jlhamm@acm.org>
Mon, 27 Apr 2015 01:26:54 +0000 (20:26 -0500)
committerShamus Hammons <jlhamm@acm.org>
Mon, 27 Apr 2015 01:26:54 +0000 (20:26 -0500)
src/applicationwindow.cpp
src/drawingview.cpp
src/drawingview.h
src/global.cpp
src/global.h
src/structs.h

index f5013ad8ae940bf714003b4d4e8e1d7f699bde5b..866750d82fc8dce1326ff8b007be6bf8045a80fd 100644 (file)
@@ -420,6 +420,7 @@ void ApplicationWindow::SetInternalToolStates(void)
        // We can be sure that if we've come here, then either an active tool is
        // being deactivated, or a new tool is being created. In either case, the
        // old tool needs to be deleted.
+       Global::toolState = TSNone;
 #if 0
        if (drawing->toolAction)
        {
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)
index c4a7234fe733314ffc34bbebfcf98b3232a314e0..3d22b44e83e97224b9e1c38eee3201d56972d2b0 100644 (file)
@@ -15,7 +15,6 @@ class DrawingView: public QWidget
                DrawingView(QWidget * parent = NULL);
 
        public:
-//             void SetToolActive(Action * action);
                void SetGridSize(uint32_t);
                void UpdateGridBackground(void);
                Point SnapPointToGrid(Point);
@@ -25,6 +24,10 @@ class DrawingView: public QWidget
                void AddHoveredToSelection(void);
                void GetSelection(std::vector<void *> &);
                void GetHovered(std::vector<void *> &);
+               void ToolMouseDown(Point);
+               void ToolMouseMove(Point);
+               void ToolMouseUp(Point);
+               void ToolDraw(Painter *);
 
        public slots:
                void AddNewObjectToDocument(Object *);
@@ -67,8 +70,13 @@ class DrawingView: public QWidget
        public:
                std::vector<void *> select;
                std::vector<void *> hover;
-//             Action * toolAction;
+//             int toolState;
+               Point toolPoint[32];
+//             Object * toolObject;
 
+       // Tool methods (static)
+       public:
+//             static void foo();
 //     public:
 //             static Container document;
 };
index c52a1ee66474772336d5f29403266b23b66577a5..fe758560726cf71c55c9d84009b9b600aac66f40 100644 (file)
@@ -24,6 +24,7 @@ bool Global::selectionInProgress = false;
 QRectF Global::selection;
 
 int Global::tool = TTNone;
+int Global::toolState = TSNone;
 
 double Global::gridSpacing;
 int Global::currentLayer = 0;
index fb057652e2b3a4956778a610d3d4a9186835df7f..d59155e5a0c0d1e8c8b74c124ef75859e435b202 100644 (file)
@@ -35,6 +35,7 @@ class Global
                static bool dontMove;
                static uint32_t objectID;
                static int tool;
+               static int toolState;
 
                static Point origin;
                static double zoom;
index 1bbfc3fdc589fc3ed619808f8be390c5bd725a0c..b63921248aca8fc1071d8b8fdd8f2b4b777faff6 100644 (file)
@@ -13,6 +13,8 @@ enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric
 
 enum ToolType { TTNone, TTLine, TTCircle, TTEllipse, TTArc, TTDimension, TTText, TTPolygon, TTSpline, TTRotate, TTMirror, TTTrim, TTTriangulate, TTDelete };
 
+enum ToolState { TSNone, TSPoint1, TSPoint2, TSDone };
+
 #define OBJECT_COMMON \
        int type;         \
        uint32_t id;      \