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"
23 enum { FIRST_POINT, NEXT_POINT };
26 RotateAction::RotateAction(): state(FIRST_POINT), line(NULL),
27 shiftWasPressedOnNextPoint(false), ctrlWasPressed(false),
28 spin(new Container(Vector()))
30 ApplicationWindow::drawing->document.CopySelectedContentsTo(spin);
35 RotateAction::~RotateAction()
40 /*virtual*/ void RotateAction::Draw(Painter * painter)
42 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
44 // I think stuff like crosshairs should be done in the DrawingView, tho
45 // (and it's done there now...)
46 if (state == FIRST_POINT)
48 painter->DrawHandle(p1);
52 painter->DrawHandle(p1);
54 // Draw the rotated objects only if there's been a line to spin around
58 painter->DrawLine(p1, p2);
60 double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
62 QString text = QChar(0x2221) + QObject::tr(": %1");
63 text = text.arg(absAngle);
68 painter->DrawInformativeText(text);
70 // this does nothing, because the objects override any color set here with
71 // their own pens... :-/
72 // Which means we have to have a flag in the object to tell it not to color itself.
73 // if (ctrlWasPressed)
74 // painter->SetPen(QPen(Qt::green, 3.0, Qt::SolidLine));
81 /*virtual*/ void RotateAction::MouseDown(Vector point)
83 // Clear our override...
84 shiftWasPressedOnNextPoint = false;
86 if (state == FIRST_POINT)
93 /*virtual*/ void RotateAction::MouseMoved(Vector point)
95 if (state == FIRST_POINT)
100 double angle = Vector(p2, p1).Angle();
102 spin->Rotate(p1, angle);
107 /*virtual*/ void RotateAction::MouseReleased(void)
109 if (state == FIRST_POINT)
114 else if (state == NEXT_POINT)
119 double angle = Vector(p2, p1).Angle();
120 ApplicationWindow::drawing->document.RotateSelected(p1, angle);
123 ApplicationWindow::drawing->document.CopySelectedContentsTo(spin);
128 spin->CopyContentsTo(&(ApplicationWindow::drawing->document));
134 /*virtual*/ void RotateAction::KeyDown(int key)
136 if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
138 shiftWasPressedOnNextPoint = true;
144 else if (key == Qt::Key_Control)
146 ctrlWasPressed = true;
152 /*virtual*/ void RotateAction::KeyReleased(int key)
154 if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
156 shiftWasPressedOnNextPoint = false;
162 else if (key == Qt::Key_Control)
164 ctrlWasPressed = false;