1 // rotateaction.cpp: Action class for rotating 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 09/03/2011 Created this file
14 #include "rotateaction.h"
15 #include "applicationwindow.h"
16 #include "container.h"
17 #include "drawingview.h"
19 #include "mathconstants.h"
24 //#define FIRST_POINT 0
25 //#define NEXT_POINT 1
26 enum { FIRST_POINT, NEXT_POINT };
29 RotateAction::RotateAction(): state(FIRST_POINT), line(NULL),
30 shiftWasPressedOnNextPoint(false), spin(new Container(Vector()))
32 // ApplicationWindow::drawing->document.CopySelectedContentsTo(selected);
33 ApplicationWindow::drawing->document.CopySelectedContentsTo(spin);
35 // for(std::vector<Object *>::iterator i=spin->objects.begin(); i!=spin->objects.end(); i++)
41 RotateAction::~RotateAction()
46 /*virtual*/ void RotateAction::Draw(Painter * painter)
48 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
50 // I think stuff like crosshairs should be done in the DrawingView, tho
51 // (and it's done there now...)
52 if (state == FIRST_POINT)
54 painter->DrawHandle(p1);
58 // Vector reflectedP2 = -(p2 - p1);
59 // Point newP2 = p1 + reflectedP2;
60 painter->DrawLine(p1, p2);
61 painter->DrawHandle(p1);
63 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
65 // Keep the angle between 0 and 180 degrees
66 // if (absAngle > 180.0)
69 QString text = QChar(0x2221) + QObject::tr(": %1");
70 text = text.arg(absAngle);
71 // QString text = tr("Length: %1 in.");
72 // text = text.arg(Vector::Magnitude(p1, p2));
73 painter->DrawInformativeText(text);
75 // Draw the rotated objects only if there's been a line to spin around
82 /*virtual*/ void RotateAction::MouseDown(Vector point)
84 // Clear our override...
85 shiftWasPressedOnNextPoint = false;
87 if (state == FIRST_POINT)
94 /*virtual*/ void RotateAction::MouseMoved(Vector point)
96 if (state == FIRST_POINT)
101 double angle = Vector(p2, p1).Angle();
103 for(std::vector<Object *>::iterator i=spin->objects.begin(); i!=spin->objects.end(); i++)
106 (*i)->Rotate(p1, angle);
112 /*virtual*/ void RotateAction::MouseReleased(void)
114 if (state == FIRST_POINT)
119 else if (state == NEXT_POINT)
123 std::vector<Object *> & objs = ApplicationWindow::drawing->document.objects;
124 double angle = Vector(p2, p1).Angle();
126 for(std::vector<Object *>::iterator i=objs.begin(); i!=objs.end(); i++)
128 if ((*i)->state == OSSelected)
129 (*i)->Rotate(p1, angle);
133 ApplicationWindow::drawing->document.CopySelectedContentsTo(spin);
139 /*virtual*/ bool RotateAction::KeyDown(int key)
141 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
143 shiftWasPressedOnNextPoint = true;
154 /*virtual*/ bool RotateAction::KeyReleased(int key)
156 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
158 shiftWasPressedOnNextPoint = false;