]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Preliminary Add Line tool work...
[architektonas] / src / drawingview.cpp
index 4a71fa6469a7160c644dddce86bd0a394927497e..a214f02fd901d4b0d339bd3dca571be9dd810044 100644 (file)
@@ -34,6 +34,7 @@
 #include "arc.h"
 #include "circle.h"
 #include "dimension.h"
+#include "drawlineaction.h"
 #include "line.h"
 #include "painter.h"
 
@@ -44,7 +45,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        scale(1.0), offsetX(-10), offsetY(-10),
        document(Vector(0, 0)),
        gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
-       scrollDrag(false)
+       scrollDrag(false), addLineTool(false), toolAction(NULL)
 {
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -70,6 +71,8 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        // Alternate way to do the above...
        line->SetDimensionOnLine();
 #endif
+//     connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+//             SLOT(AddNewObjectToDocument(Object *)));
 }
 
 void DrawingView::SetRotateToolActive(bool state/*= true*/)
@@ -78,6 +81,36 @@ void DrawingView::SetRotateToolActive(bool state/*= true*/)
        update();
 }
 
+void DrawingView::SetAddLineToolActive(bool state/*= true*/)
+{
+       if (state && toolAction == NULL)
+       {
+               toolAction = new DrawLineAction();
+               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+                       SLOT(AddNewObjectToDocument(Object *)));
+       }
+       else if (!state && toolAction)
+       {
+               delete toolAction;
+               toolAction = NULL;
+       }
+
+       addLineTool = state;
+       update();
+//printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
+}
+
+void DrawingView::AddNewObjectToDocument(Object * object)
+{
+       if (object)
+       {
+               object->Reparent(&document);
+               document.Add(object);
+               update();
+       }
+//printf("DrawingView::AddNewObjectToDocument(). object=%08X\n", object);
+}
+
 QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
 {
        // This is undoing the transform, e.g. going from client coords to local coords.
@@ -144,6 +177,9 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
 
        // The top level document takes care of rendering for us...
        document.Draw(&painter);
+
+       if (toolAction)
+               toolAction->Draw(&painter);
 }
 
 void DrawingView::mousePressEvent(QMouseEvent * event)
@@ -155,6 +191,9 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
 
                if (collided)
                        update();       // Do an update if collided with at least *one* object in the document
+
+               if (toolAction)
+                       toolAction->MouseDown(point);
        }
        else if (event->button() == Qt::MiddleButton)
        {
@@ -173,7 +212,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        {
                point = Vector(event->x(), event->y());
                // Since we're using Qt coords for scrolling, we have to adjust them here to
-               // conform to Cartesian coords, since the origin is using them. :-)
+               // conform to Cartesian coords, since the origin is using Cartesian. :-)
                Vector delta(point, oldPoint);
                delta /= Painter::zoom;
                delta.y = -delta.y;
@@ -207,6 +246,12 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
        if (document.NeedsUpdate())
                update();
+
+       if (toolAction)
+       {
+               toolAction->MouseMoved(point);
+               update();
+       }
 }
 
 void DrawingView::mouseReleaseEvent(QMouseEvent * event)
@@ -221,6 +266,9 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
 //             if (document.NeedsUpdate())
 //             if (collided)
                        update();       // Do an update if collided with at least *one* object in the document
+
+               if (toolAction)
+                       toolAction->MouseReleased();
        }
        else if (event->button() == Qt::MiddleButton)
        {