1 // rs_actiondrawlinefree.cpp
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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "rs_actiondrawlinefree.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_polyline.h"
21 RS_ActionDrawLineFree::RS_ActionDrawLineFree(RS_EntityContainer & container, GraphicView & graphicView): RS_ActionInterface("Draw freehand lines",
22 container, graphicView)
24 vertex = Vector(false);
28 RS_ActionDrawLineFree::~RS_ActionDrawLineFree()
34 void RS_ActionDrawLineFree::trigger()
38 container->addEntity(polyline);
43 document->startUndoCycle();
44 document->addUndoable(polyline);
45 document->endUndoCycle();
48 RS_DEBUG->print("RS_ActionDrawLineFree::trigger():"
49 " polyline added: %d", polyline->getId());
54 void RS_ActionDrawLineFree::mouseMoveEvent(QMouseEvent * e)
56 if (vertex.valid && polyline != NULL)
58 Vector v = snapPoint(e);
59 RS_Entity * ent = polyline->addVertex(v);
60 ent->setLayerToActive();
61 ent->setPenToActive();
64 graphicView->drawEntity(ent);
69 RS_DEBUG->print("RS_ActionDrawLineFree::mouseMoveEvent():"
70 " line added: %d", ent->getId());
74 void RS_ActionDrawLineFree::mousePressEvent(QMouseEvent * e)
76 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
77 if (e->button() == Qt::LeftButton)
79 vertex = snapPoint(e);
80 polyline = new RS_Polyline(container, RS_PolylineData(vertex, vertex, 0));
81 polyline->setLayerToActive();
82 polyline->setPenToActive();
84 //else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton && !vertex.valid) {
88 void RS_ActionDrawLineFree::mouseReleaseEvent(QMouseEvent * e)
90 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
91 if (e->button() == Qt::LeftButton)
93 vertex = Vector(false);
96 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
97 else if (e->button() == Qt::RightButton)
106 init(getStatus() - 1);
110 void RS_ActionDrawLineFree::updateMouseButtonHints()
115 RS_DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
119 RS_DIALOGFACTORY->updateMouseWidget("", "");
124 void RS_ActionDrawLineFree::updateMouseCursor()
126 graphicView->setMouseCursor(RS2::CadCursor);
129 void RS_ActionDrawLineFree::updateToolBar()
132 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
134 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);