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_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDimLeader::RS_ActionDimLeader(RS_EntityContainer & container, GraphicView & graphicView):
23 RS_PreviewActionInterface("Draw leaders", container, graphicView)
28 RS_ActionDimLeader::~RS_ActionDimLeader()
32 /*virtual*/ RS2::ActionType RS_ActionDimLeader::rtti()
34 return RS2::ActionDimLeader;
37 void RS_ActionDimLeader::reset()
39 //data = RS_LineData(Vector(false), Vector(false));
40 //start = Vector(false);
45 void RS_ActionDimLeader::init(int status)
47 RS_PreviewActionInterface::init(status);
52 void RS_ActionDimLeader::trigger()
54 RS_PreviewActionInterface::trigger();
56 if (points.count() > 0)
58 RS_Leader * leader = new RS_Leader(container, RS_LeaderData(true));
59 leader->setLayerToActive();
60 leader->setPenToActive();
62 // for(Vector * v=points.first(); v!=NULL; v=points.next())
63 // leader->addVertex(*v);
64 for (int i = 0; i < points.size(); i++)
65 leader->addVertex(*(points[i]));
67 container->addEntity(leader);
72 document->startUndoCycle();
73 document->addUndoable(leader);
74 document->endUndoCycle();
80 Vector rz = graphicView->getRelativeZero();
81 graphicView->moveRelativeZero(Vector(0.0, 0.0));
82 graphicView->drawEntity(leader);
83 graphicView->moveRelativeZero(rz);
86 RS_DEBUG->print("RS_ActionDimLeader::trigger(): leader added: %d", leader->getId());
90 void RS_ActionDimLeader::mouseMoveEvent(QMouseEvent * e)
92 RS_DEBUG->print("RS_ActionDimLeader::mouseMoveEvent begin");
94 Vector mouse = snapPoint(e);
96 if (getStatus() == SetEndpoint && points.last() != NULL)
101 // fill in lines that were already set:
104 // for(Vector * v=points.first(); v!=NULL; v=points.next())
105 for (int i = 0; i < points.size(); i++)
107 Vector * v = points[i];
110 preview->addEntity(new RS_Line(preview, RS_LineData(last, *v)));
115 Vector p = *points.last();
116 preview->addEntity(new RS_Line(preview, RS_LineData(p, mouse)));
120 RS_DEBUG->print("RS_ActionDimLeader::mouseMoveEvent end");
123 void RS_ActionDimLeader::mouseReleaseEvent(QMouseEvent * e)
125 if (e->button() == Qt::LeftButton)
127 Vector ce(snapPoint(e));
128 coordinateEvent(&ce);
130 else if (e->button() == Qt::RightButton)
132 if (getStatus() == SetEndpoint)
136 setStatus(SetStartpoint);
142 init(getStatus() - 1);
147 void RS_ActionDimLeader::keyPressEvent(QKeyEvent * e)
149 if (getStatus() == SetEndpoint && e->key() == Qt::Key_Enter)
153 setStatus(SetStartpoint);
157 void RS_ActionDimLeader::coordinateEvent(Vector * e)
167 //data.startpoint = mouse;
169 points.append(new Vector(mouse));
170 //start = data.startpoint;
171 setStatus(SetEndpoint);
172 graphicView->moveRelativeZero(mouse);
176 //data.endpoint = mouse;
177 points.append(new Vector(mouse));
179 //data.startpoint = data.endpoint;
180 graphicView->moveRelativeZero(mouse);
188 void RS_ActionDimLeader::commandEvent(RS_CommandEvent * e)
190 QString c = e->getCommand().toLower();
192 if (checkCommand("help", c))
194 if (RS_DIALOGFACTORY != NULL)
195 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
196 + getAvailableCommands().join(", "));
206 setStatus(SetStartpoint);
211 QStringList RS_ActionDimLeader::getAvailableCommands()
218 void RS_ActionDimLeader::updateMouseButtonHints()
220 if (RS_DIALOGFACTORY != NULL)
225 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Cancel"));
229 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Finish"));
233 RS_DIALOGFACTORY->updateMouseWidget("", "");
239 void RS_ActionDimLeader::showOptions()
241 RS_ActionInterface::showOptions();
243 //RS_DIALOGFACTORY->requestOptions(this, true);
246 void RS_ActionDimLeader::hideOptions()
248 RS_ActionInterface::hideOptions();
250 //RS_DIALOGFACTORY->requestOptions(this, false);
253 void RS_ActionDimLeader::updateMouseCursor()
255 graphicView->setMouseCursor(RS2::CadCursor);
258 void RS_ActionDimLeader::updateToolBar()
260 if (RS_DIALOGFACTORY != NULL)
263 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
265 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);