Object::SetDeleteActive(deleteAct->isChecked());
Object::SetDimensionActive(addDimensionAct->isChecked());
drawing->SetRotateToolActive(rotateAct->isChecked());
+
+ // We can be sure that if we've come here, then either an active tool is
+ // being deactivated, or a new tool is being created. In either case, the
+ // old tool needs to be deleted.
+ if (drawing->toolAction)
+ {
+ delete drawing->toolAction;
+ drawing->toolAction = NULL;
+ }
+
drawing->SetAddLineToolActive(addLineAct->isChecked());
drawing->SetAddCircleToolActive(addCircleAct->isChecked());
+ drawing->SetAddDimensionToolActive(addDimensionAct->isChecked());
}
Document passes in the correct Cartesian coordinates being pointed to by the mouse.
So all we have to be concerned with is properly scaling our hot zones/handle sizes,
since we generally *don't* want those to scale with the zoom level. ;-)
+
+What is going on here?
+If we're zoomed out to, say, 50%, & our radius is 10.0 (absolute), then on screen
+the radius will be 5.0. By multiplying the length by the zoom factor, we align our
+pointed at length with our on screen length.
*/
- if (length < 8.0)
+ if ((length * Painter::zoom) < 8.0)
hitCenter = true;
- else if ((length < (radius + 2.0)) && (length > (radius - 2.0)))
+//wrong: else if ((length < (radius + 2.0)) && (length > (radius - 2.0)))
+/*NB: The following should be identical to what we have down below, but it doesn't work out that way... :-P */
+//close, but no else if (((length * Painter::zoom) < ((radius * Painter::zoom) + 2.0)) && ((length * Painter::zoom) > ((radius * Painter::zoom) - 2.0)))
+//really wrong! else if (((length * Painter::zoom) < (radius + 2.0)) && ((length * Painter::zoom) > (radius - 2.0)))
+// close again, but sill no else if (((length * Painter::zoom) < ((radius + 2.0) * Painter::zoom)) && ((length * Painter::zoom) > ((radius - 2.0) * Painter::zoom)))
+ else if ((fabs(length - radius) * Painter::zoom) < 2.0)
hitCircle = true;
return StateChanged();
/*virtual*/ void Dimension::Disconnect(Object * obj, double param)
{
if (point1.object == obj && point1.t == param)
- point1 = NULL;
+ point1.object = NULL;
else if (point2.object == obj && point2.t == param)
- point2 = NULL;
+ point2.object = NULL;
}
/*virtual*/ void Dimension::DisconnectAll(Object * obj)
{
if (point1.object == obj)
- point1 = NULL;
+ point1.object = NULL;
if (point2.object == obj)
- point2 = NULL;
+ point2.object = NULL;
}
#include "connection.h"
#include "object.h"
-enum DimensionType { DTLinear, DTRadial, DTDiametric, DTCircumferential, DTLeader };
+enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric, DTCircumferential, DTAngular, DTLeader };
class Dimension: public Object
{
DimensionType type;
// We use these in lieu of the built-in connected[] array; no reason to
- // do this way especially
+ // do it this way especially
Connection point1;
Connection point2;
};
// We create the new object here, and then pass it off to the
// DrawingView which stuffs it into the document.
// line = new Line(p1, p2);
+ dimension = new Dimension(p1, p2);
// We don't need no stinkin' sentinels, when we have signals & slots!
emit ObjectReady(dimension);
- p1 = p2;
+ state = FIRST_POINT;
+// p1 = p2;
}
}
#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), toolAction(NULL)
{
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);
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()));
}
}
+
void DrawingView::mouseReleaseEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
setCursor(Qt::ArrowCursor);
}
}
+
void SetRotateToolActive(bool state = true);
void SetAddLineToolActive(bool state = true);
void SetAddCircleToolActive(bool state = true);
+ void SetAddDimensionToolActive(bool state = true);
void UpdateGridBackground(void);
public slots:
Vector oldPoint;
bool addLineTool;
bool addCircleTool;
- Action * toolAction;
-/* QSize minimumSizeHint() const;
- QSize sizeHint() const;
-
- private:
- void CreateCursors(void);
- QPoint GetAdjustedMousePosition(QMouseEvent * event);
- QPoint GetAdjustedClientPosition(int x, int y);
-
- QImage image;
- QPoint pt, ptOffset, ptPrevious;
- ToolType tool; // Current tool
- GlyphPoints pts; // Glyph point structure
- int32 ptHighlight, oldPtHighlight, ptNextHighlight, oldPtNextHighlight;
- bool polyFirstPoint;
+ bool addDimensionTool;
- ToolWindow * toolPalette;
- QCursor cur[8];
-*/
+ public:
+ Action * toolAction;
};
#endif // __DRAWINGVIEW_H__
+/*
+An ellipse is just a variant of a circle, do we really need a separate class
+for them?
+
+We have a separate class for arcs, and those are circle variants too.
+
+Maybe. The ellipse (and elliptical arc) have two focii and a rotation angle.
+But there's no reason why those extras couldn't go into the Circle class as
+well.
+*/