]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioninfodist.cpp
Initial import
[architektonas] / src / actions / rs_actioninfodist.cpp
1 /****************************************************************************
2 ** $Id: rs_actioninfodist.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_actioninfodist.h"
28
29 #include "rs_snapper.h"
30
31
32
33 RS_ActionInfoDist::RS_ActionInfoDist(RS_EntityContainer& container,
34                                      RS_GraphicView& graphicView)
35         :RS_PreviewActionInterface("Info Dist",
36                            container, graphicView) {}
37
38
39 QAction* RS_ActionInfoDist::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
40 {
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"));
46         return action;
47 }
48
49
50 void RS_ActionInfoDist::init(int status) {
51     RS_ActionInterface::init(status);
52
53 }
54
55
56
57 void RS_ActionInfoDist::trigger() {
58
59     RS_DEBUG->print("RS_ActionInfoDist::trigger()");
60
61     if (point1.valid && point2.valid) {
62         double dist = point1.distanceTo(point2);
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_ActionInfoDist::mouseMoveEvent(QMouseEvent* e) {
72     RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent begin");
73
74     if (getStatus()==SetPoint1 ||
75             getStatus()==SetPoint2) {
76
77         Vector mouse = snapPoint(e);
78         switch (getStatus()) {
79         case SetPoint1:
80             break;
81
82         case SetPoint2:
83             if (point1.valid) {
84                 point2 = mouse;
85
86                 deletePreview();
87                 clearPreview();
88
89                 preview->addEntity(new RS_Line(preview,
90                                                RS_LineData(point1,
91                                                            point2)));
92
93                 drawPreview();
94             }
95             break;
96
97         default:
98             break;
99         }
100     }
101
102     RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent end");
103 }
104
105
106
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) {
112         deletePreview();
113         deleteSnapper();
114         init(getStatus()-1);
115     }
116 }
117
118
119
120 void RS_ActionInfoDist::coordinateEvent(RS_CoordinateEvent* e) {
121     if (e==NULL) {
122         return;
123     }
124
125     Vector mouse = e->getCoordinate();
126
127     switch (getStatus()) {
128     case SetPoint1:
129         point1 = mouse;
130         graphicView->moveRelativeZero(point1);
131         setStatus(SetPoint2);
132         break;
133
134     case SetPoint2:
135         if (point1.valid) {
136             point2 = mouse;
137             deletePreview();
138             clearPreview();
139                 graphicView->moveRelativeZero(point2);
140             trigger();
141             setStatus(SetPoint1);
142         }
143         break;
144
145     default:
146         break;
147     }
148 }
149
150
151 void RS_ActionInfoDist::updateMouseButtonHints() {
152     switch (getStatus()) {
153     case SetPoint1:
154         RS_DIALOGFACTORY->updateMouseWidget(
155             tr("Specify first point of distance"),
156             tr("Cancel"));
157         break;
158     case SetPoint2:
159         RS_DIALOGFACTORY->updateMouseWidget(
160             tr("Specify second point of distance"),
161             tr("Back"));
162         break;
163     default:
164         RS_DIALOGFACTORY->updateMouseWidget("", "");
165         break;
166     }
167 }
168
169
170
171 void RS_ActionInfoDist::updateMouseCursor() {
172     graphicView->setMouseCursor(RS2::CadCursor);
173 }
174
175
176
177 void RS_ActionInfoDist::updateToolBar() {
178     switch (getStatus()) {
179     case SetPoint1:
180     case SetPoint2:
181         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
182         break;
183     default:
184         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
185         break;
186     }
187 }
188
189
190 // EOF