]> Shamusworld >> Repos - architektonas/blob - src/mirroraction.cpp
61b14ac1276be53c1199b3b310db421e0ff07834
[architektonas] / src / mirroraction.cpp
1 // mirroraction.cpp: Action class for mirroring selected objects
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  08/27/2011  Created this file
12 //
13
14 #include "mirroraction.h"
15 #include "line.h"
16 #include "mathconstants.h"
17 #include "painter.h"
18 //#include "vector.h"
19
20
21 //#define FIRST_POINT 0
22 //#define NEXT_POINT 1
23 enum { FIRST_POINT, NEXT_POINT };
24
25
26 MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL),
27         shiftWasPressedOnNextPoint(false)
28 {
29 }
30
31
32 MirrorAction::~MirrorAction()
33 {
34 }
35
36
37 /*virtual*/ void MirrorAction::Draw(Painter * painter)
38 {
39         painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
40
41         // I think stuff like crosshairs should be done in the DrawingView, tho
42         // (and it's done there now...)
43         if (state == FIRST_POINT)
44         {
45                 painter->DrawHandle(p1);
46         }
47         else
48         {
49                 painter->DrawLine(p1, p2);
50                 painter->DrawHandle(p2);
51
52                 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
53 //              double absLength = Vector(position - endpoint).Magnitude();
54
55                 QString text = QChar(0x2221) + QObject::tr(": %1");
56                 text = text.arg(absAngle);
57 //              QString text = tr("Length: %1 in.");
58 //              text = text.arg(Vector::Magnitude(p1, p2));
59                 painter->DrawInformativeText(text);
60         }
61 }
62
63
64 /*virtual*/ void MirrorAction::MouseDown(Vector point)
65 {
66         // Clear our override...
67         shiftWasPressedOnNextPoint = false;
68
69         if (state == FIRST_POINT)
70                 p1 = point;
71         else
72                 p2 = point;
73 }
74
75
76 /*virtual*/ void MirrorAction::MouseMoved(Vector point)
77 {
78         if (state == FIRST_POINT)
79                 p1 = point;
80         else
81                 p2 = point;
82 }
83
84
85 /*virtual*/ void MirrorAction::MouseReleased(void)
86 {
87         if (state == FIRST_POINT)
88         {
89                 p2 = p1;
90                 state = NEXT_POINT;
91         }
92         else if (state == NEXT_POINT)
93         {
94                 // We create the new object here, and then pass it off to the
95                 // DrawingView which stuffs it into the document.
96 //              line = new Line(p1, p2);
97                 // We don't need no stinkin' sentinels, when we have signals & slots!
98 //              emit ObjectReady(line);
99
100                 p1 = p2;
101                 state = NEXT_POINT;
102         }
103 }
104
105
106 /*virtual*/ bool MirrorAction::KeyDown(int key)
107 {
108         if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
109         {
110                 shiftWasPressedOnNextPoint = true;
111                 p1Save = p1;
112                 p1 = p2;
113                 state = FIRST_POINT;
114                 return true;
115         }
116
117         return false;
118 }
119
120
121 /*virtual*/ bool MirrorAction::KeyReleased(int key)
122 {
123         if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
124         {
125                 shiftWasPressedOnNextPoint = false;
126                 p2 = p1;
127                 p1 = p1Save;
128                 state = NEXT_POINT;
129                 return true;
130         }
131
132         return false;
133 }
134