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 void ActionDrawPolyline::trigger()
40 container->addEntity(polyline);
45 document->startUndoCycle();
46 document->addUndoable(polyline);
47 document->endUndoCycle();
50 DEBUG->print("ActionDrawPolyline::trigger(): polyline added: %d", polyline->getId());
55 void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e)
57 if (vertex.valid && polyline)
59 Vector v = snapPoint(e);
60 Entity * ent = polyline->addVertex(v);
61 ent->setLayerToActive();
62 ent->setPenToActive();
65 // graphicView->drawEntity(ent);
69 DEBUG->print("ActionDrawPolyline::mouseMoveEvent(): line added: %d", ent->getId());
73 void ActionDrawPolyline::mousePressEvent(QMouseEvent * e)
75 if (e->button() == Qt::LeftButton)
77 vertex = snapPoint(e);
78 polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
79 polyline->setLayerToActive();
80 polyline->setPenToActive();
84 void ActionDrawPolyline::mouseReleaseEvent(QMouseEvent * e)
86 if (e->button() == Qt::LeftButton)
88 vertex = Vector(false);
91 else if (e->button() == Qt::RightButton)
100 init(getStatus() - 1);
101 graphicView->redraw(); //hm.
105 void ActionDrawPolyline::updateMouseButtonHints()
110 DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
114 DIALOGFACTORY->updateMouseWidget("", "");
119 void ActionDrawPolyline::updateMouseCursor()
121 graphicView->setMouseCursor(RS2::CadCursor);
124 void ActionDrawPolyline::updateToolBar()
127 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
129 DIALOGFACTORY->requestToolBar(RS2::ToolBarPolylines);
132 void ActionDrawPolyline::close()
135 //NOTE: We should grey out the "close" button until the conditions for its use are satisfied.
136 // Though I can see how this would be called via cmd line... So I guess it's OK
137 if (history.count() > 2 && start.valid)
139 data.endpoint = start;
141 setStatus(SetFirstPoint);
142 graphicView->moveRelativeZero(start);
145 DIALOGFACTORY->commandMessage(tr("Cannot close sequence of lines: Not enough entities defined yet."));
147 DIALOGFACTORY->commandMessage(tr("Close functionality not defined yet..."));
151 void ActionDrawPolyline::undo()
154 //NOTE: We should grey out the "undo" button until the conditions for its use are satisfied.
155 if (history.count() > 1)
157 history.removeLast();
158 graphicView->setCurrentAction(new ActionEditUndo(true, *container, *graphicView));
159 data.startpoint = *history.last();
160 graphicView->moveRelativeZero(data.startpoint);
161 graphicView->preview.clear();
162 graphicView->redraw();
165 DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet."));
167 DIALOGFACTORY->commandMessage(tr("Undo functionality not defined yet..."));