]> Shamusworld >> Repos - architektonas/blobdiff - src/drawlineaction.cpp
Added key modifiers to Actions.
[architektonas] / src / drawlineaction.cpp
index d4b35db336ae70c35bc8f7c6e69ca199d7e7426f..e14ba81ca1f440876c5e60dabba0cfe9b95c7962 100644 (file)
 //#include "vector.h"
 
 
-#define FIRST_POINT 0
-#define NEXT_POINT 1
+//#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)
 {
 }
 
@@ -37,6 +39,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);
@@ -55,6 +58,9 @@ DrawLineAction::~DrawLineAction()
 
 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
 {
+       // Clear our override...
+       shiftWasPressedOnNextPoint = false;
+
        if (state == FIRST_POINT)
                p1 = point;
        else
@@ -86,8 +92,38 @@ DrawLineAction::~DrawLineAction()
                // We don't need no stinkin' sentinels, when we have signals & slots!
                emit ObjectReady(line);
 
-//             p1 = p2;
+               p1 = p2;
+               state = NEXT_POINT;
+       }
+}
+
+
+/*virtual*/ bool DrawLineAction::KeyDown(int key)
+{
+       if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
+       {
+               shiftWasPressedOnNextPoint = true;
+               p1Save = p1;
+               p1 = p2;
                state = FIRST_POINT;
+               return true;
+       }
+
+       return false;
+}
+
+
+/*virtual*/ bool DrawLineAction::KeyReleased(int key)
+{
+       if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
+       {
+               shiftWasPressedOnNextPoint = false;
+               p2 = p1;
+               p1 = p1Save;
+               state = NEXT_POINT;
+               return true;
        }
+
+       return false;
 }