]> Shamusworld >> Repos - architektonas/blob - src/drawarcaction.cpp
Changed Actions to emit signal when needing a graphical update.
[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                 p1 = point;
61         else if (state == SECOND_POINT)
62         {
63                 p2 = point;
64                 Vector r1(p2, p1);
65                 radius = Vector::Magnitude(p1, p2);
66                 startAngle = r1.Angle();
67         }
68         else if (state == THIRD_POINT)
69         {
70                 p3 = point;
71                 Vector r2(p3, p1);
72                 span = r2.Angle() - startAngle;
73
74                 if (span < 0)
75                         span += 2.0 * PI;
76         }
77 }
78
79
80 /*virtual*/ void DrawArcAction::MouseMoved(Vector point)
81 {
82         if (state == FIRST_POINT)
83                 p1 = point;
84         else if (state == SECOND_POINT)
85         {
86                 p2 = point;
87                 Vector r1(p2, p1);
88                 radius = Vector::Magnitude(p1, p2);
89                 startAngle = r1.Angle();
90         }
91         else if (state == THIRD_POINT)
92         {
93                 p3 = point;
94                 Vector r2(p3, p1);
95                 span = r2.Angle() - startAngle;
96
97                 if (span < 0)
98                         span += 2.0 * PI;
99         }
100 }
101
102
103 /*virtual*/ void DrawArcAction::MouseReleased(void)
104 {
105         if (state == FIRST_POINT)
106         {
107                 state = SECOND_POINT;
108         }
109         else if (state == SECOND_POINT)
110         {
111                 state = THIRD_POINT;
112         }
113         else if (state == THIRD_POINT)
114         {
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);
120
121                 state = FIRST_POINT;
122         }
123 }
124
125
126 /*virtual*/ void DrawArcAction::KeyDown(int /*key*/)
127 {
128 }
129
130
131 /*virtual*/ void DrawArcAction::KeyReleased(int /*key*/)
132 {
133 }
134