1 // actiondrawlinepolygon.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 "actiondrawlinepolygon.h"
19 #include "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawLinePolygon::ActionDrawLinePolygon(EntityContainer & container,
27 GraphicView & graphicView): ActionInterface("Draw Polygons",
28 container, graphicView)
30 center = Vector(false);
31 corner = Vector(false);
36 ActionDrawLinePolygon::~ActionDrawLinePolygon()
40 /*virtual*/ RS2::ActionType ActionDrawLinePolygon::rtti()
42 return RS2::ActionDrawLinePolygon;
45 void ActionDrawLinePolygon::trigger()
47 ActionInterface::trigger();
53 Creation creation(container, graphicView);
54 bool ok = creation.createPolygon(center, corner, number);
57 DEBUG->print("ActionDrawLinePolygon::trigger: No polygon added\n");
60 void ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent * e)
62 DEBUG->print("ActionDrawLinePolygon::mouseMoveEvent begin");
64 Vector mouse = snapPoint(e);
79 // Creation creation(preview, NULL, false);
80 // creation.createPolygon(center, corner, number);
91 void ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent * e)
93 if (e->button() == Qt::LeftButton)
95 Vector ce(snapPoint(e));
98 else if (e->button() == Qt::RightButton)
103 init(getStatus() - 1);
107 void ActionDrawLinePolygon::coordinateEvent(Vector * e)
118 setStatus(SetCorner);
119 graphicView->moveRelativeZero(mouse);
132 void ActionDrawLinePolygon::updateMouseButtonHints()
134 if (DIALOGFACTORY != NULL)
139 DIALOGFACTORY->updateMouseWidget(tr("Specify center"),
144 DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), "");
148 DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
152 DIALOGFACTORY->updateMouseWidget("", "");
158 void ActionDrawLinePolygon::showOptions()
160 ActionInterface::showOptions();
162 if (DIALOGFACTORY != NULL)
163 DIALOGFACTORY->requestOptions(this, true);
166 void ActionDrawLinePolygon::hideOptions()
168 ActionInterface::hideOptions();
170 if (DIALOGFACTORY != NULL)
171 DIALOGFACTORY->requestOptions(this, false);
174 void ActionDrawLinePolygon::commandEvent(CommandEvent * e)
176 QString c = e->getCommand().toLower();
178 if (checkCommand("help", c))
180 if (DIALOGFACTORY != NULL)
181 DIALOGFACTORY->commandMessage(msgAvailableCommands()
182 + getAvailableCommands().join(", "));
191 if (checkCommand("number", c))
196 lastStatus = (Status)getStatus();
197 setStatus(SetNumber);
203 int n = c.toInt(&ok);
207 if (n > 0 && n < 10000)
209 else if (DIALOGFACTORY != NULL)
210 DIALOGFACTORY->commandMessage(tr("Not a valid number. "
214 else if (DIALOGFACTORY != NULL)
215 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
217 if (DIALOGFACTORY != NULL)
218 DIALOGFACTORY->requestOptions(this, true, true);
219 setStatus(lastStatus);
228 QStringList ActionDrawLinePolygon::getAvailableCommands()
236 cmd += command("number");
246 void ActionDrawLinePolygon::updateMouseCursor()
248 graphicView->setMouseCursor(RS2::CadCursor);
251 void ActionDrawLinePolygon::updateToolBar()
253 if (DIALOGFACTORY != NULL)
256 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
258 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
262 int ActionDrawLinePolygon::getNumber()
267 void ActionDrawLinePolygon::setNumber(int n)