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), mirror(new Container(Vector()))
32 // ApplicationWindow::drawing->document.CopySelectedContentsTo(selected);
33 ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
35 // for(std::vector<Object *>::iterator i=mirror->objects.begin(); i!=mirror->objects.end(); i++)
41 MirrorAction::~MirrorAction()
46 /*virtual*/ void MirrorAction::Draw(Painter * painter)
48 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
50 // I think stuff like crosshairs should be done in the DrawingView, tho
51 // (and it's done there now...)
52 if (state == FIRST_POINT)
54 painter->DrawHandle(p1);
58 Vector reflectedP2 = -(p2 - p1);
59 Point newP2 = p1 + reflectedP2;
60 painter->DrawLine(newP2, p2);
61 painter->DrawHandle(p1);
63 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
65 // Keep the angle between 0 and 180 degrees
69 QString text = QChar(0x2221) + QObject::tr(": %1");
70 text = text.arg(absAngle);
71 // QString text = tr("Length: %1 in.");
72 // text = text.arg(Vector::Magnitude(p1, p2));
73 painter->DrawInformativeText(text);
75 // Draw the mirror only if there's been a line to mirror around
77 mirror->Draw(painter);
82 /*virtual*/ void MirrorAction::MouseDown(Vector point)
84 // Clear our override...
85 shiftWasPressedOnNextPoint = false;
87 if (state == FIRST_POINT)
94 /*virtual*/ void MirrorAction::MouseMoved(Vector point)
96 if (state == FIRST_POINT)
102 for(std::vector<Object *>::iterator i=mirror->objects.begin(); i!=mirror->objects.end(); i++)
105 (*i)->Mirror(p1, p2);
111 /*virtual*/ void MirrorAction::MouseReleased(void)
113 if (state == FIRST_POINT)
118 else if (state == NEXT_POINT)
122 std::vector<Object *> & objs = ApplicationWindow::drawing->document.objects;
124 for(std::vector<Object *>::iterator i=objs.begin(); i!=objs.end(); i++)
126 if ((*i)->state == OSSelected)
127 (*i)->Mirror(p1, p2);
131 ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
137 /*virtual*/ bool MirrorAction::KeyDown(int key)
139 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
141 shiftWasPressedOnNextPoint = true;
152 /*virtual*/ bool MirrorAction::KeyReleased(int key)
154 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
156 shiftWasPressedOnNextPoint = false;