]> Shamusworld >> Repos - architektonas/blobdiff - src/mirroraction.cpp
Mirror tool now works successfully for all object types. :-D
[architektonas] / src / mirroraction.cpp
index 720692ed85130725ac3c2170206fa2ec251463ea..af786d7f1dc72393c3698cd09b3af38b69bf1098 100644 (file)
@@ -29,6 +29,12 @@ enum { FIRST_POINT, NEXT_POINT };
 MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL),
        shiftWasPressedOnNextPoint(false), mirror(new Container(Vector()))
 {
+//     ApplicationWindow::drawing->document.CopySelectedContentsTo(selected);
+       ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
+
+//     for(std::vector<Object *>::iterator i=mirror->objects.begin(); i!=mirror->objects.end(); i++)
+//             (*i)->Save();
+       mirror->Save();
 }
 
 
@@ -49,11 +55,16 @@ MirrorAction::~MirrorAction()
        }
        else
        {
-               painter->DrawLine(p1, p2);
-               painter->DrawHandle(p2);
+               Vector reflectedP2 = -(p2 - p1);
+               Point newP2 = p1 + reflectedP2;
+               painter->DrawLine(newP2, p2);
+               painter->DrawHandle(p1);
 
                double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES;
-//             double absLength = Vector(position - endpoint).Magnitude();
+
+               // Keep the angle between 0 and 180 degrees
+               if (absAngle > 180.0)
+                       absAngle -= 180.0;
 
                QString text = QChar(0x2221) + QObject::tr(": %1");
                text = text.arg(absAngle);
@@ -61,7 +72,9 @@ MirrorAction::~MirrorAction()
 //             text = text.arg(Vector::Magnitude(p1, p2));
                painter->DrawInformativeText(text);
 
-               mirror->Draw(painter);
+               // Draw the mirror only if there's been a line to mirror around
+               if (p1 != p2)
+                       mirror->Draw(painter);
        }
 }
 
@@ -86,17 +99,10 @@ MirrorAction::~MirrorAction()
        {
                p2 = point;
 
-               mirror->Clear();
-               int itemsSelected = ApplicationWindow::drawing->document.ItemsSelected();
-
-               if (itemsSelected == 0)
-                       return;
-
-               for(int i=0; i<itemsSelected; i++)
+               for(std::vector<Object *>::iterator i=mirror->objects.begin(); i!=mirror->objects.end(); i++)
                {
-                       Object * object = ApplicationWindow::drawing->document.SelectedItem(i);
-                       Object * mirrored = object->Mirror(p1, p2);
-                       mirror->Add(mirrored);
+                       (*i)->Restore();
+                       (*i)->Mirror(p1, p2);
                }
        }
 }
@@ -111,14 +117,19 @@ MirrorAction::~MirrorAction()
        }
        else if (state == NEXT_POINT)
        {
-               // We create the new object here, and then pass it off to the
-               // DrawingView which stuffs it into the document.
-//             line = new Line(p1, p2);
-               // We don't need no stinkin' sentinels, when we have signals & slots!
-//             emit ObjectReady(line);
+               state = FIRST_POINT;
 
-               p1 = p2;
-               state = NEXT_POINT;
+               std::vector<Object *> & objs = ApplicationWindow::drawing->document.objects;
+
+               for(std::vector<Object *>::iterator i=objs.begin(); i!=objs.end(); i++)
+               {
+                       if ((*i)->state == OSSelected)
+                               (*i)->Mirror(p1, p2);
+               }
+
+               mirror->Clear();
+               ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
+               mirror->Save();
        }
 }