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"
17 #include "mathconstants.h"
22 //#define FIRST_POINT 0
23 //#define NEXT_POINT 1
24 enum { FIRST_POINT, NEXT_POINT };
27 MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL),
28 shiftWasPressedOnNextPoint(false)
33 MirrorAction::~MirrorAction()
38 /*virtual*/ void MirrorAction::Draw(Painter * painter)
40 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
42 // I think stuff like crosshairs should be done in the DrawingView, tho
43 // (and it's done there now...)
44 if (state == FIRST_POINT)
46 painter->DrawHandle(p1);
50 painter->DrawLine(p1, p2);
51 painter->DrawHandle(p2);
53 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
54 // double absLength = Vector(position - endpoint).Magnitude();
56 QString text = QChar(0x2221) + QObject::tr(": %1");
57 text = text.arg(absAngle);
58 // QString text = tr("Length: %1 in.");
59 // text = text.arg(Vector::Magnitude(p1, p2));
60 painter->DrawInformativeText(text);
65 /*virtual*/ void MirrorAction::MouseDown(Vector point)
67 // Clear our override...
68 shiftWasPressedOnNextPoint = false;
70 if (state == FIRST_POINT)
77 /*virtual*/ void MirrorAction::MouseMoved(Vector point)
79 if (state == FIRST_POINT)
88 /*virtual*/ void MirrorAction::MouseReleased(void)
90 if (state == FIRST_POINT)
95 else if (state == NEXT_POINT)
97 // We create the new object here, and then pass it off to the
98 // DrawingView which stuffs it into the document.
99 // line = new Line(p1, p2);
100 // We don't need no stinkin' sentinels, when we have signals & slots!
101 // emit ObjectReady(line);
109 /*virtual*/ bool MirrorAction::KeyDown(int key)
111 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
113 shiftWasPressedOnNextPoint = true;
124 /*virtual*/ bool MirrorAction::KeyReleased(int key)
126 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
128 shiftWasPressedOnNextPoint = false;