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"
21 enum { FIRST_POINT, SECOND_POINT, THIRD_POINT };
24 DrawArcAction::DrawArcAction(): state(FIRST_POINT), arc(NULL)
29 DrawArcAction::~DrawArcAction()
34 /*virtual*/ void DrawArcAction::Draw(Painter * painter)
36 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
38 // I think stuff like crosshairs should be done in the DrawingView, tho
40 if (state == FIRST_POINT)
42 painter->DrawHandle(p1);
44 else if (state == SECOND_POINT)
46 painter->DrawLine(p1, p2);
47 painter->DrawHandle(p2);
49 else if (state == THIRD_POINT)
51 painter->DrawLine(p1, p2);
52 painter->DrawArc(p1, radius, startAngle, span);
53 painter->DrawHandle(p3);
58 /*virtual*/ void DrawArcAction::MouseDown(Vector point)
60 if (state == FIRST_POINT)
62 else if (state == SECOND_POINT)
66 radius = Vector::Magnitude(p1, p2);
67 startAngle = r1.Angle();
69 else if (state == THIRD_POINT)
73 span = r2.Angle() - startAngle;
81 /*virtual*/ void DrawArcAction::MouseMoved(Vector point)
83 if (state == FIRST_POINT)
85 else if (state == SECOND_POINT)
89 radius = Vector::Magnitude(p1, p2);
90 startAngle = r1.Angle();
92 else if (state == THIRD_POINT)
96 span = r2.Angle() - startAngle;
104 /*virtual*/ void DrawArcAction::MouseReleased(void)
106 if (state == FIRST_POINT)
108 state = SECOND_POINT;
110 else if (state == SECOND_POINT)
114 else if (state == THIRD_POINT)
116 // We create the new object here, and then pass it off to the
117 // DrawingView which stuffs it into the document.
118 arc = new Arc(p1, radius, startAngle, span);
119 // We don't need no stinkin' sentinels, when we have signals & slots!
120 emit ObjectReady(arc);
127 /*virtual*/ bool DrawArcAction::KeyDown(int /*key*/)
133 /*virtual*/ bool DrawArcAction::KeyReleased(int /*key*/)