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"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
24 ActionDrawLineHorVert::ActionDrawLineHorVert(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw horizontal/vertical lines",
25 container, graphicView)
28 DEBUG->print("ActionDrawLineHorVert::constructor");
31 ActionDrawLineHorVert::~ActionDrawLineHorVert()
35 void ActionDrawLineHorVert::reset()
37 data = LineData(Vector(false), Vector(false));
40 void ActionDrawLineHorVert::init(int status)
42 ActionInterface::init(status);
44 DEBUG->print("ActionDrawLineHorVert::init");
47 void ActionDrawLineHorVert::trigger()
49 ActionInterface::trigger();
51 Line * line = new Line(container, data);
52 line->setLayerToActive();
53 line->setPenToActive();
54 container->addEntity(line);
59 document->startUndoCycle();
60 document->addUndoable(line);
61 document->endUndoCycle();
65 graphicView->moveRelativeZero(Vector(0.0, 0.0));
66 graphicView->drawEntity(line);
67 graphicView->moveRelativeZero(line->getMiddlepoint());
68 DEBUG->print("ActionDrawLineHorVert::trigger():"
69 " line added: %d", line->getId());
72 void ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent * e)
74 DEBUG->print("ActionDrawLineHorVert::mouseMoveEvent begin");
76 Vector mouse = snapPoint(e);
78 if (getStatus() == SetEndpoint && p1.valid)
80 Vector p2x = Vector(mouse.x, p1.y);
81 Vector p2y = Vector(p1.x, mouse.y);
83 if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x))
90 data = LineData(p1, p2);
91 // preview->addEntity(new Line(preview, data));
95 DEBUG->print("ActionDrawLineHorVert::mouseMoveEvent end");
98 void ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent * e)
100 if (e->button() == Qt::LeftButton)
102 Vector mouse = snapPoint(e);
108 setStatus(SetEndpoint);
114 setStatus(SetStartpoint);
121 else if (e->button() == Qt::RightButton)
125 init(getStatus() - 1);
129 void ActionDrawLineHorVert::updateMouseButtonHints()
134 DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel"));
138 DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back"));
142 DIALOGFACTORY->updateMouseWidget("", "");
147 void ActionDrawLineHorVert::updateMouseCursor()
149 graphicView->setMouseCursor(RS2::CadCursor);
152 void ActionDrawLineHorVert::updateToolBar()
155 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
157 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);