1 // actiondrawpolyline.cpp
3 // Part of the Architektonas Project
5 // Copyright (C) 2010 Underground Software
6 // See the README and GPLv2 files for licensing and warranty information
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 09/13/2010 Created this file. :-)
15 #include "actiondrawpolyline.h"
18 #include "dialogfactory.h"
19 #include "graphicview.h"
22 ActionDrawPolyline::ActionDrawPolyline(EntityContainer & container,
23 GraphicView & graphicView):
24 ActionInterface("Draw polyline", container, graphicView)
26 vertex = Vector(false);
30 ActionDrawPolyline::~ActionDrawPolyline()
36 /*virtual*/ RS2::ActionType ActionDrawPolyline::rtti()
38 return RS2::ActionDrawPolyline;
41 void ActionDrawPolyline::trigger()
45 container->addEntity(polyline);
50 document->startUndoCycle();
51 document->addUndoable(polyline);
52 document->endUndoCycle();
55 DEBUG->print("ActionDrawPolyline::trigger(): polyline added: %d", polyline->getId());
60 void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e)
62 if (vertex.valid && polyline)
64 Vector v = snapPoint(e);
65 Entity * ent = polyline->addVertex(v);
66 ent->setLayerToActive();
67 ent->setPenToActive();
70 // graphicView->drawEntity(ent);
74 DEBUG->print("ActionDrawPolyline::mouseMoveEvent(): line added: %d", ent->getId());
78 void ActionDrawPolyline::mousePressEvent(QMouseEvent * e)
80 if (e->button() == Qt::LeftButton)
82 vertex = snapPoint(e);
83 polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
84 polyline->setLayerToActive();
85 polyline->setPenToActive();
89 void ActionDrawPolyline::mouseReleaseEvent(QMouseEvent * e)
91 if (e->button() == Qt::LeftButton)
93 vertex = Vector(false);
96 else if (e->button() == Qt::RightButton)
105 init(getStatus() - 1);
106 graphicView->redraw(); //hm.
110 void ActionDrawPolyline::updateMouseButtonHints()
115 DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
119 DIALOGFACTORY->updateMouseWidget("", "");
124 void ActionDrawPolyline::updateMouseCursor()
126 graphicView->setMouseCursor(RS2::CadCursor);
129 void ActionDrawPolyline::updateToolBar()
132 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
134 DIALOGFACTORY->requestToolBar(RS2::ToolBarPolylines);
137 void ActionDrawPolyline::showOptions()
139 DEBUG->print("ActionDrawPolyline::showOptions");
140 ActionInterface::showOptions();
141 DIALOGFACTORY->requestOptions(this, true);
142 DEBUG->print("ActionDrawPolyline::showOptions: OK");
145 void ActionDrawPolyline::hideOptions()
147 ActionInterface::hideOptions();
148 DIALOGFACTORY->requestOptions(this, false);
151 void ActionDrawPolyline::close()
154 //NOTE: We should grey out the "close" button until the conditions for its use are satisfied.
155 // Though I can see how this would be called via cmd line... So I guess it's OK
156 if (history.count() > 2 && start.valid)
158 data.endpoint = start;
160 setStatus(SetFirstPoint);
161 graphicView->moveRelativeZero(start);
164 DIALOGFACTORY->commandMessage(tr("Cannot close sequence of lines: Not enough entities defined yet."));
166 DIALOGFACTORY->commandMessage(tr("Close functionality not defined yet..."));
170 void ActionDrawPolyline::undo()
173 //NOTE: We should grey out the "undo" button until the conditions for its use are satisfied.
174 if (history.count() > 1)
176 history.removeLast();
177 graphicView->setCurrentAction(new ActionEditUndo(true, *container, *graphicView));
178 data.startpoint = *history.last();
179 graphicView->moveRelativeZero(data.startpoint);
180 graphicView->preview.clear();
181 graphicView->redraw();
184 DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet."));
186 DIALOGFACTORY->commandMessage(tr("Undo functionality not defined yet..."));