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 "actioninfoarea.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
24 ActionInfoArea::ActionInfoArea(EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Area",
25 container, graphicView)
29 ActionInfoArea::~ActionInfoArea()
33 void ActionInfoArea::init(int status)
35 ActionInterface::init(status);
40 //std::cout << "ActionInfoArea::init: " << status << "\n";
43 void ActionInfoArea::trigger()
45 DEBUG->print("ActionInfoArea::trigger()");
51 double area = ia.getArea();
52 double circ = ia.getCircumference();
54 DEBUG->print("ActionInfoArea::trigger: area: %f", area);
55 DIALOGFACTORY->commandMessage(tr("Area: %1").arg(area));
56 DIALOGFACTORY->commandMessage(tr("Circumference: %1").arg(circ));
62 if (point1.valid && point2.valid) {
63 double dist = point1.distanceTo(point2);
65 str.sprintf("%.6f", dist);
66 DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
71 void ActionInfoArea::mouseMoveEvent(QMouseEvent * e)
73 //DEBUG->print("ActionInfoArea::mouseMoveEvent begin");
75 if (getStatus() == SetFirstPoint
76 || getStatus() == SetNextPoint)
78 Vector mouse = snapPoint(e);
93 // preview->removeEntity(currentLine);
99 // preview->removeEntity(closingLine);
103 // currentLine = new Line(preview, LineData(prev, mouse));
104 // preview->addEntity(currentLine);
106 // if (preview->count() > 1)
108 // closingLine = new Line(preview, LineData(mouse, point1));
109 // preview->addEntity(closingLine);
122 void ActionInfoArea::mouseReleaseEvent(QMouseEvent * e)
124 if (e->button() == Qt::LeftButton)
126 Vector ce(snapPoint(e));
127 coordinateEvent(&ce);
129 else if (e->button() == Qt::RightButton)
131 // close the polygon (preview)
132 if (getStatus() == SetNextPoint && prev.valid)
136 if (currentLine != NULL)
138 // preview->removeEntity(currentLine);
142 if (closingLine != NULL)
144 // preview->removeEntity(closingLine);
148 // currentLine = new Line(preview, LineData(prev, point1));
149 // preview->addEntity(currentLine);
155 init(getStatus() - 1);
159 void ActionInfoArea::coordinateEvent(Vector * e)
175 DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
177 graphicView->moveRelativeZero(point1);
180 setStatus(SetNextPoint);
188 DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
192 graphicView->moveRelativeZero(mouse);
195 // automatically detect that the polyline is now closed
199 setStatus(SetFirstPoint);
209 void ActionInfoArea::updateMouseButtonHints()
214 DIALOGFACTORY->updateMouseWidget(
215 tr("Specify first point of polygon"),
220 DIALOGFACTORY->updateMouseWidget(
221 tr("Specify next point of polygon"),
226 DIALOGFACTORY->updateMouseWidget("", "");
231 void ActionInfoArea::updateMouseCursor()
233 graphicView->setMouseCursor(RS2::CadCursor);
236 void ActionInfoArea::updateToolBar()
242 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
246 DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);