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