1 // drawlineaction.cpp: Action class for drawing lines
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 10/04/2011 Created this file
12 // JLH 11/07/2011 Made it so this class actually does something ;-)
15 #include "drawlineaction.h"
17 #include "mathconstants.h"
21 enum { FIRST_POINT, NEXT_POINT };
24 DrawLineAction::DrawLineAction(): state(FIRST_POINT), line(NULL),
25 shiftWasPressedOnNextPoint(false)
30 DrawLineAction::~DrawLineAction()
35 /*virtual*/ void DrawLineAction::Draw(Painter * painter)
37 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
39 // I think stuff like crosshairs should be done in the DrawingView, tho
40 // (and it's done there now...)
41 if (state == FIRST_POINT)
43 painter->DrawHandle(p1);
47 painter->DrawLine(p1, p2);
48 painter->DrawHandle(p2);
51 double absAngle = v.Angle() * RADIANS_TO_DEGREES;
52 double absLength = v.Magnitude();
53 QString text = tr("Length: %1 in.\n") + QChar(0x2221) + tr(": %2");
54 text = text.arg(absLength).arg(absAngle);
55 painter->DrawInformativeText(text);
60 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
62 // Clear our override...
63 shiftWasPressedOnNextPoint = false;
65 if (state == FIRST_POINT)
72 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
74 if (state == FIRST_POINT)
81 /*virtual*/ void DrawLineAction::MouseReleased(void)
83 if (state == FIRST_POINT)
89 else if (state == NEXT_POINT)
91 Line * oldLine = line;
92 // We create the new object here, and then pass it off to the
93 // DrawingView which stuffs it into the document.
94 line = new Line(p1, p2);
96 // Connect Lines by default
99 oldLine->Connect(line, 0);
100 line->Connect(oldLine, 1.0);
103 // We don't need no stinkin' sentinels, when we have signals & slots!
104 emit ObjectReady(line);
112 /*virtual*/ void DrawLineAction::KeyDown(int key)
114 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
116 shiftWasPressedOnNextPoint = true;
125 /*virtual*/ void DrawLineAction::KeyReleased(int key)
127 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
129 shiftWasPressedOnNextPoint = false;