1 /****************************************************************************
2 ** $Id: rs_actioninfodist2.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_actioninfodist2.h"
29 #include "rs_snapper.h"
33 RS_ActionInfoDist2::RS_ActionInfoDist2(RS_EntityContainer& container,
34 RS_GraphicView& graphicView):
35 RS_PreviewActionInterface("Info Dist2", container, graphicView)
39 QAction * RS_ActionInfoDist2::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
41 QAction * action = new QAction(tr("&Distance Entity to Point"), 0);
42 // QAction* action = new QAction(tr("Distance Entity to Point"),
43 // tr("&Distance Entity to Point"),
44 // QKeySequence(), NULL);
45 action->setStatusTip(tr("Measures the distance between an entity and a point"));
49 void RS_ActionInfoDist2::init(int status)
51 RS_ActionInterface::init(status);
56 void RS_ActionInfoDist2::trigger() {
58 RS_DEBUG->print("RS_ActionInfoDist2::trigger()");
61 if (point.valid && entity!=NULL) {
62 double dist = entity->getDistanceToPoint(point);
64 str.sprintf("%.6f", dist);
65 RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
71 void RS_ActionInfoDist2::mouseMoveEvent(QMouseEvent* e) {
72 RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent begin");
74 switch (getStatus()) {
76 //entity = catchEntity(e);
89 RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent end");
94 void RS_ActionInfoDist2::mouseReleaseEvent(QMouseEvent* e) {
95 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
97 switch (getStatus()) {
99 entity = catchEntity(e);
106 RS_CoordinateEvent ce(snapPoint(e));
107 coordinateEvent(&ce);
114 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
122 void RS_ActionInfoDist2::coordinateEvent(RS_CoordinateEvent* e) {
127 if (getStatus()==SetPoint && entity!=NULL) {
128 point = e->getCoordinate();
129 graphicView->moveRelativeZero(point);
131 setStatus(SetEntity);
137 void RS_ActionInfoDist2::updateMouseButtonHints() {
138 switch (getStatus()) {
140 RS_DIALOGFACTORY->updateMouseWidget(
141 tr("Specify entity"),
145 RS_DIALOGFACTORY->updateMouseWidget(
150 RS_DIALOGFACTORY->updateMouseWidget("", "");
157 void RS_ActionInfoDist2::updateMouseCursor() {
158 graphicView->setMouseCursor(RS2::CadCursor);
163 void RS_ActionInfoDist2::updateToolBar() {
164 switch (getStatus()) {
167 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
170 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);