]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioninfodist2.cpp
95bbb3f343fdb46d3047ece8133703459308c2cf
[architektonas] / src / actions / rs_actioninfodist2.cpp
1 /****************************************************************************
2 ** $Id: rs_actioninfodist2.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
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.
12 **
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.
16 **
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.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actioninfodist2.h"
28
29 #include "rs_snapper.h"
30
31
32
33 RS_ActionInfoDist2::RS_ActionInfoDist2(RS_EntityContainer& container,
34         RS_GraphicView& graphicView):
35         RS_PreviewActionInterface("Info Dist2", container, graphicView)
36 {
37 }
38
39 QAction * RS_ActionInfoDist2::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
40 {
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"));
46         return action;
47 }
48
49 void RS_ActionInfoDist2::init(int status)
50 {
51     RS_ActionInterface::init(status);
52 }
53
54
55
56 void RS_ActionInfoDist2::trigger() {
57
58     RS_DEBUG->print("RS_ActionInfoDist2::trigger()");
59     deleteSnapper();
60
61     if (point.valid && entity!=NULL) {
62         double dist = entity->getDistanceToPoint(point);
63         QString str;
64         str.sprintf("%.6f", dist);
65         RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
66     }
67 }
68
69
70
71 void RS_ActionInfoDist2::mouseMoveEvent(QMouseEvent* e) {
72     RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent begin");
73
74     switch (getStatus()) {
75     case SetEntity:
76         //entity = catchEntity(e);
77         break;
78
79     case SetPoint:
80         if (entity!=NULL) {
81             point = snapPoint(e);
82         }
83         break;
84
85     default:
86         break;
87     }
88
89     RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent end");
90 }
91
92
93
94 void RS_ActionInfoDist2::mouseReleaseEvent(QMouseEvent* e) {
95     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
96
97         switch (getStatus()) {
98         case SetEntity:
99             entity = catchEntity(e);
100             if (entity!=NULL) {
101                 setStatus(SetPoint);
102             }
103             break;
104
105         case SetPoint: {
106                 RS_CoordinateEvent ce(snapPoint(e));
107                 coordinateEvent(&ce);
108             }
109             break;
110
111         default:
112             break;
113         }
114     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
115         deletePreview();
116         deleteSnapper();
117         init(getStatus()-1);
118     }
119 }
120
121
122 void RS_ActionInfoDist2::coordinateEvent(RS_CoordinateEvent* e) {
123     if (e==NULL) {
124         return;
125     }
126
127     if (getStatus()==SetPoint && entity!=NULL) {
128         point = e->getCoordinate();
129         graphicView->moveRelativeZero(point);
130         trigger();
131         setStatus(SetEntity);
132     }
133 }
134
135
136
137 void RS_ActionInfoDist2::updateMouseButtonHints() {
138     switch (getStatus()) {
139     case SetEntity:
140         RS_DIALOGFACTORY->updateMouseWidget(
141             tr("Specify entity"),
142             tr("Cancel"));
143         break;
144     case SetPoint:
145         RS_DIALOGFACTORY->updateMouseWidget(
146             tr("Specify point"),
147             tr("Back"));
148         break;
149     default:
150         RS_DIALOGFACTORY->updateMouseWidget("", "");
151         break;
152     }
153 }
154
155
156
157 void RS_ActionInfoDist2::updateMouseCursor() {
158     graphicView->setMouseCursor(RS2::CadCursor);
159 }
160
161
162
163 void RS_ActionInfoDist2::updateToolBar() {
164     switch (getStatus()) {
165     case SetPoint:
166     case SetEntity:
167         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
168         break;
169     default:
170         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
171         break;
172     }
173 }
174
175
176 // EOF