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 // 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 "actiondrawlinehorvert.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 ActionDrawLineHorVert::ActionDrawLineHorVert(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw horizontal/vertical lines",
24 container, graphicView)
27 RS_DEBUG->print("ActionDrawLineHorVert::constructor");
30 ActionDrawLineHorVert::~ActionDrawLineHorVert()
34 void ActionDrawLineHorVert::reset()
36 data = RS_LineData(Vector(false), Vector(false));
39 void ActionDrawLineHorVert::init(int status)
41 ActionInterface::init(status);
43 RS_DEBUG->print("ActionDrawLineHorVert::init");
46 void ActionDrawLineHorVert::trigger()
48 ActionInterface::trigger();
50 RS_Line * line = new RS_Line(container, data);
51 line->setLayerToActive();
52 line->setPenToActive();
53 container->addEntity(line);
58 document->startUndoCycle();
59 document->addUndoable(line);
60 document->endUndoCycle();
64 graphicView->moveRelativeZero(Vector(0.0, 0.0));
65 graphicView->drawEntity(line);
66 graphicView->moveRelativeZero(line->getMiddlepoint());
67 RS_DEBUG->print("ActionDrawLineHorVert::trigger():"
68 " line added: %d", line->getId());
71 void ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent * e)
73 RS_DEBUG->print("ActionDrawLineHorVert::mouseMoveEvent begin");
75 Vector mouse = snapPoint(e);
77 if (getStatus() == SetEndpoint && p1.valid)
79 Vector p2x = Vector(mouse.x, p1.y);
80 Vector p2y = Vector(p1.x, mouse.y);
82 if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x))
89 data = RS_LineData(p1, p2);
90 // preview->addEntity(new RS_Line(preview, data));
94 RS_DEBUG->print("ActionDrawLineHorVert::mouseMoveEvent end");
97 void ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent * e)
99 if (e->button() == Qt::LeftButton)
101 Vector mouse = snapPoint(e);
107 setStatus(SetEndpoint);
113 setStatus(SetStartpoint);
120 else if (e->button() == Qt::RightButton)
124 init(getStatus() - 1);
128 void 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 ActionDrawLineHorVert::updateMouseCursor()
148 graphicView->setMouseCursor(RS2::CadCursor);
151 void ActionDrawLineHorVert::updateToolBar()
154 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
156 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);