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/03/2010 Added this text. :-)
17 #include "actiondimleader.h"
19 #include "rs_commandevent.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDimLeader::ActionDimLeader(RS_EntityContainer & container, GraphicView & graphicView):
26 ActionInterface("Draw leaders", container, graphicView)
31 ActionDimLeader::~ActionDimLeader()
35 /*virtual*/ RS2::ActionType ActionDimLeader::rtti()
37 return RS2::ActionDimLeader;
40 void ActionDimLeader::reset()
42 //data = RS_LineData(Vector(false), Vector(false));
43 //start = Vector(false);
48 void ActionDimLeader::init(int status)
50 ActionInterface::init(status);
55 void ActionDimLeader::trigger()
57 ActionInterface::trigger();
59 if (points.count() > 0)
61 RS_Leader * leader = new RS_Leader(container, RS_LeaderData(true));
62 leader->setLayerToActive();
63 leader->setPenToActive();
65 // for(Vector * v=points.first(); v!=NULL; v=points.next())
66 // leader->addVertex(*v);
67 for (int i = 0; i < points.size(); i++)
68 leader->addVertex(*(points[i]));
70 container->addEntity(leader);
75 document->startUndoCycle();
76 document->addUndoable(leader);
77 document->endUndoCycle();
83 Vector rz = graphicView->getRelativeZero();
84 graphicView->moveRelativeZero(Vector(0.0, 0.0));
85 graphicView->drawEntity(leader);
86 graphicView->moveRelativeZero(rz);
89 RS_DEBUG->print("ActionDimLeader::trigger(): leader added: %d", leader->getId());
93 void ActionDimLeader::mouseMoveEvent(QMouseEvent * e)
95 RS_DEBUG->print("ActionDimLeader::mouseMoveEvent begin");
97 Vector mouse = snapPoint(e);
99 if (getStatus() == SetEndpoint && points.last() != NULL)
104 // fill in lines that were already set:
107 for(int i=0; i<points.size(); i++)
109 Vector * v = points[i];
112 // preview->addEntity(new RS_Line(preview, RS_LineData(last, *v)));
117 Vector p = *points.last();
118 // preview->addEntity(new RS_Line(preview, RS_LineData(p, mouse)));
122 RS_DEBUG->print("ActionDimLeader::mouseMoveEvent end");
125 void ActionDimLeader::mouseReleaseEvent(QMouseEvent * e)
127 if (e->button() == Qt::LeftButton)
129 Vector ce(snapPoint(e));
130 coordinateEvent(&ce);
132 else if (e->button() == Qt::RightButton)
134 if (getStatus() == SetEndpoint)
138 setStatus(SetStartpoint);
144 init(getStatus() - 1);
149 void ActionDimLeader::keyPressEvent(QKeyEvent * e)
151 if (getStatus() == SetEndpoint && e->key() == Qt::Key_Enter)
155 setStatus(SetStartpoint);
159 void ActionDimLeader::coordinateEvent(Vector * e)
169 //data.startpoint = mouse;
171 points.append(new Vector(mouse));
172 //start = data.startpoint;
173 setStatus(SetEndpoint);
174 graphicView->moveRelativeZero(mouse);
178 //data.endpoint = mouse;
179 points.append(new Vector(mouse));
181 //data.startpoint = data.endpoint;
182 graphicView->moveRelativeZero(mouse);
190 void ActionDimLeader::commandEvent(RS_CommandEvent * e)
192 QString c = e->getCommand().toLower();
194 if (checkCommand("help", c))
196 if (RS_DIALOGFACTORY != NULL)
197 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
198 + getAvailableCommands().join(", "));
208 setStatus(SetStartpoint);
213 QStringList ActionDimLeader::getAvailableCommands()
220 void ActionDimLeader::updateMouseButtonHints()
222 if (RS_DIALOGFACTORY != NULL)
227 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Cancel"));
231 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Finish"));
235 RS_DIALOGFACTORY->updateMouseWidget("", "");
241 void ActionDimLeader::showOptions()
243 ActionInterface::showOptions();
246 void ActionDimLeader::hideOptions()
248 ActionInterface::hideOptions();
251 void ActionDimLeader::updateMouseCursor()
253 graphicView->setMouseCursor(RS2::CadCursor);
256 void ActionDimLeader::updateToolBar()
258 if (RS_DIALOGFACTORY)
261 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
263 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);