X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmirroraction.cpp;h=af786d7f1dc72393c3698cd09b3af38b69bf1098;hb=67fbc130b4b6b4d253f69a9c32980d3d3306def5;hp=720692ed85130725ac3c2170206fa2ec251463ea;hpb=4b37ccbdf263a4798e53a62e33d869a728ace283;p=architektonas diff --git a/src/mirroraction.cpp b/src/mirroraction.cpp index 720692e..af786d7 100644 --- a/src/mirroraction.cpp +++ b/src/mirroraction.cpp @@ -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::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::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 & objs = ApplicationWindow::drawing->document.objects; + + for(std::vector::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(); } }