]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Fixed loading code, added "Base Unit" dialog.
[architektonas] / src / drawingview.cpp
index 31aeaf028193e6fe9c43cb530a9a166d7c6befce..5bbcddf62ffeb0396b5f5edc5924e46ceaea9a5e 100644 (file)
 #include "arc.h"
 #include "circle.h"
 #include "dimension.h"
-#include "drawarcaction.h"
-#include "drawcircleaction.h"
-#include "drawdimensionaction.h"
-#include "drawlineaction.h"
 #include "line.h"
 #include "painter.h"
 
@@ -129,22 +125,7 @@ need a thickness parameter similar to the "size" param for dimensions. (And now
 we do! :-)
 
 */
-#if 0
-       QPainter pmp(&gridBackground);
-       pmp.fillRect(0, 0, BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE, QColor(240, 240, 240));
-       pmp.setPen(QPen(QColor(210, 210, 255), 2.0, Qt::SolidLine));
-
-       for(int i=0; i<(BACKGROUND_MAX_SIZE-1); i+=12)
-       {
-               pmp.drawLine(i, 0, i, BACKGROUND_MAX_SIZE - 1);
-               pmp.drawLine(0, i, BACKGROUND_MAX_SIZE - 1, i);
-       }
-
-       pmp.end();
-       UpdateGridBackground();
-#else
        SetGridSize(12);
-#endif
 }
 
 
@@ -155,56 +136,14 @@ void DrawingView::SetRotateToolActive(bool state/*= true*/)
 }
 
 
-void DrawingView::SetAddLineToolActive(bool state/*= true*/)
+void DrawingView::SetToolActive(Action * action)
 {
-       if (state)
+       if (action != NULL)
        {
-               toolAction = new DrawLineAction();
+               toolAction = action;
                connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
                        SLOT(AddNewObjectToDocument(Object *)));
        }
-
-       update();
-//printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
-}
-
-
-void DrawingView::SetAddCircleToolActive(bool state/*= true*/)
-{
-       if (state)
-       {
-               toolAction = new DrawCircleAction();
-               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
-                       SLOT(AddNewObjectToDocument(Object *)));
-       }
-
-       update();
-}
-
-
-void DrawingView::SetAddArcToolActive(bool state/*= true*/)
-{
-       if (state)
-       {
-               toolAction = new DrawArcAction();
-               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
-                       SLOT(AddNewObjectToDocument(Object *)));
-       }
-
-       update();
-}
-
-
-void DrawingView::SetAddDimensionToolActive(bool state/*= true*/)
-{
-       if (state)
-       {
-               toolAction = new DrawDimensionAction();
-               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
-                       SLOT(AddNewObjectToDocument(Object *)));
-       }
-
-       update();
 }
 
 
@@ -398,7 +337,12 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
        document.Draw(&painter);
 
        if (toolAction)
+       {
+//             painter.SetPen(QPen(Qt::green, 1.0, Qt::DashLine));
+               painter.SetPen(QPen(QColor(200, 100, 0, 255), 1.0, Qt::DashLine));
+               painter.DrawCrosshair(oldPoint);
                toolAction->Draw(&painter);
+       }
 
        if (Object::selectionInProgress)
        {
@@ -424,6 +368,14 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
        {
                Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
 
+// Problem with this: Can't select stuff very well with the snap grid on.
+// Completely screws things up, as sometimes things don't fall on the grid.
+/*
+So, how to fix this? Have the Object check itself?
+Maybe we can fix this by having the initial point not be snapped, but when there's
+a drag, we substitute the snapped point 'oldPoint' which the Object keeps track of
+internally to know how far it was dragged...
+*/
                if (Object::snapToGrid)
                        point = SnapPointToGrid(point);
 
@@ -494,6 +446,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 #endif
        }
 #endif
+       oldPoint = point;
 //we should keep track of the last point here and only pass this down *if* the point
 //changed...
        document.PointerMoved(point);
@@ -503,6 +456,12 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
        if (toolAction)
        {
+               if (Object::snapToGrid)
+               {
+                       point = SnapPointToGrid(point);
+                       oldPoint = point;
+               }
+
                toolAction->MouseMoved(point);
                update();
        }