]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actiondrawline.cpp
Last checkin before major refactor...
[architektonas] / src / actions / rs_actiondrawline.cpp
index d911e779c02016f7258631b1c4d6a58075bbdc6b..d3fad7284b9939c27f3deda7411751eb78d12b24 100644 (file)
@@ -1,5 +1,6 @@
 // rs_actiondrawline.cpp
 //
+// Part of the Architektonas Project
 // Originally part of QCad Community Edition by Andrew Mustun
 // Extensively rewritten and refactored by James L. Hammons
 // (C) 2010 Underground Software
@@ -55,19 +56,15 @@ void RS_ActionDrawLine::reset()
 void RS_ActionDrawLine::init(int status)
 {
        RS_DEBUG->print("RS_ActionDrawLine::init");
-       RS_PreviewActionInterface::init(status);
+//     RS_PreviewActionInterface::init(status);
+       RS_ActionInterface::init(status);
        reset();
        RS_DEBUG->print("RS_ActionDrawLine::init: OK");
 }
 
 void RS_ActionDrawLine::trigger()
 {
-#if 0
-       RS_PreviewActionInterface::trigger();   // XOR off screen, delete entities in container
-#else
        graphicView->preview.clear();
-//     graphicView->redraw();
-#endif
 
        RS_Line * line = new RS_Line(container, data);
        line->setLayerToActive();
@@ -104,23 +101,25 @@ void RS_ActionDrawLine::mouseMoveEvent(QMouseEvent * e)
        if (getStatus() == SetEndpoint && data.startpoint.valid)
        {
                RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: update preview");
-#if 0
-//not needed, but without this, it doesn't draw... strange...
-//obviously we haven't gotten our rendering path correct...
-//             deletePreview();                // XOR off of screen
-               clearPreview();                 // Remove entities from the container
-               preview->addEntity(new RS_Line(preview, RS_LineData(data.startpoint, mouse)));
-               RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: draw preview");
-//             drawPreview();                  // XOR on screen
-               xorPreview();                   // XOR on screen
-#else
                // This is lame. Creating a new Line every time the endpoint moves.
                // Surely we can alter the line entity inside the preview, no?
+#if 0
                graphicView->preview.clear();                   // Remove entities from the container
                RS_Line * line = new RS_Line(&(graphicView->preview), RS_LineData(data.startpoint, mouse));
-//wha? Even THIS doesn't work!!! It was the container...
-//             line->setPen(RS_Pen(RS_Color(60, 255, 60), RS2::Width00, RS2::SolidLine));
                graphicView->preview.addEntity(line);
+#else
+               // We can assume there's only one line in there, can't we?
+               RS_Line * line = (RS_Line *)graphicView->preview.firstEntity(RS2::ResolveNone);
+
+               if (line)
+               {
+                       line->setEndpoint(mouse);
+               }
+               else
+               {
+                       line = new RS_Line(&(graphicView->preview), RS_LineData(data.startpoint, mouse));
+                       graphicView->preview.addEntity(line);
+               }
 #endif
        }
 
@@ -133,7 +132,7 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
 {
        if (e->button() == Qt::LeftButton)
        {
-               Vector ce(snapPoint(e));
+               Vector ce(graphicView->snapper.snapPoint(e));
                coordinateEvent(&ce);
        }
        else if (e->button() == Qt::RightButton)
@@ -144,11 +143,6 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
                        graphicView->preview.SetVisible(false);
                }
 
-#if 0
-               deletePreview();                // XOR off of screen
-               clearPreview();                 // Remove entities from the container
-#else
-#endif
                init(getStatus() - 1);
        }
 
@@ -289,7 +283,7 @@ void RS_ActionDrawLine::updateMouseButtonHints()
                else
                        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Back"));
        }
-       break;
+               break;
 
        default:
                RS_DIALOGFACTORY->updateMouseWidget("", "");
@@ -345,13 +339,11 @@ void RS_ActionDrawLine::undo()
        if (history.count() > 1)
        {
                history.removeLast();
-//             deletePreview();                // XOR off of screen
-//             clearPreview();                 // Delete entities in container
                graphicView->setCurrentAction(new RS_ActionEditUndo(true, *container, *graphicView));
                data.startpoint = *history.last();
                graphicView->moveRelativeZero(data.startpoint);
-graphicView->preview.clear();
-graphicView->redraw();
+               graphicView->preview.clear();
+               graphicView->redraw();
        }
        else
                RS_DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet."));