X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmirroraction.cpp;h=6bc5b59f207c844f9ea5709a1e8af5670aee9bd9;hb=dbfab6256efe6b03e9750e33081d9dcdcdfc1c34;hp=500f59d9e6cd89633c1571e85ee2fe8b0de21083;hpb=428876081ee41d40e32f5b4f2bfcfdb7a835e6e1;p=architektonas diff --git a/src/mirroraction.cpp b/src/mirroraction.cpp index 500f59d..6bc5b59 100644 --- a/src/mirroraction.cpp +++ b/src/mirroraction.cpp @@ -12,7 +12,11 @@ // #include "mirroraction.h" +#include "applicationwindow.h" +#include "container.h" +#include "drawingview.h" #include "line.h" +#include "mathconstants.h" #include "painter.h" //#include "vector.h" @@ -23,8 +27,11 @@ enum { FIRST_POINT, NEXT_POINT }; MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL), - shiftWasPressedOnNextPoint(false) + shiftWasPressedOnNextPoint(false), ctrlWasPressed(false), + mirror(new Container(Vector())) { + ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror); + mirror->Save(); } @@ -45,12 +52,28 @@ 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; + + // 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); + + if (ctrlWasPressed) + text += " (Copy)"; - QString text = tr("Length: %1 in."); - text = text.arg(Vector::Magnitude(p1, p2)); painter->DrawInformativeText(text); + + // Draw the mirror only if there's been a line to mirror around + if (p1 != p2) + mirror->Draw(painter); } } @@ -72,7 +95,11 @@ MirrorAction::~MirrorAction() if (state == FIRST_POINT) p1 = point; else + { p2 = point; + mirror->Restore(); + mirror->Mirror(p1, p2); + } } @@ -85,19 +112,25 @@ 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); - - p1 = p2; - state = NEXT_POINT; + if (!ctrlWasPressed) + { + state = FIRST_POINT; + ApplicationWindow::drawing->document.MirrorSelected(p1, p2); + + mirror->Clear(); + ApplicationWindow::drawing->document.CopySelectedContentsTo(mirror); + mirror->Save(); + } + else + { + mirror->CopyContentsTo(&(ApplicationWindow::drawing->document)); +// mirror->CopyContentsTo(&(DrawingView.document)); + } } } -/*virtual*/ bool MirrorAction::KeyDown(int key) +/*virtual*/ void MirrorAction::KeyDown(int key) { if ((key == Qt::Key_Shift) && (state == NEXT_POINT)) { @@ -105,14 +138,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) { @@ -120,9 +156,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; }