]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Fix tool handling and circle highlighting.
[architektonas] / src / drawingview.cpp
index 3f27f96f84c5284b24d7efb5b06f67e7f32c14a8..330f73377540c8e96c9cd2388f0888344534dfde 100644 (file)
@@ -35,6 +35,7 @@
 #include "circle.h"
 #include "dimension.h"
 #include "drawcircleaction.h"
+#include "drawdimensionaction.h"
 #include "drawlineaction.h"
 #include "line.h"
 #include "painter.h"
@@ -48,7 +49,8 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        document(Vector(0, 0)),
 //     gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
        gridSpacing(12.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
-       scrollDrag(false), addLineTool(false), toolAction(NULL)
+       scrollDrag(false), addLineTool(false), addCircleTool(false),
+       addDimensionTool(false), toolAction(NULL)
 {
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -102,58 +104,54 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        UpdateGridBackground();
 }
 
+
 void DrawingView::SetRotateToolActive(bool state/*= true*/)
 {
        rotateTool = state;
        update();
 }
 
+
 void DrawingView::SetAddLineToolActive(bool state/*= true*/)
 {
-       if (state)// && toolAction == NULL)
+       if (state)
        {
-               if (toolAction)
-                       delete toolAction;
-
-               addCircleTool = false;
                toolAction = new DrawLineAction();
                connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
                        SLOT(AddNewObjectToDocument(Object *)));
        }
-       else if (!state && addLineTool && toolAction)
-       {
-               delete toolAction;
-               toolAction = NULL;
-       }
 
-       addLineTool = state;
        update();
 //printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
 }
 
+
 void DrawingView::SetAddCircleToolActive(bool state/*= true*/)
 {
-       if (state)// && toolAction == NULL)
+       if (state)
        {
-               if (toolAction)
-                       delete toolAction;
-
-               addLineTool = false;
                toolAction = new DrawCircleAction();
                connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
                        SLOT(AddNewObjectToDocument(Object *)));
        }
-       else if (!state && addCircleTool && toolAction)
+
+       update();
+}
+
+
+void DrawingView::SetAddDimensionToolActive(bool state/*= true*/)
+{
+       if (state)
        {
-               delete toolAction;
-               toolAction = NULL;
+               toolAction = new DrawDimensionAction();
+               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+                       SLOT(AddNewObjectToDocument(Object *)));
        }
 
-       addCircleTool = state;
        update();
-//printf("DrawingView::SetAddCircleToolActive(). toolAction=%08X\n", toolAction);
 }
 
+
 void DrawingView::UpdateGridBackground(void)
 {
 #if 0
@@ -194,6 +192,7 @@ setPalette(pal);
 #endif
 }
 
+
 void DrawingView::AddNewObjectToDocument(Object * object)
 {
        if (object)
@@ -205,6 +204,7 @@ void DrawingView::AddNewObjectToDocument(Object * object)
 //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.
@@ -213,6 +213,7 @@ QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
        return QPoint(offsetX + event->x(), offsetY + (size().height() - event->y()));
 }
 
+
 QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
 {
        // VOODOO ALERT (ON Y COMPONENT!!!!) (eh?)
@@ -221,6 +222,7 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
        return QPoint(-offsetX + x, (size().height() - (-offsetY + y)) * +1.0);
 }
 
+
 void DrawingView::paintEvent(QPaintEvent * /*event*/)
 {
        QPainter qtPainter(this);
@@ -280,6 +282,7 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
                toolAction->Draw(&painter);
 }
 
+
 void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -302,6 +305,7 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
        }
 }
 
+
 void DrawingView::mouseMoveEvent(QMouseEvent * event)
 {
        Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
@@ -358,6 +362,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        }
 }
 
+
 void DrawingView::mouseReleaseEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -380,3 +385,4 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
                setCursor(Qt::ArrowCursor);
        }
 }
+