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"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
24 ActionDrawLineFree::ActionDrawLineFree(EntityContainer & container,
25 GraphicView & graphicView): ActionInterface("Draw freehand lines",
26 container, graphicView)
28 vertex = Vector(false);
32 ActionDrawLineFree::~ActionDrawLineFree()
38 void ActionDrawLineFree::trigger()
42 container->addEntity(polyline);
47 document->startUndoCycle();
48 document->addUndoable(polyline);
49 document->endUndoCycle();
52 DEBUG->print("ActionDrawLineFree::trigger():"
53 " polyline added: %d", polyline->getId());
58 void ActionDrawLineFree::mouseMoveEvent(QMouseEvent * e)
60 if (vertex.valid && polyline)
62 Vector v = snapPoint(e);
63 Entity * ent = polyline->addVertex(v);
64 ent->setLayerToActive();
65 ent->setPenToActive();
68 graphicView->drawEntity(ent);
73 DEBUG->print("ActionDrawLineFree::mouseMoveEvent():"
74 " line added: %d", ent->getId());
78 void ActionDrawLineFree::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 ActionDrawLineFree::mouseReleaseEvent(QMouseEvent * e)
91 if (e->button() == Qt::LeftButton)
93 vertex = Vector(false);
96 else if (e->button() == Qt::RightButton)
105 init(getStatus() - 1);
109 void ActionDrawLineFree::updateMouseButtonHints()
114 DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
118 DIALOGFACTORY->updateMouseWidget("", "");
123 void ActionDrawLineFree::updateMouseCursor()
125 graphicView->setMouseCursor(RS2::CadCursor);
128 void ActionDrawLineFree::updateToolBar()
131 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
133 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);