X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Factiondrawpolyline.cpp;h=1ddd4121ca303066c07a40909e4eadd332d3a0b9;hb=5adb444f3e523d3fd028617ced72d1ea6661db21;hp=03925ab8439e53609338b5ba5b7150d10a80ace8;hpb=806890f384b382a02675cadc33c15fdbcec7d432;p=architektonas diff --git a/src/actions/actiondrawpolyline.cpp b/src/actions/actiondrawpolyline.cpp index 03925ab..1ddd412 100644 --- a/src/actions/actiondrawpolyline.cpp +++ b/src/actions/actiondrawpolyline.cpp @@ -21,10 +21,9 @@ ActionDrawPolyline::ActionDrawPolyline(EntityContainer & container, GraphicView & graphicView): - ActionInterface("Draw polyline", container, graphicView) + ActionInterface("Draw polyline", container, graphicView), vertex(false), polyline(NULL) { - vertex = Vector(false); - polyline = NULL; +// vertex = Vector(false); } ActionDrawPolyline::~ActionDrawPolyline() @@ -43,7 +42,6 @@ void ActionDrawPolyline::trigger() if (polyline) { container->addEntity(polyline); -// deleteSnapper(); if (document) { @@ -54,11 +52,13 @@ void ActionDrawPolyline::trigger() DEBUG->print("ActionDrawPolyline::trigger(): polyline added: %d", polyline->getId()); polyline = NULL; + graphicView->redraw(); //hm. } } void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e) { +#if 0 if (vertex.valid && polyline) { Vector v = snapPoint(e); @@ -73,16 +73,68 @@ void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e) vertex = v; DEBUG->print("ActionDrawPolyline::mouseMoveEvent(): line added: %d", ent->getId()); } +#else + Vector mouse = graphicView->SnapPoint(e); + + if (getStatus() == SetNextPoint && startPoint.valid) + { + // We have to draw a line or arc depending on the state of the "Arc" + // checkbox. + // We'll start with lines... + graphicView->preview.clear(); + Line * line = new Line(&(graphicView->preview), LineData(startPoint, mouse)); + + if (polyline) + graphicView->preview.addEntity(polyline); + + graphicView->preview.addEntity(line); + } + + graphicView->redraw(); //hm. +#endif + +#if 0 + Vector mouse = graphicView->snapper.snapPoint(e); + DEBUG->print("ActionDrawLine::mouseMoveEvent: snap point: OK"); + + if (getStatus() == SetEndpoint && data.startpoint.valid) + { + DEBUG->print("ActionDrawLine::mouseMoveEvent: update preview"); + // 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 + Line * line = new Line(&(graphicView->preview), LineData(data.startpoint, mouse)); + graphicView->preview.addEntity(line); +#else + // We can assume there's only one line in there, can't we? + Line * line = (Line *)graphicView->preview.firstEntity(RS2::ResolveNone); + + if (line) + { + line->setEndpoint(mouse); + } + else + { + line = new Line(&(graphicView->preview), LineData(data.startpoint, mouse)); + graphicView->preview.addEntity(line); + } +#endif + } + + //hm. [ok, this works. :-D] + graphicView->redraw(); +#endif } void ActionDrawPolyline::mousePressEvent(QMouseEvent * e) { if (e->button() == Qt::LeftButton) { - vertex = snapPoint(e); - polyline = new Polyline(container, PolylineData(vertex, vertex, 0)); - polyline->setLayerToActive(); - polyline->setPenToActive(); +// vertex = snapPoint(e); +// polyline = new Polyline(container, PolylineData(vertex, vertex, 0)); +// polyline->setLayerToActive(); +// polyline->setPenToActive(); } } @@ -90,29 +142,97 @@ void ActionDrawPolyline::mouseReleaseEvent(QMouseEvent * e) { if (e->button() == Qt::LeftButton) { - vertex = Vector(false); - trigger(); + Vector ce(graphicView->SnapPoint(e)); + coordinateEvent(&ce); + +//let's try this... + if (!polyline) + { +//printf("ActionDrawPolyline::mouseReleaseEvent(): Creating polyline...\n"); + polyline = new Polyline(container, PolylineData(ce, ce, 0)); +// vertex = snapPoint(e); +// polyline = new Polyline(container, PolylineData(vertex, vertex, 0)); + polyline->setLayerToActive(); + polyline->setPenToActive(); + } + else + { +//printf("ActionDrawPolyline::mouseReleaseEvent(): Adding vertex to polyline...\n"); + Entity * ent = polyline->addVertex(ce); + ent->setLayerToActive(); + ent->setPenToActive(); + } } else if (e->button() == Qt::RightButton) { +#if 0 if (polyline) { delete polyline; polyline = NULL; } +#else +// if (getStatus() == SetFirstPoint) +//ANY right button should trigger (? what about adding twice? won't happen) + trigger(); // this will set the polyline to NULL once added to the container +#endif -// deleteSnapper(); init(getStatus() - 1); graphicView->redraw(); //hm. } } +void ActionDrawPolyline::coordinateEvent(Vector * coordinate) +{ + DEBUG->print("ActionDrawPolyline::coordinateEvent"); + + if (!coordinate) + { + DEBUG->print("ActionDrawPolyline::coordinateEvent: event was NULL"); + return; + } + +// Vector mouse = *e; + + switch (getStatus()) + { + case SetFirstPoint: + startPoint = *coordinate; +// ClearHistory(); +// history.append(new Vector(mouse)); +// start = data.startpoint; + setStatus(SetNextPoint); + graphicView->moveRelativeZero(*coordinate); +// trigger(); + updateMouseButtonHints(); + break; + + case SetNextPoint: +// data.endpoint = mouse; +// history.append(new Vector(mouse)); +// startPoint = endPoint; + startPoint = *coordinate; +// trigger(); + updateMouseButtonHints(); + break; + + default: + break; + } + + DEBUG->print("ActionDrawPolyline::coordinateEvent: OK"); +} + void ActionDrawPolyline::updateMouseButtonHints() { switch (getStatus()) { - case 0: - DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel")); + case SetFirstPoint: + DIALOGFACTORY->updateMouseWidget(tr("Set first point"), tr("Cancel")); + break; + + case SetNextPoint: + DIALOGFACTORY->updateMouseWidget(tr("Set next point"), tr("Back")); break; default: