]> Shamusworld >> Repos - architektonas/blobdiff - src/rotateaction.cpp
Changed Actions to emit signal when needing a graphical update.
[architektonas] / src / rotateaction.cpp
index 661e617314d359a92c202da9fb5fa1751228744d..071b31d93ba321a712ea97b7961090c029b92650 100644 (file)
 #include "line.h"
 #include "mathconstants.h"
 #include "painter.h"
-//#include "vector.h"
 
 
-//#define FIRST_POINT 0
-//#define NEXT_POINT 1
 enum { FIRST_POINT, NEXT_POINT };
 
 
 RotateAction::RotateAction(): state(FIRST_POINT), line(NULL),
-       shiftWasPressedOnNextPoint(false), spin(new Container(Vector()))
+       shiftWasPressedOnNextPoint(false), ctrlWasPressed(false),
+       spin(new Container(Vector()))
 {
-//     ApplicationWindow::drawing->document.CopySelectedContentsTo(selected);
        ApplicationWindow::drawing->document.CopySelectedContentsTo(spin);
-
-//     for(std::vector<Object *>::iterator i=spin->objects.begin(); i!=spin->objects.end(); i++)
-//             (*i)->Save();
        spin->Save();
 }
 
@@ -55,26 +49,31 @@ RotateAction::~RotateAction()
        }
        else
        {
-//             Vector reflectedP2 = -(p2 - p1);
-//             Point newP2 = p1 + reflectedP2;
-               painter->DrawLine(p1, p2);
                painter->DrawHandle(p1);
 
-               double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
+               // Draw the rotated objects only if there's been a line to spin around
+               if (p1 == p2)
+                       return;
 
-               // Keep the angle between 0 and 180 degrees
-//             if (absAngle > 180.0)
-//                     absAngle -= 180.0;
+               painter->DrawLine(p1, p2);
+
+               double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
 
                QString text = QChar(0x2221) + QObject::tr(": %1");
                text = text.arg(absAngle);
-//             QString text = tr("Length: %1 in.");
-//             text = text.arg(Vector::Magnitude(p1, p2));
+
+               if (ctrlWasPressed)
+                       text += " (Copy)";
+
                painter->DrawInformativeText(text);
 
-               // Draw the rotated objects only if there's been a line to spin around
-               if (p1 != p2)
-                       spin->Draw(painter);
+// this does nothing, because the objects override any color set here with
+// their own pens... :-/
+// Which means we have to have a flag in the object to tell it not to color itself.
+//             if (ctrlWasPressed)
+//                     painter->SetPen(QPen(Qt::green, 3.0, Qt::SolidLine));
+
+               spin->Draw(painter);
        }
 }
 
@@ -99,12 +98,8 @@ RotateAction::~RotateAction()
        {
                p2 = point;
                double angle = Vector(p2, p1).Angle();
-
-               for(std::vector<Object *>::iterator i=spin->objects.begin(); i!=spin->objects.end(); i++)
-               {
-                       (*i)->Restore();
-                       (*i)->Rotate(p1, angle);
-               }
+               spin->Restore();
+               spin->Rotate(p1, angle);
        }
 }
 
@@ -118,25 +113,25 @@ RotateAction::~RotateAction()
        }
        else if (state == NEXT_POINT)
        {
-               state = FIRST_POINT;
-
-               std::vector<Object *> & objs = ApplicationWindow::drawing->document.objects;
-               double angle = Vector(p2, p1).Angle();
+               if (!ctrlWasPressed)
+               {
+                       state = FIRST_POINT;
+                       double angle = Vector(p2, p1).Angle();
+                       ApplicationWindow::drawing->document.RotateSelected(p1, angle);
 
-               for(std::vector<Object *>::iterator i=objs.begin(); i!=objs.end(); i++)
+                       spin->Clear();
+                       ApplicationWindow::drawing->document.CopySelectedContentsTo(spin);
+                       spin->Save();
+               }
+               else
                {
-                       if ((*i)->state == OSSelected)
-                               (*i)->Rotate(p1, angle);
+                       spin->CopyContentsTo(&(ApplicationWindow::drawing->document));
                }
-
-               spin->Clear();
-               ApplicationWindow::drawing->document.CopySelectedContentsTo(spin);
-               spin->Save();
        }
 }
 
 
-/*virtual*/ bool RotateAction::KeyDown(int key)
+/*virtual*/ void RotateAction::KeyDown(int key)
 {
        if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
        {
@@ -144,14 +139,17 @@ RotateAction::~RotateAction()
                p1Save = p1;
                p1 = p2;
                state = FIRST_POINT;
-               return true;
+               emit(NeedRefresh());
+       }
+       else if (key == Qt::Key_Control)
+       {
+               ctrlWasPressed = true;
+               emit(NeedRefresh());
        }
-
-       return false;
 }
 
 
-/*virtual*/ bool RotateAction::KeyReleased(int key)
+/*virtual*/ void RotateAction::KeyReleased(int key)
 {
        if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
        {
@@ -159,9 +157,12 @@ RotateAction::~RotateAction()
                p2 = p1;
                p1 = p1Save;
                state = NEXT_POINT;
-               return true;
+               emit(NeedRefresh());
+       }
+       else if (key == Qt::Key_Control)
+       {
+               ctrlWasPressed = false;
+               emit(NeedRefresh());
        }
-
-       return false;
 }