]> Shamusworld >> Repos - architektonas/blob - src/drawarcaction.cpp
Added ability to manipulate Arcs.
[architektonas] / src / drawarcaction.cpp
1 // drawarcaction.cpp: Draw arc object
2 //
3 // Part of the Architektonas Project
4 // (C) 2011 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // WHO  WHEN        WHAT
10 // ---  ----------  ------------------------------------------------------------
11 // JLH  08/13/2013  Created this file
12 //
13
14 #include "drawarcaction.h"
15 #include "arc.h"
16 #include "mathconstants.h"
17 #include "painter.h"
18
19
20 enum { FIRST_POINT, SECOND_POINT, THIRD_POINT };
21
22
23 DrawArcAction::DrawArcAction(): state(FIRST_POINT), arc(NULL)
24 {
25 }
26
27
28 DrawArcAction::~DrawArcAction()
29 {
30 }
31
32
33 /*virtual*/ void DrawArcAction::Draw(Painter * painter)
34 {
35         painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
36
37         // I think stuff like crosshairs should be done in the DrawingView, tho
38         // (and it is! :-D)
39         if (state == FIRST_POINT)
40         {
41                 painter->DrawHandle(p1);
42         }
43         else if (state == SECOND_POINT)
44         {
45                 painter->DrawLine(p1, p2);
46                 painter->DrawHandle(p2);
47         }
48         else if (state == THIRD_POINT)
49         {
50                 painter->DrawLine(p1, p2);
51                 painter->DrawArc(p1, radius, startAngle, span);
52                 painter->DrawHandle(p3);
53         }
54 }
55
56
57 /*virtual*/ void DrawArcAction::MouseDown(Vector point)
58 {
59         if (state == FIRST_POINT)
60                 // How to check for hitting an object here?
61                 p1 = point;
62         else if (state == SECOND_POINT)
63         {
64                 p2 = point;
65                 Vector r1(p2, p1);
66                 radius = Vector::Magnitude(p1, p2);
67                 startAngle = r1.Angle();
68         }
69         else if (state == THIRD_POINT)
70         {
71                 p3 = point;
72                 Vector r2(p3, p1);
73                 span = r2.Angle() - startAngle;
74
75                 if (span < 0)
76                         span += 2.0 * PI;
77         }
78 }
79
80
81 /*virtual*/ void DrawArcAction::MouseMoved(Vector point)
82 {
83         if (state == FIRST_POINT)
84                 p1 = point;
85         else if (state == SECOND_POINT)
86         {
87                 p2 = point;
88                 Vector r1(p2, p1);
89                 radius = Vector::Magnitude(p1, p2);
90                 startAngle = r1.Angle();
91         }
92         else if (state == THIRD_POINT)
93         {
94                 p3 = point;
95                 Vector r2(p3, p1);
96                 span = r2.Angle() - startAngle;
97
98                 if (span < 0)
99                         span += 2.0 * PI;
100         }
101 }
102
103
104 /*virtual*/ void DrawArcAction::MouseReleased(void)
105 {
106         if (state == FIRST_POINT)
107         {
108                 state = SECOND_POINT;
109         }
110         else if (state == SECOND_POINT)
111         {
112                 state = THIRD_POINT;
113         }
114         else if (state == THIRD_POINT)
115         {
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);
121
122                 state = FIRST_POINT;
123         }
124 }
125
126
127 /*virtual*/ void DrawArcAction::KeyDown(int /*key*/)
128 {
129 }
130
131
132 /*virtual*/ void DrawArcAction::KeyReleased(int /*key*/)
133 {
134 }
135