]> Shamusworld >> Repos - architektonas/blob - src/drawcircleaction.cpp
Added Architektonas drawing file loading/saving infrastructure.
[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 #define FIRST_POINT 0
21 #define NEXT_POINT 1
22
23
24 DrawCircleAction::DrawCircleAction(): state(0), circle(NULL)
25 {
26 }
27
28 DrawCircleAction::~DrawCircleAction()
29 {
30 }
31
32
33 /*virtual*/ void DrawCircleAction::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         if (state == FIRST_POINT)
39         {
40                 painter->DrawHandle(p1);
41         }
42         else
43         {
44                 painter->DrawHandle(p1);
45                 double radius = Vector::Magnitude(p1, p2);
46                 painter->DrawEllipse(p1, radius, radius);
47         }
48 }
49
50 /*virtual*/ void DrawCircleAction::MouseDown(Vector point)
51 {
52         if (state == FIRST_POINT)
53                 p1 = point;
54         else
55                 p2 = point;
56 }
57
58 /*virtual*/ void DrawCircleAction::MouseMoved(Vector point)
59 {
60         if (state == FIRST_POINT)
61                 p1 = point;
62         else
63                 p2 = point;
64 }
65
66 /*virtual*/ void DrawCircleAction::MouseReleased(void)
67 {
68         if (state == FIRST_POINT)
69         {
70                 p2 = p1;
71                 state = NEXT_POINT;
72         }
73         else if (state == NEXT_POINT)
74         {
75                 // We create the new object here, and then pass it off to the
76                 // DrawingView which stuffs it into the document.
77                 circle = new Circle(p1, Vector::Magnitude(p1, p2));
78                 // We don't need no stinkin' sentinels, when we have signals & slots!
79                 emit ObjectReady(circle);
80
81                 state = FIRST_POINT;
82                 p1 = p2;
83         }
84 }