From: Shamus Hammons Date: Sat, 16 Mar 2013 03:47:58 +0000 (-0500) Subject: Initial addition of Dimension action object. More to come. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a13a1484af21f55d5be4847d0b158a43f9c36d2;p=architektonas Initial addition of Dimension action object. More to come. --- diff --git a/architektonas.pro b/architektonas.pro index 40ac752..a634111 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -51,6 +51,7 @@ HEADERS = \ src/dimension.h \ src/drawingview.h \ src/drawcircleaction.h \ + src/drawdimensionaction.h \ src/drawlineaction.h \ src/drawtextaction.h \ src/ellipse.h \ @@ -76,6 +77,7 @@ SOURCES = \ src/dimension.cpp \ src/drawingview.cpp \ src/drawcircleaction.cpp \ + src/drawdimensionaction.cpp \ src/drawlineaction.cpp \ src/drawtextaction.cpp \ src/ellipse.cpp \ diff --git a/src/drawdimensionaction.cpp b/src/drawdimensionaction.cpp new file mode 100644 index 0000000..2414afa --- /dev/null +++ b/src/drawdimensionaction.cpp @@ -0,0 +1,87 @@ +// drawdimensionaction.cpp: Action class for drawing dimensions +// +// Part of the Architektonas Project +// (C) 2011 Underground Software +// See the README and GPLv3 files for licensing and warranty information +// +// JLH = James Hammons +// +// WHO WHEN WHAT +// --- ---------- ------------------------------------------------------------ +// JLH 03/15/2013 Created this file +// + +#include "drawdimensionaction.h" +#include "dimension.h" +#include "painter.h" +//#include "vector.h" + + +#define FIRST_POINT 0 +#define NEXT_POINT 1 + + +DrawDimensionAction::DrawDimensionAction(): state(0), dimension(NULL) +{ +} + + +DrawDimensionAction::~DrawDimensionAction() +{ +} + + +/*virtual*/ void DrawDimensionAction::Draw(Painter * painter) +{ + 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 + { + painter->DrawLine(p1, p2); + painter->DrawHandle(p2); + } +} + + +/*virtual*/ void DrawDimensionAction::MouseDown(Vector point) +{ + if (state == FIRST_POINT) + p1 = point; + else + p2 = point; +} + + +/*virtual*/ void DrawDimensionAction::MouseMoved(Vector point) +{ + if (state == FIRST_POINT) + p1 = point; + else + p2 = point; +} + + +/*virtual*/ void DrawDimensionAction::MouseReleased(void) +{ + if (state == FIRST_POINT) + { + p2 = p1; + state = NEXT_POINT; + } + else if (state == NEXT_POINT) + { + // 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); + // We don't need no stinkin' sentinels, when we have signals & slots! + emit ObjectReady(dimension); + + p1 = p2; + } +} + diff --git a/src/drawdimensionaction.h b/src/drawdimensionaction.h new file mode 100644 index 0000000..ccb9132 --- /dev/null +++ b/src/drawdimensionaction.h @@ -0,0 +1,25 @@ +#ifndef __DRAWDIMENSIONACTION_H__ +#define __DRAWDIMENSIONACTION_H__ + +#include "action.h" + +class Dimension; + +class DrawDimensionAction: public Action +{ + public: + DrawDimensionAction(); + ~DrawDimensionAction(); + + virtual void Draw(Painter *); + virtual void MouseDown(Vector); + virtual void MouseMoved(Vector); + virtual void MouseReleased(void); + + private: + int state; + Dimension * dimension; + Vector p1, p2; +}; + +#endif // __DRAWDIMENSIONACTION_H__