X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=23c1d49100ad95f26a55aeb7e1a441a1a8875d0b;hb=d549bfdc8c872b966b9d787c00e5e8027366093c;hp=8c706a9372b8f27330bcff2c4b1f7f299b68b284;hpb=5446001bd9adfd9f4787f5de5a2a7afd8d7cdb5a;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 8c706a9..23c1d49 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -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); @@ -67,7 +72,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), document.Add(new Arc(Vector(300, 300), 32, PI / 4.0, PI * 1.3, &document)), document.Add(new Arc(Vector(200, 200), 60, PI / 2.0, PI * 1.5, &document)); #if 1 - Dimension * dimension = new Dimension(Vector(0, 0), Vector(0, 0), &document); + Dimension * dimension = new Dimension(Vector(0, 0), Vector(0, 0), DTLinear, &document); line->SetDimensionOnLine(dimension); document.Add(dimension); #else @@ -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); @@ -242,7 +247,8 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/) painter.DrawLine(-16384, 0, 16384, 0); // Draw supplemental (tool related) points - +// NOTE that this can be done as an action! +// In that case, we would need access to the document... if (rotateTool) { painter.SetPen(QPen(QColor(0, 200, 0), 2.0, Qt::SolidLine)); @@ -277,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) @@ -291,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) { @@ -301,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) { @@ -347,7 +373,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) //changed... document.PointerMoved(point); - if (document.NeedsUpdate()) + if (document.NeedsUpdate() || Object::selectionInProgress) update(); if (toolAction) @@ -357,6 +383,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) } } + void DrawingView::mouseReleaseEvent(QMouseEvent * event) { if (event->button() == Qt::LeftButton) @@ -372,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) { @@ -379,3 +412,4 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) setCursor(Qt::ArrowCursor); } } +