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();
}
}
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);
// 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);
}
}
{
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);
}
}
}
}
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();
}
}