1 // rs_actiondrawlineangle.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 05/22/2010 Added this text. :-)
15 #include "rs_actiondrawlineangle.h"
16 #include "rs_snapper.h"
18 RS_ActionDrawLineAngle::RS_ActionDrawLineAngle(RS_EntityContainer& container,
19 RS_GraphicView& graphicView,
22 :RS_PreviewActionInterface("Draw lines with given angle",
23 container, graphicView)
28 this->fixedAngle = fixedAngle;
33 RS_ActionDrawLineAngle::~RS_ActionDrawLineAngle()
37 QAction * RS_ActionDrawLineAngle::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
39 QAction * action = NULL;
41 if (type == RS2::ActionDrawLineAngle)
43 action = new QAction(tr("&Angle"), 0);
44 // action = new QAction(tr("Line: Angle"), tr("&Angle"),
45 // QKeySequence(), NULL);
46 action->setStatusTip(tr("Draw lines with a given angle"));
48 else if (type == RS2::ActionDrawLineHorizontal)
50 action = new QAction(tr("&Horizontal"), 0);
51 // action = new QAction(tr("Line: Horizontal"), tr("&Horizontal"),
52 // QKeySequence(), NULL);
53 action->setStatusTip(tr("Draw horizontal lines"));
55 else if (type == RS2::ActionDrawLineVertical)
57 action = new QAction(tr("H&orizontal / Vertical"), 0);
58 // action = new QAction(tr("hor./vert. line"), tr("H&orizontal / Vertical"),
59 // QKeySequence(), NULL);
60 action->setStatusTip(tr("Draw horizontal/vertical lines"));
66 void RS_ActionDrawLineAngle::reset()
68 data = RS_LineData(Vector(false), Vector(false));
73 void RS_ActionDrawLineAngle::init(int status) {
74 RS_PreviewActionInterface::init(status);
81 void RS_ActionDrawLineAngle::trigger() {
82 RS_PreviewActionInterface::trigger();
85 RS_Line* line = new RS_Line(container,
87 line->setLayerToActive();
88 line->setPenToActive();
89 container->addEntity(line);
93 document->startUndoCycle();
94 document->addUndoable(line);
95 document->endUndoCycle();
98 graphicView->moveRelativeZero(Vector(0.0,0.0));
99 graphicView->drawEntity(line);
100 graphicView->moveRelativeZero(data.startpoint);
101 RS_DEBUG->print("RS_ActionDrawLineAngle::trigger(): line added: %d",
107 void RS_ActionDrawLineAngle::mouseMoveEvent(QMouseEvent* e) {
108 RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent begin");
110 if (getStatus()==SetPos) {
115 preview->addEntity(new RS_Line(preview,
120 RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent end");
125 void RS_ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent* e) {
126 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
127 if (getStatus()==SetPos) {
128 RS_CoordinateEvent ce(snapPoint(e));
129 coordinateEvent(&ce);
131 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
139 void RS_ActionDrawLineAngle::preparePreview() {
143 p2.setPolar(length * -1, angle);
145 p2.setPolar(length, angle);
156 data = RS_LineData(p1, p2);
160 void RS_ActionDrawLineAngle::coordinateEvent(RS_CoordinateEvent* e) {
165 switch (getStatus()) {
167 pos = e->getCoordinate();
178 void RS_ActionDrawLineAngle::commandEvent(RS_CommandEvent* e) {
179 QString c = e->getCommand().toLower();
181 if (checkCommand("help", c)) {
182 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
183 + getAvailableCommands().join(", "));
187 switch (getStatus()) {
189 if (!fixedAngle && checkCommand("angle", c)) {
194 } else if (checkCommand("length", c)) {
198 setStatus(SetLength);
204 double a = RS_Math::eval(c, &ok);
206 angle = RS_Math::deg2rad(a);
208 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
210 RS_DIALOGFACTORY->requestOptions(this, true, true);
217 double l = RS_Math::eval(c, &ok);
221 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
223 RS_DIALOGFACTORY->requestOptions(this, true, true);
235 QStringList RS_ActionDrawLineAngle::getAvailableCommands() {
238 switch (getStatus()) {
241 cmd += command("angle");
243 cmd += command("length");
253 void RS_ActionDrawLineAngle::updateMouseButtonHints() {
254 switch (getStatus()) {
256 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
261 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
265 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
275 void RS_ActionDrawLineAngle::showOptions() {
276 RS_ActionInterface::showOptions();
278 RS_DIALOGFACTORY->requestOptions(this, true);
283 void RS_ActionDrawLineAngle::hideOptions() {
284 RS_ActionInterface::hideOptions();
286 RS_DIALOGFACTORY->requestOptions(this, false);
291 void RS_ActionDrawLineAngle::updateMouseCursor() {
292 graphicView->setMouseCursor(RS2::CadCursor);
297 void RS_ActionDrawLineAngle::updateToolBar() {
299 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
301 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);