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 "actiondimleader.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 ActionDimLeader::ActionDimLeader(RS_EntityContainer & container, GraphicView & graphicView):
23 ActionInterface("Draw leaders", container, graphicView)
28 ActionDimLeader::~ActionDimLeader()
32 /*virtual*/ RS2::ActionType ActionDimLeader::rtti()
34 return RS2::ActionDimLeader;
37 void ActionDimLeader::reset()
39 //data = RS_LineData(Vector(false), Vector(false));
40 //start = Vector(false);
45 void ActionDimLeader::init(int status)
47 ActionInterface::init(status);
52 void ActionDimLeader::trigger()
54 ActionInterface::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("ActionDimLeader::trigger(): leader added: %d", leader->getId());
90 void ActionDimLeader::mouseMoveEvent(QMouseEvent * e)
92 RS_DEBUG->print("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(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("ActionDimLeader::mouseMoveEvent end");
122 void 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 ActionDimLeader::keyPressEvent(QKeyEvent * e)
148 if (getStatus() == SetEndpoint && e->key() == Qt::Key_Enter)
152 setStatus(SetStartpoint);
156 void 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 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 ActionDimLeader::getAvailableCommands()
217 void 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 ActionDimLeader::showOptions()
240 ActionInterface::showOptions();
243 void ActionDimLeader::hideOptions()
245 ActionInterface::hideOptions();
248 void ActionDimLeader::updateMouseCursor()
250 graphicView->setMouseCursor(RS2::CadCursor);
253 void ActionDimLeader::updateToolBar()
255 if (RS_DIALOGFACTORY)
258 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
260 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);