]> Shamusworld >> Repos - architektonas/blobdiff - src/mirroraction.cpp
Added Mirror tool
[architektonas] / src / mirroraction.cpp
index af786d7f1dc72393c3698cd09b3af38b69bf1098..877017355cdb7c2f46af067edc7a3917700157cd 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 };
 
 
 MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL),
-       shiftWasPressedOnNextPoint(false), mirror(new Container(Vector()))
+       shiftWasPressedOnNextPoint(false), ctrlWasPressed(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();
 }
 
@@ -47,8 +41,6 @@ MirrorAction::~MirrorAction()
 {
        painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
 
-       // I think stuff like crosshairs should be done in the DrawingView, tho
-       // (and it's done there now...)
        if (state == FIRST_POINT)
        {
                painter->DrawHandle(p1);
@@ -68,8 +60,10 @@ MirrorAction::~MirrorAction()
 
                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 mirror only if there's been a line to mirror around
@@ -98,12 +92,8 @@ MirrorAction::~MirrorAction()
        else
        {
                p2 = point;
-
-               for(std::vector<Object *>::iterator i=mirror->objects.begin(); i!=mirror->objects.end(); i++)
-               {
-                       (*i)->Restore();
-                       (*i)->Mirror(p1, p2);
-               }
+               mirror->Restore();
+               mirror->Mirror(p1, p2);
        }
 }
 
@@ -117,24 +107,24 @@ MirrorAction::~MirrorAction()
        }
        else if (state == NEXT_POINT)
        {
-               state = FIRST_POINT;
-
-               std::vector<Object *> & objs = ApplicationWindow::drawing->document.objects;
+               if (!ctrlWasPressed)
+               {
+                       state = FIRST_POINT;
+                       ApplicationWindow::drawing->document.MirrorSelected(p1, p2);
 
-               for(std::vector<Object *>::iterator i=objs.begin(); i!=objs.end(); i++)
+                       mirror->Clear();
+                       ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
+                       mirror->Save();
+               }
+               else
                {
-                       if ((*i)->state == OSSelected)
-                               (*i)->Mirror(p1, p2);
+                       mirror->CopyContentsTo(&(ApplicationWindow::drawing->document));
                }
-
-               mirror->Clear();
-               ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror);
-               mirror->Save();
        }
 }
 
 
-/*virtual*/ bool MirrorAction::KeyDown(int key)
+/*virtual*/ void MirrorAction::KeyDown(int key)
 {
        if ((key == Qt::Key_Shift) && (state == NEXT_POINT))
        {
@@ -142,14 +132,17 @@ MirrorAction::~MirrorAction()
                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 MirrorAction::KeyReleased(int key)
+/*virtual*/ void MirrorAction::KeyReleased(int key)
 {
        if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint)
        {
@@ -157,9 +150,12 @@ MirrorAction::~MirrorAction()
                p2 = p1;
                p1 = p1Save;
                state = NEXT_POINT;
-               return true;
+               emit(NeedRefresh());
+       }
+       else if (key == Qt::Key_Control)
+       {
+               ctrlWasPressed = false;
+               emit(NeedRefresh());
        }
-
-       return false;
 }