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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actiondrawlinerectangle.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 ActionDrawLineRectangle::ActionDrawLineRectangle(
25 RS_EntityContainer & container, GraphicView & graphicView):
26 ActionInterface("Draw rectangles", container, graphicView)
31 ActionDrawLineRectangle::~ActionDrawLineRectangle()
35 void ActionDrawLineRectangle::reset()
37 for(int i=0; i<4; i++)
38 data[i] = RS_LineData(Vector(false), Vector(false));
41 void ActionDrawLineRectangle::init(int status)
43 ActionInterface::init(status);
47 void ActionDrawLineRectangle::trigger()
49 ActionInterface::trigger();
54 // create and add rectangle:
55 for(int i=0; i<4; i++)
57 line[i] = new RS_Line(container, data[i]);
58 line[i]->setLayerToActive();
59 line[i]->setPenToActive();
60 container->addEntity(line[i]);
66 document->startUndoCycle();
68 for(int i=0; i<4; i++)
69 document->addUndoable(line[i]);
71 document->endUndoCycle();
76 graphicView->moveRelativeZero(Vector(0.0, 0.0));
78 for(int i=0; i<4; i++)
80 graphicView->drawEntity(line[i]);
81 RS_DEBUG->print("ActionDrawLineRectangle::trigger(): line added: %d",
84 graphicView->moveRelativeZero(corner2);
87 void ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent * e)
89 RS_DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent begin");
91 Vector mouse = snapPoint(e);
93 if (getStatus() == SetCorner2 && corner1.valid)
101 // for(int i=0; i<4; i++)
102 // preview->addEntity(new RS_Line(preview, data[i]));
107 RS_DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent end");
110 void ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent * e)
112 if (e->button() == Qt::LeftButton)
114 Vector ce(snapPoint(e));
115 coordinateEvent(&ce);
117 else if (e->button() == Qt::RightButton)
121 init(getStatus() - 1);
125 void ActionDrawLineRectangle::preparePreview()
127 data[0] = RS_LineData(corner1, Vector(corner2.x, corner1.y));
128 data[1] = RS_LineData(Vector(corner2.x, corner1.y), corner2);
129 data[2] = RS_LineData(corner2, Vector(corner1.x, corner2.y));
130 data[3] = RS_LineData(Vector(corner1.x, corner2.y), corner1);
133 void ActionDrawLineRectangle::coordinateEvent(Vector * e)
144 graphicView->moveRelativeZero(mouse);
145 setStatus(SetCorner2);
151 setStatus(SetCorner1);
159 void ActionDrawLineRectangle::commandEvent(RS_CommandEvent * e)
161 QString c = e->getCommand().toLower();
163 if (checkCommand("help", c))
165 if (RS_DIALOGFACTORY != NULL)
166 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
167 + getAvailableCommands().join(", "));
172 QStringList ActionDrawLineRectangle::getAvailableCommands()
178 void ActionDrawLineRectangle::updateMouseButtonHints()
180 if (RS_DIALOGFACTORY != NULL)
185 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
190 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
195 RS_DIALOGFACTORY->updateMouseWidget("", "");
201 void ActionDrawLineRectangle::updateMouseCursor()
203 graphicView->setMouseCursor(RS2::CadCursor);
206 void ActionDrawLineRectangle::updateToolBar()
208 if (RS_DIALOGFACTORY != NULL)
211 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
213 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);