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_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawLineRectangle::RS_ActionDrawLineRectangle(
23 RS_EntityContainer & container, GraphicView & graphicView):
24 RS_PreviewActionInterface("Draw rectangles", container, graphicView)
29 RS_ActionDrawLineRectangle::~RS_ActionDrawLineRectangle()
33 void RS_ActionDrawLineRectangle::reset()
35 for (int i = 0; i < 4; ++i)
36 data[i] = RS_LineData(Vector(false), Vector(false));
39 void RS_ActionDrawLineRectangle::init(int status)
41 RS_PreviewActionInterface::init(status);
45 void RS_ActionDrawLineRectangle::trigger()
47 RS_PreviewActionInterface::trigger();
52 // create and add rectangle:
53 for (int i = 0; i < 4; ++i)
55 line[i] = new RS_Line(container,
57 line[i]->setLayerToActive();
58 line[i]->setPenToActive();
59 container->addEntity(line[i]);
65 document->startUndoCycle();
67 for (int i = 0; i < 4; ++i)
68 document->addUndoable(line[i]);
69 document->endUndoCycle();
74 graphicView->moveRelativeZero(Vector(0.0, 0.0));
76 for (int i = 0; i < 4; ++i)
78 graphicView->drawEntity(line[i]);
79 RS_DEBUG->print("RS_ActionDrawLineRectangle::trigger():"
83 graphicView->moveRelativeZero(corner2);
86 void RS_ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent * e)
88 RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent begin");
90 Vector mouse = snapPoint(e);
92 if (getStatus() == SetCorner2 && corner1.valid)
100 for (int i = 0; i < 4; ++i)
101 preview->addEntity(new RS_Line(preview, data[i]));
105 RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent end");
108 void RS_ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent * e)
110 if (e->button() == Qt::LeftButton)
112 Vector ce(snapPoint(e));
113 coordinateEvent(&ce);
115 else if (e->button() == Qt::RightButton)
119 init(getStatus() - 1);
123 void RS_ActionDrawLineRectangle::preparePreview()
125 data[0] = RS_LineData(corner1, Vector(corner2.x, corner1.y));
126 data[1] = RS_LineData(Vector(corner2.x, corner1.y), corner2);
127 data[2] = RS_LineData(corner2, Vector(corner1.x, corner2.y));
128 data[3] = RS_LineData(Vector(corner1.x, corner2.y), corner1);
131 void RS_ActionDrawLineRectangle::coordinateEvent(Vector * e)
142 graphicView->moveRelativeZero(mouse);
143 setStatus(SetCorner2);
149 setStatus(SetCorner1);
157 void RS_ActionDrawLineRectangle::commandEvent(RS_CommandEvent * e)
159 QString c = e->getCommand().toLower();
161 if (checkCommand("help", c))
163 if (RS_DIALOGFACTORY != NULL)
164 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
165 + getAvailableCommands().join(", "));
170 QStringList RS_ActionDrawLineRectangle::getAvailableCommands()
176 void RS_ActionDrawLineRectangle::updateMouseButtonHints()
178 if (RS_DIALOGFACTORY != NULL)
183 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
188 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
193 RS_DIALOGFACTORY->updateMouseWidget("", "");
199 void RS_ActionDrawLineRectangle::updateMouseCursor()
201 graphicView->setMouseCursor(RS2::CadCursor);
204 void RS_ActionDrawLineRectangle::updateToolBar()
206 if (RS_DIALOGFACTORY != NULL)
209 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
211 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);