]> Shamusworld >> Repos - architektonas/blob - src/drawlineaction.cpp
Added Architektonas drawing file loading/saving infrastructure.
[architektonas] / src / drawlineaction.cpp
1 // drawlineaction.cpp: Action class for drawing lines
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  10/04/2011  Created this file
12 // JLH  11/07/2011  Made it so this class actually does something ;-)
13 //
14
15 #include "drawlineaction.h"
16 #include "line.h"
17 #include "painter.h"
18 //#include "vector.h"
19
20
21 #define FIRST_POINT 0
22 #define NEXT_POINT 1
23
24
25 DrawLineAction::DrawLineAction(): state(0), line(NULL)
26 {
27 }
28
29 DrawLineAction::~DrawLineAction()
30 {
31 }
32
33
34 /*virtual*/ void DrawLineAction::Draw(Painter * painter)
35 {
36         painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
37
38         // I think stuff like crosshairs should be done in the DrawingView, tho
39         if (state == FIRST_POINT)
40         {
41                 painter->DrawHandle(p1);
42         }
43         else
44         {
45                 painter->DrawLine(p1, p2);
46                 painter->DrawHandle(p2);
47         }
48 }
49
50 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
51 {
52         if (state == FIRST_POINT)
53                 p1 = point;
54         else
55                 p2 = point;
56 }
57
58 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
59 {
60         if (state == FIRST_POINT)
61                 p1 = point;
62         else
63                 p2 = point;
64 }
65
66 /*virtual*/ void DrawLineAction::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                 line = new Line(p1, p2);
78                 // We don't need no stinkin' sentinels, when we have signals & slots!
79                 emit ObjectReady(line);
80
81                 p1 = p2;
82         }
83 }