]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Initial work on BlockWidget.
[architektonas] / src / drawingview.cpp
index 330f73377540c8e96c9cd2388f0888344534dfde..23c1d49100ad95f26a55aeb7e1a441a1a8875d0b 100644 (file)
@@ -50,8 +50,11 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
 //     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), addCircleTool(false),
-       addDimensionTool(false), toolAction(NULL)
+       addDimensionTool(false),
+//     selectionInProgress(false),
+       toolAction(NULL)
 {
+       document.isTopLevelContainer = true;
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
@@ -280,6 +283,15 @@ 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);
+       }
 }
 
 
@@ -295,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)
        {
@@ -309,6 +329,7 @@ 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)
        {
@@ -352,7 +373,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 //changed...
        document.PointerMoved(point);
 
-       if (document.NeedsUpdate())
+       if (document.NeedsUpdate() || Object::selectionInProgress)
                update();
 
        if (toolAction)
@@ -378,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)
        {