1 // drawsplineaction.cpp: Action class for drawing NURBS
3 // Part of the Architektonas Project
4 // (C) 2014 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- ------------------------------------------------------------
11 // JLH 03/20/2014 Created this file
14 #include "drawsplineaction.h"
16 #include "mathconstants.h"
20 enum { FIRST_POINT, NEXT_POINT };
23 DrawSplineAction::DrawSplineAction(): state(FIRST_POINT), spline(NULL),
24 shiftWasPressedOnNextPoint(false)
29 DrawSplineAction::~DrawSplineAction()
34 /*virtual*/ void DrawSplineAction::Draw(Painter * painter)
36 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
38 // I think stuff like crosshairs should be done in the DrawingView, tho
39 // (and it's done there now...)
40 if (state == FIRST_POINT)
42 painter->DrawHandle(p1);
46 painter->DrawLine(p1, p2);
47 painter->DrawHandle(p2);
50 double absAngle = v.Angle() * RADIANS_TO_DEGREES;
51 double absLength = v.Magnitude();
52 QString text = tr("Length: %1 in.\n") + QChar(0x2221) + tr(": %2");
53 text = text.arg(absLength).arg(absAngle);
54 painter->DrawInformativeText(text);
59 /*virtual*/ void DrawSplineAction::MouseDown(Vector point)
61 // Clear our override...
62 shiftWasPressedOnNextPoint = false;
64 if (state == FIRST_POINT)
71 /*virtual*/ void DrawSplineAction::MouseMoved(Vector point)
73 if (state == FIRST_POINT)
80 /*virtual*/ void DrawSplineAction::MouseReleased(void)
82 if (state == FIRST_POINT)
88 else if (state == NEXT_POINT)
90 Spline * oldSpline = spline;
91 // We create the new object here, and then pass it off to the
92 // DrawingView which stuffs it into the document.
93 spline = new Spline(p1, p2.Angle());
95 // Connect Lines by default
98 oldSpline->Connect(spline, 0);
99 spline->Connect(oldSpline, 1.0);
102 // We don't need no stinkin' sentinels, when we have signals & slots!
103 emit ObjectReady(spline);
111 /*virtual*/ void DrawSplineAction::KeyDown(int key)
113 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
115 shiftWasPressedOnNextPoint = true;
124 /*virtual*/ void DrawSplineAction::KeyReleased(int key)
126 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
128 shiftWasPressedOnNextPoint = false;