1 // 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 "actiondrawlinerectangle.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 ActionDrawLineRectangle::ActionDrawLineRectangle(
23 RS_EntityContainer & container, GraphicView & graphicView):
24 ActionInterface("Draw rectangles", container, graphicView)
29 ActionDrawLineRectangle::~ActionDrawLineRectangle()
33 void ActionDrawLineRectangle::reset()
35 for(int i=0; i<4; i++)
36 data[i] = RS_LineData(Vector(false), Vector(false));
39 void ActionDrawLineRectangle::init(int status)
41 ActionInterface::init(status);
45 void ActionDrawLineRectangle::trigger()
47 ActionInterface::trigger();
52 // create and add rectangle:
53 for(int i=0; i<4; i++)
55 line[i] = new RS_Line(container, data[i]);
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]);
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("ActionDrawLineRectangle::trigger(): line added: %d",
82 graphicView->moveRelativeZero(corner2);
85 void ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent * e)
87 RS_DEBUG->print("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]));
105 RS_DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent end");
108 void 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 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 ActionDrawLineRectangle::coordinateEvent(Vector * e)
142 graphicView->moveRelativeZero(mouse);
143 setStatus(SetCorner2);
149 setStatus(SetCorner1);
157 void 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 ActionDrawLineRectangle::getAvailableCommands()
176 void 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 ActionDrawLineRectangle::updateMouseCursor()
201 graphicView->setMouseCursor(RS2::CadCursor);
204 void ActionDrawLineRectangle::updateToolBar()
206 if (RS_DIALOGFACTORY != NULL)
209 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
211 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);