]> Shamusworld >> Repos - architektonas/blob - src/drawdimensionaction.cpp
Added key modifiers to Actions.
[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 //#include "vector.h"
18
19
20 #define FIRST_POINT 0
21 #define NEXT_POINT 1
22
23
24 DrawDimensionAction::DrawDimensionAction(): state(0), dimension(NULL)
25 {
26 }
27
28
29 DrawDimensionAction::~DrawDimensionAction()
30 {
31 }
32
33
34 /*virtual*/ void DrawDimensionAction::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
51 /*virtual*/ void DrawDimensionAction::MouseDown(Vector point)
52 {
53         if (state == FIRST_POINT)
54                 p1 = point;
55         else
56                 p2 = point;
57 }
58
59
60 /*virtual*/ void DrawDimensionAction::MouseMoved(Vector point)
61 {
62         if (state == FIRST_POINT)
63                 p1 = point;
64         else
65                 p2 = point;
66 }
67
68
69 /*virtual*/ void DrawDimensionAction::MouseReleased(void)
70 {
71         if (state == FIRST_POINT)
72         {
73                 p2 = p1;
74                 state = NEXT_POINT;
75         }
76         else if (state == NEXT_POINT)
77         {
78                 // We create the new object here, and then pass it off to the
79                 // DrawingView which stuffs it into the document.
80 //              line = new Line(p1, p2);
81                 dimension = new Dimension(p1, p2);
82                 // We don't need no stinkin' sentinels, when we have signals & slots!
83                 emit ObjectReady(dimension);
84
85                 state = FIRST_POINT;
86 //              p1 = p2;
87         }
88 }
89
90
91 /*virtual*/ bool DrawDimensionAction::KeyDown(int /*key*/)
92 {
93         return false;
94 }
95
96
97 /*virtual*/ bool DrawDimensionAction::KeyReleased(int /*key*/)
98 {
99         return false;
100 }
101