#include "circle.h"
#include "dimension.h"
#include "drawcircleaction.h"
+#include "drawdimensionaction.h"
#include "drawlineaction.h"
#include "line.h"
#include "painter.h"
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);
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
#endif
}
+
void DrawingView::AddNewObjectToDocument(Object * object)
{
if (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.
return QPoint(offsetX + event->x(), offsetY + (size().height() - event->y()));
}
+
QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
{
// VOODOO ALERT (ON Y COMPONENT!!!!) (eh?)
return QPoint(-offsetX + x, (size().height() - (-offsetY + y)) * +1.0);
}
+
void DrawingView::paintEvent(QPaintEvent * /*event*/)
{
QPainter qtPainter(this);
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)
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)
{
}
}
+
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)
{
//changed...
document.PointerMoved(point);
- if (document.NeedsUpdate())
+ if (document.NeedsUpdate() || Object::selectionInProgress)
update();
if (toolAction)
}
}
+
void DrawingView::mouseReleaseEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
if (toolAction)
toolAction->MouseReleased();
+
+ if (Object::selectionInProgress)
+ {
+ // Select all the stuff inside of selection
+ Object::selectionInProgress = false;
+ }
}
else if (event->button() == Qt::MiddleButton)
{
setCursor(Qt::ArrowCursor);
}
}
+