#include "arc.h"
#include "circle.h"
#include "dimension.h"
+#include "drawlineaction.h"
#include "line.h"
#include "painter.h"
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);
// Alternate way to do the above...
line->SetDimensionOnLine();
#endif
+// connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+// SLOT(AddNewObjectToDocument(Object *)));
}
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.
// The top level document takes care of rendering for us...
document.Draw(&painter);
+
+ if (toolAction)
+ toolAction->Draw(&painter);
}
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)
{
{
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;
if (document.NeedsUpdate())
update();
+
+ if (toolAction)
+ {
+ toolAction->MouseMoved(point);
+ update();
+ }
}
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)
{