]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Initial work on BlockWidget.
[architektonas] / src / drawingview.cpp
index 3f27f96f84c5284b24d7efb5b06f67e7f32c14a8..23c1d49100ad95f26a55aeb7e1a441a1a8875d0b 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,8 +49,12 @@ 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),
+//     selectionInProgress(false),
+       toolAction(NULL)
 {
+       document.isTopLevelContainer = true;
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
@@ -102,58 +107,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 +195,7 @@ setPalette(pal);
 #endif
 }
 
+
 void DrawingView::AddNewObjectToDocument(Object * object)
 {
        if (object)
@@ -205,6 +207,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 +216,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 +225,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);
@@ -278,8 +283,18 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
 
        if (toolAction)
                toolAction->Draw(&painter);
+
+       if (Object::selectionInProgress)
+       {
+//             painter.SetPen(QPen(Qt::green, 1.0, Qt::SolidLine));
+               painter.SetPen(QPen(QColor(255, 127, 0, 255)));
+//             painter.SetBrush(QBrush(Qt::NoBrush));
+               painter.SetBrush(QBrush(QColor(255, 127, 0, 100)));
+               painter.DrawRect(Object::selection);
+       }
 }
 
+
 void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -292,6 +307,14 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
 
                if (toolAction)
                        toolAction->MouseDown(point);
+
+               // Didn't hit any object and not using a tool, so do a selection rectangle
+               if (!(collided || toolAction))
+               {
+                       Object::selectionInProgress = true;
+                       Object::selection.setTopLeft(QPointF(point.x, point.y));
+                       Object::selection.setBottomRight(QPointF(point.x, point.y));
+               }
        }
        else if (event->button() == Qt::MiddleButton)
        {
@@ -302,9 +325,11 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
        }
 }
 
+
 void DrawingView::mouseMoveEvent(QMouseEvent * event)
 {
        Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
+       Object::selection.setBottomRight(QPointF(point.x, point.y));
 
        if (event->buttons() & Qt::MiddleButton)
        {
@@ -348,7 +373,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 //changed...
        document.PointerMoved(point);
 
-       if (document.NeedsUpdate())
+       if (document.NeedsUpdate() || Object::selectionInProgress)
                update();
 
        if (toolAction)
@@ -358,6 +383,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        }
 }
 
+
 void DrawingView::mouseReleaseEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -373,6 +399,12 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
 
                if (toolAction)
                        toolAction->MouseReleased();
+
+               if (Object::selectionInProgress)
+               {
+                       // Select all the stuff inside of selection
+                       Object::selectionInProgress = false;
+               }
        }
        else if (event->button() == Qt::MiddleButton)
        {
@@ -380,3 +412,4 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
                setCursor(Qt::ArrowCursor);
        }
 }
+