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"
20 enum { FIRST_POINT, NEXT_POINT };
23 DrawLineAction::DrawLineAction(): state(FIRST_POINT), line(NULL),
24 shiftWasPressedOnNextPoint(false)
29 DrawLineAction::~DrawLineAction()
34 /*virtual*/ void DrawLineAction::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);
49 QString text = tr("Length: %1 in.");
50 text = text.arg(Vector::Magnitude(p1, p2));
51 painter->DrawInformativeText(text);
56 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
58 // Clear our override...
59 shiftWasPressedOnNextPoint = false;
61 if (state == FIRST_POINT)
68 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
70 if (state == FIRST_POINT)
77 /*virtual*/ void DrawLineAction::MouseReleased(void)
79 if (state == FIRST_POINT)
84 else if (state == NEXT_POINT)
86 // We create the new object here, and then pass it off to the
87 // DrawingView which stuffs it into the document.
88 line = new Line(p1, p2);
89 // We don't need no stinkin' sentinels, when we have signals & slots!
90 emit ObjectReady(line);
98 /*virtual*/ void DrawLineAction::KeyDown(int key)
100 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
102 shiftWasPressedOnNextPoint = true;
111 /*virtual*/ void DrawLineAction::KeyReleased(int key)
113 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
115 shiftWasPressedOnNextPoint = false;