X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawarcaction.cpp;h=624e4ee74a04a23f0e4b682d892f22eeef4e52e1;hb=86caae9cadd6e1877a4e6226533521ef0d1c6389;hp=96db3098d2b59c82e0f8c18bf098708f00e7824b;hpb=bb8d0671717bac2c5350e34024273381be1d8175;p=architektonas diff --git a/src/drawarcaction.cpp b/src/drawarcaction.cpp index 96db309..624e4ee 100644 --- a/src/drawarcaction.cpp +++ b/src/drawarcaction.cpp @@ -12,15 +12,13 @@ // #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) @@ -38,14 +36,21 @@ DrawArcAction::~DrawArcAction() 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); } } @@ -54,8 +59,22 @@ DrawArcAction::~DrawArcAction() { 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; + } } @@ -63,8 +82,22 @@ DrawArcAction::~DrawArcAction() { 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; + } } @@ -72,17 +105,21 @@ DrawArcAction::~DrawArcAction() { 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; } }