]> Shamusworld >> Repos - architektonas/blob - src/drawcircleaction.cpp
Changed Actions to emit signal when needing a graphical update.
[architektonas] / src / drawcircleaction.cpp
1 // drawcircleaction.cpp: Action class for drawing circles
2 //
3 // Part of the Architektonas Project
4 // (C) 2012 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  02/01/2012  Created this file
12 //
13
14 #include "drawcircleaction.h"
15 #include "circle.h"
16 #include "painter.h"
17 #include "vector.h"
18
19
20 enum { FIRST_POINT, NEXT_POINT };
21
22
23 DrawCircleAction::DrawCircleAction(): state(0), circle(NULL)
24 {
25 }
26
27 DrawCircleAction::~DrawCircleAction()
28 {
29 }
30
31
32 /*virtual*/ void DrawCircleAction::Draw(Painter * painter)
33 {
34         painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
35
36         // I think stuff like crosshairs should be done in the DrawingView, tho
37         if (state == FIRST_POINT)
38         {
39                 painter->DrawHandle(p1);
40         }
41         else
42         {
43                 painter->DrawHandle(p1);
44                 double radius = Vector::Magnitude(p1, p2);
45                 painter->DrawEllipse(p1, radius, radius);
46         }
47 }
48
49 /*virtual*/ void DrawCircleAction::MouseDown(Vector point)
50 {
51         if (state == FIRST_POINT)
52                 p1 = point;
53         else
54                 p2 = point;
55 }
56
57 /*virtual*/ void DrawCircleAction::MouseMoved(Vector point)
58 {
59         if (state == FIRST_POINT)
60                 p1 = point;
61         else
62                 p2 = point;
63 }
64
65 /*virtual*/ void DrawCircleAction::MouseReleased(void)
66 {
67         if (state == FIRST_POINT)
68         {
69                 p2 = p1;
70                 state = NEXT_POINT;
71         }
72         else if (state == NEXT_POINT)
73         {
74                 // We create the new object here, and then pass it off to the
75                 // DrawingView which stuffs it into the document.
76                 circle = new Circle(p1, Vector::Magnitude(p1, p2));
77                 // We don't need no stinkin' sentinels, when we have signals & slots!
78                 emit ObjectReady(circle);
79
80                 state = FIRST_POINT;
81                 p1 = p2;
82         }
83 }
84
85
86 /*virtual*/ void DrawCircleAction::KeyDown(int /*key*/)
87 {
88 }
89
90
91 /*virtual*/ void DrawCircleAction::KeyReleased(int /*key*/)
92 {
93 }
94