#include "rs_actiondrawline.h"
#include "rs_actioneditundo.h"
-#include "rs_snapper.h"
+#include "rs_commandevent.h"
+#include "commands.h"
+#include "rs_dialogfactory.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");
}
return RS2::ActionDrawLine;
}
-/*static*/ QAction * RS_ActionDrawLine::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
-{
- QAction * action = new QAction(tr("&2 Points"), 0);
- action->setEnabled(true);
-// QAction* action = new QAction(tr("Line: 2 Points"), tr("&2 Points"),
-// QKeySequence(), NULL);
- action->setStatusTip(tr("Draw lines"));
- return action;
-}
-
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");
}
{
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();
//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());
}
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)
{
- RS_CoordinateEvent ce(snapPoint(e));
+ 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(RS_CoordinateEvent * e)
+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;
}
- Vector mouse = e->getCoordinate();
+ Vector mouse = *e;
switch (getStatus())
{
case SetStartpoint:
data.startpoint = mouse;
-// history.clear();
ClearHistory();
history.append(new Vector(mouse));
start = data.startpoint;
switch (getStatus())
{
case SetStartpoint:
+
if (checkCommand("help", c))
{
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
break;
case SetEndpoint:
+
if (checkCommand("close", c))
{
close();
{
case SetStartpoint:
break;
+
case SetEndpoint:
+
if (history.count() >= 2)
cmd += command("undo");
cmd += command("close");
break;
+
default:
break;
}
case SetStartpoint:
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel"));
break;
+
case SetEndpoint:
{
QString msg = "";
}
if (history.count() >= 2)
- {
msg += RS_COMMANDS->command("undo");
- }
if (history.count() >= 2)
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point or [%1]").arg(msg), tr("Back"));
else
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Back"));
}
- break;
+ break;
+
default:
RS_DIALOGFACTORY->updateMouseWidget("", "");
break;
{
RS_DEBUG->print("RS_ActionDrawLine::showOptions");
RS_ActionInterface::showOptions();
-
RS_DIALOGFACTORY->requestOptions(this, true);
RS_DEBUG->print("RS_ActionDrawLine::showOptions: OK");
}
void RS_ActionDrawLine::hideOptions()
{
RS_ActionInterface::hideOptions();
-
RS_DIALOGFACTORY->requestOptions(this, false);
}
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;
graphicView->moveRelativeZero(start);
}
else
- {
RS_DIALOGFACTORY->commandMessage(tr("Cannot close sequence of lines: Not enough entities defined yet."));
- }
}
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."));
- }
}
void RS_ActionDrawLine::ClearHistory(void)