]> Shamusworld >> Repos - architektonas/commitdiff
Initial addition of Dimension action object. More to come.
authorShamus Hammons <jlhamm@acm.org>
Sat, 16 Mar 2013 03:47:58 +0000 (22:47 -0500)
committerShamus Hammons <jlhamm@acm.org>
Sat, 16 Mar 2013 03:47:58 +0000 (22:47 -0500)
architektonas.pro
src/drawdimensionaction.cpp [new file with mode: 0644]
src/drawdimensionaction.h [new file with mode: 0644]

index 40ac752b5b5d6106a8f5a9532ffc4605d6731259..a634111d69402ccbc0beddaf2fa7e5dd860a7720 100644 (file)
@@ -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 (file)
index 0000000..2414afa
--- /dev/null
@@ -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 <jlhamm@acm.org>
+//
+// 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 (file)
index 0000000..ccb9132
--- /dev/null
@@ -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__