X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawdimensionaction.cpp;h=d366c2277dacee4137a551b3d46e5e17fb645269;hb=6533354910fbf76d9747deeae02b2e910ef9aa48;hp=2414afa107285fd8e5b2238a07c80f42dfaed7e3;hpb=1a13a1484af21f55d5be4847d0b158a43f9c36d2;p=architektonas diff --git a/src/drawdimensionaction.cpp b/src/drawdimensionaction.cpp index 2414afa..d366c22 100644 --- a/src/drawdimensionaction.cpp +++ b/src/drawdimensionaction.cpp @@ -12,13 +12,14 @@ // #include "drawdimensionaction.h" +#include "applicationwindow.h" #include "dimension.h" +#include "drawingview.h" +#include "line.h" #include "painter.h" -//#include "vector.h" -#define FIRST_POINT 0 -#define NEXT_POINT 1 +enum { FIRST_POINT, NEXT_POINT, NO_POINT }; DrawDimensionAction::DrawDimensionAction(): state(0), dimension(NULL) @@ -35,12 +36,11 @@ DrawDimensionAction::~DrawDimensionAction() { painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine)); - // I think stuff like crosshairs should be done in the DrawingView, tho if (state == FIRST_POINT) { painter->DrawHandle(p1); } - else + else if (state == NEXT_POINT) { painter->DrawLine(p1, p2); painter->DrawHandle(p2); @@ -50,6 +50,21 @@ DrawDimensionAction::~DrawDimensionAction() /*virtual*/ void DrawDimensionAction::MouseDown(Vector point) { + obj = ApplicationWindow::drawing->document.lastObjectClicked; + + if (obj) + { + if (obj->type == OTLine) + { + // Make sure we didn't hit an endpoint... + if (!(((Line *) obj)->hitPoint1 || ((Line *)obj)->hitPoint2)) + { + state = NO_POINT; + return; + } + } + } + if (state == FIRST_POINT) p1 = point; else @@ -68,7 +83,12 @@ DrawDimensionAction::~DrawDimensionAction() /*virtual*/ void DrawDimensionAction::MouseReleased(void) { - if (state == FIRST_POINT) + if (state == NO_POINT) + { + HandleAddDimensionToObject();//ApplicationWindow::drawing->document.lastObjectClicked); + state = FIRST_POINT; + } + else if (state == FIRST_POINT) { p2 = p1; state = NEXT_POINT; @@ -77,11 +97,45 @@ DrawDimensionAction::~DrawDimensionAction() { // 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); + dimension = new Dimension(p1, p2); // We don't need no stinkin' sentinels, when we have signals & slots! emit ObjectReady(dimension); - p1 = p2; + state = FIRST_POINT; + } +} + + +/*virtual*/ void DrawDimensionAction::KeyDown(int /*key*/) +{ +} + + +/*virtual*/ void DrawDimensionAction::KeyReleased(int /*key*/) +{ +} + + +void DrawDimensionAction::HandleAddDimensionToObject(void)//Object * obj) +{ +//printf("Adding dimension to object...\n"); + if (obj->type == OTLine) + { + Object * existing = ((Line *)obj)->FindAttachedDimension(); + + if (existing) + { + ((Dimension *)existing)->FlipSides(); + } +//printf("--> type == LINE\n"); + // Should also check here to see if it hit the line proper or just hit + // an endpoint... + else + { + dimension = new Dimension(p1, p2); + ((Line *)obj)->SetDimensionOnLine(dimension); + emit ObjectReady(dimension); + } } }