// Who When What
// --- ---------- -----------------------------------------------------------
// JLH 06/03/2010 Added this text. :-)
+// JLH 09/11/2010 Fixed preview/snapper rendering.
//
#include "actiondrawcircle.h"
-#include "rs_commandevent.h"
-#include "rs_dialogfactory.h"
+#include "commandevent.h"
+#include "debug.h"
+#include "dialogfactory.h"
#include "graphicview.h"
-#include "rs_preview.h"
+#include "preview.h"
-ActionDrawCircle::ActionDrawCircle(RS_EntityContainer & container, GraphicView & graphicView):
+ActionDrawCircle::ActionDrawCircle(EntityContainer & container, GraphicView & graphicView):
ActionInterface("Draw circles", container, graphicView)
{
reset();
void ActionDrawCircle::reset()
{
- data = RS_CircleData(Vector(false), 0.0);
+ data = CircleData(Vector(false), 0.0);
}
void ActionDrawCircle::init(int status)
{
ActionInterface::trigger();
- RS_Circle * circle = new RS_Circle(container, data);
+ Circle * circle = new Circle(container, data);
circle->setLayerToActive();
circle->setPenToActive();
container->addEntity(circle);
// upd. undo list:
- if (document != NULL)
+ if (document)
{
document->startUndoCycle();
document->addUndoable(circle);
document->endUndoCycle();
}
- deleteSnapper();
- Vector rz = graphicView->getRelativeZero();
- graphicView->moveRelativeZero(Vector(0.0, 0.0));
- graphicView->drawEntity(circle);
+ graphicView->preview.clear(); // hm.
+// deleteSnapper();
+// Vector rz = graphicView->getRelativeZero();
+// graphicView->moveRelativeZero(Vector(0.0, 0.0));
+// graphicView->drawEntity(circle);
graphicView->moveRelativeZero(circle->getCenter());
- drawSnapper();
+// drawSnapper();
+ graphicView->redraw();
setStatus(SetCenter);
reset();
- RS_DEBUG->print("ActionDrawCircle::trigger(): circle added: %d", circle->getId());
+ DEBUG->print("ActionDrawCircle::trigger(): circle added: %d", circle->getId());
}
void ActionDrawCircle::mouseMoveEvent(QMouseEvent * e)
{
- RS_DEBUG->print("ActionDrawCircle::mouseMoveEvent begin");
+ DEBUG->print("ActionDrawCircle::mouseMoveEvent begin");
Vector mouse = snapPoint(e);
break;
case SetRadius:
-
if (data.center.valid)
{
data.radius = data.center.distanceTo(mouse);
- deletePreview();
- clearPreview();
-// preview->addEntity(new RS_Circle(preview, data));
- drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Circle(&(graphicView->preview), data));
}
break;
}
- RS_DEBUG->print("ActionDrawCircle::mouseMoveEvent end");
+ graphicView->redraw();
+ DEBUG->print("ActionDrawCircle::mouseMoveEvent end");
}
void ActionDrawCircle::mouseReleaseEvent(QMouseEvent * e)
}
else if (e->button() == Qt::RightButton)
{
- deletePreview();
- deleteSnapper();
+// deletePreview();
+// deleteSnapper();
+// //Is this necessary? Or should the base class take care of this kind of crap?
+// graphicView->preview.clear();
init(getStatus() - 1);
+ // Looks like we need at least to redraw... Though shouldn't base class do it???
+ graphicView->redraw();
}
}
break;
case SetRadius:
-
if (data.center.valid)
{
graphicView->moveRelativeZero(mouse);
data.radius = data.center.distanceTo(mouse);
trigger();
}
- //setStatus(SetCenter);
+
break;
default:
}
}
-void ActionDrawCircle::commandEvent(RS_CommandEvent * e)
+void ActionDrawCircle::commandEvent(CommandEvent * e)
{
QString c = e->getCommand().toLower();
if (checkCommand("help", c))
{
- if (RS_DIALOGFACTORY)
- RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ if (DIALOGFACTORY)
+ DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ getAvailableCommands().join(", "));
return;
}
case SetRadius:
{
bool ok;
- double r = RS_Math::eval(c, &ok);
+ double r = Math::eval(c, &ok);
if (ok)
data.radius = r;
- else if (RS_DIALOGFACTORY)
- RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+ else if (DIALOGFACTORY)
+ DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
trigger();
//setStatus(SetCenter);
switch (getStatus())
{
case SetCenter:
- if (RS_DIALOGFACTORY)
- RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel"));
+ if (DIALOGFACTORY)
+ DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel"));
break;
case SetRadius:
- if (RS_DIALOGFACTORY)
- RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back"));
+ if (DIALOGFACTORY)
+ DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back"));
break;
default:
- if (RS_DIALOGFACTORY)
- RS_DIALOGFACTORY->updateMouseWidget("", "");
+ if (DIALOGFACTORY)
+ DIALOGFACTORY->updateMouseWidget("", "");
break;
}
}
{
if (!isFinished())
{
- if (RS_DIALOGFACTORY)
- RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+ if (DIALOGFACTORY)
+ DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
}
- else if (RS_DIALOGFACTORY)
- RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);
+ else if (DIALOGFACTORY)
+ DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);
}