X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawlineaction.cpp;h=e14ba81ca1f440876c5e60dabba0cfe9b95c7962;hb=428876081ee41d40e32f5b4f2bfcfdb7a835e6e1;hp=ffa2e7eaea35c71cd39ca24be6c9dbe785860eb7;hpb=043ecf4d074909ba2f7f53237962f9eaa72f19c2;p=architektonas diff --git a/src/drawlineaction.cpp b/src/drawlineaction.cpp index ffa2e7e..e14ba81 100644 --- a/src/drawlineaction.cpp +++ b/src/drawlineaction.cpp @@ -18,14 +18,17 @@ //#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) { } + DrawLineAction::~DrawLineAction() { } @@ -33,26 +36,38 @@ 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); + + 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) @@ -61,6 +76,7 @@ DrawLineAction::~DrawLineAction() p2 = point; } + /*virtual*/ void DrawLineAction::MouseReleased(void) { if (state == FIRST_POINT) @@ -77,5 +93,37 @@ DrawLineAction::~DrawLineAction() emit ObjectReady(line); 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; +} +