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"
16 #include "mathconstants.h"
21 //#define FIRST_POINT 0
22 //#define NEXT_POINT 1
23 enum { FIRST_POINT, NEXT_POINT };
26 MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL),
27 shiftWasPressedOnNextPoint(false)
32 MirrorAction::~MirrorAction()
37 /*virtual*/ void MirrorAction::Draw(Painter * painter)
39 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
41 // I think stuff like crosshairs should be done in the DrawingView, tho
42 // (and it's done there now...)
43 if (state == FIRST_POINT)
45 painter->DrawHandle(p1);
49 painter->DrawLine(p1, p2);
50 painter->DrawHandle(p2);
52 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
53 // double absLength = Vector(position - endpoint).Magnitude();
55 QString text = QChar(0x2221) + QObject::tr(": %1");
56 text = text.arg(absAngle);
57 // QString text = tr("Length: %1 in.");
58 // text = text.arg(Vector::Magnitude(p1, p2));
59 painter->DrawInformativeText(text);
64 /*virtual*/ void MirrorAction::MouseDown(Vector point)
66 // Clear our override...
67 shiftWasPressedOnNextPoint = false;
69 if (state == FIRST_POINT)
76 /*virtual*/ void MirrorAction::MouseMoved(Vector point)
78 if (state == FIRST_POINT)
85 /*virtual*/ void MirrorAction::MouseReleased(void)
87 if (state == FIRST_POINT)
92 else if (state == NEXT_POINT)
94 // We create the new object here, and then pass it off to the
95 // DrawingView which stuffs it into the document.
96 // line = new Line(p1, p2);
97 // We don't need no stinkin' sentinels, when we have signals & slots!
98 // emit ObjectReady(line);
106 /*virtual*/ bool MirrorAction::KeyDown(int key)
108 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
110 shiftWasPressedOnNextPoint = true;
121 /*virtual*/ bool MirrorAction::KeyReleased(int key)
123 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
125 shiftWasPressedOnNextPoint = false;