1 // actiondrawlinehorvert.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 "actiondrawlinehorvert.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
21 ActionDrawLineHorVert::ActionDrawLineHorVert(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw horizontal/vertical lines",
22 container, graphicView)
25 RS_DEBUG->print("ActionDrawLineHorVert::constructor");
28 ActionDrawLineHorVert::~ActionDrawLineHorVert()
32 void ActionDrawLineHorVert::reset()
34 data = RS_LineData(Vector(false), Vector(false));
37 void ActionDrawLineHorVert::init(int status)
39 ActionInterface::init(status);
41 RS_DEBUG->print("ActionDrawLineHorVert::init");
44 void ActionDrawLineHorVert::trigger()
46 ActionInterface::trigger();
48 RS_Line * line = new RS_Line(container, data);
49 line->setLayerToActive();
50 line->setPenToActive();
51 container->addEntity(line);
56 document->startUndoCycle();
57 document->addUndoable(line);
58 document->endUndoCycle();
62 graphicView->moveRelativeZero(Vector(0.0, 0.0));
63 graphicView->drawEntity(line);
64 graphicView->moveRelativeZero(line->getMiddlepoint());
65 RS_DEBUG->print("ActionDrawLineHorVert::trigger():"
66 " line added: %d", line->getId());
69 void ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent * e)
71 RS_DEBUG->print("ActionDrawLineHorVert::mouseMoveEvent begin");
73 Vector mouse = snapPoint(e);
75 if (getStatus() == SetEndpoint && p1.valid)
77 Vector p2x = Vector(mouse.x, p1.y);
78 Vector p2y = Vector(p1.x, mouse.y);
80 if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x))
87 data = RS_LineData(p1, p2);
88 // preview->addEntity(new RS_Line(preview, data));
92 RS_DEBUG->print("ActionDrawLineHorVert::mouseMoveEvent end");
95 void ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent * e)
97 if (e->button() == Qt::LeftButton)
99 Vector mouse = snapPoint(e);
105 setStatus(SetEndpoint);
111 setStatus(SetStartpoint);
118 else if (e->button() == Qt::RightButton)
122 init(getStatus() - 1);
126 void ActionDrawLineHorVert::updateMouseButtonHints()
131 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel"));
135 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back"));
139 RS_DIALOGFACTORY->updateMouseWidget("", "");
144 void ActionDrawLineHorVert::updateMouseCursor()
146 graphicView->setMouseCursor(RS2::CadCursor);
149 void ActionDrawLineHorVert::updateToolBar()
152 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
154 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);