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)
60 // How to check for hitting an object here?
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*/ void DrawArcAction::KeyDown(int /*key*/)
132 /*virtual*/ void DrawArcAction::KeyReleased(int /*key*/)