]> Shamusworld >> Repos - architektonas/blobdiff - src/drawlineaction.cpp
Changed Actions to emit signal when needing a graphical update.
[architektonas] / src / drawlineaction.cpp
index 780ad58a66c3fd49f9e563f3156aa3af29ffa98f..27b9513c04574e395ca22a7273c3b3ed126b003d 100644 (file)
 #include "drawlineaction.h"
 #include "line.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()
 {
 }
@@ -36,6 +36,7 @@ DrawLineAction::~DrawLineAction()
        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->DrawHandle(p1);
@@ -44,17 +45,26 @@ DrawLineAction::~DrawLineAction()
        {
                painter->DrawLine(p1, p2);
                painter->DrawHandle(p2);
+
+               QString text = tr("Length: %1 in.");
+               text = text.arg(Vector::Magnitude(p1, p2));
+               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)
@@ -63,6 +73,7 @@ DrawLineAction::~DrawLineAction()
                p2 = point;
 }
 
+
 /*virtual*/ void DrawLineAction::MouseReleased(void)
 {
        if (state == FIRST_POINT)
@@ -79,5 +90,33 @@ DrawLineAction::~DrawLineAction()
                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());
+       }
+}
+