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