1 // rs_actiondrawlinerectangle.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "rs_actiondrawlinerectangle.h"
17 #include "rs_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
21 RS_ActionDrawLineRectangle::RS_ActionDrawLineRectangle(
22 RS_EntityContainer & container, RS_GraphicView & graphicView):
23 RS_PreviewActionInterface("Draw rectangles", container, graphicView)
28 RS_ActionDrawLineRectangle::~RS_ActionDrawLineRectangle()
32 void RS_ActionDrawLineRectangle::reset()
34 for (int i = 0; i < 4; ++i)
35 data[i] = RS_LineData(Vector(false), Vector(false));
38 void RS_ActionDrawLineRectangle::init(int status)
40 RS_PreviewActionInterface::init(status);
44 void RS_ActionDrawLineRectangle::trigger()
46 RS_PreviewActionInterface::trigger();
51 // create and add rectangle:
52 for (int i = 0; i < 4; ++i)
54 line[i] = new RS_Line(container,
56 line[i]->setLayerToActive();
57 line[i]->setPenToActive();
58 container->addEntity(line[i]);
64 document->startUndoCycle();
66 for (int i = 0; i < 4; ++i)
67 document->addUndoable(line[i]);
68 document->endUndoCycle();
73 graphicView->moveRelativeZero(Vector(0.0, 0.0));
75 for (int i = 0; i < 4; ++i)
77 graphicView->drawEntity(line[i]);
78 RS_DEBUG->print("RS_ActionDrawLineRectangle::trigger():"
82 graphicView->moveRelativeZero(corner2);
85 void RS_ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent * e)
87 RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent begin");
89 Vector mouse = snapPoint(e);
91 if (getStatus() == SetCorner2 && corner1.valid)
99 for (int i = 0; i < 4; ++i)
100 preview->addEntity(new RS_Line(preview, data[i]));
104 RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent end");
107 void RS_ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent * e)
109 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
111 Vector ce(snapPoint(e));
112 coordinateEvent(&ce);
114 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
118 init(getStatus() - 1);
122 void RS_ActionDrawLineRectangle::preparePreview()
124 data[0] = RS_LineData(corner1, Vector(corner2.x, corner1.y));
125 data[1] = RS_LineData(Vector(corner2.x, corner1.y), corner2);
126 data[2] = RS_LineData(corner2, Vector(corner1.x, corner2.y));
127 data[3] = RS_LineData(Vector(corner1.x, corner2.y), corner1);
130 void RS_ActionDrawLineRectangle::coordinateEvent(Vector * e)
141 graphicView->moveRelativeZero(mouse);
142 setStatus(SetCorner2);
148 setStatus(SetCorner1);
156 void RS_ActionDrawLineRectangle::commandEvent(RS_CommandEvent * e)
158 QString c = e->getCommand().toLower();
160 if (checkCommand("help", c))
162 if (RS_DIALOGFACTORY != NULL)
163 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
164 + getAvailableCommands().join(", "));
169 QStringList RS_ActionDrawLineRectangle::getAvailableCommands()
175 void RS_ActionDrawLineRectangle::updateMouseButtonHints()
177 if (RS_DIALOGFACTORY != NULL)
182 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
187 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
192 RS_DIALOGFACTORY->updateMouseWidget("", "");
198 void RS_ActionDrawLineRectangle::updateMouseCursor()
200 graphicView->setMouseCursor(RS2::CadCursor);
203 void RS_ActionDrawLineRectangle::updateToolBar()
205 if (RS_DIALOGFACTORY != NULL)
208 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
210 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);