#include "about.h"
#include "blockwidget.h"
#include "drawingview.h"
+#include "drawarcaction.h"
+#include "drawcircleaction.h"
+#include "drawdimensionaction.h"
+#include "drawlineaction.h"
#include "fileio.h"
#include "generaltab.h"
#include "layerwidget.h"
drawing->toolAction = NULL;
}
+#if 0
drawing->SetAddLineToolActive(addLineAct->isChecked());
drawing->SetAddCircleToolActive(addCircleAct->isChecked());
drawing->SetAddArcToolActive(addArcAct->isChecked());
drawing->SetAddDimensionToolActive(addDimensionAct->isChecked());
+#else
+ drawing->SetToolActive(addLineAct->isChecked() ? new DrawLineAction() : NULL);
+ drawing->SetToolActive(addCircleAct->isChecked() ? new DrawCircleAction() : NULL);
+ drawing->SetToolActive(addArcAct->isChecked() ? new DrawArcAction() : NULL);
+ drawing->SetToolActive(addDimensionAct->isChecked() ? new DrawDimensionAction() : NULL);
+#endif
+
+ update();
}
//
#include "drawarcaction.h"
-#include "painter.h"
#include "arc.h"
+#include "mathconstants.h"
+#include "painter.h"
//#include "vector.h"
enum { FIRST_POINT, SECOND_POINT, THIRD_POINT };
-//#define FIRST_POINT 0
-//#define SECOND_POINT 1
-#define NEXT_POINT 2
DrawArcAction::DrawArcAction(): state(FIRST_POINT), arc(NULL)
painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
// I think stuff like crosshairs should be done in the DrawingView, tho
+ // (and it is! :-D)
if (state == FIRST_POINT)
{
painter->DrawHandle(p1);
}
- else
+ else if (state == SECOND_POINT)
{
-// painter->DrawLine(p1, p2);
-// painter->DrawHandle(p2);
+ painter->DrawLine(p1, p2);
+ painter->DrawHandle(p2);
+ }
+ else if (state == THIRD_POINT)
+ {
+ painter->DrawLine(p1, p2);
+ painter->DrawArc(p1, radius, startAngle, span);
+ painter->DrawHandle(p3);
}
}
{
if (state == FIRST_POINT)
p1 = point;
-// else
-// p2 = point;
+ else if (state == SECOND_POINT)
+ {
+ p2 = point;
+ Vector r1(p2, p1);
+ radius = Vector::Magnitude(p1, p2);
+ startAngle = r1.Angle();
+ }
+ else if (state == THIRD_POINT)
+ {
+ p3 = point;
+ Vector r2(p3, p1);
+ span = r2.Angle() - startAngle;
+
+ if (span < 0)
+ span += 2.0 * PI;
+ }
}
{
if (state == FIRST_POINT)
p1 = point;
-// else
-// p2 = point;
+ else if (state == SECOND_POINT)
+ {
+ p2 = point;
+ Vector r1(p2, p1);
+ radius = Vector::Magnitude(p1, p2);
+ startAngle = r1.Angle();
+ }
+ else if (state == THIRD_POINT)
+ {
+ p3 = point;
+ Vector r2(p3, p1);
+ span = r2.Angle() - startAngle;
+
+ if (span < 0)
+ span += 2.0 * PI;
+ }
}
{
if (state == FIRST_POINT)
{
-// p2 = p1;
- state = NEXT_POINT;
+ state = SECOND_POINT;
+ }
+ else if (state == SECOND_POINT)
+ {
+ state = THIRD_POINT;
}
- else if (state == NEXT_POINT)
+ else if (state == THIRD_POINT)
{
// We create the new object here, and then pass it off to the
// DrawingView which stuffs it into the document.
-// text = new Text(p1, p2);
-// arc = new Arc(...);
+ arc = new Arc(p1, radius, startAngle, span);
// We don't need no stinkin' sentinels, when we have signals & slots!
emit ObjectReady(arc);
+
+ state = FIRST_POINT;
}
}
private:
int state;
Arc * arc;
- Vector p1, p2;
+ Vector p1, p2, p3;
+ double radius, startAngle, span;
};
#endif // __DRAWARCACTION_H__
#include "arc.h"
#include "circle.h"
#include "dimension.h"
-#include "drawarcaction.h"
-#include "drawcircleaction.h"
-#include "drawdimensionaction.h"
-#include "drawlineaction.h"
#include "line.h"
#include "painter.h"
we do! :-)
*/
-#if 0
- QPainter pmp(&gridBackground);
- pmp.fillRect(0, 0, BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE, QColor(240, 240, 240));
- pmp.setPen(QPen(QColor(210, 210, 255), 2.0, Qt::SolidLine));
-
- for(int i=0; i<(BACKGROUND_MAX_SIZE-1); i+=12)
- {
- pmp.drawLine(i, 0, i, BACKGROUND_MAX_SIZE - 1);
- pmp.drawLine(0, i, BACKGROUND_MAX_SIZE - 1, i);
- }
-
- pmp.end();
- UpdateGridBackground();
-#else
SetGridSize(12);
-#endif
}
}
-void DrawingView::SetAddLineToolActive(bool state/*= true*/)
+void DrawingView::SetToolActive(Action * action)
{
- if (state)
+ if (action != NULL)
{
- toolAction = new DrawLineAction();
+ toolAction = action;
connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
SLOT(AddNewObjectToDocument(Object *)));
}
-
- update();
-//printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
-}
-
-
-void DrawingView::SetAddCircleToolActive(bool state/*= true*/)
-{
- if (state)
- {
- toolAction = new DrawCircleAction();
- connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
- SLOT(AddNewObjectToDocument(Object *)));
- }
-
- update();
-}
-
-
-void DrawingView::SetAddArcToolActive(bool state/*= true*/)
-{
- if (state)
- {
- toolAction = new DrawArcAction();
- connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
- SLOT(AddNewObjectToDocument(Object *)));
- }
-
- update();
-}
-
-
-void DrawingView::SetAddDimensionToolActive(bool state/*= true*/)
-{
- if (state)
- {
- toolAction = new DrawDimensionAction();
- connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
- SLOT(AddNewObjectToDocument(Object *)));
- }
-
- update();
}
document.Draw(&painter);
if (toolAction)
+ {
+// painter.SetPen(QPen(Qt::green, 1.0, Qt::DashLine));
+ painter.SetPen(QPen(QColor(200, 100, 0, 255), 1.0, Qt::DashLine));
+ painter.DrawCrosshair(oldPoint);
toolAction->Draw(&painter);
+ }
if (Object::selectionInProgress)
{
{
Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
+// Problem with this: Can't select stuff very well with the snap grid on.
+// Completely screws things up.
if (Object::snapToGrid)
point = SnapPointToGrid(point);
#endif
}
#endif
+ oldPoint = point;
//we should keep track of the last point here and only pass this down *if* the point
//changed...
document.PointerMoved(point);
if (toolAction)
{
+ if (Object::snapToGrid)
+ {
+ point = SnapPointToGrid(point);
+ oldPoint = point;
+ }
+
toolAction->MouseMoved(point);
update();
}
public:
void SetRotateToolActive(bool state = true);
+#if 0
void SetAddLineToolActive(bool state = true);
void SetAddCircleToolActive(bool state = true);
void SetAddArcToolActive(bool state = true);
void SetAddDimensionToolActive(bool state = true);
+#endif
+// void SetToolActive(Action * action, bool state = true);
+ void SetToolActive(Action * action);//, bool state = true);
void SetGridSize(uint32_t);
void UpdateGridBackground(void);
}
-// This is drawn in Qt coordinates...
+// The rect passed in is in Qt coordinates...
void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
{
if (!painter)
}
-// This is drawn partially in Cartesian coordinates, and partially in Qt
-// coordinates. The rect itself is in Cartesian but we want to pad it by a set
-// number of pixels.
+// The rect passed in is in Cartesian but we want to pad it by a set number of
+// pixels (currently set at 8), so the pad looks the same regardless of zoom.
void Painter::DrawPaddedRect(QRectF rect)
{
if (!painter)
void Painter::DrawArrowhead(Vector head, Vector tail, double size)
{
+ if (!painter)
+ return;
+
QPolygonF arrow;
// We draw the arrowhead aligned along the line from tail to head
painter->drawPolygon(arrow);
}
+
+// Point is given in Cartesian coordinates
+void Painter::DrawCrosshair(Vector point)
+{
+ if (!painter)
+ return;
+
+ Vector screenPoint = CartesianToQtCoords(point);
+ painter->drawLine(0, screenPoint.y, screenSize.x, screenPoint.y);
+ painter->drawLine(screenPoint.x, 0, screenPoint.x, screenSize.y);
+}
+
void DrawRect(QRectF);
void DrawText(QRectF, int, QString);
void DrawArrowhead(Vector, Vector, double);
+ void DrawCrosshair(Vector);
public:
static Vector CartesianToQtCoords(Vector);