1 /****************************************************************************
2 ** $Id: rs_actioninfodist.cpp 1161 2004-12-09 23:10:09Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actioninfodist.h"
29 #include "rs_snapper.h"
33 RS_ActionInfoDist::RS_ActionInfoDist(RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Info Dist",
36 container, graphicView) {}
39 QAction* RS_ActionInfoDist::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
41 QAction * action = new QAction(tr("&Distance Point to Point"), 0);
42 // QAction* action = new QAction(tr("Distance Point to Point"),
43 // tr("&Distance Point to Point"),
44 // QKeySequence(), NULL);
45 action->setStatusTip(tr("Measures the distance between two points"));
50 void RS_ActionInfoDist::init(int status) {
51 RS_ActionInterface::init(status);
57 void RS_ActionInfoDist::trigger() {
59 RS_DEBUG->print("RS_ActionInfoDist::trigger()");
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));
71 void RS_ActionInfoDist::mouseMoveEvent(QMouseEvent* e) {
72 RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent begin");
74 if (getStatus()==SetPoint1 ||
75 getStatus()==SetPoint2) {
77 Vector mouse = snapPoint(e);
78 switch (getStatus()) {
89 preview->addEntity(new RS_Line(preview,
102 RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent end");
107 void RS_ActionInfoDist::mouseReleaseEvent(QMouseEvent* e) {
108 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
109 RS_CoordinateEvent ce(snapPoint(e));
110 coordinateEvent(&ce);
111 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
120 void RS_ActionInfoDist::coordinateEvent(RS_CoordinateEvent* e) {
125 Vector mouse = e->getCoordinate();
127 switch (getStatus()) {
130 graphicView->moveRelativeZero(point1);
131 setStatus(SetPoint2);
139 graphicView->moveRelativeZero(point2);
141 setStatus(SetPoint1);
151 void RS_ActionInfoDist::updateMouseButtonHints() {
152 switch (getStatus()) {
154 RS_DIALOGFACTORY->updateMouseWidget(
155 tr("Specify first point of distance"),
159 RS_DIALOGFACTORY->updateMouseWidget(
160 tr("Specify second point of distance"),
164 RS_DIALOGFACTORY->updateMouseWidget("", "");
171 void RS_ActionInfoDist::updateMouseCursor() {
172 graphicView->setMouseCursor(RS2::CadCursor);
177 void RS_ActionInfoDist::updateToolBar() {
178 switch (getStatus()) {
181 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
184 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);