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"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 ActionDimLeader::ActionDimLeader(RS_EntityContainer & container, GraphicView & graphicView):
25 ActionInterface("Draw leaders", container, graphicView)
30 ActionDimLeader::~ActionDimLeader()
34 /*virtual*/ RS2::ActionType ActionDimLeader::rtti()
36 return RS2::ActionDimLeader;
39 void ActionDimLeader::reset()
41 //data = RS_LineData(Vector(false), Vector(false));
42 //start = Vector(false);
47 void ActionDimLeader::init(int status)
49 ActionInterface::init(status);
54 void ActionDimLeader::trigger()
56 ActionInterface::trigger();
58 if (points.count() > 0)
60 RS_Leader * leader = new RS_Leader(container, RS_LeaderData(true));
61 leader->setLayerToActive();
62 leader->setPenToActive();
64 // for(Vector * v=points.first(); v!=NULL; v=points.next())
65 // leader->addVertex(*v);
66 for (int i = 0; i < points.size(); i++)
67 leader->addVertex(*(points[i]));
69 container->addEntity(leader);
74 document->startUndoCycle();
75 document->addUndoable(leader);
76 document->endUndoCycle();
82 Vector rz = graphicView->getRelativeZero();
83 graphicView->moveRelativeZero(Vector(0.0, 0.0));
84 graphicView->drawEntity(leader);
85 graphicView->moveRelativeZero(rz);
88 RS_DEBUG->print("ActionDimLeader::trigger(): leader added: %d", leader->getId());
92 void ActionDimLeader::mouseMoveEvent(QMouseEvent * e)
94 RS_DEBUG->print("ActionDimLeader::mouseMoveEvent begin");
96 Vector mouse = snapPoint(e);
98 if (getStatus() == SetEndpoint && points.last() != NULL)
103 // fill in lines that were already set:
106 for(int i=0; i<points.size(); i++)
108 Vector * v = points[i];
111 // preview->addEntity(new RS_Line(preview, RS_LineData(last, *v)));
116 Vector p = *points.last();
117 // preview->addEntity(new RS_Line(preview, RS_LineData(p, mouse)));
121 RS_DEBUG->print("ActionDimLeader::mouseMoveEvent end");
124 void ActionDimLeader::mouseReleaseEvent(QMouseEvent * e)
126 if (e->button() == Qt::LeftButton)
128 Vector ce(snapPoint(e));
129 coordinateEvent(&ce);
131 else if (e->button() == Qt::RightButton)
133 if (getStatus() == SetEndpoint)
137 setStatus(SetStartpoint);
143 init(getStatus() - 1);
148 void ActionDimLeader::keyPressEvent(QKeyEvent * e)
150 if (getStatus() == SetEndpoint && e->key() == Qt::Key_Enter)
154 setStatus(SetStartpoint);
158 void ActionDimLeader::coordinateEvent(Vector * e)
168 //data.startpoint = mouse;
170 points.append(new Vector(mouse));
171 //start = data.startpoint;
172 setStatus(SetEndpoint);
173 graphicView->moveRelativeZero(mouse);
177 //data.endpoint = mouse;
178 points.append(new Vector(mouse));
180 //data.startpoint = data.endpoint;
181 graphicView->moveRelativeZero(mouse);
189 void ActionDimLeader::commandEvent(RS_CommandEvent * e)
191 QString c = e->getCommand().toLower();
193 if (checkCommand("help", c))
195 if (RS_DIALOGFACTORY != NULL)
196 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
197 + getAvailableCommands().join(", "));
207 setStatus(SetStartpoint);
212 QStringList ActionDimLeader::getAvailableCommands()
219 void ActionDimLeader::updateMouseButtonHints()
221 if (RS_DIALOGFACTORY != NULL)
226 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Cancel"));
230 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Finish"));
234 RS_DIALOGFACTORY->updateMouseWidget("", "");
240 void ActionDimLeader::showOptions()
242 ActionInterface::showOptions();
245 void ActionDimLeader::hideOptions()
247 ActionInterface::hideOptions();
250 void ActionDimLeader::updateMouseCursor()
252 graphicView->setMouseCursor(RS2::CadCursor);
255 void ActionDimLeader::updateToolBar()
257 if (RS_DIALOGFACTORY)
260 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
262 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);