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()))
35 MirrorAction::~MirrorAction()
40 /*virtual*/ void MirrorAction::Draw(Painter * painter)
42 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
44 // I think stuff like crosshairs should be done in the DrawingView, tho
45 // (and it's done there now...)
46 if (state == FIRST_POINT)
48 painter->DrawHandle(p1);
52 painter->DrawLine(p1, p2);
53 painter->DrawHandle(p2);
55 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
56 // double absLength = Vector(position - endpoint).Magnitude();
58 QString text = QChar(0x2221) + QObject::tr(": %1");
59 text = text.arg(absAngle);
60 // QString text = tr("Length: %1 in.");
61 // text = text.arg(Vector::Magnitude(p1, p2));
62 painter->DrawInformativeText(text);
64 mirror->Draw(painter);
69 /*virtual*/ void MirrorAction::MouseDown(Vector point)
71 // Clear our override...
72 shiftWasPressedOnNextPoint = false;
74 if (state == FIRST_POINT)
81 /*virtual*/ void MirrorAction::MouseMoved(Vector point)
83 if (state == FIRST_POINT)
90 int itemsSelected = ApplicationWindow::drawing->document.ItemsSelected();
92 if (itemsSelected == 0)
95 for(int i=0; i<itemsSelected; i++)
97 Object * object = ApplicationWindow::drawing->document.SelectedItem(i);
98 Object * mirrored = object->Mirror(p1, p2);
99 mirror->Add(mirrored);
105 /*virtual*/ void MirrorAction::MouseReleased(void)
107 if (state == FIRST_POINT)
112 else if (state == NEXT_POINT)
114 // We create the new object here, and then pass it off to the
115 // DrawingView which stuffs it into the document.
116 // line = new Line(p1, p2);
117 // We don't need no stinkin' sentinels, when we have signals & slots!
118 // emit ObjectReady(line);
126 /*virtual*/ bool MirrorAction::KeyDown(int key)
128 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
130 shiftWasPressedOnNextPoint = true;
141 /*virtual*/ bool MirrorAction::KeyReleased(int key)
143 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
145 shiftWasPressedOnNextPoint = false;