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"
21 //#define FIRST_POINT 0
22 //#define NEXT_POINT 1
23 enum { FIRST_POINT, NEXT_POINT };
26 DrawLineAction::DrawLineAction(): state(FIRST_POINT), line(NULL),
27 shiftWasPressedOnNextPoint(false)
32 DrawLineAction::~DrawLineAction()
37 /*virtual*/ void DrawLineAction::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 QString text = tr("Length: %1 in.");
53 text = text.arg(Vector::Magnitude(p1, p2));
54 painter->DrawInformativeText(text);
59 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
61 // Clear our override...
62 shiftWasPressedOnNextPoint = false;
64 if (state == FIRST_POINT)
71 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
73 if (state == FIRST_POINT)
80 /*virtual*/ void DrawLineAction::MouseReleased(void)
82 if (state == FIRST_POINT)
87 else if (state == NEXT_POINT)
89 // We create the new object here, and then pass it off to the
90 // DrawingView which stuffs it into the document.
91 line = new Line(p1, p2);
92 // We don't need no stinkin' sentinels, when we have signals & slots!
93 emit ObjectReady(line);
101 /*virtual*/ bool DrawLineAction::KeyDown(int key)
103 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
105 shiftWasPressedOnNextPoint = true;
116 /*virtual*/ bool DrawLineAction::KeyReleased(int key)
118 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
120 shiftWasPressedOnNextPoint = false;