X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawlineaction.cpp;h=5490e9829bcc553fc71fbd8213c402a4b66a74b8;hb=31dd33b097661175a86b6799df525972055099fb;hp=d4b35db336ae70c35bc8f7c6e69ca199d7e7426f;hpb=143b369c0308a8cd524cb0ed51c5d67d6be69603;p=architektonas diff --git a/src/drawlineaction.cpp b/src/drawlineaction.cpp index d4b35db..5490e98 100644 --- a/src/drawlineaction.cpp +++ b/src/drawlineaction.cpp @@ -15,14 +15,13 @@ #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) { } @@ -37,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); @@ -55,6 +55,9 @@ DrawLineAction::~DrawLineAction() /*virtual*/ void DrawLineAction::MouseDown(Vector point) { + // Clear our override... + shiftWasPressedOnNextPoint = false; + if (state == FIRST_POINT) p1 = point; else @@ -77,17 +80,53 @@ DrawLineAction::~DrawLineAction() { 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; + 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()); } }