1 // drawarcaction.cpp: Draw arc object
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 08/13/2013 Created this file
14 #include "drawarcaction.h"
16 #include "mathconstants.h"
20 enum { FIRST_POINT, SECOND_POINT, THIRD_POINT };
23 DrawArcAction::DrawArcAction(): state(FIRST_POINT), arc(NULL)
28 DrawArcAction::~DrawArcAction()
33 /*virtual*/ void DrawArcAction::Draw(Painter * painter)
35 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
37 // I think stuff like crosshairs should be done in the DrawingView, tho
39 if (state == FIRST_POINT)
41 painter->DrawHandle(p1);
43 else if (state == SECOND_POINT)
45 painter->DrawLine(p1, p2);
46 painter->DrawHandle(p2);
48 else if (state == THIRD_POINT)
50 painter->DrawLine(p1, p2);
51 painter->DrawArc(p1, radius, startAngle, span);
52 painter->DrawHandle(p3);
57 /*virtual*/ void DrawArcAction::MouseDown(Vector point)
59 if (state == FIRST_POINT)
61 else if (state == SECOND_POINT)
65 radius = Vector::Magnitude(p1, p2);
66 startAngle = r1.Angle();
68 else if (state == THIRD_POINT)
72 span = r2.Angle() - startAngle;
80 /*virtual*/ void DrawArcAction::MouseMoved(Vector point)
82 if (state == FIRST_POINT)
84 else if (state == SECOND_POINT)
88 radius = Vector::Magnitude(p1, p2);
89 startAngle = r1.Angle();
91 else if (state == THIRD_POINT)
95 span = r2.Angle() - startAngle;
103 /*virtual*/ void DrawArcAction::MouseReleased(void)
105 if (state == FIRST_POINT)
107 state = SECOND_POINT;
109 else if (state == SECOND_POINT)
113 else if (state == THIRD_POINT)
115 // We create the new object here, and then pass it off to the
116 // DrawingView which stuffs it into the document.
117 arc = new Arc(p1, radius, startAngle, span);
118 // We don't need no stinkin' sentinels, when we have signals & slots!
119 emit ObjectReady(arc);
126 /*virtual*/ void DrawArcAction::KeyDown(int /*key*/)
131 /*virtual*/ void DrawArcAction::KeyReleased(int /*key*/)