1 // drawdimensionaction.cpp: Action class for drawing dimensions
3 // Part of the Architektonas Project
4 // (C) 2011 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- ------------------------------------------------------------
11 // JLH 03/15/2013 Created this file
14 #include "drawdimensionaction.h"
15 #include "applicationwindow.h"
16 #include "dimension.h"
17 #include "drawingview.h"
22 enum { FIRST_POINT, NEXT_POINT, NO_POINT };
25 DrawDimensionAction::DrawDimensionAction(): state(0), dimension(NULL)
30 DrawDimensionAction::~DrawDimensionAction()
35 /*virtual*/ void DrawDimensionAction::Draw(Painter * painter)
37 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
39 if (state == FIRST_POINT)
41 painter->DrawHandle(p1);
43 else if (state == NEXT_POINT)
45 painter->DrawLine(p1, p2);
46 painter->DrawHandle(p2);
51 /*virtual*/ void DrawDimensionAction::MouseDown(Vector point)
53 obj = ApplicationWindow::drawing->document.lastObjectClicked;
57 if (obj->type == OTLine)
59 // Make sure we didn't hit an endpoint...
60 if (!(((Line *) obj)->hitPoint1 || ((Line *)obj)->hitPoint2))
68 if (state == FIRST_POINT)
75 /*virtual*/ void DrawDimensionAction::MouseMoved(Vector point)
77 if (state == FIRST_POINT)
84 /*virtual*/ void DrawDimensionAction::MouseReleased(void)
86 if (state == NO_POINT)
88 HandleAddDimensionToObject();//ApplicationWindow::drawing->document.lastObjectClicked);
91 else if (state == FIRST_POINT)
96 else if (state == NEXT_POINT)
98 // We create the new object here, and then pass it off to the
99 // DrawingView which stuffs it into the document.
100 dimension = new Dimension(p1, p2);
101 // We don't need no stinkin' sentinels, when we have signals & slots!
102 emit ObjectReady(dimension);
109 /*virtual*/ void DrawDimensionAction::KeyDown(int /*key*/)
114 /*virtual*/ void DrawDimensionAction::KeyReleased(int /*key*/)
119 void DrawDimensionAction::HandleAddDimensionToObject(void)//Object * obj)
121 //printf("Adding dimension to object...\n");
122 if (obj->type == OTLine)
124 Object * existing = ((Line *)obj)->FindAttachedDimension();
128 ((Dimension *)existing)->FlipSides();
130 //printf("--> type == LINE\n");
131 // Should also check here to see if it hit the line proper or just hit
135 dimension = new Dimension(p1, p2);
136 ((Line *)obj)->SetDimensionOnLine(dimension);
137 emit ObjectReady(dimension);