#include "circle.h"
#include "dimension.h"
#include "drawcircleaction.h"
+#include "drawdimensionaction.h"
#include "drawlineaction.h"
#include "line.h"
#include "painter.h"
gridBackground(256, 256),
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), addLineTool(false), toolAction(NULL)
+// 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)
{
setBackgroundRole(QPalette::Base);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
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
pmp.fillRect(192, 128, 64, 64, Qt::darkGray);
#else
pmp.fillRect(0, 0, 256, 256, QColor(240, 240, 240));
- pmp.setPen(QPen(QColor(190, 190, 255), 2.0, Qt::SolidLine));
+ pmp.setPen(QPen(QColor(210, 210, 255), 2.0, Qt::SolidLine));
for(int i=0; i<255; i+=12)
pmp.drawLine(i, 0, i, 255);
for(int i=0; i<255; i+=12)
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
Vector pixmapOrigin = Painter::CartesianToQtCoords(Vector());
int x = (int)pixmapOrigin.x;
int y = (int)pixmapOrigin.y;
+ // Use mod arithmetic to grab the correct swatch of background
// Problem with mod 128: Negative numbers screw it up... [FIXED]
x = (x < 0 ? 0 : BG_BRUSH_SPAN - 1) - (x % BG_BRUSH_SPAN);
y = (y < 0 ? 0 : BG_BRUSH_SPAN - 1) - (y % BG_BRUSH_SPAN);
#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);
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));
painter.drawLine(-16384, (int)y, 16384, (int)y);
#endif
- painter.SetPen(QPen(Qt::black, 1.0, Qt::SolidLine));
-
- for(double x=0; x<size().width(); x+=gridSpacing)
- for(double y=0; y<size().height(); y+=gridSpacing)
- painter.DrawPoint((int)x, (int)y);
+// painter.SetPen(QPen(Qt::black, 1.0, Qt::SolidLine));
+//
+// for(double x=0; x<size().width(); x+=gridSpacing)
+// for(double y=0; y<size().height(); y+=gridSpacing)
+// painter.DrawPoint((int)x, (int)y);
// The top level document takes care of rendering for us...
document.Draw(&painter);
toolAction->Draw(&painter);
}
+
void DrawingView::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
}
}
+
void DrawingView::mouseMoveEvent(QMouseEvent * event)
{
Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
{
point += gridSpacing / 2.0; // *This* adds to Z!!!
point /= gridSpacing;
+//200% is ok, gridSpacing = 6 in this case...
+//won't run into problems until gridSpacing = 1.5 (zoom = 800%)
+//run into problems with this approach: when zoom level is 200% this truncates to
+//integers, which is *not* what's wanted here...
point.x = floor(point.x);//need to fix this for negative numbers...
point.y = floor(point.y);
point.z = 0; // Make *sure* Z doesn't go anywhere!!!
}
}
+
void DrawingView::mouseReleaseEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
setCursor(Qt::ArrowCursor);
}
}
+