// 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
+// Portions copyright (C) 2001-2003 RibbonSoft
+// Copyright (C) 2010 Underground Software
+// See the README and GPLv2 files for licensing and warranty information
//
// JLH = James L. Hammons <jlhamm@acm.org>
//
#include "actiondrawlinerectangle.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"
ActionDrawLineRectangle::ActionDrawLineRectangle(
- RS_EntityContainer & container, GraphicView & graphicView):
+ EntityContainer & container, GraphicView & graphicView):
ActionInterface("Draw rectangles", container, graphicView)
{
reset();
void ActionDrawLineRectangle::reset()
{
for(int i=0; i<4; i++)
- data[i] = RS_LineData(Vector(false), Vector(false));
+ data[i] = LineData(Vector(false), Vector(false));
}
void ActionDrawLineRectangle::init(int status)
{
ActionInterface::trigger();
- RS_Line * line[4];
+ Line * line[4];
preparePreview();
// create and add rectangle:
for(int i=0; i<4; i++)
{
- line[i] = new RS_Line(container, data[i]);
+ line[i] = new Line(container, data[i]);
line[i]->setLayerToActive();
line[i]->setPenToActive();
container->addEntity(line[i]);
}
// upd. view
- deleteSnapper();
+// deleteSnapper();
graphicView->moveRelativeZero(Vector(0.0, 0.0));
for(int i=0; i<4; i++)
{
graphicView->drawEntity(line[i]);
- RS_DEBUG->print("ActionDrawLineRectangle::trigger(): line added: %d",
- line[i]->getId());
+ DEBUG->print("ActionDrawLineRectangle::trigger(): line added: %d", line[i]->getId());
}
+
graphicView->moveRelativeZero(corner2);
+ graphicView->redraw();
}
void ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent * e)
{
- RS_DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent begin");
+ DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent begin");
Vector mouse = snapPoint(e);
if (getStatus() == SetCorner2 && corner1.valid)
{
corner2 = mouse;
- deletePreview();
- clearPreview();
-
- preparePreview();
+// deletePreview();
+// clearPreview();
+// preparePreview();
// for(int i=0; i<4; i++)
-// preview->addEntity(new RS_Line(preview, data[i]));
+// preview->addEntity(new Line(preview, data[i]));
+
+// drawPreview();
+ preparePreview();
+ graphicView->preview.clear();
- drawPreview();
+ for(int i=0; i<4; i++)
+ graphicView->preview.addEntity(new Line(&(graphicView->preview), data[i]));
}
- RS_DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent end");
+ graphicView->redraw();
+ DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent end");
}
void ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent * e)
{
if (e->button() == Qt::LeftButton)
{
- Vector ce(snapPoint(e));
+// Vector ce(snapPoint(e));
+ Vector ce(graphicView->snapper.snapPoint(e));
coordinateEvent(&ce);
}
else if (e->button() == Qt::RightButton)
{
- deletePreview();
- deleteSnapper();
+// deletePreview();
+// deleteSnapper();
init(getStatus() - 1);
}
+
+ graphicView->preview.clear(); // Remove entities from container
+ graphicView->redraw();
}
void ActionDrawLineRectangle::preparePreview()
{
- data[0] = RS_LineData(corner1, Vector(corner2.x, corner1.y));
- data[1] = RS_LineData(Vector(corner2.x, corner1.y), corner2);
- data[2] = RS_LineData(corner2, Vector(corner1.x, corner2.y));
- data[3] = RS_LineData(Vector(corner1.x, corner2.y), corner1);
+ data[0] = LineData(corner1, Vector(corner2.x, corner1.y));
+ data[1] = LineData(Vector(corner2.x, corner1.y), corner2);
+ data[2] = LineData(corner2, Vector(corner1.x, corner2.y));
+ data[3] = LineData(Vector(corner1.x, corner2.y), corner1);
}
void ActionDrawLineRectangle::coordinateEvent(Vector * e)
{
- if (e == NULL)
+ if (!e)
return;
Vector mouse = *e;
}
}
-void ActionDrawLineRectangle::commandEvent(RS_CommandEvent * e)
+void ActionDrawLineRectangle::commandEvent(CommandEvent * e)
{
QString c = e->getCommand().toLower();
if (checkCommand("help", c))
{
- if (RS_DIALOGFACTORY != NULL)
- RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ if (DIALOGFACTORY)
+ DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ getAvailableCommands().join(", "));
return;
}
void ActionDrawLineRectangle::updateMouseButtonHints()
{
- if (RS_DIALOGFACTORY != NULL)
+ if (DIALOGFACTORY)
{
switch (getStatus())
{
case SetCorner1:
- RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
- tr("Cancel"));
+ DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), tr("Cancel"));
break;
case SetCorner2:
- RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
- tr("Back"));
+ DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), tr("Back"));
break;
default:
- RS_DIALOGFACTORY->updateMouseWidget("", "");
+ DIALOGFACTORY->updateMouseWidget("", "");
break;
}
}
void ActionDrawLineRectangle::updateToolBar()
{
- if (RS_DIALOGFACTORY != NULL)
+ if (DIALOGFACTORY)
{
if (!isFinished())
- RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+ DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
else
- RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
+ DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
}
}
-
-