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"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 ActionInfoArea::ActionInfoArea(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Area",
24 container, graphicView)
28 ActionInfoArea::~ActionInfoArea()
32 void ActionInfoArea::init(int status)
34 ActionInterface::init(status);
39 //std::cout << "ActionInfoArea::init: " << status << "\n";
42 void ActionInfoArea::trigger()
44 RS_DEBUG->print("ActionInfoArea::trigger()");
50 double area = ia.getArea();
51 double circ = ia.getCircumference();
53 RS_DEBUG->print("ActionInfoArea::trigger: area: %f", area);
54 RS_DIALOGFACTORY->commandMessage(tr("Area: %1").arg(area));
55 RS_DIALOGFACTORY->commandMessage(tr("Circumference: %1").arg(circ));
61 if (point1.valid && point2.valid) {
62 double dist = point1.distanceTo(point2);
64 str.sprintf("%.6f", dist);
65 RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
70 void ActionInfoArea::mouseMoveEvent(QMouseEvent * e)
72 //RS_DEBUG->print("ActionInfoArea::mouseMoveEvent begin");
74 if (getStatus() == SetFirstPoint
75 || getStatus() == SetNextPoint)
77 Vector mouse = snapPoint(e);
92 // preview->removeEntity(currentLine);
98 // preview->removeEntity(closingLine);
102 // currentLine = new RS_Line(preview, RS_LineData(prev, mouse));
103 // preview->addEntity(currentLine);
105 // if (preview->count() > 1)
107 // closingLine = new RS_Line(preview, RS_LineData(mouse, point1));
108 // preview->addEntity(closingLine);
121 void ActionInfoArea::mouseReleaseEvent(QMouseEvent * e)
123 if (e->button() == Qt::LeftButton)
125 Vector ce(snapPoint(e));
126 coordinateEvent(&ce);
128 else if (e->button() == Qt::RightButton)
130 // close the polygon (preview)
131 if (getStatus() == SetNextPoint && prev.valid)
135 if (currentLine != NULL)
137 // preview->removeEntity(currentLine);
141 if (closingLine != NULL)
143 // preview->removeEntity(closingLine);
147 // currentLine = new RS_Line(preview, RS_LineData(prev, point1));
148 // preview->addEntity(currentLine);
154 init(getStatus() - 1);
158 void ActionInfoArea::coordinateEvent(Vector * e)
174 RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
176 graphicView->moveRelativeZero(point1);
179 setStatus(SetNextPoint);
187 RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y));
191 graphicView->moveRelativeZero(mouse);
194 // automatically detect that the polyline is now closed
198 setStatus(SetFirstPoint);
208 void ActionInfoArea::updateMouseButtonHints()
213 RS_DIALOGFACTORY->updateMouseWidget(
214 tr("Specify first point of polygon"),
219 RS_DIALOGFACTORY->updateMouseWidget(
220 tr("Specify next point of polygon"),
225 RS_DIALOGFACTORY->updateMouseWidget("", "");
230 void ActionInfoArea::updateMouseCursor()
232 graphicView->setMouseCursor(RS2::CadCursor);
235 void ActionInfoArea::updateToolBar()
241 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
245 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);