]> Shamusworld >> Repos - architektonas/blob - src/drawdimensionaction.cpp
66b2bfb1a176c149107eb5782e56859155590eac
[architektonas] / src / drawdimensionaction.cpp
1 // drawdimensionaction.cpp: Action class for drawing dimensions
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  03/15/2013  Created this file
12 //
13
14 #include "drawdimensionaction.h"
15 #include "dimension.h"
16 #include "painter.h"
17
18
19 enum { FIRST_POINT, NEXT_POINT };
20
21
22 DrawDimensionAction::DrawDimensionAction(): state(0), dimension(NULL)
23 {
24 }
25
26
27 DrawDimensionAction::~DrawDimensionAction()
28 {
29 }
30
31
32 /*virtual*/ void DrawDimensionAction::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->DrawLine(p1, p2);
44                 painter->DrawHandle(p2);
45         }
46 }
47
48
49 /*virtual*/ void DrawDimensionAction::MouseDown(Vector point)
50 {
51         if (state == FIRST_POINT)
52                 p1 = point;
53         else
54                 p2 = point;
55 }
56
57
58 /*virtual*/ void DrawDimensionAction::MouseMoved(Vector point)
59 {
60         if (state == FIRST_POINT)
61                 p1 = point;
62         else
63                 p2 = point;
64 }
65
66
67 /*virtual*/ void DrawDimensionAction::MouseReleased(void)
68 {
69         if (state == FIRST_POINT)
70         {
71                 p2 = p1;
72                 state = NEXT_POINT;
73         }
74         else if (state == NEXT_POINT)
75         {
76                 // We create the new object here, and then pass it off to the
77                 // DrawingView which stuffs it into the document.
78                 dimension = new Dimension(p1, p2);
79                 // We don't need no stinkin' sentinels, when we have signals & slots!
80                 emit ObjectReady(dimension);
81
82                 state = FIRST_POINT;
83         }
84 }
85
86
87 /*virtual*/ void DrawDimensionAction::KeyDown(int /*key*/)
88 {
89 }
90
91
92 /*virtual*/ void DrawDimensionAction::KeyReleased(int /*key*/)
93 {
94 }
95