1 // rs_actiondimleader.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/03/2010 Added this text. :-)
15 #include "rs_actiondimleader.h"
17 #include "rs_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
21 RS_ActionDimLeader::RS_ActionDimLeader(RS_EntityContainer & container, RS_GraphicView & graphicView):
22 RS_PreviewActionInterface("Draw leaders", container, graphicView)
27 RS_ActionDimLeader::~RS_ActionDimLeader()
31 /*virtual*/ RS2::ActionType RS_ActionDimLeader::rtti()
33 return RS2::ActionDimLeader;
36 void RS_ActionDimLeader::reset()
38 //data = RS_LineData(Vector(false), Vector(false));
39 //start = Vector(false);
44 void RS_ActionDimLeader::init(int status)
46 RS_PreviewActionInterface::init(status);
51 void RS_ActionDimLeader::trigger()
53 RS_PreviewActionInterface::trigger();
55 if (points.count() > 0)
57 RS_Leader * leader = new RS_Leader(container, RS_LeaderData(true));
58 leader->setLayerToActive();
59 leader->setPenToActive();
61 // for(Vector * v=points.first(); v!=NULL; v=points.next())
62 // leader->addVertex(*v);
63 for (int i = 0; i < points.size(); i++)
64 leader->addVertex(*(points[i]));
66 container->addEntity(leader);
71 document->startUndoCycle();
72 document->addUndoable(leader);
73 document->endUndoCycle();
79 Vector rz = graphicView->getRelativeZero();
80 graphicView->moveRelativeZero(Vector(0.0, 0.0));
81 graphicView->drawEntity(leader);
82 graphicView->moveRelativeZero(rz);
85 RS_DEBUG->print("RS_ActionDimLeader::trigger(): leader added: %d", leader->getId());
89 void RS_ActionDimLeader::mouseMoveEvent(QMouseEvent * e)
91 RS_DEBUG->print("RS_ActionDimLeader::mouseMoveEvent begin");
93 Vector mouse = snapPoint(e);
95 if (getStatus() == SetEndpoint && points.last() != NULL)
100 // fill in lines that were already set:
103 // for(Vector * v=points.first(); v!=NULL; v=points.next())
104 for (int i = 0; i < points.size(); i++)
106 Vector * v = points[i];
109 preview->addEntity(new RS_Line(preview, RS_LineData(last, *v)));
114 Vector p = *points.last();
115 preview->addEntity(new RS_Line(preview, RS_LineData(p, mouse)));
119 RS_DEBUG->print("RS_ActionDimLeader::mouseMoveEvent end");
122 void RS_ActionDimLeader::mouseReleaseEvent(QMouseEvent * e)
124 if (e->button() == Qt::LeftButton)
126 Vector ce(snapPoint(e));
127 coordinateEvent(&ce);
129 else if (e->button() == Qt::RightButton)
131 if (getStatus() == SetEndpoint)
135 setStatus(SetStartpoint);
141 init(getStatus() - 1);
146 void RS_ActionDimLeader::keyPressEvent(QKeyEvent * e)
148 if (getStatus() == SetEndpoint && e->key() == Qt::Key_Enter)
152 setStatus(SetStartpoint);
156 void RS_ActionDimLeader::coordinateEvent(Vector * e)
166 //data.startpoint = mouse;
168 points.append(new Vector(mouse));
169 //start = data.startpoint;
170 setStatus(SetEndpoint);
171 graphicView->moveRelativeZero(mouse);
175 //data.endpoint = mouse;
176 points.append(new Vector(mouse));
178 //data.startpoint = data.endpoint;
179 graphicView->moveRelativeZero(mouse);
187 void RS_ActionDimLeader::commandEvent(RS_CommandEvent * e)
189 QString c = e->getCommand().toLower();
191 if (checkCommand("help", c))
193 if (RS_DIALOGFACTORY != NULL)
194 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
195 + getAvailableCommands().join(", "));
205 setStatus(SetStartpoint);
210 QStringList RS_ActionDimLeader::getAvailableCommands()
217 void RS_ActionDimLeader::updateMouseButtonHints()
219 if (RS_DIALOGFACTORY != NULL)
224 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Cancel"));
228 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Finish"));
232 RS_DIALOGFACTORY->updateMouseWidget("", "");
238 void RS_ActionDimLeader::showOptions()
240 RS_ActionInterface::showOptions();
242 //RS_DIALOGFACTORY->requestOptions(this, true);
245 void RS_ActionDimLeader::hideOptions()
247 RS_ActionInterface::hideOptions();
249 //RS_DIALOGFACTORY->requestOptions(this, false);
252 void RS_ActionDimLeader::updateMouseCursor()
254 graphicView->setMouseCursor(RS2::CadCursor);
257 void RS_ActionDimLeader::updateToolBar()
259 if (RS_DIALOGFACTORY != NULL)
262 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
264 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);