X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawline.cpp;h=d911e779c02016f7258631b1c4d6a58075bbdc6b;hb=c715d05d11ffe2913fe3465ec43d456ee9b85964;hp=89a8ea5f4f00993c8ef81d052ade73cc9c1617e7;hpb=ee048ce722e7beb53e702825bb3285cd5cacd8bb;p=architektonas diff --git a/src/actions/rs_actiondrawline.cpp b/src/actions/rs_actiondrawline.cpp index 89a8ea5..d911e77 100644 --- a/src/actions/rs_actiondrawline.cpp +++ b/src/actions/rs_actiondrawline.cpp @@ -14,18 +14,22 @@ #include "rs_actiondrawline.h" #include "rs_actioneditundo.h" +#include "rs_commandevent.h" #include "commands.h" #include "rs_dialogfactory.h" -#include "rs_graphicview.h" +#include "graphicview.h" #include "rs_preview.h" -RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container, RS_GraphicView & graphicView): +RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw lines", container, graphicView) { RS_DEBUG->print("RS_ActionDrawLine::RS_ActionDrawLine"); reset(); -//[DONE]#warning "!!! Need to port setAutoDelete() behaviour from Qt3 to Qt4 !!!" -// history.setAutoDelete(true); + //hm. + graphicView.snapper.SetContainer(&container); + graphicView.snapper.SetGraphicView(&graphicView); + graphicView.snapper.SetVisible(); + graphicView.preview.SetVisible(); RS_DEBUG->print("RS_ActionDrawLine::RS_ActionDrawLine: OK"); } @@ -44,7 +48,6 @@ void RS_ActionDrawLine::reset() RS_DEBUG->print("RS_ActionDrawLine::reset"); data = RS_LineData(Vector(false), Vector(false)); start = Vector(false); -// history.clear(); ClearHistory(); RS_DEBUG->print("RS_ActionDrawLine::reset: OK"); } @@ -53,14 +56,18 @@ void RS_ActionDrawLine::init(int status) { RS_DEBUG->print("RS_ActionDrawLine::init"); RS_PreviewActionInterface::init(status); - reset(); RS_DEBUG->print("RS_ActionDrawLine::init: OK"); } void RS_ActionDrawLine::trigger() { - RS_PreviewActionInterface::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(); @@ -73,20 +80,16 @@ void RS_ActionDrawLine::trigger() //std::cout << *container; // Update undo list: - if (document != NULL) + if (document) { document->startUndoCycle(); document->addUndoable(line); document->endUndoCycle(); } - deleteSnapper(); - graphicView->moveRelativeZero(Vector(0.0, 0.0)); -//This is unnecessary, because we added this to the container... -//#warning "!!! Here's the trouble... Trying to draw direct !!!" -// graphicView->drawEntity(line); graphicView->moveRelativeZero(line->getEndpoint()); - drawSnapper(); + //hm. [OK, it just moves the relative zero tho. Overkill. And remove preview, so OK.] + graphicView->redraw(); RS_DEBUG->print("RS_ActionDrawLine::trigger(): line added: %d", line->getId()); } @@ -95,43 +98,70 @@ void RS_ActionDrawLine::mouseMoveEvent(QMouseEvent * e) RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent begin"); RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: snap point"); - Vector mouse = snapPoint(e); + Vector mouse = graphicView->snapper.snapPoint(e); RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: snap point: OK"); if (getStatus() == SetEndpoint && data.startpoint.valid) { RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: update preview"); - deletePreview(); - clearPreview(); +#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(); +// 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? + 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); +#endif } + //hm. [ok, this works. :-D] + graphicView->redraw(); RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent end"); } void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e) { - if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + if (e->button() == Qt::LeftButton) { Vector ce(snapPoint(e)); coordinateEvent(&ce); } - else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + else if (e->button() == Qt::RightButton) { - deletePreview(); - clearPreview(); - deleteSnapper(); + if (getStatus() == 0) + { + graphicView->snapper.SetVisible(false); + graphicView->preview.SetVisible(false); + } + +#if 0 + deletePreview(); // XOR off of screen + clearPreview(); // Remove entities from the container +#else +#endif init(getStatus() - 1); } + + //hm. [Seems to work OK.] + graphicView->preview.clear(); // Remove entities from container + graphicView->redraw(); } void RS_ActionDrawLine::coordinateEvent(Vector * e) { RS_DEBUG->print("RS_ActionDrawLine::coordinateEvent"); - if (e == NULL) + if (!e) { RS_DEBUG->print("RS_ActionDrawLine::coordinateEvent: event was NULL"); return; @@ -143,7 +173,6 @@ void RS_ActionDrawLine::coordinateEvent(Vector * e) { case SetStartpoint: data.startpoint = mouse; -// history.clear(); ClearHistory(); history.append(new Vector(mouse)); start = data.startpoint; @@ -272,7 +301,6 @@ void RS_ActionDrawLine::showOptions() { RS_DEBUG->print("RS_ActionDrawLine::showOptions"); RS_ActionInterface::showOptions(); - RS_DIALOGFACTORY->requestOptions(this, true); RS_DEBUG->print("RS_ActionDrawLine::showOptions: OK"); } @@ -280,7 +308,6 @@ void RS_ActionDrawLine::showOptions() void RS_ActionDrawLine::hideOptions() { RS_ActionInterface::hideOptions(); - RS_DIALOGFACTORY->requestOptions(this, false); } @@ -299,6 +326,8 @@ void RS_ActionDrawLine::updateToolBar() void RS_ActionDrawLine::close() { +//NOTE: We should grey out the "close" button until the conditions for its use are satisfied. +// Though I can see how this would be called via cmd line... So I guess it's OK if (history.count() > 2 && start.valid) { data.endpoint = start; @@ -312,14 +341,17 @@ void RS_ActionDrawLine::close() void RS_ActionDrawLine::undo() { +//NOTE: We should grey out the "undo" button until the conditions for its use are satisfied. if (history.count() > 1) { history.removeLast(); - deletePreview(); - clearPreview(); +// 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(); } else RS_DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet.")); @@ -330,4 +362,3 @@ void RS_ActionDrawLine::ClearHistory(void) while (!history.isEmpty()) delete history.takeFirst(); } -