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"
23 enum { FIRST_POINT, NEXT_POINT };
26 MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL),
27 shiftWasPressedOnNextPoint(false), ctrlWasPressed(false),
28 mirror(new Container(Vector()))
30 ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
35 MirrorAction::~MirrorAction()
40 /*virtual*/ void MirrorAction::Draw(Painter * painter)
42 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
44 if (state == FIRST_POINT)
46 painter->DrawHandle(p1);
50 Vector reflectedP2 = -(p2 - p1);
51 Point newP2 = p1 + reflectedP2;
52 painter->DrawLine(newP2, p2);
53 painter->DrawHandle(p1);
55 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
57 // Keep the angle between 0 and 180 degrees
61 QString text = QChar(0x2221) + QObject::tr(": %1");
62 text = text.arg(absAngle);
67 painter->DrawInformativeText(text);
69 // Draw the mirror only if there's been a line to mirror around
71 mirror->Draw(painter);
76 /*virtual*/ void MirrorAction::MouseDown(Vector point)
78 // Clear our override...
79 shiftWasPressedOnNextPoint = false;
81 if (state == FIRST_POINT)
88 /*virtual*/ void MirrorAction::MouseMoved(Vector point)
90 if (state == FIRST_POINT)
96 mirror->Mirror(p1, p2);
101 /*virtual*/ void MirrorAction::MouseReleased(void)
103 if (state == FIRST_POINT)
108 else if (state == NEXT_POINT)
113 ApplicationWindow::drawing->document.MirrorSelected(p1, p2);
116 ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
121 mirror->CopyContentsTo(&(ApplicationWindow::drawing->document));
127 /*virtual*/ void MirrorAction::KeyDown(int key)
129 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
131 shiftWasPressedOnNextPoint = true;
137 else if (key == Qt::Key_Control)
139 ctrlWasPressed = true;
145 /*virtual*/ void MirrorAction::KeyReleased(int key)
147 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
149 shiftWasPressedOnNextPoint = false;
155 else if (key == Qt::Key_Control)
157 ctrlWasPressed = false;