]> Shamusworld >> Repos - architektonas/blobdiff - src/drawlineaction.cpp
Added ability to manipulate Arcs.
[architektonas] / src / drawlineaction.cpp
index 65b9fc1b85e6ced0bb085e53840cd44fda222e05..3dc9f7d240922b1c14f1122a9fa3d791941251a3 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
 
 #include "drawlineaction.h"
 #include "line.h"
+#include "mathconstants.h"
 #include "painter.h"
-//#include "vector.h"
 
 
-#define FIRST_POINT 0
-#define NEXT_POINT 1
+enum { FIRST_POINT, NEXT_POINT };
 
 
-DrawLineAction::DrawLineAction(): state(0), line(NULL)
+DrawLineAction::DrawLineAction(): state(FIRST_POINT), line(NULL),
+       shiftWasPressedOnNextPoint(false)
 {
 }
 
+
 DrawLineAction::~DrawLineAction()
 {
 }
@@ -33,26 +34,41 @@ DrawLineAction::~DrawLineAction()
 
 /*virtual*/ void DrawLineAction::Draw(Painter * painter)
 {
-       // Need to fix pen colors, etc...
+       painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
+
        // I think stuff like crosshairs should be done in the DrawingView, tho
+       // (and it's done there now...)
        if (state == FIRST_POINT)
        {
-               painter->DrawPoint(p1.x, p1.y);
+               painter->DrawHandle(p1);
        }
        else
        {
                painter->DrawLine(p1, p2);
+               painter->DrawHandle(p2);
+
+               Vector v(p1, p2);
+               double absAngle = v.Angle() * RADIANS_TO_DEGREES;
+               double absLength = v.Magnitude();
+               QString text = tr("Length: %1 in.\n") + QChar(0x2221) + tr(": %2");
+               text = text.arg(absLength).arg(absAngle);
+               painter->DrawInformativeText(text);
        }
 }
 
+
 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
 {
+       // Clear our override...
+       shiftWasPressedOnNextPoint = false;
+
        if (state == FIRST_POINT)
                p1 = point;
        else
                p2 = point;
 }
 
+
 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
 {
        if (state == FIRST_POINT)
@@ -61,21 +77,60 @@ DrawLineAction::~DrawLineAction()
                p2 = point;
 }
 
+
 /*virtual*/ void DrawLineAction::MouseReleased(void)
 {
        if (state == FIRST_POINT)
        {
                p2 = p1;
                state = NEXT_POINT;
+               line = NULL;
        }
        else if (state == NEXT_POINT)
        {
+               Line * oldLine = line;
                // 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);
+
+               // Connect Lines by default
+               if (oldLine)
+               {
+                       oldLine->Connect(line, 0);
+                       line->Connect(oldLine, 1.0);
+               }
+
                // We don't need no stinkin' sentinels, when we have signals & slots!
                emit ObjectReady(line);
 
                p1 = p2;
+               state = NEXT_POINT;
+       }
+}
+
+
+/*virtual*/ void DrawLineAction::KeyDown(int key)
+{
+       if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
+       {
+               shiftWasPressedOnNextPoint = true;
+               p1Save = p1;
+               p1 = p2;
+               state = FIRST_POINT;
+               emit NeedRefresh();
        }
 }
+
+
+/*virtual*/ void DrawLineAction::KeyReleased(int key)
+{
+       if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
+       {
+               shiftWasPressedOnNextPoint = false;
+               p2 = p1;
+               p1 = p1Save;
+               state = NEXT_POINT;
+               emit(NeedRefresh());
+       }
+}
+