]> Shamusworld >> Repos - architektonas/blob - src/drawlineaction.cpp
d4b35db336ae70c35bc8f7c6e69ca199d7e7426f
[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
30 DrawLineAction::~DrawLineAction()
31 {
32 }
33
34
35 /*virtual*/ void DrawLineAction::Draw(Painter * painter)
36 {
37         painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
38
39         // I think stuff like crosshairs should be done in the DrawingView, tho
40         if (state == FIRST_POINT)
41         {
42                 painter->DrawHandle(p1);
43         }
44         else
45         {
46                 painter->DrawLine(p1, p2);
47                 painter->DrawHandle(p2);
48
49                 QString text = tr("Length: %1 in.");
50                 text = text.arg(Vector::Magnitude(p1, p2));
51                 painter->DrawInformativeText(text);
52         }
53 }
54
55
56 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
57 {
58         if (state == FIRST_POINT)
59                 p1 = point;
60         else
61                 p2 = point;
62 }
63
64
65 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
66 {
67         if (state == FIRST_POINT)
68                 p1 = point;
69         else
70                 p2 = point;
71 }
72
73
74 /*virtual*/ void DrawLineAction::MouseReleased(void)
75 {
76         if (state == FIRST_POINT)
77         {
78                 p2 = p1;
79                 state = NEXT_POINT;
80         }
81         else if (state == NEXT_POINT)
82         {
83                 // We create the new object here, and then pass it off to the
84                 // DrawingView which stuffs it into the document.
85                 line = new Line(p1, p2);
86                 // We don't need no stinkin' sentinels, when we have signals & slots!
87                 emit ObjectReady(line);
88
89 //              p1 = p2;
90                 state = FIRST_POINT;
91         }
92 }
93