1 // 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 // 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/04/2010 Added this text. :-)
17 #include "actiondrawlinefree.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_polyline.h"
23 ActionDrawLineFree::ActionDrawLineFree(RS_EntityContainer & container,
24 GraphicView & graphicView): ActionInterface("Draw freehand lines",
25 container, graphicView)
27 vertex = Vector(false);
31 ActionDrawLineFree::~ActionDrawLineFree()
37 void ActionDrawLineFree::trigger()
41 container->addEntity(polyline);
46 document->startUndoCycle();
47 document->addUndoable(polyline);
48 document->endUndoCycle();
51 RS_DEBUG->print("ActionDrawLineFree::trigger():"
52 " polyline added: %d", polyline->getId());
57 void ActionDrawLineFree::mouseMoveEvent(QMouseEvent * e)
59 if (vertex.valid && polyline)
61 Vector v = snapPoint(e);
62 RS_Entity * ent = polyline->addVertex(v);
63 ent->setLayerToActive();
64 ent->setPenToActive();
67 graphicView->drawEntity(ent);
72 RS_DEBUG->print("ActionDrawLineFree::mouseMoveEvent():"
73 " line added: %d", ent->getId());
77 void ActionDrawLineFree::mousePressEvent(QMouseEvent * e)
79 if (e->button() == Qt::LeftButton)
81 vertex = snapPoint(e);
82 polyline = new RS_Polyline(container, RS_PolylineData(vertex, vertex, 0));
83 polyline->setLayerToActive();
84 polyline->setPenToActive();
88 void ActionDrawLineFree::mouseReleaseEvent(QMouseEvent * e)
90 if (e->button() == Qt::LeftButton)
92 vertex = Vector(false);
95 else if (e->button() == Qt::RightButton)
104 init(getStatus() - 1);
108 void ActionDrawLineFree::updateMouseButtonHints()
113 RS_DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
117 RS_DIALOGFACTORY->updateMouseWidget("", "");
122 void ActionDrawLineFree::updateMouseCursor()
124 graphicView->setMouseCursor(RS2::CadCursor);
127 void ActionDrawLineFree::updateToolBar()
130 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
132 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);