1 // rs_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 "rs_actiondrawlinehorvert.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
21 RS_ActionDrawLineHorVert::RS_ActionDrawLineHorVert(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw horizontal/vertical lines",
22 container, graphicView)
25 RS_DEBUG->print("RS_ActionDrawLineHorVert::constructor");
28 RS_ActionDrawLineHorVert::~RS_ActionDrawLineHorVert()
32 void RS_ActionDrawLineHorVert::reset()
34 data = RS_LineData(Vector(false), Vector(false));
37 void RS_ActionDrawLineHorVert::init(int status)
39 RS_PreviewActionInterface::init(status);
41 RS_DEBUG->print("RS_ActionDrawLineHorVert::init");
44 void RS_ActionDrawLineHorVert::trigger()
46 RS_PreviewActionInterface::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("RS_ActionDrawLineHorVert::trigger():"
66 " line added: %d", line->getId());
69 void RS_ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent * e)
71 RS_DEBUG->print("RS_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("RS_ActionDrawLineHorVert::mouseMoveEvent end");
95 void RS_ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent * e)
97 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
98 if (e->button() == Qt::LeftButton)
100 Vector mouse = snapPoint(e);
106 setStatus(SetEndpoint);
112 setStatus(SetStartpoint);
119 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
120 else if (e->button() == Qt::RightButton)
124 init(getStatus() - 1);
128 void RS_ActionDrawLineHorVert::updateMouseButtonHints()
133 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel"));
137 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back"));
141 RS_DIALOGFACTORY->updateMouseWidget("", "");
146 void RS_ActionDrawLineHorVert::updateMouseCursor()
148 graphicView->setMouseCursor(RS2::CadCursor);
151 void RS_ActionDrawLineHorVert::updateToolBar()
154 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
156 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);