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. :-)
15 // JLH 09/11/2010 Fixed preview/snapper rendering.
18 #include "actiondimleader.h"
20 #include "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDimLeader::ActionDimLeader(EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Draw leaders", container, graphicView)
32 ActionDimLeader::~ActionDimLeader()
36 /*virtual*/ RS2::ActionType ActionDimLeader::rtti()
38 return RS2::ActionDimLeader;
41 void ActionDimLeader::reset()
46 void ActionDimLeader::init(int status)
48 ActionInterface::init(status);
53 void ActionDimLeader::trigger()
55 ActionInterface::trigger();
57 if (points.count() > 0)
59 Leader * leader = new Leader(container, LeaderData(true));
60 leader->setLayerToActive();
61 leader->setPenToActive();
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);
83 graphicView->preview.clear(); //hm.
84 graphicView->redraw();
86 DEBUG->print("ActionDimLeader::trigger(): leader added: %d", leader->getId());
90 void ActionDimLeader::mouseMoveEvent(QMouseEvent * e)
92 DEBUG->print("ActionDimLeader::mouseMoveEvent begin");
94 Vector mouse = snapPoint(e);
96 if (getStatus() == SetEndpoint && points.last() != NULL)
100 graphicView->preview.clear();
102 // fill in lines that were already set:
105 for(int i=0; i<points.size(); i++)
107 Vector * v = points[i];
110 // preview->addEntity(new Line(preview, LineData(last, *v)));
112 graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(last, *v)));
117 Vector p = *points.last();
118 // preview->addEntity(new Line(preview, LineData(p, mouse)));
120 graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(p, mouse)));
123 graphicView->redraw();
125 DEBUG->print("ActionDimLeader::mouseMoveEvent end");
128 void ActionDimLeader::mouseReleaseEvent(QMouseEvent * e)
130 if (e->button() == Qt::LeftButton)
132 Vector ce(snapPoint(e));
133 coordinateEvent(&ce);
135 else if (e->button() == Qt::RightButton)
137 if (getStatus() == SetEndpoint)
141 setStatus(SetStartpoint);
147 init(getStatus() - 1);
148 graphicView->redraw(); //hm.
153 void ActionDimLeader::keyPressEvent(QKeyEvent * e)
155 if (getStatus() == SetEndpoint && e->key() == Qt::Key_Enter)
159 setStatus(SetStartpoint);
163 void ActionDimLeader::coordinateEvent(Vector * e)
173 //data.startpoint = mouse;
175 points.append(new Vector(mouse));
176 //start = data.startpoint;
177 setStatus(SetEndpoint);
178 graphicView->moveRelativeZero(mouse);
182 //data.endpoint = mouse;
183 points.append(new Vector(mouse));
185 //data.startpoint = data.endpoint;
186 graphicView->moveRelativeZero(mouse);
194 void ActionDimLeader::commandEvent(CommandEvent * e)
196 QString c = e->getCommand().toLower();
198 if (checkCommand("help", c))
201 DIALOGFACTORY->commandMessage(msgAvailableCommands()
202 + getAvailableCommands().join(", "));
212 setStatus(SetStartpoint);
217 QStringList ActionDimLeader::getAvailableCommands()
224 void ActionDimLeader::updateMouseButtonHints()
226 if (DIALOGFACTORY != NULL)
231 DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Cancel"));
235 DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Finish"));
239 DIALOGFACTORY->updateMouseWidget("", "");
245 void ActionDimLeader::showOptions()
247 ActionInterface::showOptions();
250 void ActionDimLeader::hideOptions()
252 ActionInterface::hideOptions();
255 void ActionDimLeader::updateMouseCursor()
257 graphicView->setMouseCursor(RS2::CadCursor);
260 void ActionDimLeader::updateToolBar()
265 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
267 DIALOGFACTORY->requestToolBar(RS2::ToolBarDim);