1 // mirroraction.cpp: Action class for mirroring selected objects
3 // Part of the Architektonas Project
4 // (C) 2011 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- ------------------------------------------------------------
11 // JLH 08/27/2011 Created this file
14 #include "mirroraction.h"
15 #include "applicationwindow.h"
16 #include "container.h"
17 #include "drawingview.h"
19 #include "mathconstants.h"
24 //#define FIRST_POINT 0
25 //#define NEXT_POINT 1
26 enum { FIRST_POINT, NEXT_POINT };
29 MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL),
30 shiftWasPressedOnNextPoint(false), ctrlWasPressed(false),
31 mirror(new Container(Vector()))
33 ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
38 MirrorAction::~MirrorAction()
43 /*virtual*/ void MirrorAction::Draw(Painter * painter)
45 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
47 // I think stuff like crosshairs should be done in the DrawingView, tho
48 // (and it's done there now...)
49 if (state == FIRST_POINT)
51 painter->DrawHandle(p1);
55 Vector reflectedP2 = -(p2 - p1);
56 Point newP2 = p1 + reflectedP2;
57 painter->DrawLine(newP2, p2);
58 painter->DrawHandle(p1);
60 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
62 // Keep the angle between 0 and 180 degrees
66 QString text = QChar(0x2221) + QObject::tr(": %1");
67 text = text.arg(absAngle);
72 painter->DrawInformativeText(text);
74 // Draw the mirror only if there's been a line to mirror around
76 mirror->Draw(painter);
81 /*virtual*/ void MirrorAction::MouseDown(Vector point)
83 // Clear our override...
84 shiftWasPressedOnNextPoint = false;
86 if (state == FIRST_POINT)
93 /*virtual*/ void MirrorAction::MouseMoved(Vector point)
95 if (state == FIRST_POINT)
101 mirror->Mirror(p1, p2);
106 /*virtual*/ void MirrorAction::MouseReleased(void)
108 if (state == FIRST_POINT)
113 else if (state == NEXT_POINT)
118 ApplicationWindow::drawing->document.MirrorSelected(p1, p2);
121 ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
126 mirror->CopyContentsTo(&(ApplicationWindow::drawing->document));
127 // mirror->CopyContentsTo(&(DrawingView.document));
133 /*virtual*/ void MirrorAction::KeyDown(int key)
135 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
137 shiftWasPressedOnNextPoint = true;
143 else if (key == Qt::Key_Control)
145 ctrlWasPressed = true;
151 /*virtual*/ void MirrorAction::KeyReleased(int key)
153 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
155 shiftWasPressedOnNextPoint = false;
161 else if (key == Qt::Key_Control)
163 ctrlWasPressed = false;