1 // actiondrawcircle2p.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/03/2010 Added this text. :-)
15 // JLH 09/11/2010 Fixed preview/snapper rendering.
18 #include "actiondrawcircle2p.h"
20 #include "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
25 ActionDrawCircle2P::ActionDrawCircle2P(EntityContainer & container,
26 GraphicView & graphicView):
27 ActionInterface("Draw circles", container, graphicView)
32 ActionDrawCircle2P::~ActionDrawCircle2P()
36 void ActionDrawCircle2P::reset()
39 point1 = Vector(false);
40 point2 = Vector(false);
43 void ActionDrawCircle2P::init(int status)
45 ActionInterface::init(status);
49 void ActionDrawCircle2P::trigger()
51 ActionInterface::trigger();
56 Circle * circle = new Circle(container, data);
57 circle->setLayerToActive();
58 circle->setPenToActive();
59 container->addEntity(circle);
64 document->startUndoCycle();
65 document->addUndoable(circle);
66 document->endUndoCycle();
70 // Vector rz = graphicView->getRelativeZero();
71 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
72 // graphicView->drawEntity(circle);
73 // graphicView->moveRelativeZero(rz);
75 graphicView->preview.clear(); // hm.
76 graphicView->redraw();
81 else if (DIALOGFACTORY)
82 DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data."));
85 void ActionDrawCircle2P::preparePreview()
89 if (point1.valid && point2.valid)
91 Circle circle(NULL, data);
92 bool success = circle.createFrom2P(point1, point2);
95 data = circle.getData();
99 void ActionDrawCircle2P::mouseMoveEvent(QMouseEvent * e)
101 Vector mouse = snapPoint(e);
115 // Circle * circle = new Circle(preview, data);
118 // preview->addEntity(circle);
120 graphicView->preview.clear();
121 graphicView->preview.addEntity(new Circle(&(graphicView->preview), data));
129 graphicView->redraw();
132 void ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent * e)
134 if (e->button() == Qt::LeftButton)
136 Vector ce(snapPoint(e));
137 coordinateEvent(&ce);
139 else if (e->button() == Qt::RightButton)
143 init(getStatus() - 1);
144 graphicView->redraw();
148 void ActionDrawCircle2P::coordinateEvent(Vector * e)
159 graphicView->moveRelativeZero(mouse);
160 setStatus(SetPoint2);
165 graphicView->moveRelativeZero(mouse);
174 void ActionDrawCircle2P::commandEvent(CommandEvent * e)
176 QString c = e->getCommand().toLower();
178 if (checkCommand("help", c))
180 if (DIALOGFACTORY != NULL)
181 DIALOGFACTORY->commandMessage(msgAvailableCommands()
182 + getAvailableCommands().join(", "));
187 QStringList ActionDrawCircle2P::getAvailableCommands()
193 void ActionDrawCircle2P::updateMouseButtonHints()
195 if (DIALOGFACTORY != NULL)
200 DIALOGFACTORY->updateMouseWidget(
201 tr("Specify first point"), tr("Cancel"));
205 DIALOGFACTORY->updateMouseWidget(
206 tr("Specify second point"), tr("Back"));
210 DIALOGFACTORY->updateMouseWidget("", "");
216 void ActionDrawCircle2P::updateMouseCursor()
218 graphicView->setMouseCursor(RS2::CadCursor);
221 void ActionDrawCircle2P::updateToolBar()
226 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
228 DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);